Skip to content

Commit

Permalink
Merge pull request #40225 from radcortez/sr-config-3.8.0
Browse files Browse the repository at this point in the history
Update SmallRye Config to 3.8.1
  • Loading branch information
gsmet authored Apr 27, 2024
2 parents ba118c6 + 0a775e3 commit 9a768bb
Show file tree
Hide file tree
Showing 32 changed files with 389 additions and 187 deletions.
2 changes: 1 addition & 1 deletion bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<microprofile-lra.version>2.0</microprofile-lra.version>
<microprofile-openapi.version>3.1.1</microprofile-openapi.version>
<smallrye-common.version>2.3.0</smallrye-common.version>
<smallrye-config.version>3.7.1</smallrye-config.version>
<smallrye-config.version>3.8.1</smallrye-config.version>
<smallrye-health.version>4.1.0</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.10.0</smallrye-open-api.version>
Expand Down
4 changes: 4 additions & 0 deletions core/deployment/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-development-mode-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-validator-spi</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-class-change-agent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

public final class ConfigClassBuildItem extends MultiBuildItem {
private final Class<?> configClass;
/**
* All the config interfaces registered for this config mapping (including the nested ones)
*/
private final Set<Class<?>> configComponentInterfaces;
private final Set<Type> types;
private final Set<String> generatedClasses;
private final String prefix;
Expand All @@ -19,12 +23,14 @@ public final class ConfigClassBuildItem extends MultiBuildItem {

public ConfigClassBuildItem(
final Class<?> configClass,
final Set<Class<?>> configComponentInterfaces,
final Set<Type> types,
final Set<String> generatedClasses,
final String prefix,
final Kind kind) {

this.configClass = configClass;
this.configComponentInterfaces = configComponentInterfaces;
this.types = types;
this.generatedClasses = generatedClasses;
this.prefix = prefix;
Expand All @@ -36,6 +42,10 @@ public Class<?> getConfigClass() {
return configClass;
}

public Set<Class<?>> getConfigComponentInterfaces() {
return configComponentInterfaces;
}

public Set<Type> getTypes() {
return types;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,12 +524,6 @@ ReadResult run() {
buildTimeRunTimeValues.putAll(getDefaults(config, buildTimeRunTimePatternMap));
runTimeDefaultValues.putAll(getDefaults(runtimeConfig, runTimePatternMap));

// Register defaults for Mappings
// Runtime defaults are added in ConfigGenerationBuildStep.generateBuilders to include user mappings
for (ConfigClassWithPrefix buildTimeRunTimeMapping : buildTimeRunTimeMappings) {
buildTimeRunTimeValues.putAll(ConfigMappings.getDefaults(buildTimeRunTimeMapping));
}

Set<String> registeredRoots = allRoots.stream().map(RootDefinition::getName).collect(toSet());
registeredRoots.add("quarkus");
Set<String> allProperties = getAllProperties(registeredRoots);
Expand Down Expand Up @@ -1118,7 +1112,7 @@ public Set<String> getPropertyNames() {
}
});

String[] profiles = config.getProfiles().toArray(String[]::new);
List<String> profiles = config.getProfiles();
for (String property : builder.build().getPropertyNames()) {
properties.add(ProfileConfigSourceInterceptor.activeName(property, profiles));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import io.quarkus.deployment.builditem.ConfigClassBuildItem.Kind;
import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveMethodBuildItem;
import io.quarkus.deployment.util.ReflectUtil;
import io.quarkus.hibernate.validator.spi.AdditionalConstrainedClassBuildItem;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.ConfigMappingInterface;
import io.smallrye.config.ConfigMappingInterface.LeafProperty;
Expand All @@ -46,7 +48,9 @@ public static void processConfigClasses(
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethods,
BuildProducer<ConfigClassBuildItem> configClasses,
BuildProducer<AdditionalConstrainedClassBuildItem> additionalConstrainedClasses,
DotName configAnnotation) {

for (AnnotationInstance instance : combinedIndex.getIndex().getAnnotations(configAnnotation)) {
Expand All @@ -61,27 +65,32 @@ public static void processConfigClasses(
String prefix = Optional.ofNullable(annotationPrefix).map(AnnotationValue::asString).orElse("");
Kind configClassKind = getConfigClassType(instance);
processConfigClass(configClassWithPrefix(configClass, prefix), configClassKind, true, combinedIndex,
generatedClasses, reflectiveClasses, configClasses);
generatedClasses, reflectiveClasses, reflectiveMethods, configClasses, additionalConstrainedClasses);
}
}

public static void processConfigMapping(
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ConfigClassBuildItem> configClasses) {
processConfigClasses(combinedIndex, generatedClasses, reflectiveClasses, configClasses, CONFIG_MAPPING_NAME);
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethods,
BuildProducer<ConfigClassBuildItem> configClasses,
BuildProducer<AdditionalConstrainedClassBuildItem> additionalConstrainedClasses) {
processConfigClasses(combinedIndex, generatedClasses, reflectiveClasses, reflectiveMethods, configClasses,
additionalConstrainedClasses, CONFIG_MAPPING_NAME);
}

public static void processExtensionConfigMapping(
ConfigClassWithPrefix configClass,
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ConfigClassBuildItem> configClasses) {
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethods,
BuildProducer<ConfigClassBuildItem> configClasses,
BuildProducer<AdditionalConstrainedClassBuildItem> additionalConstrainedClasses) {

processConfigClass(configClass, Kind.MAPPING, false, combinedIndex, generatedClasses, reflectiveClasses,
configClasses);
reflectiveMethods, configClasses, additionalConstrainedClasses);
}

private static void processConfigClass(
Expand All @@ -91,30 +100,37 @@ private static void processConfigClass(
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ConfigClassBuildItem> configClasses) {
BuildProducer<ReflectiveMethodBuildItem> reflectiveMethods,
BuildProducer<ConfigClassBuildItem> configClasses,
BuildProducer<AdditionalConstrainedClassBuildItem> additionalConstrainedClasses) {

Class<?> configClass = configClassWithPrefix.getKlass();
String prefix = configClassWithPrefix.getPrefix();

List<ConfigMappingMetadata> configMappingsMetadata = ConfigMappingLoader.getConfigMappingsMetadata(configClass);
Set<String> generatedClassesNames = new HashSet<>();
// all the config interfaces including nested ones
Set<Class<?>> configComponentInterfaces = new HashSet<>();
configMappingsMetadata.forEach(mappingMetadata -> {
generatedClassesNames.add(mappingMetadata.getClassName());
// This is the generated implementation of the mapping by SmallRye Config.
byte[] classBytes = mappingMetadata.getClassBytes();
generatedClasses.produce(new GeneratedClassBuildItem(isApplicationClass, mappingMetadata.getClassName(),
mappingMetadata.getClassBytes()));
// Register the interface and implementation methods for reflection. This is required for Bean Validation.
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(mappingMetadata.getInterfaceType()).methods().build());
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(mappingMetadata.getClassName()).methods().build());
// Register also the interface hierarchy
for (Class<?> parent : getHierarchy(mappingMetadata.getInterfaceType())) {
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(parent).methods().build());
}
classBytes));
additionalConstrainedClasses.produce(AdditionalConstrainedClassBuildItem.of(mappingMetadata.getClassName(),
classBytes));
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(mappingMetadata.getClassName()).constructors().build());
reflectiveMethods
.produce(new ReflectiveMethodBuildItem(mappingMetadata.getClassName(), "getDefaults", new String[0]));
reflectiveMethods.produce(new ReflectiveMethodBuildItem(mappingMetadata.getClassName(), "getNames", new String[0]));

configComponentInterfaces.add(mappingMetadata.getInterfaceType());

processProperties(mappingMetadata.getInterfaceType(), reflectiveClasses);
});

