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

Improve reportUnknown allocations #1263

Merged
merged 1 commit into from
Dec 3, 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 @@ -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
Loading