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

Update SmallRye Config to 3.11.0 #44924

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<microprofile-lra.version>2.0</microprofile-lra.version>
<microprofile-openapi.version>4.0.2</microprofile-openapi.version>
<smallrye-common.version>2.9.0</smallrye-common.version>
<smallrye-config.version>3.10.2</smallrye-config.version>
<smallrye-config.version>3.11.1</smallrye-config.version>
<smallrye-health.version>4.1.1</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>4.0.6</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1212,7 +1212,7 @@ private static void getDefaults(
.withName(propertyName.toString())
.withValue(defaultValue)
.withRawValue(defaultValue)
.withConfigSourceName("DefaultValuesConfigSource")
.withConfigSourceName(DefaultValuesConfigSource.NAME)
.withConfigSourceOrdinal(Integer.MIN_VALUE)
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ private static void processConfigClass(
.reason(ConfigMappingUtils.class.getName())
.build());
reflectiveMethods.produce(new ReflectiveMethodBuildItem(ConfigMappingUtils.class.getName(),
mappingMetadata.getClassName(), "getDefaults", new String[0]));
reflectiveMethods.produce(new ReflectiveMethodBuildItem(ConfigMappingUtils.class.getName(),
mappingMetadata.getClassName(), "getNames", new String[0]));
mappingMetadata.getClassName(), "getProperties", new String[0]));

configComponentInterfaces.add(mappingMetadata.getInterfaceType());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.ArrayDeque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -64,8 +64,6 @@
import io.quarkus.runtime.configuration.NameIterator;
import io.quarkus.runtime.configuration.PropertiesUtil;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.smallrye.config.ConfigMappingInterface;
import io.smallrye.config.ConfigMappings;
import io.smallrye.config.ConfigMappings.ConfigClass;
import io.smallrye.config.Converters;
import io.smallrye.config.PropertyName;
Expand All @@ -89,7 +87,6 @@ public final class RunTimeConfigurationGenerator {
void.class);
public static final MethodDescriptor C_READ_CONFIG = MethodDescriptor.ofMethod(CONFIG_CLASS_NAME, "readConfig", void.class);

static final FieldDescriptor C_MAPPED_PROPERTIES = FieldDescriptor.of(CONFIG_CLASS_NAME, "mappedProperties", Set.class);
static final FieldDescriptor C_UNKNOWN = FieldDescriptor.of(CONFIG_CLASS_NAME, "unknown", Set.class);
static final FieldDescriptor C_UNKNOWN_RUNTIME = FieldDescriptor.of(CONFIG_CLASS_NAME, "unknownRuntime", Set.class);

Expand Down Expand Up @@ -149,6 +146,7 @@ public final class RunTimeConfigurationGenerator {
boolean.class, String.class);
static final MethodDescriptor NI_NEXT = MethodDescriptor.ofMethod(NameIterator.class, "next", void.class);
static final MethodDescriptor NI_PREVIOUS = MethodDescriptor.ofMethod(NameIterator.class, "previous", void.class);
static final MethodDescriptor NI_GO_TO_START = MethodDescriptor.ofMethod(NameIterator.class, "goToStart", void.class);

static final MethodDescriptor OBJ_TO_STRING = MethodDescriptor.ofMethod(Object.class, "toString", String.class);

