Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix order of defaults recording #36753

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,7 @@ final class ReadOperation {
final Map<String, String> allBuildTimeValues = new TreeMap<>();
final Map<String, String> buildTimeRunTimeValues = new TreeMap<>();
final Map<String, String> runTimeDefaultValues = new TreeMap<>();
final Map<String, String> runTimeValues = new TreeMap<>();

final Map<ConverterType, Converter<?>> convByType = new HashMap<>();

Expand Down Expand Up @@ -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());
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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());
}
}
}
Expand All @@ -664,6 +665,7 @@ ReadResult run() {
.setAllBuildTimeValues(allBuildTimeValues)
.setBuildTimeRunTimeValues(filterActiveProfileProperties(buildTimeRunTimeValues))
.setRunTimeDefaultValues(filterActiveProfileProperties(runTimeDefaultValues))
.setRuntimeValues(runTimeValues)
.setBuildTimePatternMap(buildTimePatternMap)
.setBuildTimeRunTimePatternMap(buildTimeRunTimePatternMap)
.setRunTimePatternMap(runTimePatternMap)
Expand Down Expand Up @@ -1139,6 +1141,7 @@ public static final class ReadResult {
final Map<String, String> allBuildTimeValues;
final Map<String, String> buildTimeRunTimeValues;
final Map<String, String> runTimeDefaultValues;
final Map<String, String> runTimeValues;

final ConfigPatternMap<Container> buildTimePatternMap;
final ConfigPatternMap<Container> buildTimeRunTimePatternMap;
Expand All @@ -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();
Expand Down Expand Up @@ -1219,6 +1223,10 @@ public Map<String, String> getRunTimeDefaultValues() {
return runTimeDefaultValues;
}

public Map<String, String> getRunTimeValues() {
return runTimeValues;
}

public ConfigPatternMap<Container> getBuildTimePatternMap() {
return buildTimePatternMap;
}
Expand Down Expand Up @@ -1280,6 +1288,7 @@ static class Builder {
private Map<String, String> allBuildTimeValues;
private Map<String, String> buildTimeRunTimeValues;
private Map<String, String> runTimeDefaultValues;
private Map<String, String> runtimeValues;
private ConfigPatternMap<Container> buildTimePatternMap;
private ConfigPatternMap<Container> buildTimeRunTimePatternMap;
private ConfigPatternMap<Container> runTimePatternMap;
Expand Down Expand Up @@ -1327,6 +1336,15 @@ Builder setRunTimeDefaultValues(final Map<String, String> runTimeDefaultValues)
return this;
}

Map<String, String> getRuntimeValues() {
return runtimeValues;
}

Builder setRuntimeValues(final Map<String, String> runtimeValues) {
this.runtimeValues = runtimeValues;
return this;
}

ConfigPatternMap<Container> getBuildTimePatternMap() {
return buildTimePatternMap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,14 @@ void generateBuilders(
BuildProducer<GeneratedClassBuildItem> generatedClass,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) throws Exception {

// Default Values collected from mappings / roots and build item
// Default values from @ConfigRoot
Map<String, String> 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<String> converters = discoverService(Converter.class, reflectiveClass);
Set<String> interceptors = discoverService(ConfigSourceInterceptor.class, reflectiveClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -486,6 +487,11 @@ void neverRunThisOne() {
throw new IllegalStateException("Not supposed to run!");
}

@BuildStep
void recordProperty(BuildProducer<RunTimeConfigurationDefaultBuildItem> runTimeConfigurationDefault) {
runTimeConfigurationDefault.produce(new RunTimeConfigurationDefaultBuildItem("recorded.property", "from-build-step"));
}

public static final class Never implements BooleanSupplier {
TestBuildTimeConfig config;

Expand Down
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Loading