Skip to content

Commit

Permalink
Merge pull request #36264 from gsmet/3.2-backports-doc
Browse files Browse the repository at this point in the history
3.2 backports documentation
  • Loading branch information
gsmet authored Oct 4, 2023
2 parents cca68dd + 85a5a4d commit 9f813f6
Show file tree
Hide file tree
Showing 26 changed files with 347 additions and 211 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 @@ -261,7 +266,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 @@ -292,7 +297,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 @@ -319,7 +325,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 @@ -423,11 +429,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 @@ -536,7 +546,8 @@ private List<ConfigDocItem> readConfigGroupItems(
String configGroup,
ConfigDocSection configSection,
boolean withinAMap,
boolean generateSeparateConfigGroupDocs)
boolean generateSeparateConfigGroupDocs,
boolean configMapping)
throws JsonProcessingException {

configSection.setConfigGroupType(configGroup);
Expand All @@ -556,7 +567,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
2 changes: 0 additions & 2 deletions docs/downstreamdoc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,3 @@ guides:
- src/main/asciidoc/security-openid-connect-client-reference.adoc
- src/main/asciidoc/security-overview.adoc
- src/main/asciidoc/security-proactive-authentication.adoc
- src/main/asciidoc/security-vulnerability-detection.adoc
- src/main/asciidoc/update-quarkus.adoc
Loading

0 comments on commit 9f813f6

Please sign in to comment.