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

Strict config lookup for the REST Client #43345

Merged
merged 2 commits into from
Oct 22, 2024
Merged
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 @@ -48,7 +48,7 @@
<microprofile-lra.version>2.0</microprofile-lra.version>
<microprofile-openapi.version>3.1.2</microprofile-openapi.version>
<smallrye-common.version>2.8.0</smallrye-common.version>
<smallrye-config.version>3.9.1</smallrye-config.version>
<smallrye-config.version>3.10.0</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.13.0</smallrye-open-api.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
import io.quarkus.runtime.annotations.Recorder;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.quarkus.runtime.util.HashUtil;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigMappings.ConfigClass;
import io.smallrye.config.SmallRyeConfig;

/**
Expand Down Expand Up @@ -172,7 +172,7 @@ public String getId() {

// this has to be an identity hash map else the recorder will get angry
Map<Object, FieldDescriptor> rootFields = new IdentityHashMap<>();
Map<Object, ConfigClassWithPrefix> mappingClasses = new IdentityHashMap<>();
Map<Object, ConfigClass> mappingClasses = new IdentityHashMap<>();
for (Map.Entry<Class<?>, Object> entry : proxies.entrySet()) {
// ConfigRoot
RootDefinition root = readResult.getAllRootsByClass().get(entry.getKey());
Expand All @@ -182,7 +182,7 @@ public String getId() {
}

// ConfigMapping
ConfigClassWithPrefix mapping = readResult.getAllMappings().get(entry.getKey());
ConfigClass mapping = readResult.getAllMappings().get(entry.getKey());
if (mapping != null) {
mappingClasses.put(entry.getValue(), mapping);
continue;
Expand Down Expand Up @@ -210,7 +210,7 @@ public boolean canHandleObject(final Object obj, final boolean staticInit) {
ObjectLoader mappingLoader = new ObjectLoader() {
@Override
public ResultHandle load(final BytecodeCreator body, final Object obj, final boolean staticInit) {
ConfigClassWithPrefix mapping = mappingClasses.get(obj);
ConfigClass mapping = mappingClasses.get(obj);
MethodDescriptor getConfig = MethodDescriptor.ofMethod(ConfigProvider.class, "getConfig", Config.class);
ResultHandle config = body.invokeStaticMethod(getConfig);
MethodDescriptor getMapping = MethodDescriptor.ofMethod(SmallRyeConfig.class, "getConfigMapping",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

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

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

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

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import static io.quarkus.deployment.util.ReflectUtil.toError;
import static io.quarkus.deployment.util.ReflectUtil.typeOfParameter;
import static io.quarkus.deployment.util.ReflectUtil.unwrapInvocationTargetException;
import static io.quarkus.runtime.configuration.PropertiesUtil.isPropertyInRoots;
import static io.smallrye.config.ConfigMappings.ConfigClassWithPrefix.configClassWithPrefix;
import static io.smallrye.config.ConfigMappings.ConfigClass.configClass;
import static io.smallrye.config.Expressions.withoutExpansion;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE;
import static io.smallrye.config.SmallRyeConfig.SMALLRYE_CONFIG_PROFILE_PARENT;
Expand Down Expand Up @@ -74,7 +73,7 @@
import io.quarkus.runtime.configuration.PropertiesUtil;
import io.smallrye.config.ConfigMapping;
import io.smallrye.config.ConfigMappings;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigMappings.ConfigClass;
import io.smallrye.config.ConfigValue;
import io.smallrye.config.Converters;
import io.smallrye.config.DefaultValuesConfigSource;
Expand Down Expand Up @@ -119,10 +118,10 @@ private static List<Class<?>> collectConfigRoots(ClassLoader classLoader) throws
final List<RootDefinition> allRoots;
final List<RootDefinition> buildTimeVisibleRoots;

final List<ConfigClassWithPrefix> buildTimeMappings;
final List<ConfigClassWithPrefix> buildTimeRunTimeMappings;
final List<ConfigClassWithPrefix> runTimeMappings;
final List<ConfigClassWithPrefix> buildTimeVisibleMappings;
final List<ConfigClass> buildTimeMappings;
final List<ConfigClass> buildTimeRunTimeMappings;
final List<ConfigClass> runTimeMappings;
final List<ConfigClass> buildTimeVisibleMappings;

final Set<String> deprecatedProperties;
final Set<String> deprecatedRuntimeProperties;
Expand Down Expand Up @@ -183,7 +182,7 @@ private BuildTimeConfigurationReader(ClassLoader classLoader, final List<Class<?
phase = annotation.phase();
}

ConfigClassWithPrefix mapping = configClassWithPrefix(configRoot);
ConfigClass mapping = configClass(configRoot);
if (phase.equals(ConfigPhase.BUILD_TIME)) {
buildTimeMappings.add(mapping);
} else if (phase.equals(ConfigPhase.BUILD_AND_RUN_TIME_FIXED)) {
Expand Down Expand Up @@ -360,15 +359,15 @@ public List<RootDefinition> getAllRoots() {
return allRoots;
}

public List<ConfigClassWithPrefix> getBuildTimeMappings() {
public List<ConfigClass> getBuildTimeMappings() {
return buildTimeMappings;
}

public List<ConfigClassWithPrefix> getBuildTimeRunTimeMappings() {
public List<ConfigClass> getBuildTimeRunTimeMappings() {
return buildTimeRunTimeMappings;
}

public List<ConfigClassWithPrefix> getBuildTimeVisibleMappings() {
public List<ConfigClass> getBuildTimeVisibleMappings() {
return buildTimeVisibleMappings;
}

Expand Down Expand Up @@ -401,8 +400,8 @@ public SmallRyeConfig initConfiguration(LaunchMode launchMode, Properties buildS
new DefaultValuesConfigSource(platformProperties, "Quarkus platform", Integer.MIN_VALUE + 1000));
}

for (ConfigClassWithPrefix mapping : getBuildTimeVisibleMappings()) {
builder.withMapping(mapping.getKlass(), mapping.getPrefix());
for (ConfigClass mapping : getBuildTimeVisibleMappings()) {
builder.withMapping(mapping);
}

builder.withInterceptors(buildConfigTracker);
Expand Down Expand Up @@ -623,12 +622,12 @@ ReadResult run() {
configSource -> unknownBuildProperties.removeAll(configSource.getPropertyNames()));

// ConfigMappings
for (ConfigClassWithPrefix mapping : buildTimeVisibleMappings) {
for (ConfigClass mapping : buildTimeVisibleMappings) {
objectsByClass.put(mapping.getKlass(), config.getConfigMapping(mapping.getKlass(), mapping.getPrefix()));
}

// Build Time Values Recording
for (ConfigClassWithPrefix mapping : buildTimeMappings) {
for (ConfigClass mapping : buildTimeMappings) {
Set<String> mappedProperties = ConfigMappings.mappedProperties(mapping, allProperties);
for (String property : mappedProperties) {
unknownBuildProperties.remove(property);
Expand All @@ -640,7 +639,7 @@ ReadResult run() {
}

// Build Time and Run Time Values Recording
for (ConfigClassWithPrefix mapping : buildTimeRunTimeMappings) {
for (ConfigClass mapping : buildTimeRunTimeMappings) {
Set<String> mappedProperties = ConfigMappings.mappedProperties(mapping, allProperties);
for (String property : mappedProperties) {
unknownBuildProperties.remove(property);
Expand All @@ -653,7 +652,7 @@ ReadResult run() {
}

// Run Time Values Recording
for (ConfigClassWithPrefix mapping : runTimeMappings) {
for (ConfigClass mapping : runTimeMappings) {
Set<String> mappedProperties = ConfigMappings.mappedProperties(mapping, allProperties);
for (String property : mappedProperties) {
unknownBuildProperties.remove(property);
Expand Down Expand Up @@ -1234,10 +1233,10 @@ public static final class ReadResult {
final List<RootDefinition> allRoots;
final Map<Class<?>, RootDefinition> allRootsByClass;

final List<ConfigClassWithPrefix> buildTimeMappings;
final List<ConfigClassWithPrefix> buildTimeRunTimeMappings;
final List<ConfigClassWithPrefix> runTimeMappings;
final Map<Class<?>, ConfigClassWithPrefix> allMappings;
final List<ConfigClass> buildTimeMappings;
final List<ConfigClass> buildTimeRunTimeMappings;
final List<ConfigClass> runTimeMappings;
final Map<Class<?>, ConfigClass> allMappings;

final Set<String> unknownBuildProperties;
final Set<String> deprecatedRuntimeProperties;
Expand Down Expand Up @@ -1277,15 +1276,15 @@ private static Map<Class<?>, RootDefinition> rootsToMap(Builder builder) {
return map;
}

private static Map<Class<?>, ConfigClassWithPrefix> mappingsToMap(Builder builder) {
Map<Class<?>, ConfigClassWithPrefix> map = new HashMap<>();
for (ConfigClassWithPrefix mapping : builder.getBuildTimeMappings()) {
private static Map<Class<?>, ConfigClass> mappingsToMap(Builder builder) {
Map<Class<?>, ConfigClass> map = new HashMap<>();
for (ConfigClass mapping : builder.getBuildTimeMappings()) {
map.put(mapping.getKlass(), mapping);
}
for (ConfigClassWithPrefix mapping : builder.getBuildTimeRunTimeMappings()) {
for (ConfigClass mapping : builder.getBuildTimeRunTimeMappings()) {
map.put(mapping.getKlass(), mapping);
}
for (ConfigClassWithPrefix mapping : builder.getRunTimeMappings()) {
for (ConfigClass mapping : builder.getRunTimeMappings()) {
map.put(mapping.getKlass(), mapping);
}
return map;
Expand Down Expand Up @@ -1331,19 +1330,19 @@ public Map<Class<?>, RootDefinition> getAllRootsByClass() {
return allRootsByClass;
}

public List<ConfigClassWithPrefix> getBuildTimeMappings() {
public List<ConfigClass> getBuildTimeMappings() {
return buildTimeMappings;
}

public List<ConfigClassWithPrefix> getBuildTimeRunTimeMappings() {
public List<ConfigClass> getBuildTimeRunTimeMappings() {
return buildTimeRunTimeMappings;
}

public List<ConfigClassWithPrefix> getRunTimeMappings() {
public List<ConfigClass> getRunTimeMappings() {
return runTimeMappings;
}

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

Expand Down Expand Up @@ -1377,9 +1376,9 @@ static class Builder {
private ConfigPatternMap<Container> buildTimeRunTimePatternMap;
private ConfigPatternMap<Container> runTimePatternMap;
private List<RootDefinition> allRoots;
private List<ConfigClassWithPrefix> buildTimeMappings;
private List<ConfigClassWithPrefix> buildTimeRunTimeMappings;
private List<ConfigClassWithPrefix> runTimeMappings;
private List<ConfigClass> buildTimeMappings;
private List<ConfigClass> buildTimeRunTimeMappings;
private List<ConfigClass> runTimeMappings;
private Set<String> unknownBuildProperties;
private Set<String> deprecatedRuntimeProperties;
private ConfigTrackingInterceptor buildConfigTracker;
Expand Down Expand Up @@ -1465,29 +1464,29 @@ Builder setAllRoots(final List<RootDefinition> allRoots) {
return this;
}

List<ConfigClassWithPrefix> getBuildTimeMappings() {
List<ConfigClass> getBuildTimeMappings() {
return buildTimeMappings;
}

Builder setBuildTimeMappings(final List<ConfigClassWithPrefix> buildTimeMappings) {
Builder setBuildTimeMappings(final List<ConfigClass> buildTimeMappings) {
this.buildTimeMappings = buildTimeMappings;
return this;
}

List<ConfigClassWithPrefix> getBuildTimeRunTimeMappings() {
List<ConfigClass> getBuildTimeRunTimeMappings() {
return buildTimeRunTimeMappings;
}

Builder setBuildTimeRunTimeMappings(final List<ConfigClassWithPrefix> buildTimeRunTimeMappings) {
Builder setBuildTimeRunTimeMappings(final List<ConfigClass> buildTimeRunTimeMappings) {
this.buildTimeRunTimeMappings = buildTimeRunTimeMappings;
return this;
}

List<ConfigClassWithPrefix> getRunTimeMappings() {
List<ConfigClass> getRunTimeMappings() {
return runTimeMappings;
}

Builder setRunTimeMappings(final List<ConfigClassWithPrefix> runTimeMappings) {
Builder setRunTimeMappings(final List<ConfigClass> runTimeMappings) {
this.runTimeMappings = runTimeMappings;
return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package io.quarkus.deployment.configuration;

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

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -35,7 +34,7 @@
import io.smallrye.config.ConfigMappingInterface.Property;
import io.smallrye.config.ConfigMappingLoader;
import io.smallrye.config.ConfigMappingMetadata;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigMappings.ConfigClass;

public class ConfigMappingUtils {

Expand Down Expand Up @@ -64,7 +63,7 @@ public static void processConfigClasses(
Class<?> configClass = toClass(target.asClass().name());
String prefix = Optional.ofNullable(annotationPrefix).map(AnnotationValue::asString).orElse("");
Kind configClassKind = getConfigClassType(instance);
processConfigClass(configClassWithPrefix(configClass, prefix), configClassKind, true, combinedIndex,
processConfigClass(configClass(configClass, prefix), configClassKind, true, combinedIndex,
generatedClasses, reflectiveClasses, reflectiveMethods, configClasses, additionalConstrainedClasses);
}
}
Expand All @@ -81,7 +80,7 @@ public static void processConfigMapping(
}

public static void processExtensionConfigMapping(
ConfigClassWithPrefix configClass,
ConfigClass configClass,
CombinedIndexBuildItem combinedIndex,
BuildProducer<GeneratedClassBuildItem> generatedClasses,
BuildProducer<ReflectiveClassBuildItem> reflectiveClasses,
Expand All @@ -94,7 +93,7 @@ public static void processExtensionConfigMapping(
}

private static void processConfigClass(
ConfigClassWithPrefix configClassWithPrefix,
ConfigClass configClassWithPrefix,
Kind configClassKind,
boolean isApplicationClass,
CombinedIndexBuildItem combinedIndex,
Expand Down Expand Up @@ -143,7 +142,6 @@ private static void processProperties(

ConfigMappingInterface mapping = ConfigMappingLoader.getConfigMapping(configClass);
for (Property property : mapping.getProperties()) {
Class<?> returnType = property.getMethod().getReturnType();
String reason = ConfigMappingUtils.class.getSimpleName() + " Required to process property "
+ property.getPropertyName();

Expand Down Expand Up @@ -220,15 +218,6 @@ private static Kind getConfigClassType(AnnotationInstance instance) {
}
}

private static List<Class<?>> getHierarchy(Class<?> mapping) {
List<Class<?>> interfaces = new ArrayList<>();
for (Class<?> i : mapping.getInterfaces()) {
interfaces.add(i);
interfaces.addAll(getHierarchy(i));
}
return interfaces;
}

private static Set<Type> collectTypes(CombinedIndexBuildItem combinedIndex, Class<?> configClass) {
IndexView index = combinedIndex.getIndex();
DotName configIfaceName = DotName.createSimple(configClass.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
import io.quarkus.runtime.configuration.PropertiesUtil;
import io.quarkus.runtime.configuration.QuarkusConfigFactory;
import io.smallrye.config.ConfigMappings;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigMappings.ConfigClass;
import io.smallrye.config.Converters;
import io.smallrye.config.KeyMap;
import io.smallrye.config.SmallRyeConfig;
Expand Down Expand Up @@ -1198,13 +1198,13 @@ private FieldDescriptor getOrCreateConverterInstance(Field field, ConverterType

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.smallrye.config.ConfigMappingInterface.PrimitiveProperty;
import io.smallrye.config.ConfigMappingInterface.Property;
import io.smallrye.config.ConfigMappings;
import io.smallrye.config.ConfigMappings.ConfigClassWithPrefix;
import io.smallrye.config.ConfigMappings.ConfigClass;

public class ConfigDescriptionBuildStep {

Expand Down Expand Up @@ -120,9 +120,9 @@ public void accept(Container node) {
}
}

private void processMappings(List<ConfigClassWithPrefix> mappings, List<ConfigDescriptionBuildItem> descriptionBuildItems,
private void processMappings(List<ConfigClass> mappings, List<ConfigDescriptionBuildItem> descriptionBuildItems,
Properties javaDocProperties, ConfigPhase configPhase) {
for (ConfigClassWithPrefix mapping : mappings) {
for (ConfigClass mapping : mappings) {
Map<String, Property> properties = ConfigMappings.getProperties(mapping);
for (Map.Entry<String, Property> entry : properties.entrySet()) {
String propertyName = entry.getKey();
Expand Down
Loading
Loading