getProfiles() {
+ return ConfigProvider.getConfig().unwrap(SmallRyeConfig.class).getProfiles();
+ }
+
+ public static boolean isProfileActive(final String profile) {
+ return getProfiles().contains(profile);
+ }
+
/**
* Checks if a property is present in the current Configuration.
*
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java
index ce264bbbc1fb5..c1a58d7963778 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ProfileManager.java
@@ -40,6 +40,12 @@ public static void setRuntimeDefaultProfile(final String profile) {
}
//NOTE: changes made here must be replicated in BootstrapProfile
+
+ /**
+ * @deprecated This method is not suited to multiple profiles, because it returns a single string. Please use
+ * {@link ConfigUtils#getProfiles()} instead, which returns a List of profiles.
+ */
+ @Deprecated
public static String getActiveProfile() {
if (launchMode == LaunchMode.TEST) {
String profile = System.getProperty(QUARKUS_TEST_PROFILE_PROP);
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java
index 0ea4c1503e66a..eafd80022e91b 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/QuarkusConfigFactory.java
@@ -26,14 +26,7 @@ public SmallRyeConfig getConfigFor(final SmallRyeConfigProviderResolver configPr
//TODO: this code path is only hit when start fails in dev mode very early in the process
//the recovery code will fail without this as it cannot read any properties such as
//the HTTP port or logging info
- return configProviderResolver.getBuilder().forClassLoader(classLoader)
- .addDefaultSources()
- .addDefaultInterceptors()
- .addDiscoveredSources()
- .addDiscoveredConverters()
- .addDiscoveredInterceptors()
- .withProfile(ProfileManager.getActiveProfile())
- .build();
+ return ConfigUtils.emptyConfigBuilder().addDefaultSources().addDiscoveredSources().build();
}
return config;
}
diff --git a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java
index 8bbcf1fdc8805..ed3f9c559fb63 100644
--- a/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java
+++ b/core/runtime/src/test/java/io/quarkus/runtime/configuration/ConfigProfileTestCase.java
@@ -1,5 +1,6 @@
package io.quarkus.runtime.configuration;
+import static io.quarkus.runtime.configuration.ConfigUtils.emptyConfigBuilder;
import static java.util.stream.Collectors.toList;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
@@ -20,17 +21,14 @@
import io.smallrye.config.SmallRyeConfigBuilder;
public class ConfigProfileTestCase {
-
private SmallRyeConfigBuilder configBuilder(String... keyValues) {
- return new SmallRyeConfigBuilder()
- .addDefaultInterceptors()
- .withSources(new PropertiesConfigSource(maps(keyValues), "test input", 500))
- .withProfile(ProfileManager.getActiveProfile());
+ return emptyConfigBuilder()
+ .addDefaultSources()
+ .withSources(new PropertiesConfigSource(maps(keyValues), "test input", 500));
}
private SmallRyeConfig buildConfig(String... keyValues) {
- final SmallRyeConfig config = configBuilder(keyValues).build();
- return config;
+ return configBuilder(keyValues).build();
}
private Map maps(String... keyValues) {
@@ -79,7 +77,7 @@ void overriddenProfile() {
@Test
void overriddenProfileHigherOrdinal() {
- System.setProperty("quarkus-profile", "foo");
+ System.setProperty("quarkus.profile", "foo");
try {
final SmallRyeConfig config = configBuilder()
.withSources(new PropertiesConfigSource(maps("foo", "default"), "source", 1000))
@@ -88,25 +86,25 @@ void overriddenProfileHigherOrdinal() {
assertEquals("default", config.getRawValue("foo"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
void profileNoErrorOnExpansion() {
- System.setProperty("quarkus-profile", "foo");
+ System.setProperty("quarkus.profile", "foo");
try {
final SmallRyeConfig config = configBuilder("foo", "${noExpansionAvailable}", "%foo.foo", "profile").build();
assertEquals("profile", config.getRawValue("foo"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void profile() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1", "%prof.my.prop", "2");
@@ -115,51 +113,51 @@ public void profile() {
assertEquals("my.prop", config.getConfigValue("my.prop").getName());
assertEquals("my.prop", config.getConfigValue("%prof.my.prop").getName());
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void profileOnly() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1", "%prof.my.prop", "2");
assertEquals("2", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void fallback() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1");
assertEquals("1", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void expressions() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
System.setProperty("my.prop", "1");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1", "%prof.my.prop", "${my.prop}");
assertThrows(IllegalArgumentException.class, () -> config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
System.clearProperty("my.prop");
}
}
@Test
public void profileExpressions() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
System.setProperty("%prof.my.prop.profile", "2");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1",
@@ -168,14 +166,14 @@ public void profileExpressions() {
assertEquals("2", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
System.clearProperty("%prof.my.prop.profile");
}
}
@Test
public void customConfigProfile() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = configBuilder()
.addDefaultSources()
@@ -184,7 +182,7 @@ public void customConfigProfile() {
assertEquals("2", config.getValue("my.prop", String.class));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@@ -203,7 +201,7 @@ public void noConfigProfile() {
@Test
public void priorityProfile() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = configBuilder()
.addDefaultSources()
@@ -214,13 +212,13 @@ public void priorityProfile() {
assertEquals("higher-profile", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void priorityOverrideProfile() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = new SmallRyeConfigBuilder()
.addDefaultSources()
@@ -231,13 +229,13 @@ public void priorityOverrideProfile() {
assertEquals("higher", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void priorityProfileOverOriginal() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = configBuilder()
.addDefaultSources()
@@ -249,13 +247,13 @@ public void priorityProfileOverOriginal() {
assertEquals("higher-profile", config.getRawValue("my.prop"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
@Test
public void propertyNames() {
- System.setProperty("quarkus-profile", "prof");
+ System.setProperty("quarkus.profile", "prof");
try {
final SmallRyeConfig config = buildConfig("my.prop", "1", "%prof.my.prop", "2", "%prof.prof.only", "1");
@@ -268,7 +266,7 @@ public void propertyNames() {
assertTrue(properties.contains("my.prop"));
assertTrue(properties.contains("prof.only"));
} finally {
- System.clearProperty("quarkus-profile");
+ System.clearProperty("quarkus.profile");
}
}
}
diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BuildTimeEnabledProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BuildTimeEnabledProcessor.java
index caa4d1c7d521f..af0554f12876c 100644
--- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BuildTimeEnabledProcessor.java
+++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/BuildTimeEnabledProcessor.java
@@ -37,7 +37,7 @@
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
-import io.quarkus.runtime.configuration.ProfileManager;
+import io.quarkus.runtime.configuration.ConfigUtils;
public class BuildTimeEnabledProcessor {
@@ -60,7 +60,7 @@ void ifBuildProfile(CombinedIndexBuildItem index, BuildProducer annotationInstances = index.getIndex().getAnnotations(IF_BUILD_PROFILE);
for (AnnotationInstance instance : annotationInstances) {
String profileOnInstance = instance.value().asString();
- boolean enabled = profileOnInstance.equals(ProfileManager.getActiveProfile());
+ boolean enabled = ConfigUtils.isProfileActive(profileOnInstance);
if (enabled) {
LOGGER.debug("Enabling " + instance.target() + " since the profile value matches the active profile.");
} else {
@@ -75,7 +75,7 @@ void unlessBuildProfile(CombinedIndexBuildItem index, BuildProducer annotationInstances = index.getIndex().getAnnotations(UNLESS_BUILD_PROFILE);
for (AnnotationInstance instance : annotationInstances) {
String profileOnInstance = instance.value().asString();
- boolean enabled = !profileOnInstance.equals(ProfileManager.getActiveProfile());
+ boolean enabled = !ConfigUtils.isProfileActive(profileOnInstance);
if (enabled) {
LOGGER.debug("Enabling " + instance.target() + " since the profile value does not match the active profile.");
} else {
diff --git a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java
index 6a64312e47773..456320c9d91e3 100644
--- a/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java
+++ b/extensions/vertx-http/deployment/src/main/java/io/quarkus/vertx/http/deployment/devmode/console/ConfigEditorProcessor.java
@@ -46,7 +46,7 @@
import io.quarkus.devconsole.runtime.spi.DevConsolePostHandler;
import io.quarkus.devconsole.spi.DevConsoleRouteBuildItem;
import io.quarkus.devconsole.spi.DevConsoleRuntimeTemplateInfoBuildItem;
-import io.quarkus.runtime.configuration.ProfileManager;
+import io.quarkus.runtime.configuration.ConfigUtils;
import io.quarkus.vertx.http.runtime.devmode.ConfigDescription;
import io.quarkus.vertx.http.runtime.devmode.ConfigDescriptionsManager;
import io.quarkus.vertx.http.runtime.devmode.ConfigDescriptionsRecorder;
@@ -215,18 +215,22 @@ static void updateConfig(Map values) {
if (values != null && !values.isEmpty()) {
try {
Path configPath = getConfigPath();
- String profile = ProfileManager.getActiveProfile();
+ List profiles = ConfigUtils.getProfiles();
List lines = Files.readAllLines(configPath);
for (Map.Entry entry : values.entrySet()) {
String name = entry.getKey();
String value = entry.getValue();
- name = !profile.equals(DEVELOPMENT.getDefaultProfile()) ? "%" + profile + "." + name : name;
int nameLine = -1;
for (int i = 0, linesSize = lines.size(); i < linesSize; i++) {
- final String line = lines.get(i);
- if (line.startsWith(name + "=")) {
- nameLine = i;
- break;
+ String line = lines.get(i);
+ for (String profile : profiles) {
+ String profileName = !profile.equals(DEVELOPMENT.getDefaultProfile()) ? "%" + profile + "." + name
+ : name;
+ if (line.startsWith(profileName + "=")) {
+ name = profileName;
+ nameLine = i;
+ break;
+ }
}
}
@@ -259,9 +263,6 @@ static void updateConfig(Map values) {
static void setConfig(String value) {
try {
Path configPath = getConfigPath();
- String profile = ProfileManager.getActiveProfile();
- List lines = Files.readAllLines(configPath);
-
try (BufferedWriter writer = Files.newBufferedWriter(configPath)) {
if (value == null || value.isEmpty()) {
writer.newLine();
diff --git a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/configurationless/CRUDResource.java b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/configurationless/CRUDResource.java
index faec3b6ddcc51..f51b59dacb89f 100644
--- a/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/configurationless/CRUDResource.java
+++ b/integration-tests/jpa/src/main/java/io/quarkus/it/jpa/configurationless/CRUDResource.java
@@ -17,7 +17,7 @@
import org.hibernate.internal.SessionImpl;
import io.quarkus.runtime.LaunchMode;
-import io.quarkus.runtime.configuration.ProfileManager;
+import io.quarkus.runtime.configuration.ConfigUtils;
/**
* @author Emmanuel Bernard emmanuel@hibernate.org
@@ -82,7 +82,7 @@ public Map createUserTransaction() {
@Transactional
@Path("/import")
public Map get() {
- boolean isProdMode = ProfileManager.getActiveProfile().equals(LaunchMode.NORMAL.getDefaultProfile());
+ boolean isProdMode = ConfigUtils.isProfileActive(LaunchMode.NORMAL.getDefaultProfile());
Gift gift = em.find(Gift.class, 100000L);
Map map = new HashMap<>();
// Native tests are run under the 'prod' profile for now. In NORMAL mode, Quarkus doesn't execute the SQL import file
diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecordedBuildProfileInRuntimeTest.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecordedBuildProfileInRuntimeTest.java
new file mode 100644
index 0000000000000..3d938f1b963b9
--- /dev/null
+++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecordedBuildProfileInRuntimeTest.java
@@ -0,0 +1,41 @@
+package io.quarkus.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.util.Optional;
+
+import javax.inject.Inject;
+
+import org.eclipse.microprofile.config.spi.ConfigSource;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.RegisterExtension;
+
+import io.quarkus.test.QuarkusUnitTest;
+import io.smallrye.config.ConfigValue;
+import io.smallrye.config.SmallRyeConfig;
+
+public class RecordedBuildProfileInRuntimeTest {
+ @RegisterExtension
+ static final QuarkusUnitTest TEST = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class))
+ .withConfigurationResource("application.properties");
+
+ @Inject
+ SmallRyeConfig config;
+
+ @Test
+ void recordedBuildProfileInRuntime() {
+ ConfigValue profile = config.getConfigValue("quarkus.test.profile");
+ assertEquals("test", profile.getValue());
+ // Recorded by ProfileBuildStep
+ assertEquals("RunTime Defaults", profile.getConfigSourceName());
+
+ Optional defaultValuesConfigSource = config.getConfigSource("DefaultValuesConfigSource");
+ assertTrue(defaultValuesConfigSource.isPresent());
+ // The default set in ConfigUtils, based on the LaunchMode
+ assertEquals("test", defaultValuesConfigSource.get().getValue("quarkus.test.profile"));
+ }
+}