Skip to content

Commit

Permalink
Register RuntimeOverrideConfigSource in STATIC_INIT
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Oct 11, 2023
1 parent 049f6f0 commit 055d5ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -157,6 +158,15 @@ void buildTimeRunTimeConfig(
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(builderClassName));
}

@BuildStep(onlyIfNot = { IsNormal.class }) // for dev or test
void runtimeOverrideConfig(
BuildProducer<StaticInitConfigBuilderBuildItem> staticInitConfigBuilder,
BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilder) {
staticInitConfigBuilder
.produce(new StaticInitConfigBuilderBuildItem(RuntimeOverrideConfigSourceBuilder.class.getName()));
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(RuntimeOverrideConfigSourceBuilder.class.getName()));
}

@BuildStep
void generateMappings(
ConfigurationBuildItem configItem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
*
Expand Down Expand Up @@ -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()));
}
}
Original file line number Diff line number Diff line change
@@ -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()));
}
}

0 comments on commit 055d5ac

Please sign in to comment.