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

Always record original default values #40516

Merged
merged 1 commit into from
May 10, 2024
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 @@ -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
Loading