Skip to content

Commit

Permalink
Merge pull request #35618 from gsmet/fix-configitem-method
Browse files Browse the repository at this point in the history
Config doc - Avoid processing methods if not @ConfigMapping
  • Loading branch information
gsmet authored Aug 29, 2023
2 parents cb7a296 + 8dc1754 commit 6c9fa0a
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> 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<String, String> ALIASED_TYPES = Map.of(
OptionalLong.class.getName(), Long.class.getName(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,9 @@ public void doProcess(Set<? extends TypeElement> annotations, RoundEnvironment r
trackAnnotationUsed(Constants.ANNOTATION_RECORDER);
processRecorder(roundEnv, annotation);
break;
case Constants.ANNOTATION_CONFIG_MAPPING:
trackAnnotationUsed(Constants.ANNOTATION_CONFIG_MAPPING);
break;
}
}
}
Expand Down Expand Up @@ -257,7 +260,7 @@ public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
try {
if (generateDocs) {
final Set<ConfigDocGeneratedOutput> outputs = configDocItemScanner
.scanExtensionsConfigurationItems(javaDocProperties);
.scanExtensionsConfigurationItems(javaDocProperties, isAnnotationUsed(ANNOTATION_CONFIG_MAPPING));
for (ConfigDocGeneratedOutput output : outputs) {
DocGeneratorUtil.sort(output.getConfigDocItems()); // sort before writing
configDocWriter.writeAllExtensionConfigDocumentation(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,18 @@ class ConfigDocItemFinder {
private final Map<String, TypeElement> configGroupQualifiedNameToTypeElementMap;
private final FsMap allConfigurationGroups;
private final FsMap allConfigurationRoots;
private final boolean configMapping;

public ConfigDocItemFinder(Set<ConfigRootInfo> configRoots,
Map<String, TypeElement> 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;
}

/**
Expand All @@ -97,7 +100,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() throws IOException
ConfigPhase buildTime = ConfigPhase.BUILD_TIME;
final List<ConfigDocItem> configDocItems = recursivelyFindConfigItems(entry.getValue(), EMPTY, EMPTY, buildTime,
false, 1,
false);
false, configMapping);
allConfigurationGroups.put(entry.getKey(), OBJECT_MAPPER.writeValueAsString(configDocItems));
}

Expand All @@ -107,7 +110,7 @@ ScannedConfigDocsItemHolder findInMemoryConfigurationItems() throws IOException
String rootName = configRootInfo.getName();
ConfigPhase configPhase = configRootInfo.getConfigPhase();
final List<ConfigDocItem> 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));
}
Expand All @@ -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<ConfigDocItem> 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<ConfigDocItem> configDocItems = new ArrayList<>();
TypeElement asTypeElement = (TypeElement) element;
Expand All @@ -138,7 +142,8 @@ private List<ConfigDocItem> 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);
}
Expand All @@ -148,7 +153,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
}

for (Element enclosedElement : element.getEnclosedElements()) {
if (!shouldProcessElement(enclosedElement)) {
if (!shouldProcessElement(enclosedElement, configMapping)) {
continue;
}

Expand Down Expand Up @@ -262,7 +267,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r

if (isConfigGroup(type)) {
List<ConfigDocItem> groupConfigItems = readConfigGroupItems(configPhase, rootName, name, emptyList(), type,
configSection, withinAMap, generateSeparateConfigGroupDocsFiles);
configSection, withinAMap, generateSeparateConfigGroupDocsFiles, configMapping);
DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems);
} else {
final ConfigDocKey configDocKey = new ConfigDocKey();
Expand Down Expand Up @@ -293,7 +298,8 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
additionalNames = emptyList();
}
List<ConfigDocItem> groupConfigItems = readConfigGroupItems(configPhase, rootName, name,
additionalNames, type, configSection, true, generateSeparateConfigGroupDocsFiles);
additionalNames, type, configSection, true, generateSeparateConfigGroupDocsFiles,
configMapping);
DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems);
continue;
} else {
Expand All @@ -320,7 +326,7 @@ private List<ConfigDocItem> recursivelyFindConfigItems(Element element, String r
configSection.setOptional(true);
List<ConfigDocItem> groupConfigItems = readConfigGroupItems(configPhase, rootName, name,
emptyList(), typeInString, configSection, withinAMap,
generateSeparateConfigGroupDocsFiles);
generateSeparateConfigGroupDocsFiles, configMapping);
DocGeneratorUtil.appendConfigItemsIntoExistingOnes(configDocItems, groupConfigItems);
continue;
} else if ((typeInString.startsWith(List.class.getName())
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -537,7 +547,8 @@ private List<ConfigDocItem> readConfigGroupItems(
String configGroup,
ConfigDocSection configSection,
boolean withinAMap,
boolean generateSeparateConfigGroupDocs)
boolean generateSeparateConfigGroupDocs,
boolean configMapping)
throws JsonProcessingException {

configSection.setConfigGroupType(configGroup);
Expand All @@ -557,7 +568,7 @@ private List<ConfigDocItem> 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));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,12 @@ public void addConfigRoot(final PackageElement pkg, TypeElement clazz) {
}
}

public Set<ConfigDocGeneratedOutput> scanExtensionsConfigurationItems(Properties javaDocProperties)
public Set<ConfigDocGeneratedOutput> scanExtensionsConfigurationItems(Properties javaDocProperties, boolean configMapping)
throws IOException {

Set<ConfigDocGeneratedOutput> 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()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public class AzureFunctionsConfig {
/**
* Specifies the instrumentation key of application insights which will bind to your function app
*/
@ConfigItem
public Optional<String> appInsightsKey;

public RuntimeConfig runtime;
Expand All @@ -85,15 +86,18 @@ public class AzureFunctionsConfig {
/**
*
*/
@ConfigItem
public Optional<String> appServicePlanResourceGroup;

/**
* Azure subscription id. Required only if there are more than one subscription in your account
*/
@ConfigItem
public Optional<String> subscriptionId;
/**
*
*/
@ConfigItem
public Optional<String> pricingTier;

/**
Expand Down Expand Up @@ -233,6 +237,7 @@ public static class AuthConfig {
/**
* Filesystem path to properties file if using <i>file</i> type
*/
@ConfigItem
public Optional<String> path;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public class DockerConfig {
/**
* The networking mode for the RUN instructions during build
*/
@ConfigItem
public Optional<String> network;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> imagePushSecret;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class HibernateOrmConfigPersistenceUnit {
* <p>
* If undefined, it will use the default datasource.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
public Optional<String> datasource;

/**
* The packages in which the entities affected to this persistence unit are located.
*/
@ConfigItem
@ConvertWith(TrimmedStringConverter.class)
public Optional<Set<String>> packages;

Expand Down Expand Up @@ -195,6 +197,7 @@ public class HibernateOrmConfigPersistenceUnit {
/**
* Caching configuration
*/
@ConfigItem
@ConfigDocSection
public Map<String, HibernateOrmConfigPersistenceUnitCache> cache;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;

@ConfigGroup
public class AutoScalingConfig {
Expand All @@ -16,6 +17,7 @@ public class AutoScalingConfig {
*
* @return The autoscaler class.
*/
@ConfigItem
Optional<AutoScalerClass> autoScalerClass;

/**
Expand All @@ -24,13 +26,15 @@ public class AutoScalingConfig {
*
* @return The cpu metric or NONE if no metric has been selected.
*/
@ConfigItem
Optional<AutoScalingMetric> metric;

/**
* The autoscaling target.
*
* @return the selected target or zero if no target is selected.
*/
@ConfigItem
Optional<Integer> target;

/**
Expand All @@ -39,10 +43,12 @@ public class AutoScalingConfig {
*
* @return the container concurrency, or zero if it is not bound.
*/
@ConfigItem
Optional<Integer> containerConcurrency;

/**
* This value specifies a percentage of the target to actually be targeted by the autoscaler.
*/
@ConfigItem
Optional<Integer> targetUtilizationPercentage;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.Optional;

import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigItem;

@ConfigGroup
public class GlobalAutoScalingConfig {
Expand All @@ -15,6 +16,7 @@ public class GlobalAutoScalingConfig {
*
* @return The autoscaler class.
*/
@ConfigItem
Optional<AutoScalerClass> autoScalerClass;

/**
Expand All @@ -25,16 +27,19 @@ public class GlobalAutoScalingConfig {
* concurrency: Hard Limit</a>
* @return the container concurrency, or zero if it is not bound.
*/
@ConfigItem
Optional<Integer> containerConcurrency;

/**
* This value specifies a percentage of the target to actually be targeted by the autoscaler.
*/
@ConfigItem
Optional<Integer> targetUtilizationPercentage;

/**
* The requests per second per replica.
*/
@ConfigItem
Optional<Integer> requestsPerSecond;

}
Original file line number Diff line number Diff line change
Expand Up @@ -484,11 +484,13 @@ public EnvVarsConfig getEnv() {
/**
* The name of the revision.
*/
@ConfigItem
Optional<String> revisionName;

/**
* Traffic configuration.
*/
@ConfigItem
Map<String, TrafficConfig> traffic;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public final class SmallRyeOpenApiConfig {
/**
* Add a certain SecurityScheme with config
*/
@ConfigItem
public Optional<SecurityScheme> securityScheme;

/**
Expand Down

0 comments on commit 6c9fa0a

Please sign in to comment.