Skip to content

Commit

Permalink
Always record profiles
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Mar 31, 2024
1 parent 8823d1f commit dbc3bae
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
import static io.smallrye.config.Expressions.withoutExpansion;
import static io.smallrye.config.PropertiesConfigSourceProvider.classPathSources;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT;
import static io.smallrye.config.SmallRyeConfigBuilder.META_INF_MICROPROFILE_CONFIG_PROPERTIES;
import static java.util.stream.Collectors.toSet;

Expand Down Expand Up @@ -1104,8 +1106,8 @@ public String getValue(final String propertyName) {
Map.of("quarkus.profile", "",
"quarkus.config.profile.parent", "",
"quarkus.test.profile", "",
SmallRyeConfig.SMALLRYE_CONFIG_PROFILE, "",
SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT, "",
SMALLRYE_CONFIG_PROFILE, "",
SMALLRYE_CONFIG_PROFILE_PARENT, "",
Config.PROFILE, ""),
Integer.MAX_VALUE) {
@Override
Expand Down Expand Up @@ -1154,6 +1156,28 @@ private SmallRyeConfig getConfigForRuntimeRecording() {
}
builder.withSources(configSource);
}
builder.withSources(new AbstractConfigSource("Profiles", Integer.MAX_VALUE) {
private final Set<String> profiles = Set.of(
"quarkus.profile",
"quarkus.config.profile.parent",
"quarkus.test.profile",
SMALLRYE_CONFIG_PROFILE,
SMALLRYE_CONFIG_PROFILE_PARENT,
Config.PROFILE);

@Override
public Set<String> getPropertyNames() {
return Collections.emptySet();
}

@Override
public String getValue(final String propertyName) {
if (profiles.contains(propertyName)) {
return config.getConfigValue(propertyName).getValue();
}
return null;
};
});
return builder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,11 @@ void doNotRecordActiveUnprofiledPropertiesDefaults() {
assertEquals("properties", defaultValues.get().getValue("%test.bt.profile.record"));
assertNull(defaultValues.get().getValue("bt.profile.record"));
}

@Test
void recordProfile() {
Optional<ConfigSource> defaultValues = config.getConfigSource("DefaultValuesConfigSource");
assertTrue(defaultValues.isPresent());
assertEquals("record", config.getRawValue("quarkus.profile"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
public class EnvBuildTimeConfigSource extends EnvConfigSource {
public EnvBuildTimeConfigSource() {
super(Map.of(
"QUARKUS_PROFILE", "record",
"QUARKUS_MAPPING_RT_DO_NOT_RECORD", "value",
"BT_OK_TO_RECORD", "from-env",
"BT_DO_NOT_RECORD", "value",
Expand Down

0 comments on commit dbc3bae

Please sign in to comment.