Expand Down Expand Up @@ -186,18 +184,16 @@ public final class RunTimeConfigurationGenerator {
static final MethodDescriptor SRCB_BUILD = MethodDescriptor.ofMethod(SmallRyeConfigBuilder.class, "build",
SmallRyeConfig.class);

static final MethodDescriptor PU_IS_MAPPED = MethodDescriptor.ofMethod(PropertiesUtil.class, "isMapped", boolean.class,
NameIterator.class, String.class);
static final MethodDescriptor PU_IS_PROPERTY_QUARKUS_COMPOUND_NAME = MethodDescriptor.ofMethod(PropertiesUtil.class,
"isPropertyQuarkusCompoundName", boolean.class, NameIterator.class);
static final MethodDescriptor PU_IS_PROPERTY_IN_ROOTS = MethodDescriptor.ofMethod(PropertiesUtil.class, "isPropertyInRoots",
boolean.class, String.class, Set.class);

static final MethodDescriptor HS_NEW = MethodDescriptor.ofConstructor(HashSet.class);
static final MethodDescriptor HS_NEW_SIZED = MethodDescriptor.ofConstructor(HashSet.class, int.class);
static final MethodDescriptor HS_ADD = MethodDescriptor.ofMethod(HashSet.class, "add", boolean.class, Object.class);
static final MethodDescriptor HS_ADD_ALL = MethodDescriptor.ofMethod(HashSet.class, "addAll", boolean.class,
Collection.class);
static final MethodDescriptor HS_CONTAINS = MethodDescriptor.ofMethod(HashSet.class, "contains", boolean.class,
Object.class);
static final MethodDescriptor PN_NEW = MethodDescriptor.ofConstructor(PropertyName.class, String.class);

// todo: more space-efficient sorted map impl
static final MethodDescriptor TM_NEW = MethodDescriptor.ofConstructor(TreeMap.class);
Expand Down Expand Up @@ -274,17 +270,13 @@ public static final class GenerateOperation implements AutoCloseable {
clinit = cc.getMethodCreator(MethodDescriptor.ofMethod(CONFIG_CLASS_NAME, "<clinit>", void.class));
clinit.setModifiers(Opcodes.ACC_STATIC);

cc.getFieldCreator(C_MAPPED_PROPERTIES).setModifiers(Opcodes.ACC_STATIC);
clinit.writeStaticField(C_MAPPED_PROPERTIES, clinit.newInstance(HS_NEW_SIZED,
clinit.load((int) ((float) buildTimeConfigResult.getAllMappingsNames().size() / 0.75f + 1.0f))));

cc.getFieldCreator(C_UNKNOWN).setModifiers(Opcodes.ACC_STATIC);
clinit.writeStaticField(C_UNKNOWN, clinit.newInstance(HS_NEW));

cc.getFieldCreator(C_UNKNOWN_RUNTIME).setModifiers(Opcodes.ACC_STATIC);
clinit.writeStaticField(C_UNKNOWN_RUNTIME, clinit.newInstance(HS_NEW));

generateMappedProperties();
generateIsMapped();

clinitNameBuilder = clinit.newInstance(SB_NEW);

Expand Down Expand Up @@ -530,14 +522,18 @@ private void configSweepLoop(MethodDescriptor parserBody, MethodCreator method,
.trueBranch()) {
ResultHandle key = hasNext.checkCast(hasNext.invokeInterfaceMethod(ITR_NEXT, iterator), String.class);

// !mappedProperties.contains(new PropertyName(key)) continue sweepLoop;
hasNext.ifNonZero(
hasNext.invokeVirtualMethod(HS_CONTAINS, hasNext.readStaticField(C_MAPPED_PROPERTIES),
hasNext.newInstance(PN_NEW, key)))
.trueBranch().continueScope(sweepLoop);

// NameIterator keyIter = new NameIterator(key);
ResultHandle keyIter = hasNext.newInstance(NI_NEW_STRING, key);
// if (!isMappedProperty(keyIter))
ResultHandle isMappedName = hasNext.invokeStaticMethod(
MethodDescriptor.ofMethod(CONFIG_CLASS_NAME, "isMapped", boolean.class, NameIterator.class),
keyIter);
try (BytecodeCreator isMappedPropertyTrue = hasNext.ifTrue(isMappedName).trueBranch()) {
isMappedPropertyTrue.continueScope(sweepLoop);
}

// keyIter.goToStart() - reset the NameIterator so it can be used by the ConfigRoot code
hasNext.invokeVirtualMethod(NI_GO_TO_START, keyIter);

// if (PropertiesUtil.isPropertyQuarkusCompoundName(keyIter))
BranchResult quarkusCompoundName = hasNext
Expand Down Expand Up @@ -1186,33 +1182,74 @@ private FieldDescriptor getOrCreateConverterInstance(Field field, ConverterType
return fd;
}

private void generateMappedProperties() {
MethodDescriptor method = MethodDescriptor.ofMethod(CONFIG_CLASS_NAME, "addMappedProperties", void.class);
MethodCreator mc = cc.getMethodCreator(method);
mc.setModifiers(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
for (ConfigClass mapping : buildTimeConfigResult.getAllMappings()) {
mc.invokeStaticMethod(generateMappedProperties(mapping, buildTimeConfigResult.getAllMappingsNames()));
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);
}
current = child;
name.next();
}
current.setMatched(true);
}
mc.returnVoid();
mc.close();
clinit.invokeStaticMethod(method);

generateIsMapped("isMapped", patterns);
}

private MethodDescriptor generateMappedProperties(final ConfigClass mapping,
final Map<PropertyName, String> propertyNames) {
MethodDescriptor method = MethodDescriptor.ofMethod(CONFIG_CLASS_NAME,
"addMappedProperties$" + mapping.getKlass().getName().replace('.', '$'), void.class);
private void generateIsMapped(final String methodName, final ConfigPatternMap<Boolean> names) {
MethodDescriptor method = MethodDescriptor.ofMethod(CONFIG_CLASS_NAME, methodName, boolean.class,
NameIterator.class);
MethodCreator mc = cc.getMethodCreator(method);
mc.setModifiers(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
Map<String, ConfigMappingInterface.Property> properties = ConfigMappings.getProperties(mapping);
ResultHandle set = mc.readStaticField(C_MAPPED_PROPERTIES);
for (String propertyName : properties.keySet()) {
String name = propertyNames.get(new PropertyName(propertyName));
mc.invokeVirtualMethod(HS_ADD, set, mc.newInstance(PN_NEW, mc.load(name)));

ResultHandle nameIterator = mc.getMethodParam(0);
BranchResult hasNext = mc.ifTrue(mc.invokeVirtualMethod(NI_HAS_NEXT, nameIterator));

try (BytecodeCreator hasNextTrue = hasNext.trueBranch()) {
ArrayDeque<String> childNames = new ArrayDeque<>();
// * matching has to come last
for (String childName : names.childNames()) {
if (childName.startsWith("*")) {
childNames.addLast(childName);
} else {
childNames.addFirst(childName);
}
}

for (String childName : childNames) {
ConfigPatternMap<Boolean> child = names.getChild(childName);
BranchResult nextEquals = hasNextTrue
.ifTrue(hasNextTrue.invokeStaticMethod(PU_IS_MAPPED, nameIterator, hasNextTrue.load(childName)));
try (BytecodeCreator nextEqualsTrue = nextEquals.trueBranch()) {
String childMethodName = methodName + "$" + childName.replace("[*]", "-collection");
if (child.getMatched() == null) {
generateIsMapped(childMethodName, child);
nextEqualsTrue.invokeVirtualMethod(NI_NEXT, nameIterator);
nextEqualsTrue
.returnValue(nextEqualsTrue.invokeStaticMethod(MethodDescriptor.ofMethod(CONFIG_CLASS_NAME,
childMethodName, boolean.class, NameIterator.class), nameIterator));
} else {
nextEqualsTrue.returnBoolean(true);
}
}
}
hasNextTrue.returnBoolean(false);
}
mc.returnVoid();

try (BytecodeCreator hasNextFalse = hasNext.falseBranch()) {
hasNextFalse.returnBoolean(false);
}

mc.returnBoolean(false);
mc.close();
return method;
}

private void reportUnknown(BytecodeCreator bc, ResultHandle unknownProperty) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ void generateBuilders(
SmallRyeConfig config = ConfigProvider.getConfig().unwrap(SmallRyeConfig.class);
List<String> profiles = config.getProfiles();
for (Map.Entry<String, ConfigValue> entry : configItem.getReadResult().getRunTimeValues().entrySet()) {
if ("DefaultValuesConfigSource".equals(entry.getValue().getConfigSourceName())) {
if (DefaultValuesConfigSource.NAME.equals(entry.getValue().getConfigSourceName())) {
continue;
}
// Runtime values may contain active profiled names that override sames names in defaults
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.jboss.logging.Logger;

import io.quarkus.runtime.annotations.Recorder;
import io.smallrye.config.DefaultValuesConfigSource;
import io.smallrye.config.SmallRyeConfig;

@Recorder
Expand All @@ -20,7 +21,7 @@ public void reportDeprecatedProperties(Set<String> deprecatedRuntimeProperties)
if (deprecatedRuntimeProperties.contains(property)) {
String configSourceName = ((SmallRyeConfig) config).getConfigValue(property).getConfigSourceName();
// this condition can be removed when support of the @ConfigRoot annotation on classes is removed
if ("DefaultValuesConfigSource".equals(configSourceName)) {
if (DefaultValuesConfigSource.NAME.equals(configSourceName)) {
continue;
}
log.warnf("The '%s' config property is deprecated and should not be used anymore", property);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@

import java.util.Set;

import io.smallrye.config.PropertyName;

public class PropertiesUtil {
private PropertiesUtil() {
throw new IllegalStateException("Utility class");
}

public static boolean isMapped(final NameIterator name, final String mapped) {
int offset = name.getPosition() == -1 ? 0 : name.getPosition() + 1;
int len = name.getNextEnd() == 0 ? name.getName().length() : name.getNextEnd() - offset;
return PropertyName.equals(name.getName(), offset, len, mapped, 0, mapped.length());
}

public static boolean isPropertyInRoots(final String property, final Set<String> roots) {
for (String root : roots) {
if (isPropertyInRoot(property, root)) {
Expand Down
2 changes: 1 addition & 1 deletion devtools/gradle/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugin-publish = "1.3.0"

# updating Kotlin here makes QuarkusPluginTest > shouldNotFailOnProjectDependenciesWithoutMain(Path) fail
kotlin = "2.0.21"
smallrye-config = "3.10.2"
smallrye-config = "3.11.1"

junit5 = "5.10.5"
assertj = "3.27.2"
Expand Down
Loading
Loading