From 91cddc603fcee915d328f3b0c0460a1eb2e9c773 Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Wed, 11 Oct 2023 12:42:09 +0100 Subject: [PATCH] Register RuntimeOverrideConfigSource in STATIC_INIT (cherry picked from commit 47888dbb5f2ab18d4923aab9f25156d3ed3a5972) --- .../configuration/RunTimeConfigurationGenerator.java | 12 ------------ .../deployment/steps/ConfigGenerationBuildStep.java | 10 ++++++++++ .../configuration/RuntimeOverrideConfigSource.java | 6 ------ .../RuntimeOverrideConfigSourceBuilder.java | 10 ++++++++++ 4 files changed, 20 insertions(+), 18 deletions(-) create mode 100644 core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSourceBuilder.java diff --git a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java index 145e95cdd6eb9..bbcdade143c99 100644 --- a/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java +++ b/core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java @@ -23,7 +23,6 @@ import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.spi.ConfigBuilder; import org.eclipse.microprofile.config.spi.ConfigProviderResolver; -import org.eclipse.microprofile.config.spi.ConfigSource; import org.eclipse.microprofile.config.spi.Converter; import org.objectweb.asm.Opcodes; import org.wildfly.common.Assert; @@ -66,7 +65,6 @@ import io.quarkus.runtime.configuration.NameIterator; import io.quarkus.runtime.configuration.PropertiesUtil; import io.quarkus.runtime.configuration.QuarkusConfigFactory; -import io.quarkus.runtime.configuration.RuntimeOverrideConfigSource; import io.smallrye.config.ConfigMappings; import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix; import io.smallrye.config.Converters; @@ -191,8 +189,6 @@ public final class RunTimeConfigurationGenerator { static final MethodDescriptor SRCB_WITH_CONVERTER = MethodDescriptor.ofMethod(SmallRyeConfigBuilder.class, "withConverter", ConfigBuilder.class, Class.class, int.class, Converter.class); - static final MethodDescriptor SRCB_WITH_SOURCES = MethodDescriptor.ofMethod(SmallRyeConfigBuilder.class, - "withSources", ConfigBuilder.class, ConfigSource[].class); static final MethodDescriptor SRCB_WITH_CUSTOMIZER = MethodDescriptor.ofMethod(AbstractConfigBuilder.class, "withCustomizer", void.class, SmallRyeConfigBuilder.class, String.class); static final MethodDescriptor SRCB_BUILD = MethodDescriptor.ofMethod(SmallRyeConfigBuilder.class, "build", @@ -391,14 +387,6 @@ public void run() { // runtime config builder readConfig.invokeStaticMethod(SRCB_WITH_CUSTOMIZER, runTimeBuilder, readConfig.load(CONFIG_RUNTIME_NAME)); - // add in our custom sources - if (launchMode.isDevOrTest()) { - MethodDescriptor registerRuntimeOverrideConfigSource = MethodDescriptor.ofMethod( - RuntimeOverrideConfigSource.class, "registerRuntimeOverrideConfigSource", void.class, - SmallRyeConfigBuilder.class); - readConfig.invokeStaticMethod(registerRuntimeOverrideConfigSource, runTimeBuilder); - } - final ResultHandle runTimeConfig = readConfig.invokeVirtualMethod(SRCB_BUILD, runTimeBuilder); installConfiguration(runTimeConfig, readConfig); 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 c05f81ffe0bc8..b1ae0b60f8459 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 @@ -83,6 +83,7 @@ import io.quarkus.runtime.configuration.QuarkusConfigValue; import io.quarkus.runtime.configuration.RuntimeConfigBuilder; import io.quarkus.runtime.configuration.RuntimeOverrideConfigSource; +import io.quarkus.runtime.configuration.RuntimeOverrideConfigSourceBuilder; import io.quarkus.runtime.configuration.StaticInitConfigBuilder; import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix; import io.smallrye.config.ConfigSourceFactory; @@ -157,6 +158,15 @@ void buildTimeRunTimeConfig( runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(builderClassName)); } + @BuildStep(onlyIfNot = { IsNormal.class }) // for dev or test + void runtimeOverrideConfig( + BuildProducer staticInitConfigBuilder, + BuildProducer runTimeConfigBuilder) { + staticInitConfigBuilder + .produce(new StaticInitConfigBuilderBuildItem(RuntimeOverrideConfigSourceBuilder.class.getName())); + runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(RuntimeOverrideConfigSourceBuilder.class.getName())); + } + @BuildStep void generateMappings( ConfigurationBuildItem configItem, diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSource.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSource.java index db6cd6bc3bc5c..f388155d10e1f 100644 --- a/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSource.java +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSource.java @@ -7,8 +7,6 @@ import org.eclipse.microprofile.config.spi.ConfigSource; -import io.smallrye.config.SmallRyeConfigBuilder; - /** * Config source that is used to handle {@code io.quarkus.bootstrap.app.StartupAction#overrideConfig(java.util.Map)} * @@ -63,8 +61,4 @@ public String getValue(String s) { public String getName() { return "Config Override Config Source"; } - - public static void registerRuntimeOverrideConfigSource(SmallRyeConfigBuilder builder) { - builder.withSources(new RuntimeOverrideConfigSource(builder.getClassLoader())); - } } diff --git a/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSourceBuilder.java b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSourceBuilder.java new file mode 100644 index 0000000000000..dbabbae38317b --- /dev/null +++ b/core/runtime/src/main/java/io/quarkus/runtime/configuration/RuntimeOverrideConfigSourceBuilder.java @@ -0,0 +1,10 @@ +package io.quarkus.runtime.configuration; + +import io.smallrye.config.SmallRyeConfigBuilder; + +public class RuntimeOverrideConfigSourceBuilder implements ConfigBuilder { + @Override + public SmallRyeConfigBuilder configBuilder(final SmallRyeConfigBuilder builder) { + return builder.withSources(new RuntimeOverrideConfigSource(builder.getClassLoader())); + } +}