diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/merger/ModelMerger.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/merger/ModelMerger.java index 4deff0ca7c3be..a101d7a8caf76 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/merger/ModelMerger.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/merger/ModelMerger.java @@ -43,12 +43,29 @@ public static MergedModel mergeModel(List buildOutputDirectories) { * target/ directories found in the parent directory scanned). */ public static MergedModel mergeModel(JavadocRepository javadocRepository, List buildOutputDirectories) { + return mergeModel(javadocRepository, buildOutputDirectories, false); + } + + /** + * Merge all the resolved models obtained from a list of build output directories (e.g. in the case of Maven, the list of + * target/ directories found in the parent directory scanned). + */ + public static MergedModel mergeModel(List buildOutputDirectories, boolean mergeCommonOrInternalExtensions) { + return mergeModel(null, buildOutputDirectories, mergeCommonOrInternalExtensions); + } + + /** + * Merge all the resolved models obtained from a list of build output directories (e.g. in the case of Maven, the list of + * target/ directories found in the parent directory scanned). + */ + public static MergedModel mergeModel(JavadocRepository javadocRepository, List buildOutputDirectories, + boolean mergeCommonOrInternalExtensions) { // keyed on extension and then top level prefix Map> configRoots = new HashMap<>(); // keyed on file name Map configRootsInSpecificFile = new TreeMap<>(); // keyed on extension - Map> generatedConfigSections = new TreeMap<>(); + Map> generatedConfigSections = new HashMap<>(); for (Path buildOutputDirectory : buildOutputDirectories) { Path resolvedModelPath = buildOutputDirectory.resolve(Outputs.QUARKUS_CONFIG_DOC_MODEL); @@ -85,7 +102,8 @@ public static MergedModel mergeModel(JavadocRepository javadocRepository, List

extensionConfigRoots = configRoots.computeIfAbsent(configRoot.getExtension(), + Map extensionConfigRoots = configRoots.computeIfAbsent( + normalizeExtension(configRoot.getExtension(), mergeCommonOrInternalExtensions), e -> new TreeMap<>()); ConfigRootKey configRootKey = getConfigRootKey(javadocRepository, configRoot); @@ -102,6 +120,7 @@ public static MergedModel mergeModel(JavadocRepository javadocRepository, List

> extensionConfigRootsEntry : configRoots.entrySet()) { @@ -116,6 +135,18 @@ public static MergedModel mergeModel(JavadocRepository javadocRepository, List

> retainBestExtensionKey( Map> configRoots) { return configRoots.entrySet().stream().collect(Collectors.toMap(e -> { diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/Extension.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/Extension.java index fcb44039f24de..8472659071881 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/Extension.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/Extension.java @@ -5,10 +5,24 @@ import com.fasterxml.jackson.annotation.JsonIgnore; public record Extension(String groupId, String artifactId, String name, - NameSource nameSource, boolean detected) implements Comparable { + NameSource nameSource, boolean commonOrInternal, boolean detected) implements Comparable { + + private static final String ARTIFACT_COMMON_SUFFIX = "-common"; + private static final String ARTIFACT_INTERNAL_SUFFIX = "-internal"; + + public static Extension of(String groupId, String artifactId, String name, + NameSource nameSource) { + boolean commonOrInternal = artifactId.endsWith(ARTIFACT_COMMON_SUFFIX) || artifactId.endsWith(ARTIFACT_INTERNAL_SUFFIX); + if (commonOrInternal) { + nameSource = nameSource == NameSource.EXTENSION_METADATA ? NameSource.EXTENSION_METADATA_COMMON_INTERNAL + : (nameSource == NameSource.POM_XML ? NameSource.POM_XML_COMMON_INTERNAL : nameSource); + } + + return new Extension(groupId, artifactId, name, nameSource, commonOrInternal, true); + } public static Extension createNotDetected() { - return new Extension("not.detected", "not.detected", "Not detected", NameSource.NONE, false); + return new Extension("not.detected", "not.detected", "Not detected", NameSource.NONE, false, false); } @Override @@ -50,6 +64,27 @@ public boolean splitOnConfigRootDescription() { return "io.quarkus".equals(groupId) && "quarkus-core".equals(artifactId); } + @JsonIgnore + public Extension normalizeCommonOrInternal() { + if (!commonOrInternal()) { + return this; + } + + String normalizedArtifactId = artifactId; + if (artifactId.endsWith(ARTIFACT_COMMON_SUFFIX)) { + normalizedArtifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_COMMON_SUFFIX.length()); + } + if (artifactId.endsWith(ARTIFACT_INTERNAL_SUFFIX)) { + normalizedArtifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_INTERNAL_SUFFIX.length()); + } + + if (normalizedArtifactId.equals(artifactId)) { + return this; + } + + return new Extension(groupId, normalizedArtifactId, name, nameSource, commonOrInternal, detected); + } + @Override public int compareTo(Extension other) { if (name != null && other.name != null) { diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/util/ExtensionUtil.java b/core/processor/src/main/java/io/quarkus/annotation/processor/util/ExtensionUtil.java index 6634c70469e59..f30eca643686e 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/util/ExtensionUtil.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/util/ExtensionUtil.java @@ -1,11 +1,15 @@ package io.quarkus.annotation.processor.util; +import java.io.IOException; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Map; import java.util.Optional; import javax.annotation.processing.ProcessingEnvironment; import javax.tools.Diagnostic.Kind; +import javax.tools.StandardLocation; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; @@ -19,14 +23,12 @@ public final class ExtensionUtil { + private static final String RUNTIME_MARKER_FILE = "META-INF/quarkus.properties"; + private static final String ARTIFACT_DEPLOYMENT_SUFFIX = "-deployment"; - private static final String ARTIFACT_COMMON_SUFFIX = "-common"; - private static final String ARTIFACT_INTERNAL_SUFFIX = "-internal"; private static final String NAME_QUARKUS_PREFIX = "Quarkus - "; private static final String NAME_RUNTIME_SUFFIX = " - Runtime"; private static final String NAME_DEPLOYMENT_SUFFIX = " - Deployment"; - private static final String NAME_COMMON_SUFFIX = " - Common"; - private static final String NAME_INTERNAL_SUFFIX = " - Internal"; private final ProcessingEnvironment processingEnv; private final FilerUtil filerUtil; @@ -111,27 +113,19 @@ private Extension getExtensionFromPom(Path pom, Document doc) { return Extension.createNotDetected(); } - boolean commonOrInternal = false; + boolean runtime = isRuntime(); - if (artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) { + if (!runtime && artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) { artifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_DEPLOYMENT_SUFFIX.length()); } - if (artifactId.endsWith(ARTIFACT_COMMON_SUFFIX)) { - artifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_COMMON_SUFFIX.length()); - commonOrInternal = true; - } - if (artifactId.endsWith(ARTIFACT_INTERNAL_SUFFIX)) { - artifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_INTERNAL_SUFFIX.length()); - commonOrInternal = true; - } NameSource nameSource; Optional nameFromExtensionMetadata = getExtensionNameFromExtensionMetadata(); if (nameFromExtensionMetadata.isPresent()) { name = nameFromExtensionMetadata.get(); - nameSource = commonOrInternal ? NameSource.EXTENSION_METADATA_COMMON_INTERNAL : NameSource.EXTENSION_METADATA; + nameSource = NameSource.EXTENSION_METADATA; } else if (name != null) { - nameSource = commonOrInternal ? NameSource.POM_XML_COMMON_INTERNAL : NameSource.POM_XML; + nameSource = NameSource.POM_XML; } else { nameSource = NameSource.NONE; } @@ -140,18 +134,15 @@ private Extension getExtensionFromPom(Path pom, Document doc) { if (name.startsWith(NAME_QUARKUS_PREFIX)) { name = name.substring(NAME_QUARKUS_PREFIX.length()).trim(); } - if (name.endsWith(NAME_DEPLOYMENT_SUFFIX)) { + if (!runtime && name.endsWith(NAME_DEPLOYMENT_SUFFIX)) { name = name.substring(0, name.length() - NAME_DEPLOYMENT_SUFFIX.length()); - } else if (name.endsWith(NAME_RUNTIME_SUFFIX)) { + } + if (runtime && name.endsWith(NAME_RUNTIME_SUFFIX)) { name = name.substring(0, name.length() - NAME_RUNTIME_SUFFIX.length()); - } else if (name.endsWith(NAME_COMMON_SUFFIX)) { - name = name.substring(0, name.length() - NAME_COMMON_SUFFIX.length()); - } else if (name.endsWith(NAME_INTERNAL_SUFFIX)) { - name = name.substring(0, name.length() - NAME_INTERNAL_SUFFIX.length()); } } - return new Extension(groupId, artifactId, name, nameSource, true); + return Extension.of(groupId, artifactId, name, nameSource); } private Optional getExtensionNameFromExtensionMetadata() { @@ -168,4 +159,14 @@ private Optional getExtensionNameFromExtensionMetadata() { return Optional.of(extensionName.trim()); } + + private boolean isRuntime() { + try { + Path runtimeMarkerFile = Paths + .get(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", RUNTIME_MARKER_FILE).toUri()); + return Files.exists(runtimeMarkerFile); + } catch (IOException e) { + return false; + } + } } diff --git a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java index ed5626b9f1bf1..6c104ef4a7231 100644 --- a/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java +++ b/devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java @@ -92,7 +92,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { List targetDirectories = findTargetDirectories(resolvedScanDirectory); JavadocRepository javadocRepository = JavadocMerger.mergeJavadocElements(targetDirectories); - MergedModel mergedModel = ModelMerger.mergeModel(javadocRepository, targetDirectories); + MergedModel mergedModel = ModelMerger.mergeModel(javadocRepository, targetDirectories, true); Format normalizedFormat = Format.normalizeFormat(format); diff --git a/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java b/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java index 79705db38ca9e..a3b3af24b11d0 100644 --- a/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java +++ b/devtools/extension-deployment-maven-plugin/src/main/java/io/quarkus/maven/extension/deployment/metadata/AttachConfigMetadataMojo.java @@ -222,8 +222,7 @@ private List getMetaInfDirectories() { private Extension getExtension() { return new Extension(project.getGroupId(), project.getArtifactId().substring(0, project.getArtifactId().length() - DEPLOYMENT_ARTIFACT_SUFFIX.length()), - null, - NameSource.NONE, true); + null, NameSource.NONE, false, true); } private String getJavadoc(JavadocRepository javadocRepository, String sourceType, String sourceElementName) {