From 469697790acadf34326f37a35f7bdd59c3baac1a Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 29 Aug 2023 16:14:46 +0200 Subject: [PATCH 1/2] Config doc - Avoid processing methods if not @ConfigMapping Fixes #35594 --- .../annotation/processor/Constants.java | 2 +- .../ExtensionAnnotationProcessor.java | 5 ++- .../generate_doc/ConfigDocItemFinder.java | 35 ++++++++++++------- .../generate_doc/ConfigDocItemScanner.java | 4 +-- 4 files changed, 30 insertions(+), 16 deletions(-) diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java index 743c1bbf00aa1..d6251ece2eb60 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/Constants.java @@ -70,7 +70,7 @@ final public class Constants { public static final String ANNOTATION_CONFIG_WITH_UNNAMED_KEY = "io.smallrye.config.WithUnnamedKey"; public static final Set SUPPORTED_ANNOTATIONS_TYPES = Set.of(ANNOTATION_BUILD_STEP, ANNOTATION_CONFIG_GROUP, - ANNOTATION_CONFIG_ROOT, ANNOTATION_RECORDER); + ANNOTATION_CONFIG_ROOT, ANNOTATION_RECORDER, ANNOTATION_CONFIG_MAPPING); public static final Map ALIASED_TYPES = Map.of( OptionalLong.class.getName(), Long.class.getName(), diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessor.java b/core/processor/src/main/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessor.java index f6a585cd0bef0..ddd722a0e3254 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessor.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessor.java @@ -145,6 +145,9 @@ public void doProcess(Set annotations, RoundEnvironment r trackAnnotationUsed(Constants.ANNOTATION_RECORDER); processRecorder(roundEnv, annotation); break; + case Constants.ANNOTATION_CONFIG_MAPPING: + trackAnnotationUsed(Constants.ANNOTATION_CONFIG_MAPPING); + break; } } } @@ -257,7 +260,7 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc) try { if (generateDocs) { final Set outputs = configDocItemScanner - .scanExtensionsConfigurationItems(javaDocProperties); + .scanExtensionsConfigurationItems(javaDocProperties, isAnnotationUsed(ANNOTATION_CONFIG_MAPPING)); for (ConfigDocGeneratedOutput output : outputs) { DocGeneratorUtil.sort(output.getConfigDocItems()); // sort before writing configDocWriter.writeAllExtensionConfigDocumentation(output); diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java index 589085573f4d5..004ecae8dfbaa 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemFinder.java @@ -75,15 +75,18 @@ class ConfigDocItemFinder { private final Map configGroupQualifiedNameToTypeElementMap; private final FsMap allConfigurationGroups; private final FsMap allConfigurationRoots; + private final boolean configMapping; public ConfigDocItemFinder(Set configRoots, Map configGroupQualifiedNameToTypeElementMap, - Properties javaDocProperties, FsMap allConfigurationGroups, FsMap allConfigurationRoots) { + Properties javaDocProperties, FsMap allConfigurationGroups, FsMap allConfigurationRoots, + boolean configMapping) { this.configRoots = configRoots; this.configGroupQualifiedNameToTypeElementMap = configGroupQualifiedNameToTypeElementMap; this.javaDocProperties = javaDocProperties; this.allConfigurationGroups = allConfigurationGroups; this.allConfigurationRoots = allConfigurationRoots; + this.configMapping = configMapping; } /** @@ -97,7 +100,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() throws IOException ConfigPhase buildTime = ConfigPhase.BUILD_TIME; final List configDocItems = recursivelyFindConfigItems(entry.getValue(), EMPTY, EMPTY, buildTime, false, 1, - false); + false, configMapping); allConfigurationGroups.put(entry.getKey(), OBJECT_MAPPER.writeValueAsString(configDocItems)); } @@ -107,7 +110,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() throws IOException String rootName = configRootInfo.getName(); ConfigPhase configPhase = configRootInfo.getConfigPhase(); final List configDocItems = recursivelyFindConfigItems(element, rootName, rootName, configPhase, - false, sectionLevel, true); + false, sectionLevel, true, configMapping); holder.addConfigRootItems(configRootInfo, configDocItems); allConfigurationRoots.put(configRootInfo.getClazz().toString(), OBJECT_MAPPER.writeValueAsString(configDocItems)); } @@ -119,7 +122,8 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() throws IOException * Recursively find config item found in a config root or config group given as {@link Element} */ private List recursivelyFindConfigItems(Element element, String rootName, String parentName, - ConfigPhase configPhase, boolean withinAMap, int sectionLevel, boolean generateSeparateConfigGroupDocsFiles) + ConfigPhase configPhase, boolean withinAMap, int sectionLevel, boolean generateSeparateConfigGroupDocsFiles, + boolean configMapping) throws JsonProcessingException { List configDocItems = new ArrayList<>(); TypeElement asTypeElement = (TypeElement) element; @@ -138,7 +142,8 @@ private List recursivelyFindConfigItems(Element element, String r if (rawConfigItems == null) { // element not yet scanned Element superElement = ((DeclaredType) superType).asElement(); superTypeConfigItems = recursivelyFindConfigItems(superElement, rootName, parentName, - configPhase, withinAMap, sectionLevel, generateSeparateConfigGroupDocsFiles); + configPhase, withinAMap, sectionLevel, generateSeparateConfigGroupDocsFiles, + configMapping); } else { superTypeConfigItems = OBJECT_MAPPER.readValue(rawConfigItems, LIST_OF_CONFIG_ITEMS_TYPE_REF); } @@ -148,7 +153,7 @@ private List recursivelyFindConfigItems(Element element, String r } for (Element enclosedElement : element.getEnclosedElements()) { - if (!shouldProcessElement(enclosedElement)) { + if (!shouldProcessElement(enclosedElement, configMapping)) { continue; } @@ -262,7 +267,7 @@ private List recursivelyFindConfigItems(Element element, String r if (isConfigGroup(type)) { List groupConfigItems = readConfigGroupItems(configPhase, rootName, name, emptyList(), type, - configSection, withinAMap, generateSeparateConfigGroupDocsFiles); + configSection, withinAMap, generateSeparateConfigGroupDocsFiles, configMapping); DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems); } else { final ConfigDocKey configDocKey = new ConfigDocKey(); @@ -293,7 +298,8 @@ private List recursivelyFindConfigItems(Element element, String r additionalNames = emptyList(); } List groupConfigItems = readConfigGroupItems(configPhase, rootName, name, - additionalNames, type, configSection, true, generateSeparateConfigGroupDocsFiles); + additionalNames, type, configSection, true, generateSeparateConfigGroupDocsFiles, + configMapping); DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems); continue; } else { @@ -320,7 +326,7 @@ private List recursivelyFindConfigItems(Element element, String r configSection.setOptional(true); List groupConfigItems = readConfigGroupItems(configPhase, rootName, name, emptyList(), typeInString, configSection, withinAMap, - generateSeparateConfigGroupDocsFiles); + generateSeparateConfigGroupDocsFiles, configMapping); DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems); continue; } else if ((typeInString.startsWith(List.class.getName()) @@ -424,11 +430,15 @@ private boolean isConfigGroup(String type) { return configGroupQualifiedNameToTypeElementMap.containsKey(type) || allConfigurationGroups.hasKey(type); } - private boolean shouldProcessElement(final Element enclosedElement) { + private boolean shouldProcessElement(final Element enclosedElement, final boolean configMapping) { if (enclosedElement.getKind().isField()) { return true; } + if (!configMapping && enclosedElement.getKind() == ElementKind.METHOD) { + return false; + } + // A ConfigMapping method if (enclosedElement.getKind().equals(ElementKind.METHOD)) { ExecutableElement method = (ExecutableElement) enclosedElement; @@ -537,7 +547,8 @@ private List readConfigGroupItems( String configGroup, ConfigDocSection configSection, boolean withinAMap, - boolean generateSeparateConfigGroupDocs) + boolean generateSeparateConfigGroupDocs, + boolean configMapping) throws JsonProcessingException { configSection.setConfigGroupType(configGroup); @@ -557,7 +568,7 @@ private List readConfigGroupItems( } else { TypeElement configGroupTypeElement = configGroupQualifiedNameToTypeElementMap.get(configGroup); groupConfigItems = recursivelyFindConfigItems(configGroupTypeElement, EMPTY, EMPTY, configPhase, - false, 1, generateSeparateConfigGroupDocs); + false, 1, generateSeparateConfigGroupDocs, configMapping); allConfigurationGroups.put(configGroup, OBJECT_MAPPER.writeValueAsString(groupConfigItems)); } diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java index 317b7767864fc..4881cf3e87478 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java @@ -118,12 +118,12 @@ public void addConfigRoot(final PackageElement pkg, TypeElement clazz) { } } - public Set scanExtensionsConfigurationItems(Properties javaDocProperties) + public Set scanExtensionsConfigurationItems(Properties javaDocProperties, boolean configMapping) throws IOException { Set configDocGeneratedOutputs = new HashSet<>(); final ConfigDocItemFinder configDocItemFinder = new ConfigDocItemFinder(configRoots, configGroupsToTypeElement, - javaDocProperties, allConfigGroupGeneratedDocs, allExtensionGeneratedDocs); + javaDocProperties, allConfigGroupGeneratedDocs, allExtensionGeneratedDocs, configMapping); final ScannedConfigDocsItemHolder inMemoryScannedItemsHolder = configDocItemFinder.findInMemoryConfigurationItems(); if (!inMemoryScannedItemsHolder.isEmpty()) { From 8dc17544fd2f7ad640976bc2464aad9e48fa90bf Mon Sep 17 00:00:00 2001 From: Guillaume Smet Date: Tue, 29 Aug 2023 16:18:11 +0200 Subject: [PATCH 2/2] Add some missing @ConfigItem annotations Noticed while working on another approach to fix #35594. --- .../azure/functions/deployment/AzureFunctionsConfig.java | 5 +++++ .../container/image/docker/deployment/DockerConfig.java | 1 + .../openshift/deployment/ContainerImageOpenshiftConfig.java | 1 + .../orm/deployment/HibernateOrmConfigPersistenceUnit.java | 3 +++ .../io/quarkus/kubernetes/deployment/AutoScalingConfig.java | 6 ++++++ .../kubernetes/deployment/GlobalAutoScalingConfig.java | 5 +++++ .../io/quarkus/kubernetes/deployment/KnativeConfig.java | 2 ++ .../openapi/common/deployment/SmallRyeOpenApiConfig.java | 1 + 8 files changed, 24 insertions(+) diff --git a/extensions/azure-functions/deployment/src/main/java/io/quarkus/azure/functions/deployment/AzureFunctionsConfig.java b/extensions/azure-functions/deployment/src/main/java/io/quarkus/azure/functions/deployment/AzureFunctionsConfig.java index 049684836a21d..7e324cbee2d0b 100644 --- a/extensions/azure-functions/deployment/src/main/java/io/quarkus/azure/functions/deployment/AzureFunctionsConfig.java +++ b/extensions/azure-functions/deployment/src/main/java/io/quarkus/azure/functions/deployment/AzureFunctionsConfig.java @@ -70,6 +70,7 @@ public class AzureFunctionsConfig { /** * Specifies the instrumentation key of application insights which will bind to your function app */ + @ConfigItem public Optional appInsightsKey; public RuntimeConfig runtime; @@ -85,15 +86,18 @@ public class AzureFunctionsConfig { /** * */ + @ConfigItem public Optional appServicePlanResourceGroup; /** * Azure subscription id. Required only if there are more than one subscription in your account */ + @ConfigItem public Optional subscriptionId; /** * */ + @ConfigItem public Optional pricingTier; /** @@ -233,6 +237,7 @@ public static class AuthConfig { /** * Filesystem path to properties file if using file type */ + @ConfigItem public Optional path; /** diff --git a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerConfig.java b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerConfig.java index fa13ce661509e..cf06381a8aca5 100644 --- a/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerConfig.java +++ b/extensions/container-image/container-image-docker/deployment/src/main/java/io/quarkus/container/image/docker/deployment/DockerConfig.java @@ -49,6 +49,7 @@ public class DockerConfig { /** * The networking mode for the RUN instructions during build */ + @ConfigItem public Optional network; /** diff --git a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/ContainerImageOpenshiftConfig.java b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/ContainerImageOpenshiftConfig.java index d2adf4fe379ff..bf92f1a9d4451 100644 --- a/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/ContainerImageOpenshiftConfig.java +++ b/extensions/container-image/container-image-openshift/deployment/src/main/java/io/quarkus/container/image/openshift/deployment/ContainerImageOpenshiftConfig.java @@ -132,6 +132,7 @@ public static String getDefaultJvmImage(CompiledJavaVersionBuildItem.JavaVersion * The image push secret to use for pushing to external registries. * (see: https://cloud.redhat.com/blog/pushing-application-images-to-an-external-registry) **/ + @ConfigItem public Optional imagePushSecret; /** diff --git a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java index 7462c4b1308c9..be2da22d14f81 100644 --- a/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java +++ b/extensions/hibernate-orm/deployment/src/main/java/io/quarkus/hibernate/orm/deployment/HibernateOrmConfigPersistenceUnit.java @@ -28,12 +28,14 @@ public class HibernateOrmConfigPersistenceUnit { *

