diff --git a/bom/application/pom.xml b/bom/application/pom.xml
index 3f0935b359774..bb00ed06470fb 100644
--- a/bom/application/pom.xml
+++ b/bom/application/pom.xml
@@ -43,7 +43,7 @@
1.2
1.0
1.8.0
- 2.7.0
+ 2.8.1
3.1.2
3.0.4
2.1.16
diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java
index f7024f020f180..31d9450b14845 100644
--- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java
+++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/BuildTimeConfigurationReader.java
@@ -6,7 +6,7 @@
import static io.quarkus.deployment.util.ReflectUtil.toError;
import static io.quarkus.deployment.util.ReflectUtil.typeOfParameter;
import static io.quarkus.deployment.util.ReflectUtil.unwrapInvocationTargetException;
-import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
+import static io.smallrye.config.Expressions.withoutExpansion;
import static java.util.stream.Collectors.toSet;
import java.lang.reflect.Constructor;
@@ -59,9 +59,9 @@
import io.quarkus.runtime.configuration.NameIterator;
import io.quarkus.runtime.configuration.ProfileManager;
import io.quarkus.runtime.configuration.PropertiesUtil;
+import io.smallrye.config.ConfigValue;
import io.smallrye.config.Converters;
import io.smallrye.config.EnvConfigSource;
-import io.smallrye.config.Expressions;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;
import io.smallrye.config.SysPropConfigSource;
@@ -316,8 +316,11 @@ ReadResult run() {
// build time patterns
Container matched = buildTimePatternMap.match(ni);
if (matched instanceof FieldContainer) {
- allBuildTimeValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
+ ConfigValue configValue = config.getConfigValue(propertyName);
+ if (configValue.getValue() == null) {
+ continue;
+ }
+ allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
ni.goToEnd();
// cursor is located after group property key (if any)
getGroup((FieldContainer) matched, ni);
@@ -325,6 +328,10 @@ ReadResult run() {
continue;
} else if (matched != null) {
assert matched instanceof MapContainer;
+ ConfigValue configValue = config.getConfigValue(propertyName);
+ if (configValue.getValue() == null) {
+ continue;
+ }
// it's a leaf value within a map
// these must always be explicitly set
ni.goToEnd();
@@ -334,25 +341,30 @@ ReadResult run() {
// we always have to set the map entry ourselves
Field field = matched.findField();
Converter> converter = getConverter(config, field, ConverterType.of(field));
- map.put(key, config.getValue(propertyName, converter));
- allBuildTimeValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
+ map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter));
+ allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
continue;
}
// build time (run time visible) patterns
ni.goToStart();
matched = buildTimeRunTimePatternMap.match(ni);
if (matched instanceof FieldContainer) {
+ ConfigValue configValue = config.getConfigValue(propertyName);
+ if (configValue.getValue() == null) {
+ continue;
+ }
ni.goToEnd();
// cursor is located after group property key (if any)
getGroup((FieldContainer) matched, ni);
- allBuildTimeValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
- buildTimeRunTimeVisibleValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
+ allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
+ buildTimeRunTimeVisibleValues.put(configValue.getNameProfiled(), configValue.getValue());
continue;
} else if (matched != null) {
assert matched instanceof MapContainer;
+ ConfigValue configValue = config.getConfigValue(propertyName);
+ if (configValue.getValue() == null) {
+ continue;
+ }
// it's a leaf value within a map
// these must always be explicitly set
ni.goToEnd();
@@ -362,12 +374,10 @@ ReadResult run() {
// we always have to set the map entry ourselves
Field field = matched.findField();
Converter> converter = getConverter(config, field, ConverterType.of(field));
- map.put(key, config.getValue(propertyName, converter));
+ map.put(key, config.convertValue(configValue.getNameProfiled(), configValue.getValue(), converter));
// cache the resolved value
- buildTimeRunTimeVisibleValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
- allBuildTimeValues.put(propertyName,
- config.getOptionalValue(propertyName, String.class).orElse(""));
+ buildTimeRunTimeVisibleValues.put(configValue.getNameProfiled(), configValue.getValue());
+ allBuildTimeValues.put(configValue.getNameProfiled(), configValue.getValue());
continue;
}
// run time patterns
@@ -375,23 +385,27 @@ ReadResult run() {
matched = runTimePatternMap.match(ni);
if (matched != null) {
// it's a specified run-time default (record for later)
- specifiedRunTimeDefaultValues.put(propertyName, Expressions.withoutExpansion(
- () -> runtimeDefaultsConfig.getOptionalValue(propertyName, String.class).orElse("")));
-
- continue;
+ ConfigValue configValue = withoutExpansion(() -> runtimeDefaultsConfig.getConfigValue(propertyName));
+ if (configValue.getValue() != null) {
+ specifiedRunTimeDefaultValues.put(configValue.getNameProfiled(), configValue.getValue());
+ }
}
// also check for the bootstrap properties since those need to be added to specifiedRunTimeDefaultValues as well
ni.goToStart();
matched = bootstrapPatternMap.match(ni);
if (matched != null) {
// it's a specified run-time default (record for later)
- specifiedRunTimeDefaultValues.put(propertyName, Expressions.withoutExpansion(
- () -> runtimeDefaultsConfig.getOptionalValue(propertyName, String.class).orElse("")));
+ ConfigValue configValue = withoutExpansion(() -> runtimeDefaultsConfig.getConfigValue(propertyName));
+ if (configValue.getValue() != null) {
+ specifiedRunTimeDefaultValues.put(configValue.getNameProfiled(), configValue.getValue());
+ }
}
} else {
// it's not managed by us; record it
- specifiedRunTimeDefaultValues.put(propertyName, Expressions.withoutExpansion(
- () -> runtimeDefaultsConfig.getOptionalValue(propertyName, String.class).orElse("")));
+ ConfigValue configValue = withoutExpansion(() -> runtimeDefaultsConfig.getConfigValue(propertyName));
+ if (configValue.getValue() != null) {
+ specifiedRunTimeDefaultValues.put(configValue.getNameProfiled(), configValue.getValue());
+ }
}
}
@@ -775,9 +789,7 @@ private Set getAllProperties(final Set registeredRoots) {
* @return a new SmallRye instance without the EnvSources.
*/
private SmallRyeConfig getConfigForRuntimeDefaults() {
- SmallRyeConfigBuilder builder = new SmallRyeConfigBuilder();
- builder.withDefaultValue(SMALLRYE_CONFIG_PROFILE, ProfileManager.getActiveProfile());
- builder.addDefaultInterceptors();
+ SmallRyeConfigBuilder builder = ConfigUtils.emptyConfigBuilder();
for (ConfigSource configSource : config.getConfigSources()) {
if (configSource instanceof EnvConfigSource) {
continue;
diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
index 03dc984f47ab1..c9d19fc5f9517 100644
--- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
+++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/ConfigUtils.java
@@ -142,7 +142,7 @@ public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorConte
@Override
public OptionalInt getPriority() {
- return OptionalInt.of(Priorities.LIBRARY + 600 - 5);
+ return OptionalInt.of(Priorities.LIBRARY + 200 - 5);
}
});
@@ -157,7 +157,7 @@ public ConfigSourceInterceptor getInterceptor(final ConfigSourceInterceptorConte
@Override
public OptionalInt getPriority() {
- return OptionalInt.of(Priorities.LIBRARY + 400 - 5);
+ return OptionalInt.of(Priorities.LIBRARY + 600 - 5);
}
});
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/config/RenameConfigTest.java b/core/test-extension/deployment/src/test/java/io/quarkus/config/RenameConfigTest.java
new file mode 100644
index 0000000000000..9a9de01184ded
--- /dev/null
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/config/RenameConfigTest.java
@@ -0,0 +1,74 @@
+package io.quarkus.config;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNull;
+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.extest.runtime.config.rename.RenameConfig;
+import io.quarkus.test.QuarkusUnitTest;
+import io.smallrye.config.SmallRyeConfig;
+
+public class RenameConfigTest {
+ @RegisterExtension
+ static final QuarkusUnitTest TEST = new QuarkusUnitTest()
+ .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class));
+
+ @Inject
+ RenameConfig renameConfig;
+ @Inject
+ SmallRyeConfig config;
+
+ @Test
+ void rename() {
+ assertEquals("1234", renameConfig.prop);
+ assertEquals("1234", config.getRawValue("quarkus.rename.prop"));
+
+ assertEquals("only-in-new", renameConfig.onlyInNew);
+ assertEquals("only-in-old", renameConfig.onlyInOld);
+ assertEquals("new", renameConfig.inBoth);
+
+ // This will always return values. It lookups on "rename" first and "rename-old" next
+ assertEquals("only-in-new", config.getRawValue("quarkus.rename.only-in-new"));
+ assertEquals("only-in-old", config.getRawValue("quarkus.rename.only-in-old"));
+ assertEquals("new", config.getRawValue("quarkus.rename.in-both"));
+
+ assertEquals("only-in-new", config.getRawValue("quarkus.rename-old.only-in-new"));
+ assertEquals("only-in-old", config.getRawValue("quarkus.rename-old.only-in-old"));
+ assertEquals("new", config.getRawValue("quarkus.rename-old.in-both"));
+
+ assertEquals("old-default", config.getRawValue("quarkus.rename.with-default"));
+ assertEquals("old-default", config.getRawValue("quarkus.rename-old.with-default"));
+ assertEquals("old-default", renameConfig.withDefault);
+
+ // Make sure we only record the actual properties in the sources (and not renamed properties)
+ Optional configSource = config.getConfigSource("PropertiesConfigSource[source=Build time config]");
+ assertTrue(configSource.isPresent());
+ ConfigSource buildTimeRunTimeDefaults = configSource.get();
+
+ // In Build time source
+ assertNotNull(buildTimeRunTimeDefaults.getValue("quarkus.rename.prop"));
+ assertNotNull(buildTimeRunTimeDefaults.getValue("quarkus.rename.only-in-new"));
+ assertNotNull(buildTimeRunTimeDefaults.getValue("quarkus.rename-old.only-in-old"));
+ assertNotNull(buildTimeRunTimeDefaults.getValue("quarkus.rename.in-both"));
+ // When in both only the one that has priority (remamed) is recorded
+ assertNull(buildTimeRunTimeDefaults.getValue("quarkus.rename-old.in-both"));
+ // Relocate / Fallback properties, not in the source but values are not null when Config is queried
+ assertNull(buildTimeRunTimeDefaults.getValue("quarkus.rename-old.prop"));
+ assertNotNull(config.getRawValue("quarkus.rename-old.prop"));
+ assertNull(buildTimeRunTimeDefaults.getValue("quarkus.rename-old.only-in-new"));
+ assertNotNull(config.getRawValue("quarkus.rename-old.only-in-new"));
+ assertNull(buildTimeRunTimeDefaults.getValue("quarkus.rename.only-in-old"));
+ assertNotNull(config.getRawValue("quarkus.rename.only-in-old"));
+ }
+}
diff --git a/core/test-extension/deployment/src/test/java/io/quarkus/extest/UnknownConfigTest.java b/core/test-extension/deployment/src/test/java/io/quarkus/extest/UnknownConfigTest.java
index d17daafb46309..2378f0296ea36 100644
--- a/core/test-extension/deployment/src/test/java/io/quarkus/extest/UnknownConfigTest.java
+++ b/core/test-extension/deployment/src/test/java/io/quarkus/extest/UnknownConfigTest.java
@@ -27,7 +27,6 @@ public class UnknownConfigTest {
.assertLogRecords(logRecords -> {
Set properties = logRecords.stream().flatMap(
logRecord -> Stream.of(logRecord.getParameters())).map(Object::toString).collect(Collectors.toSet());
- assertEquals(1, properties.size());
assertTrue(properties.contains("quarkus.unknown.prop"));
});
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfig.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfig.java
new file mode 100644
index 0000000000000..9da620c017762
--- /dev/null
+++ b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfig.java
@@ -0,0 +1,34 @@
+package io.quarkus.extest.runtime.config.rename;
+
+import io.quarkus.runtime.annotations.ConfigItem;
+import io.quarkus.runtime.annotations.ConfigPhase;
+import io.quarkus.runtime.annotations.ConfigRoot;
+
+@ConfigRoot(phase = ConfigPhase.BUILD_AND_RUN_TIME_FIXED)
+public class RenameConfig {
+ /**
+ *
+ */
+ @ConfigItem
+ public String prop;
+ /**
+ *
+ */
+ @ConfigItem
+ public String onlyInNew;
+ /**
+ *
+ */
+ @ConfigItem
+ public String onlyInOld;
+ /**
+ *
+ */
+ @ConfigItem
+ public String inBoth;
+ /**
+ *
+ */
+ @ConfigItem(defaultValue = "default")
+ public String withDefault;
+}
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigFallbackInterceptor.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigFallbackInterceptor.java
new file mode 100644
index 0000000000000..f6ae5a302243c
--- /dev/null
+++ b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigFallbackInterceptor.java
@@ -0,0 +1,18 @@
+package io.quarkus.extest.runtime.config.rename;
+
+import java.util.function.Function;
+
+import io.smallrye.config.FallbackConfigSourceInterceptor;
+
+public class RenameConfigFallbackInterceptor extends FallbackConfigSourceInterceptor {
+ private static final Function FALLBACK = name -> {
+ if (name.startsWith("quarkus.rename.")) {
+ return name.replaceFirst("quarkus\\.rename\\.", "quarkus.rename-old.");
+ }
+ return name;
+ };
+
+ public RenameConfigFallbackInterceptor() {
+ super(FALLBACK);
+ }
+}
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigRelocateInterceptor.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigRelocateInterceptor.java
new file mode 100644
index 0000000000000..1e1858eddbe90
--- /dev/null
+++ b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigRelocateInterceptor.java
@@ -0,0 +1,18 @@
+package io.quarkus.extest.runtime.config.rename;
+
+import java.util.function.Function;
+
+import io.smallrye.config.RelocateConfigSourceInterceptor;
+
+public class RenameConfigRelocateInterceptor extends RelocateConfigSourceInterceptor {
+ private static final Function RELOCATE = name -> {
+ if (name.startsWith("quarkus.rename-old.")) {
+ return name.replaceFirst("quarkus\\.rename-old\\.", "quarkus.rename.");
+ }
+ return name;
+ };
+
+ public RenameConfigRelocateInterceptor() {
+ super(RELOCATE);
+ }
+}
diff --git a/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigSource.java b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigSource.java
new file mode 100644
index 0000000000000..90b169ca37d05
--- /dev/null
+++ b/core/test-extension/runtime/src/main/java/io/quarkus/extest/runtime/config/rename/RenameConfigSource.java
@@ -0,0 +1,65 @@
+package io.quarkus.extest.runtime.config.rename;
+
+import static java.util.Collections.emptySet;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigProvider;
+import org.eclipse.microprofile.config.spi.ConfigSource;
+
+import io.quarkus.runtime.annotations.StaticInitSafe;
+import io.smallrye.config.common.MapBackedConfigSource;
+
+/**
+ * This simulates a build time only source to test the recording of configuration values. It is still discovered at
+ * runtime, but it doesn't return any configuration.
+ */
+@StaticInitSafe
+public class RenameConfigSource extends MapBackedConfigSource {
+ // Because getPropertyNames() is called during SmallRyeConfig init
+ private int propertyNamesCallCount = 0;
+
+ private static final Map FALLBACK_PROPERTIES = Map.of(
+ "quarkus.rename.prop", "1234",
+ "quarkus.rename.only-in-new", "only-in-new",
+ "quarkus.rename-old.only-in-old", "only-in-old",
+ "quarkus.rename.in-both", "new",
+ "quarkus.rename-old.in-both", "old",
+ "quarkus.rename-old.with-default", "old-default");
+
+ public RenameConfigSource() {
+ super(RenameConfigSource.class.getName(), new HashMap<>());
+ }
+
+ @Override
+ public String getValue(final String propertyName) {
+ if (propertyName.startsWith("quarkus.rename") && isBuildTime()) {
+ return FALLBACK_PROPERTIES.get(propertyName);
+ }
+ return null;
+ }
+
+ @Override
+ public Set getPropertyNames() {
+ if (propertyNamesCallCount > 0) {
+ return isBuildTime() ? FALLBACK_PROPERTIES.keySet() : emptySet();
+ } else {
+ propertyNamesCallCount++;
+ return emptySet();
+ }
+ }
+
+ private static boolean isBuildTime() {
+ // We can only call this when the SmallRyeConfig is already initialized, or else we may get into a loop
+ Config config = ConfigProvider.getConfig();
+ for (ConfigSource configSource : config.getConfigSources()) {
+ if (configSource.getClass().getSimpleName().equals("BuildTimeEnvConfigSource")) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
diff --git a/core/test-extension/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor b/core/test-extension/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor
new file mode 100644
index 0000000000000..a798b3b4636eb
--- /dev/null
+++ b/core/test-extension/runtime/src/main/resources/META-INF/services/io.smallrye.config.ConfigSourceInterceptor
@@ -0,0 +1,2 @@
+io.quarkus.extest.runtime.config.rename.RenameConfigRelocateInterceptor
+io.quarkus.extest.runtime.config.rename.RenameConfigFallbackInterceptor
diff --git a/core/test-extension/runtime/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource b/core/test-extension/runtime/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
new file mode 100644
index 0000000000000..59b7341c9dbd3
--- /dev/null
+++ b/core/test-extension/runtime/src/main/resources/META-INF/services/org.eclipse.microprofile.config.spi.ConfigSource
@@ -0,0 +1 @@
+io.quarkus.extest.runtime.config.rename.RenameConfigSource
diff --git a/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientFallbackConfigSourceInterceptorTest.java b/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientFallbackConfigSourceInterceptorTest.java
index f1b9c5055d093..29945375fcf76 100644
--- a/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientFallbackConfigSourceInterceptorTest.java
+++ b/extensions/resteasy-classic/rest-client-config/runtime/src/test/java/io/quarkus/restclient/config/RestClientFallbackConfigSourceInterceptorTest.java
@@ -187,6 +187,7 @@ public ConfigValue proceed(String name) {
return ConfigValue.builder()
.withName(name)
.withValue("")
+ .withConfigSourceOrdinal(name.startsWith("quarkus.rest-client.") ? 100 : 200)
.build();
}
diff --git a/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientBuildTimeConfigSource.java b/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientBuildTimeConfigSource.java
index 94552c9519660..bc3b0098211ff 100644
--- a/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientBuildTimeConfigSource.java
+++ b/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientBuildTimeConfigSource.java
@@ -1,15 +1,28 @@
package io.quarkus.restclient.configuration;
-import java.util.Collections;
+import static java.util.Collections.emptySet;
+
import java.util.HashMap;
+import java.util.Map;
import java.util.Set;
+import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigSource;
import io.smallrye.config.common.MapBackedConfigSource;
+/**
+ * This simulates a build time only source to test the recording of configuration values. It is still discovered at
+ * runtime, but it doesn't return any configuration.
+ */
public class RestClientBuildTimeConfigSource extends MapBackedConfigSource {
+ // Because getPropertyNames() is called during SmallRyeConfig init
+ private int propertyNamesCallCount = 0;
+
+ private static final Map PROPERTIES = Map.of(
+ "io.quarkus.restclient.configuration.EchoClient/mp-rest/url", "http://nohost:${quarkus.http.test-port:8081}");
+
public RestClientBuildTimeConfigSource() {
super(RestClientBuildTimeConfigSource.class.getName(), new HashMap<>());
}
@@ -21,7 +34,7 @@ public String getValue(final String propertyName) {
}
if (isBuildTime()) {
- return "http://nohost:${quarkus.http.test-port:8081}";
+ return "http://nohost";
}
return null;
@@ -29,7 +42,12 @@ public String getValue(final String propertyName) {
@Override
public Set getPropertyNames() {
- return Collections.singleton("io.quarkus.restclient.configuration.EchoClient/mp-rest/url");
+ if (propertyNamesCallCount > 0) {
+ return isBuildTime() ? PROPERTIES.keySet() : emptySet();
+ } else {
+ propertyNamesCallCount++;
+ return emptySet();
+ }
}
@Override
@@ -38,7 +56,9 @@ public int getOrdinal() {
}
private static boolean isBuildTime() {
- for (ConfigSource configSource : ConfigProvider.getConfig().getConfigSources()) {
+ // We can only call this when the SmallRyeConfig is already initialized, or else we may get into a loop
+ Config config = ConfigProvider.getConfig();
+ for (ConfigSource configSource : config.getConfigSources()) {
if (configSource.getClass().getSimpleName().equals("BuildTimeEnvConfigSource")) {
return true;
}
diff --git a/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientOverrideRuntimeConfigTest.java b/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientOverrideRuntimeConfigTest.java
index 4fdbd5cf067b6..7b9ea2443da4f 100644
--- a/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientOverrideRuntimeConfigTest.java
+++ b/extensions/resteasy-classic/rest-client/deployment/src/test/java/io/quarkus/restclient/configuration/RestClientOverrideRuntimeConfigTest.java
@@ -1,9 +1,11 @@
package io.quarkus.restclient.configuration;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.Optional;
+import java.util.stream.StreamSupport;
import javax.inject.Inject;
@@ -36,18 +38,30 @@ public class RestClientOverrideRuntimeConfigTest {
@Test
void overrideConfig() {
+ // Build time property recording
Optional specifiedDefaultValues = config
.getConfigSource("PropertiesConfigSource[source=Specified default values]");
assertTrue(specifiedDefaultValues.isPresent());
assertTrue(specifiedDefaultValues.get().getPropertyNames()
.contains("io.quarkus.restclient.configuration.EchoClient/mp-rest/url"));
+ assertEquals("http://nohost",
+ specifiedDefaultValues.get().getValue("io.quarkus.restclient.configuration.EchoClient/mp-rest/url"));
+ // This config key comes from the interceptor. It is available in propertyNames, but is not recorded
+ assertNull(specifiedDefaultValues.get()
+ .getValue("quarkus.rest-client.\"io.quarkus.restclient.configuration.EchoClient\".url"));
+ assertTrue(StreamSupport.stream(config.getPropertyNames().spliterator(), false).anyMatch(
+ property -> property.equals("quarkus.rest-client.\"io.quarkus.restclient.configuration.EchoClient\".url")));
+ // Override MP Build time property with Quarkus property
ConfigValue mpValue = config.getConfigValue("io.quarkus.restclient.configuration.EchoClient/mp-rest/url");
// Fallbacks from runtime to the override build time value
ConfigValue quarkusValue = config
.getConfigValue("quarkus.rest-client.\"io.quarkus.restclient.configuration.EchoClient\".url");
assertEquals(mpValue.getValue(), quarkusValue.getValue());
assertEquals(RestClientRunTimeConfigSource.class.getName(), quarkusValue.getConfigSourceName());
+ // The MP name has priority over the Quarkus one, so it is the name we get (even when we lookup the quarkus one)
+ assertEquals(mpValue.getName(), "io.quarkus.restclient.configuration.EchoClient/mp-rest/url");
+ assertEquals(quarkusValue.getName(), "io.quarkus.restclient.configuration.EchoClient/mp-rest/url");
assertEquals("Hi", echoClient.echo("Hi"));
}
diff --git a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java
index 74b4941812784..edf27ed4a661b 100644
--- a/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java
+++ b/integration-tests/smallrye-config/src/main/java/io/quarkus/it/smallrye/config/ConfigResource.java
@@ -8,7 +8,7 @@
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import org.eclipse.microprofile.config.Config;
+import org.eclipse.microprofile.config.ConfigValue;
import io.quarkus.runtime.annotations.RegisterForReflection;
import io.smallrye.config.SmallRyeConfig;
@@ -17,38 +17,19 @@
@Produces(MediaType.APPLICATION_JSON)
public class ConfigResource {
@Inject
- Config config;
+ SmallRyeConfig config;
@GET
@Path("/{name}")
public Response configValue(@PathParam("name") final String name) {
- final io.smallrye.config.ConfigValue configValue = ((SmallRyeConfig) config).getConfigValue(name);
- return Response.ok(new ConfigValue(configValue.getName(), configValue.getValue(), configValue.getConfigSourceName()))
- .build();
+ return Response.ok(config.getConfigValue(name)).build();
}
- @RegisterForReflection
- public static class ConfigValue {
- final String name;
- final String value;
- final String sourceName;
+ @RegisterForReflection(targets = {
+ org.eclipse.microprofile.config.ConfigValue.class,
+ io.smallrye.config.ConfigValue.class
+ })
+ public static class ConfigValueReflection {
- public ConfigValue(final String name, final String value, final String sourceName) {
- this.name = name;
- this.value = value;
- this.sourceName = sourceName;
- }
-
- public String getName() {
- return name;
- }
-
- public String getValue() {
- return value;
- }
-
- public String getSourceName() {
- return sourceName;
- }
}
}