Skip to content

Commit

Permalink
Avoid ambiguous names when matching unknown configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Jan 14, 2025
1 parent c085eeb commit e58d214
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,6 @@ public static final class ReadResult {
final List<ConfigClass> runTimeMappings;
final List<ConfigClass> allMappings;
final Map<Class<?>, ConfigClass> allMappingsByClass;
final Map<PropertyName, String> allMappingsNames;

final Set<String> unknownBuildProperties;
final Set<String> deprecatedRuntimeProperties;
Expand All @@ -1300,7 +1299,6 @@ public ReadResult(final Builder builder) {
this.runTimeMappings = builder.getRunTimeMappings();
this.allMappings = new ArrayList<>(mappingsToMap(builder).values());
this.allMappingsByClass = mappingsToMap(builder);
this.allMappingsNames = ReadOperation.mappingsToNames(allMappings);

this.unknownBuildProperties = builder.getUnknownBuildProperties();
this.deprecatedRuntimeProperties = builder.deprecatedRuntimeProperties;
Expand Down Expand Up @@ -1390,10 +1388,6 @@ public Map<Class<?>, ConfigClass> getAllMappingsByClass() {
return allMappingsByClass;
}

public Map<PropertyName, String> getAllMappingsNames() {
return allMappingsNames;
}

public Set<String> getUnknownBuildProperties() {
return unknownBuildProperties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@
import io.quarkus.runtime.configuration.NameIterator;
import io.quarkus.runtime.configuration.PropertiesUtil;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.smallrye.config.ConfigMappings;
import io.smallrye.config.ConfigMappings.ConfigClass;
import io.smallrye.config.Converters;
import io.smallrye.config.PropertyName;
import io.smallrye.config.SmallRyeConfig;
import io.smallrye.config.SmallRyeConfigBuilder;

Expand Down Expand Up @@ -1183,24 +1183,26 @@ private FieldDescriptor getOrCreateConverterInstance(Field field, ConverterType
}

private void generateIsMapped() {
Map<PropertyName, String> names = buildTimeConfigResult.getAllMappingsNames();
ConfigPatternMap<Boolean> patterns = new ConfigPatternMap<>();
for (Map.Entry<PropertyName, String> entry : names.entrySet()) {
NameIterator name = new NameIterator(entry.getValue());
ConfigPatternMap<Boolean> current = patterns;
while (name.hasNext()) {
String segment = name.getNextSegment();
ConfigPatternMap<Boolean> child = current.getChild(segment);
if (child == null) {
child = new ConfigPatternMap<>();
current.addChild(segment, child);
List<ConfigClass> configMappings = buildTimeConfigResult.getAllMappings();
for (ConfigClass configMapping : configMappings) {
Set<String> names = ConfigMappings.getProperties(configMapping).keySet();
for (String name : names) {
NameIterator ni = new NameIterator(name);
ConfigPatternMap<Boolean> current = patterns;
while (ni.hasNext()) {
String segment = ni.getNextSegment();
ConfigPatternMap<Boolean> child = current.getChild(segment);
if (child == null) {
child = new ConfigPatternMap<>();
current.addChild(segment, child);
}
current = child;
ni.next();
}
current = child;
name.next();
current.setMatched(true);
}
current.setMatched(true);
}

generateIsMapped("isMapped", patterns);
}

Expand Down

0 comments on commit e58d214

Please sign in to comment.