* If undefined, it will use the default datasource. */ + @ConfigItem @ConvertWith(TrimmedStringConverter.class) public Optional datasource; /** * The packages in which the entities affected to this persistence unit are located. */ + @ConfigItem @ConvertWith(TrimmedStringConverter.class) public Optional> packages; @@ -195,6 +197,7 @@ public class HibernateOrmConfigPersistenceUnit { /** * Caching configuration */ + @ConfigItem @ConfigDocSection public Map cache; diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingConfig.java index 303eb62c0a330..00ca52ebb69c1 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/AutoScalingConfig.java @@ -4,6 +4,7 @@ import java.util.Optional; import io.quarkus.runtime.annotations.ConfigGroup; +import io.quarkus.runtime.annotations.ConfigItem; @ConfigGroup public class AutoScalingConfig { @@ -16,6 +17,7 @@ public class AutoScalingConfig { * * @return The autoscaler class. */ + @ConfigItem Optional autoScalerClass; /** @@ -24,6 +26,7 @@ public class AutoScalingConfig { * * @return The cpu metric or NONE if no metric has been selected. */ + @ConfigItem Optional metric; /** @@ -31,6 +34,7 @@ public class AutoScalingConfig { * * @return the selected target or zero if no target is selected. */ + @ConfigItem Optional target; /** @@ -39,10 +43,12 @@ public class AutoScalingConfig { * * @return the container concurrency, or zero if it is not bound. */ + @ConfigItem Optional containerConcurrency; /** * This value specifies a percentage of the target to actually be targeted by the autoscaler. */ + @ConfigItem Optional targetUtilizationPercentage; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/GlobalAutoScalingConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/GlobalAutoScalingConfig.java index 1ad74874d6a0b..766b8cf83e596 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/GlobalAutoScalingConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/GlobalAutoScalingConfig.java @@ -3,6 +3,7 @@ import java.util.Optional; import io.quarkus.runtime.annotations.ConfigGroup; +import io.quarkus.runtime.annotations.ConfigItem; @ConfigGroup public class GlobalAutoScalingConfig { @@ -15,6 +16,7 @@ public class GlobalAutoScalingConfig { * * @return The autoscaler class. */ + @ConfigItem Optional autoScalerClass; /** @@ -25,16 +27,19 @@ public class GlobalAutoScalingConfig { * concurrency: Hard Limit * @return the container concurrency, or zero if it is not bound. */ + @ConfigItem Optional containerConcurrency; /** * This value specifies a percentage of the target to actually be targeted by the autoscaler. */ + @ConfigItem Optional targetUtilizationPercentage; /** * The requests per second per replica. */ + @ConfigItem Optional requestsPerSecond; } diff --git a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java index 1b5d5e135ff74..ed5c47c786952 100644 --- a/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java +++ b/extensions/kubernetes/vanilla/deployment/src/main/java/io/quarkus/kubernetes/deployment/KnativeConfig.java @@ -484,11 +484,13 @@ public EnvVarsConfig getEnv() { /** * The name of the revision. */ + @ConfigItem Optional revisionName; /** * Traffic configuration. */ + @ConfigItem Map traffic; /** diff --git a/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java b/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java index 59c333fc96e20..087b9dc7cf1cf 100644 --- a/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java +++ b/extensions/smallrye-openapi-common/deployment/src/main/java/io/quarkus/smallrye/openapi/common/deployment/SmallRyeOpenApiConfig.java @@ -54,6 +54,7 @@ public final class SmallRyeOpenApiConfig { /** * Add a certain SecurityScheme with config */ + @ConfigItem public Optional securityScheme; /**