Skip to content

Commit

Permalink
Merge pull request #44782 from gsmet/3.17.1-backports-1
Browse files Browse the repository at this point in the history
[3.17] 3.17.1 backports 1
  • Loading branch information
gsmet authored Nov 28, 2024
2 parents 4c3b5f6 + 1261e26 commit 18b863c
Show file tree
Hide file tree
Showing 76 changed files with 1,487 additions and 543 deletions.
6 changes: 3 additions & 3 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>4.0.3</smallrye-open-api.version>
<smallrye-graphql.version>2.11.0</smallrye-graphql.version>
<smallrye-fault-tolerance.version>6.6.2</smallrye-fault-tolerance.version>
<smallrye-fault-tolerance.version>6.6.3</smallrye-fault-tolerance.version>
<smallrye-jwt.version>4.6.1</smallrye-jwt.version>
<smallrye-context-propagation.version>2.1.2</smallrye-context-propagation.version>
<smallrye-reactive-streams-operators.version>1.0.13</smallrye-reactive-streams-operators.version>
Expand Down Expand Up @@ -157,7 +157,7 @@
<dekorate.version>4.1.4</dekorate.version> <!-- Please check with Java Operator SDK team before updating -->
<maven-invoker.version>3.2.0</maven-invoker.version>
<awaitility.version>4.2.2</awaitility.version>
<jboss-logmanager.version>3.0.6.Final</jboss-logmanager.version>
<jboss-logmanager.version>3.1.0.Final</jboss-logmanager.version>
<flyway.version>10.21.0</flyway.version>
<yasson.version>3.0.4</yasson.version>
<!-- liquibase-mongodb is not released everytime with liquibase anymore, but the two versions need to be compatible -->
Expand Down Expand Up @@ -195,7 +195,7 @@
<avro.version>1.12.0</avro.version>
<apicurio-registry.version>2.6.5.Final</apicurio-registry.version>
<apicurio-common-rest-client.version>0.1.18.Final</apicurio-common-rest-client.version> <!-- must be the version Apicurio Registry uses -->
<testcontainers.version>1.20.3</testcontainers.version> <!-- Make sure to also update docker-java.version to match its needs -->
<testcontainers.version>1.20.4</testcontainers.version> <!-- Make sure to also update docker-java.version to match its needs -->
<docker-java.version>3.4.0</docker-java.version> <!-- must be the version Testcontainers use: https://central.sonatype.com/artifact/org.testcontainers/testcontainers -->
<!-- Check the compatibility matrix (https://github.com/opensearch-project/opensearch-testcontainers) before upgrading: -->
<opensearch-testcontainers.version>2.0.2</opensearch-testcontainers.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public String getId() {
}

// ConfigMapping
ConfigClass mapping = readResult.getAllMappings().get(entry.getKey());
ConfigClass mapping = readResult.getAllMappingsByClass().get(entry.getKey());
if (mapping != null) {
mappingClasses.put(entry.getValue(), mapping);
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -628,9 +628,9 @@ ReadResult run() {
objectsByClass.put(mapping.getKlass(), config.getConfigMapping(mapping.getKlass(), mapping.getPrefix()));
}

Set<PropertyName> buildTimeNames = getMappingsNames(buildTimeMappings);
Set<PropertyName> buildTimeRunTimeNames = getMappingsNames(buildTimeRunTimeMappings);
Set<PropertyName> runTimeNames = getMappingsNames(runTimeMappings);
Set<PropertyName> buildTimeNames = mappingsToNames(buildTimeMappings).keySet();
Set<PropertyName> buildTimeRunTimeNames = mappingsToNames(buildTimeRunTimeMappings).keySet();
Set<PropertyName> runTimeNames = mappingsToNames(runTimeMappings).keySet();
for (String property : allProperties) {
PropertyName name = new PropertyName(property);
if (buildTimeNames.contains(name)) {
Expand Down Expand Up @@ -1222,12 +1222,32 @@ private static void getDefaults(
}
}

private static Set<PropertyName> getMappingsNames(final List<ConfigClass> configMappings) {
private static Map<PropertyName, String> mappingsToNames(final List<ConfigClass> configMappings) {
Set<String> names = new HashSet<>();
for (ConfigClass configMapping : configMappings) {
names.addAll(ConfigMappings.getProperties(configMapping).keySet());
}
return PropertiesUtil.toPropertyNames(names);
Map<PropertyName, String> propertyNames = new HashMap<>();
for (String name : names) {
PropertyName propertyName = new PropertyName(name);
if (propertyNames.containsKey(propertyName)) {
String existing = propertyNames.remove(propertyName);
if (existing.length() < name.length()) {
propertyNames.put(new PropertyName(existing), existing);
} else if (existing.length() > name.length()) {
propertyNames.put(propertyName, name);
} else {
if (existing.indexOf('*') <= name.indexOf('*')) {
propertyNames.put(new PropertyName(existing), existing);
} else {
propertyNames.put(propertyName, name);
}
}
} else {
propertyNames.put(propertyName, name);
}
}
return propertyNames;
}
}

Expand All @@ -1249,7 +1269,9 @@ public static final class ReadResult {
final List<ConfigClass> buildTimeMappings;
final List<ConfigClass> buildTimeRunTimeMappings;
final List<ConfigClass> runTimeMappings;
final Map<Class<?>, ConfigClass> allMappings;
final List<ConfigClass> allMappings;
final Map<Class<?>, ConfigClass> allMappingsByClass;
final Map<PropertyName, String> allMappingsNames;

final Set<String> unknownBuildProperties;
final Set<String> deprecatedRuntimeProperties;
Expand All @@ -1273,7 +1295,9 @@ public ReadResult(final Builder builder) {
this.buildTimeMappings = builder.getBuildTimeMappings();
this.buildTimeRunTimeMappings = builder.getBuildTimeRunTimeMappings();
this.runTimeMappings = builder.getRunTimeMappings();
this.allMappings = mappingsToMap(builder);
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 @@ -1355,10 +1379,18 @@ public List<ConfigClass> getRunTimeMappings() {
return runTimeMappings;
}

public Map<Class<?>, ConfigClass> getAllMappings() {
public List<ConfigClass> getAllMappings() {
return allMappings;
}

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 @@ -6,6 +6,7 @@

import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
Expand Down Expand Up @@ -63,6 +64,7 @@
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;
Expand All @@ -88,9 +90,6 @@ public final class RunTimeConfigurationGenerator {
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 MethodDescriptor C_GENERATE_MAPPED_PROPERTIES = MethodDescriptor.ofMethod(CONFIG_CLASS_NAME,
"generateMappedProperties", Set.class);
static final MethodDescriptor PN_NEW = MethodDescriptor.ofConstructor(PropertyName.class, String.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 @@ -192,9 +191,13 @@ public final class RunTimeConfigurationGenerator {
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 @@ -262,7 +265,6 @@ public static final class GenerateOperation implements AutoCloseable {
roots = Assert.checkNotNullParam("builder.roots", builder.getBuildTimeReadResult().getAllRoots());
additionalTypes = Assert.checkNotNullParam("additionalTypes", builder.getAdditionalTypes());
cc = ClassCreator.builder().classOutput(classOutput).className(CONFIG_CLASS_NAME).setFinal(true).build();
generateMappedProperties();
generateEmptyParsers();
// not instantiable
try (MethodCreator mc = cc.getMethodCreator(MethodDescriptor.ofConstructor(CONFIG_CLASS_NAME))) {
Expand All @@ -282,14 +284,17 @@ public static final class GenerateOperation implements AutoCloseable {
clinit.setModifiers(Opcodes.ACC_STATIC);

cc.getFieldCreator(C_MAPPED_PROPERTIES).setModifiers(Opcodes.ACC_STATIC);
clinit.writeStaticField(C_MAPPED_PROPERTIES, clinit.invokeStaticMethod(C_GENERATE_MAPPED_PROPERTIES));
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();

clinitNameBuilder = clinit.newInstance(SB_NEW);

// the build time config, which is for user use only (not used by us other than for loading converters)
Expand Down Expand Up @@ -1181,26 +1186,32 @@ private FieldDescriptor getOrCreateConverterInstance(Field field, ConverterType
}

private void generateMappedProperties() {
Set<String> names = new HashSet<>();
for (ConfigClass buildTimeMapping : buildTimeConfigResult.getBuildTimeMappings()) {
names.addAll(ConfigMappings.getProperties(buildTimeMapping).keySet());
}
for (ConfigClass staticConfigMapping : buildTimeConfigResult.getBuildTimeRunTimeMappings()) {
names.addAll(ConfigMappings.getProperties(staticConfigMapping).keySet());
}
for (ConfigClass runtimeConfigMapping : buildTimeConfigResult.getRunTimeMappings()) {
names.addAll(ConfigMappings.getProperties(runtimeConfigMapping).keySet());
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()));
}
Set<PropertyName> propertyNames = PropertiesUtil.toPropertyNames(names);
mc.returnVoid();
mc.close();
clinit.invokeStaticMethod(method);
}

MethodCreator mc = cc.getMethodCreator(C_GENERATE_MAPPED_PROPERTIES);
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);
MethodCreator mc = cc.getMethodCreator(method);
mc.setModifiers(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
ResultHandle set = mc.newInstance(HS_NEW);
for (PropertyName propertyName : propertyNames) {
mc.invokeVirtualMethod(HS_ADD, set, mc.newInstance(PN_NEW, mc.load(propertyName.getName())));
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)));
}
mc.returnValue(set);
mc.returnVoid();
mc.close();
return method;
}

private void reportUnknown(BytecodeCreator bc, ResultHandle unknownProperty) {
Expand Down
Loading

0 comments on commit 18b863c

Please sign in to comment.