Skip to content

Commit

Permalink
Improve reportUnknown allocations (#1263)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Dec 3, 2024
1 parent 4e2351a commit 95881f0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -304,61 +304,51 @@ private static List<Integer> indexOfDashes(final String mappedProperty, final St
return dashesPosition;
}

void reportUnknown(final List<String> ignoredPaths) {
KeyMap<Boolean> ignoredProperties = new KeyMap<>();
void reportUnknown(final Set<String> ignoredPaths) {
Set<PropertyName> ignoredNames = new HashSet<>();
Set<String> ignoredPrefixes = new HashSet<>();
for (String ignoredPath : ignoredPaths) {
KeyMap<Boolean> found;
if (ignoredPath.endsWith(".**")) {
found = ignoredProperties.findOrAdd(ignoredPath.substring(0, ignoredPath.length() - 3));
found.putRootValue(Boolean.TRUE);
ignoreRecursively(found);
ignoredPrefixes.add(ignoredPath.substring(0, ignoredPath.length() - 3));
} else {
if (!ignoredProperties.hasRootValue(ignoredPath)) {
found = ignoredProperties.findOrAdd(ignoredPath);
found.putRootValue(Boolean.TRUE);
}
ignoredNames.add(new PropertyName(ignoredPath));
}
}

Set<String> roots = new HashSet<>();
Set<String> prefixes = new HashSet<>();
for (Map<String, ConfigMappingObject> value : this.roots.values()) {
roots.addAll(value.keySet());
prefixes.addAll(value.keySet());
}
if (prefixes.contains("")) {
prefixes.clear();
}

for (String name : filterPropertiesInRoots(config.getPropertyNames(), roots)) {
if (usedProperties.contains(name)) {
propertyNames: for (String propertyName : config.getPropertyNames()) {
if (usedProperties.contains(propertyName)) {
continue;
}

if (!ignoredProperties.hasRootValue(name)) {
ConfigValue configValue = config.getConfigValue(name);
// TODO - https://github.com/quarkusio/quarkus/issues/38479
if (configValue.getSourceName() != null && configValue.getSourceName().startsWith(EnvConfigSource.NAME)) {
continue;
}
problems.add(new Problem(
ConfigMessages.msg.propertyDoesNotMapToAnyRoot(name, configValue.getLocation())));
if (ignoredNames.contains(new PropertyName(propertyName))) {
continue;
}
}
}

private static void ignoreRecursively(KeyMap<Boolean> root) {
if (root.getRootValue() == null) {
root.putRootValue(Boolean.TRUE);
}

if (root.getAny() == null) {
//noinspection CollectionAddedToSelf
root.putAny(root);
} else {
var any = root.getAny();
if (root != any) {
ignoreRecursively(any);
for (String ignoredPrefix : ignoredPrefixes) {
if (propertyName.startsWith(ignoredPrefix)) {
continue propertyNames;
}
}
}

for (var value : root.values()) {
ignoreRecursively(value);
for (String prefix : prefixes) {
if (isPropertyInRoot(propertyName, prefix)) {
ConfigValue configValue = config.getConfigValue(propertyName);
// TODO - https://github.com/quarkusio/quarkus/issues/38479
if (configValue.getSourceName() != null && configValue.getSourceName().startsWith(EnvConfigSource.NAME)) {
continue;
}
problems.add(new Problem(
ConfigMessages.msg.propertyDoesNotMapToAnyRoot(propertyName, configValue.getLocation())));
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static boolean equals(final String name, final String other) {
return true;
}

if (name.equals("*") && (other.equals("") || other.equals("\"\""))) {
if (name.equals("*") && (other.isEmpty() || other.equals("\"\""))) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public SmallRyeConfig build() {

public final class MappingBuilder {
private final Map<Class<?>, Set<String>> mappings = new HashMap<>();
private final List<String> ignoredPaths = new ArrayList<>();
private final Set<String> ignoredPaths = new HashSet<>();

private final StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -818,7 +818,7 @@ public Map<Class<?>, Set<String>> getMappings() {
return mappings;
}

public List<String> getIgnoredPaths() {
public Set<String> getIgnoredPaths() {
return ignoredPaths;
}

Expand Down

0 comments on commit 95881f0

Please sign in to comment.