Skip to content

Commit

Permalink
Use SmallRyeConfigBuilder Customizer to generate Quarkus configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez committed Sep 26, 2023
1 parent 705de0b commit db75685
Show file tree
Hide file tree
Showing 41 changed files with 605 additions and 777 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.1.2</smallrye-common.version>
<smallrye-config.version>3.3.4</smallrye-config.version>
<smallrye-config.version>3.4.0</smallrye-config.version>
<smallrye-health.version>4.0.4</smallrye-health.version>
<smallrye-metrics.version>4.0.0</smallrye-metrics.version>
<smallrye-open-api.version>3.5.2</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.jboss.logging.Logger;
import org.wildfly.common.function.Functions;

Expand Down Expand Up @@ -136,16 +135,8 @@ public static Consumer<BuildChainBuilder> loadStepsFrom(ClassLoader classLoader,

final BuildTimeConfigurationReader reader = new BuildTimeConfigurationReader(classLoader);
final SmallRyeConfig src = reader.initConfiguration(launchMode, buildSystemProps, appModel.getPlatformProperties());

// install globally
QuarkusConfigFactory.setConfig(src);
final ConfigProviderResolver cpr = ConfigProviderResolver.instance();
try {
cpr.releaseConfig(cpr.getConfig());
} catch (IllegalStateException ignored) {
// just means no config was installed, which is fine
}

final BuildTimeConfigurationReader.ReadResult readResult = reader.readConfiguration(src);
final BooleanSupplierFactoryBuildItem bsf = new BooleanSupplierFactoryBuildItem(readResult, launchMode, devModeType);

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

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.runtime.annotations.StaticInitSafe;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;

public final class ConfigMappingBuildItem extends MultiBuildItem {
private final Class<?> configClass;
Expand All @@ -26,6 +27,10 @@ public boolean isStaticInitSafe() {
return configClass.isAnnotationPresent(StaticInitSafe.class);
}

public ConfigClassWithPrefix toConfigClassWithPrefix() {
return new ConfigClassWithPrefix(configClass, prefix);
}

@Override
public boolean equals(final Object o) {
if (this == o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,6 @@ final class ReadOperation {
final SmallRyeConfig config;
final ConfigTrackingInterceptor buildConfigTracker;
final Set<String> processedNames = new HashSet<>();

final Map<Class<?>, Object> objectsByClass = new HashMap<>();
final Map<String, String> allBuildTimeValues = new TreeMap<>();
final Map<String, String> buildTimeRunTimeValues = new TreeMap<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.deployment.configuration;

import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
import static org.jboss.jandex.AnnotationTarget.Kind.CLASS;

import java.util.ArrayList;
Expand Down Expand Up @@ -32,6 +33,7 @@
import io.smallrye.config.ConfigMappingInterface.Property;
import io.smallrye.config.ConfigMappingLoader;
import io.smallrye.config.ConfigMappingMetadata;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;

public class ConfigMappingUtils {

Expand All @@ -58,33 +60,42 @@ public static void processConfigClasses(
Class<?> configClass = toClass(target.asClass().name());
String prefix = Optional.ofNullable(annotationPrefix).map(AnnotationValue::asString).orElse("");
Kind configClassKind = getConfigClassType(instance);
processConfigClass(configClass, configClassKind, prefix, true, combinedIndex, generatedClasses, reflectiveClasses,
configClasses);
processConfigClass(configClassWithPrefix(configClass, prefix), configClassKind, true, combinedIndex,
generatedClasses, reflectiveClasses, configClasses);
}
}

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

public static void processExtensionConfigMapping(
Class<?> configClass,
String prefix,
ConfigClassWithPrefix configClass,
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ConfigClassBuildItem> configClasses) {

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

private static void processConfigClass(
Class<?> configClass,
ConfigClassWithPrefix configClassWithPrefix,
Kind configClassKind,
String prefix,
boolean isApplicationClass,
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
BuildProducer<ConfigClassBuildItem> configClasses) {

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

List<ConfigMappingMetadata> configMappingsMetadata = ConfigMappingLoader.getConfigMappingsMetadata(configClass);
Set<String> generatedClassesNames = new HashSet<>();
configMappingsMetadata.forEach(mappingMetadata -> {
Expand Down
Loading

0 comments on commit db75685

Please sign in to comment.