Skip to content

Commit

Permalink
Always record original default values
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed May 8, 2024
1 parent 4331897 commit 3877f16
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1211,12 +1211,12 @@ private static void getDefaults(
ClassDefinition.ItemMember itemMember = (ClassDefinition.ItemMember) member;
String defaultValue = itemMember.getDefaultValue();
if (defaultValue != null) {
// lookup config to make sure we catch relocates or fallbacks
// lookup config to make sure we catch relocates or fallbacks and override the value
ConfigValue configValue = config.getConfigValue(propertyName.toString());
if (configValue.getValue() != null) {
defaultValues.put(configValue.getName(), configValue.getValue());
if (configValue.getValue() != null && !configValue.getName().equals(propertyName.toString())) {
defaultValues.put(propertyName.toString(), configValue.getValue());
} else {
defaultValues.put(configValue.getName(), defaultValue);
defaultValues.put(propertyName.toString(), defaultValue);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,10 @@ void generateBuilders(
// Runtime values may contain active profiled names that override sames names in defaults
// We need to keep the original name definition in case a different profile is used to run the app
String activeName = ProfileConfigSourceInterceptor.activeName(entry.getKey(), profiles);
defaultValues.remove(activeName);
// But keep the default
if (!configItem.getReadResult().getRunTimeDefaultValues().containsKey(activeName)) {
defaultValues.remove(activeName);
}
defaultValues.put(entry.getKey(), entry.getValue());
}
defaultValues.putAll(configItem.getReadResult().getRunTimeValues());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ quarkus.arc.unremovable-types[0]=foo
### recording
bt.ok.to.record=from-app
%test.bt.profile.record=properties
%test.quarkus.mapping.rt.record-default=from-app
%test.quarkus.rt.record-default=from-app

### mappings
quarkus.mapping.bt.value=value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ void doNotRecordActiveUnprofiledPropertiesDefaults() {
assertNull(defaultValues.get().getValue("bt.profile.record"));
}

@Test
void recordDefaultFromRootEvenIfInActiveProfile() {
Optional<ConfigSource> defaultValues = config.getConfigSource("DefaultValuesConfigSource");
assertTrue(defaultValues.isPresent());

// Old Roots
assertEquals("from-app", defaultValues.get().getValue("%test.quarkus.rt.record-default"));
assertEquals("from-default", defaultValues.get().getValue("quarkus.rt.record-default"));
// Mappings
assertEquals("from-app", defaultValues.get().getValue("%test.quarkus.mapping.rt.record-default"));
assertEquals("from-default", defaultValues.get().getValue("quarkus.mapping.rt.record-default"));
}

@Test
void recordProfile() {
Optional<ConfigSource> defaultValues = config.getConfigSource("DefaultValuesConfigSource");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.WithDefault;

@ConfigMapping(prefix = "quarkus.mapping.rt")
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
Expand All @@ -25,6 +26,12 @@ public interface TestMappingRunTime {
/** Record values with named profile **/
Optional<String> recordProfiled();

/**
* Record Default
*/
@WithDefault("from-default")
String recordDefault();

interface Group {
/**
* A Group value.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ public class TestRunTimeConfig {
@ConfigItem
public Optional<String> doNotRecord;

/**
* Record Default
*/
@ConfigItem(defaultValue = "from-default")
public String recordDefault;

@Override
public String toString() {
return "TestRunTimeConfig{" +
Expand Down

0 comments on commit 3877f16

Please sign in to comment.