configClasses.produce(new ConfigClassBuildItem(configClass, collectTypes(combinedIndex, configClass),
configClasses.produce(new ConfigClassBuildItem(configClass, configComponentInterfaces,
collectTypes(combinedIndex, configClass),
generatedClassesNames, prefix, configClassKind));
}

Expand All @@ -125,7 +141,6 @@ private static void processProperties(
ConfigMappingInterface mapping = ConfigMappingLoader.getConfigMapping(configClass);
for (Property property : mapping.getProperties()) {
Class<?> returnType = property.getMethod().getReturnType();
reflectiveClasses.produce(ReflectiveClassBuildItem.builder(returnType).methods().build());

if (property.hasConvertWith()) {
Class<? extends Converter<?>> convertWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,24 +1197,24 @@ private FieldDescriptor getOrCreateConverterInstance(Field field, ConverterType
Object.class);

private void generateUnknownFilter() {
Set<String> mappedProperties = new HashSet<>();
Set<String> names = new HashSet<>();
for (ConfigClassWithPrefix buildTimeMapping : buildTimeConfigResult.getBuildTimeMappings()) {
mappedProperties.addAll(ConfigMappings.getKeys(buildTimeMapping));
names.addAll(ConfigMappings.getProperties(buildTimeMapping).keySet());
}
for (ConfigClassWithPrefix staticConfigMapping : buildTimeConfigResult.getBuildTimeRunTimeMappings()) {
mappedProperties.addAll(ConfigMappings.getKeys(staticConfigMapping));
names.addAll(ConfigMappings.getProperties(staticConfigMapping).keySet());
}
for (ConfigClassWithPrefix runtimeConfigMapping : buildTimeConfigResult.getRunTimeMappings()) {
mappedProperties.addAll(ConfigMappings.getKeys(runtimeConfigMapping));
names.addAll(ConfigMappings.getProperties(runtimeConfigMapping).keySet());
}

// Add a method that generates a KeyMap that can check if a property is mapped by a @ConfigMapping
MethodCreator mc = cc.getMethodCreator(C_MAPPED_PROPERTIES);
mc.setModifiers(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
ResultHandle keyMap = mc.newInstance(KM_NEW);
for (String mappedProperty : mappedProperties) {
ResultHandle mappedPropertyKeyMap = mc.invokeVirtualMethod(KM_FIND_OR_ADD, keyMap, mc.load(mappedProperty));
mc.invokeVirtualMethod(KM_PUT_ROOT_VALUE, mappedPropertyKeyMap, mc.load(true));
for (String name : names) {
mc.invokeVirtualMethod(KM_PUT_ROOT_VALUE, mc.invokeVirtualMethod(KM_FIND_OR_ADD, keyMap, mc.load(name)),
mc.load(true));
}

mc.returnValue(keyMap);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ public void accept(Container node) {
private void processMappings(List<ConfigClassWithPrefix> mappings, List<ConfigDescriptionBuildItem> descriptionBuildItems,
Properties javaDocProperties, ConfigPhase configPhase) {
for (ConfigClassWithPrefix mapping : mappings) {
Map<String, Property> properties = ConfigMappings.getProperties(mapping).get(mapping.getKlass())
.get(mapping.getPrefix());
Map<String, Property> properties = ConfigMappings.getProperties(mapping);
for (Map.Entry<String, Property> entry : properties.entrySet()) {
String propertyName = entry.getKey();
Property property = entry.getValue();
Expand Down
Loading

0 comments on commit 9a768bb

Please sign in to comment.