Skip to content

Commit 3cafdff

Browse files
authored
Merge pull request quarkusio#35726 from radcortez/alloc-improv
Improve matching of config properties to a root
2 parents 508e4f9 + e90f074 commit 3cafdff

File tree

2 files changed

+69
-13
lines changed

2 files changed

+69
-13
lines changed

core/deployment/src/main/java/io/quarkus/deployment/configuration/RunTimeConfigurationGenerator.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,9 @@ public final class RunTimeConfigurationGenerator {
227227

228228
static final MethodDescriptor PU_IS_PROPERTY_IN_ROOT = MethodDescriptor.ofMethod(PropertiesUtil.class,
229229
"isPropertyInRoot", boolean.class, Set.class, NameIterator.class);
230+
static final MethodDescriptor PU_FILTER_PROPERTIES_IN_ROOTS = MethodDescriptor.ofMethod(PropertiesUtil.class,
231+
"filterPropertiesInRoots", Iterable.class, Iterable.class, Set.class);
232+
230233
static final MethodDescriptor PU_IS_PROPERTY_QUARKUS_COMPOUND_NAME = MethodDescriptor.ofMethod(PropertiesUtil.class,
231234
"isPropertyQuarkusCompoundName", boolean.class, NameIterator.class);
232235
static final MethodDescriptor PU_FILTER_UNKNOWN = MethodDescriptor.ofMethod(PropertiesUtil.class, "filterUnknown",
@@ -668,16 +671,10 @@ public void run() {
668671

669672
private void configSweepLoop(MethodDescriptor parserBody, MethodCreator method, ResultHandle config,
670673
Set<String> registeredRoots, Type type) {
671-
ResultHandle rootSet;
672674
ResultHandle nameSet;
673675
ResultHandle iterator;
674676

675-
rootSet = method.newInstance(HS_NEW);
676-
for (String registeredRoot : registeredRoots) {
677-
method.invokeVirtualMethod(HS_ADD, rootSet, method.load(registeredRoot));
678-
}
679-
680-
nameSet = method.invokeVirtualMethod(SRC_GET_PROPERTY_NAMES, config);
677+
nameSet = filterProperties(method, config, registeredRoots);
681678
iterator = method.invokeInterfaceMethod(ITRA_ITERATOR, nameSet);
682679

683680
try (BytecodeCreator sweepLoop = method.createScope()) {
@@ -701,8 +698,6 @@ private void configSweepLoop(MethodDescriptor parserBody, MethodCreator method,
701698
// if (! keyIter.hasNext()) continue sweepLoop;
702699
hasNext.ifNonZero(hasNext.invokeVirtualMethod(NI_HAS_NEXT, keyIter)).falseBranch().continueScope(sweepLoop);
703700
// if (! keyIter.nextSegmentEquals("quarkus")) continue sweepLoop;
704-
hasNext.ifNonZero(hasNext.invokeStaticMethod(PU_IS_PROPERTY_IN_ROOT, rootSet, keyIter)).falseBranch()
705-
.continueScope(sweepLoop);
706701
// parse(config, keyIter);
707702
hasNext.invokeStaticMethod(parserBody, config, keyIter);
708703
// continue sweepLoop;
@@ -711,6 +706,21 @@ private void configSweepLoop(MethodDescriptor parserBody, MethodCreator method,
711706
}
712707
}
713708

709+
private ResultHandle filterProperties(MethodCreator method, ResultHandle config, Set<String> registeredRoots) {
710+
// Roots
711+
ResultHandle rootSet;
712+
rootSet = method.newInstance(HS_NEW);
713+
for (String registeredRoot : registeredRoots) {
714+
method.invokeVirtualMethod(HS_ADD, rootSet, method.load(registeredRoot));
715+
}
716+
717+
// PropertyNames
718+
ResultHandle properties = method.invokeVirtualMethod(SRC_GET_PROPERTY_NAMES, config);
719+
720+
// Filtered Properties
721+
return method.invokeStaticMethod(PU_FILTER_PROPERTIES_IN_ROOTS, properties, rootSet);
722+
}
723+
714724
private Set<String> getRegisteredRoots(ConfigPhase configPhase) {
715725
Set<String> registeredRoots = new HashSet<>();
716726
for (RootDefinition root : roots) {

core/runtime/src/main/java/io/quarkus/runtime/configuration/PropertiesUtil.java

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package io.quarkus.runtime.configuration;
22

3+
import java.util.ArrayList;
34
import java.util.HashSet;
5+
import java.util.List;
46
import java.util.Set;
57

68
import io.smallrye.config.KeyMap;
@@ -51,11 +53,55 @@ public static boolean isPropertyInRoot(Set<String> roots, NameIterator propertyN
5153
return false;
5254
}
5355

54-
public static boolean isPropertyQuarkusCompoundName(NameIterator propertyName) {
55-
if (propertyName.hasNext()) {
56-
return propertyName.getNextSegment().startsWith("quarkus.");
56+
public static Iterable<String> filterPropertiesInRoots(final Iterable<String> properties, final Set<String> roots) {
57+
if (roots.isEmpty()) {
58+
return properties;
5759
}
58-
return false;
60+
61+
// Will match everything, so no point in filtering
62+
if (roots.contains("")) {
63+
return properties;
64+
}
65+
66+
List<String> matchedProperties = new ArrayList<>();
67+
for (String property : properties) {
68+
// This is a Quarkus compound name, usually by setting something like `quarkus.foo.bar` in the YAML source
69+
// TODO - We let it through to match it later again to place it in the right unknown reporting (static or runtime). We can improve this too.
70+
if (property.startsWith("\"quarkus.")) {
71+
matchedProperties.add(property);
72+
continue;
73+
}
74+
75+
for (String root : roots) {
76+
// if property is less than the root no way to match
77+
if (property.length() < root.length()) {
78+
continue;
79+
}
80+
81+
// if it is the same, then it can still map with parent name
82+
if (property.equals(root)) {
83+
matchedProperties.add(property);
84+
break;
85+
} else if (property.length() == root.length()) {
86+
continue;
87+
}
88+
89+
// foo.bar
90+
// foo.bar."baz"
91+
// foo.bar[0]
92+
char c = property.charAt(root.length());
93+
if ((c == '.') || c == '[') {
94+
if (property.startsWith(root)) {
95+
matchedProperties.add(property);
96+
}
97+
}
98+
}
99+
}
100+
return matchedProperties;
101+
}
102+
103+
public static boolean isPropertyQuarkusCompoundName(NameIterator propertyName) {
104+
return propertyName.getName().startsWith("\"quarkus.");
59105
}
60106

61107
/**

0 commit comments

Comments
 (0)