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 c3ef229b00ead..a701d35b55683 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 @@ -474,6 +474,7 @@ final class ReadOperation { final Map allBuildTimeValues = new TreeMap<>(); final Map buildTimeRunTimeValues = new TreeMap<>(); final Map runTimeDefaultValues = new TreeMap<>(); + final Map runTimeValues = new TreeMap<>(); final Map> convByType = new HashMap<>(); @@ -593,7 +594,7 @@ ReadResult run() { // it's a run-time default (record for later) ConfigValue configValue = withoutExpansion(() -> runtimeDefaultsConfig.getConfigValue(propertyName)); if (configValue.getValue() != null) { - runTimeDefaultValues.put(configValue.getNameProfiled(), configValue.getValue()); + runTimeValues.put(configValue.getNameProfiled(), configValue.getValue()); } } @@ -604,7 +605,7 @@ ReadResult run() { // it's not managed by us; record it ConfigValue configValue = withoutExpansion(() -> runtimeDefaultsConfig.getConfigValue(propertyName)); if (configValue.getValue() != null) { - runTimeDefaultValues.put(configValue.getNameProfiled(), configValue.getValue()); + runTimeValues.put(configValue.getNameProfiled(), configValue.getValue()); } // in the case the user defined compound keys in YAML (or similar config source, that quotes the name) @@ -655,7 +656,7 @@ ReadResult run() { unknownBuildProperties.remove(property); ConfigValue value = config.getConfigValue(property); if (value != null && value.getRawValue() != null) { - runTimeDefaultValues.put(property, value.getRawValue()); + runTimeValues.put(property, value.getRawValue()); } } } @@ -664,6 +665,7 @@ ReadResult run() { .setAllBuildTimeValues(allBuildTimeValues) .setBuildTimeRunTimeValues(filterActiveProfileProperties(buildTimeRunTimeValues)) .setRunTimeDefaultValues(filterActiveProfileProperties(runTimeDefaultValues)) + .setRuntimeValues(runTimeValues) .setBuildTimePatternMap(buildTimePatternMap) .setBuildTimeRunTimePatternMap(buildTimeRunTimePatternMap) .setRunTimePatternMap(runTimePatternMap) @@ -1139,6 +1141,7 @@ public static final class ReadResult { final Map allBuildTimeValues; final Map buildTimeRunTimeValues; final Map runTimeDefaultValues; + final Map runTimeValues; final ConfigPatternMap buildTimePatternMap; final ConfigPatternMap buildTimeRunTimePatternMap; @@ -1162,6 +1165,7 @@ public ReadResult(final Builder builder) { this.allBuildTimeValues = builder.getAllBuildTimeValues(); this.buildTimeRunTimeValues = builder.getBuildTimeRunTimeValues(); this.runTimeDefaultValues = builder.getRunTimeDefaultValues(); + this.runTimeValues = builder.getRuntimeValues(); this.buildTimePatternMap = builder.getBuildTimePatternMap(); this.buildTimeRunTimePatternMap = builder.getBuildTimeRunTimePatternMap(); @@ -1219,6 +1223,10 @@ public Map getRunTimeDefaultValues() { return runTimeDefaultValues; } + public Map getRunTimeValues() { + return runTimeValues; + } + public ConfigPatternMap getBuildTimePatternMap() { return buildTimePatternMap; } @@ -1280,6 +1288,7 @@ static class Builder { private Map allBuildTimeValues; private Map buildTimeRunTimeValues; private Map runTimeDefaultValues; + private Map runtimeValues; private ConfigPatternMap buildTimePatternMap; private ConfigPatternMap buildTimeRunTimePatternMap; private ConfigPatternMap runTimePatternMap; @@ -1327,6 +1336,15 @@ Builder setRunTimeDefaultValues(final Map runTimeDefaultValues) return this; } + Map getRuntimeValues() { + return runtimeValues; + } + + Builder setRuntimeValues(final Map runtimeValues) { + this.runtimeValues = runtimeValues; + return this; + } + ConfigPatternMap getBuildTimePatternMap() { return buildTimePatternMap; } diff --git a/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java b/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java index d5f89be6eb98a..97c36ea3a1702 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/steps/ConfigGenerationBuildStep.java @@ -200,11 +200,14 @@ void generateBuilders( BuildProducer generatedClass, BuildProducer reflectiveClass) throws Exception { - // Default Values collected from mappings / roots and build item + // Default values from @ConfigRoot Map defaultValues = new HashMap<>(configItem.getReadResult().getRunTimeDefaultValues()); + // Default values from build item RunTimeConfigurationDefaultBuildItem override for (RunTimeConfigurationDefaultBuildItem e : runTimeDefaults) { defaultValues.put(e.getKey(), e.getValue()); } + // Recorded values from build time from any other source (higher ordinal then defaults, so override) + defaultValues.putAll(configItem.getReadResult().getRunTimeValues()); Set converters = discoverService(Converter.class, reflectiveClass); Set interceptors = discoverService(ConfigSourceInterceptor.class, reflectiveClass); diff --git a/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/BuildTimeCustomConfigBuilder.java b/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/BuildTimeCustomConfigBuilder.java index c52d2f5010593..6c17cb988b343 100644 --- a/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/BuildTimeCustomConfigBuilder.java +++ b/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/BuildTimeCustomConfigBuilder.java @@ -9,7 +9,11 @@ public class BuildTimeCustomConfigBuilder implements SmallRyeConfigBuilderCustomizer { @Override public void configBuilder(final SmallRyeConfigBuilder builder) { + // for ConfigBuilderTest builder.withSources( new PropertiesConfigSource(Map.of("prop.recorded.from.btconfigsource", "1234"), "BuildTimeConfigSource", 100)); + // for RecorderRuntimeConfigTest + builder.withSources( + new PropertiesConfigSource(Map.of("recorded.property", "from-application"), "BuildTimeConfigSource", 250)); } } diff --git a/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java b/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java index 34330b62fcac4..b518fe5b2e5cb 100644 --- a/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java +++ b/integration-tests/test-extension/extension/deployment/src/main/java/io/quarkus/extest/deployment/TestProcessor.java @@ -42,6 +42,7 @@ import io.quarkus.deployment.builditem.LogHandlerBuildItem; import io.quarkus.deployment.builditem.ObjectSubstitutionBuildItem; import io.quarkus.deployment.builditem.RunTimeConfigBuilderBuildItem; +import io.quarkus.deployment.builditem.RunTimeConfigurationDefaultBuildItem; import io.quarkus.deployment.builditem.ServiceStartBuildItem; import io.quarkus.deployment.builditem.ShutdownContextBuildItem; import io.quarkus.deployment.builditem.StaticInitConfigBuilderBuildItem; @@ -486,6 +487,11 @@ void neverRunThisOne() { throw new IllegalStateException("Not supposed to run!"); } + @BuildStep + void recordProperty(BuildProducer runTimeConfigurationDefault) { + runTimeConfigurationDefault.produce(new RunTimeConfigurationDefaultBuildItem("recorded.property", "from-build-step")); + } + public static final class Never implements BooleanSupplier { TestBuildTimeConfig config; diff --git a/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecorderRuntimeConfigTest.java b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecorderRuntimeConfigTest.java new file mode 100644 index 0000000000000..4964751d7d754 --- /dev/null +++ b/integration-tests/test-extension/extension/deployment/src/test/java/io/quarkus/config/RecorderRuntimeConfigTest.java @@ -0,0 +1,27 @@ +package io.quarkus.config; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import jakarta.inject.Inject; + +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.SmallRyeConfig; + +public class RecorderRuntimeConfigTest { + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest() + .setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); + + @Inject + SmallRyeConfig config; + + @Test + void runtimeConfig() { + assertEquals("from-application", config.getRawValue("recorded.property")); + } +}