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 c224ba30c764b..646d0e5cc345d 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 @@ -21,7 +21,7 @@ import org.jboss.jdeparser.JDeparser; import io.quarkus.annotation.processor.documentation.config.ConfigDocExtensionProcessor; -import io.quarkus.annotation.processor.documentation.config.model.Extension; +import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule; import io.quarkus.annotation.processor.documentation.config.util.Types; import io.quarkus.annotation.processor.extension.ExtensionBuildProcessor; import io.quarkus.annotation.processor.util.Config; @@ -45,11 +45,12 @@ public synchronized void init(ProcessingEnvironment processingEnv) { .parseBoolean(utils.processingEnv().getOptions().getOrDefault(Options.LEGACY_CONFIG_ROOT, "false")); boolean debug = Boolean.getBoolean(DEBUG); - Extension extension = utils.extension().getExtension(); - Config config = new Config(extension, useConfigMapping, debug); + ExtensionModule extensionModule = utils.extension().getExtensionModule(); + + Config config = new Config(extensionModule, useConfigMapping, debug); if (!useConfigMapping) { - processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Extension " + extension.artifactId() + processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Extension module " + extensionModule.artifactId() + " config implementation is deprecated. Please migrate to use @ConfigMapping: https://quarkus.io/guides/writing-extensions#configuration"); } @@ -61,7 +62,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) { // for now, we generate the old config doc by default but we will change this behavior soon if (generateDoc) { - if (extension.detected()) { + if (extensionModule.detected()) { extensionProcessors.add(new ConfigDocExtensionProcessor()); } else { processingEnv.getMessager().printMessage(Kind.WARNING, diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ExtensionModule.java b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ExtensionModule.java new file mode 100644 index 0000000000000..09f0b3150af6b --- /dev/null +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/model/ExtensionModule.java @@ -0,0 +1,20 @@ +package io.quarkus.annotation.processor.documentation.config.model; + +public record ExtensionModule(String groupId, String artifactId, ExtensionModuleType type, Extension extension, + boolean detected) { + + public static ExtensionModule createNotDetected() { + return new ExtensionModule("not.detected", "not.detected", ExtensionModuleType.UNKNOWN, Extension.createNotDetected(), + false); + } + + public static ExtensionModule of(String groupId, String artifactId, ExtensionModuleType type, Extension extension) { + return new ExtensionModule(groupId, artifactId, type, extension, true); + } + + public enum ExtensionModuleType { + RUNTIME, + DEPLOYMENT, + UNKNOWN; + } +} diff --git a/core/processor/src/main/java/io/quarkus/annotation/processor/util/Config.java b/core/processor/src/main/java/io/quarkus/annotation/processor/util/Config.java index 85643f62c24eb..8440155cca060 100644 --- a/core/processor/src/main/java/io/quarkus/annotation/processor/util/Config.java +++ b/core/processor/src/main/java/io/quarkus/annotation/processor/util/Config.java @@ -1,21 +1,26 @@ package io.quarkus.annotation.processor.util; import io.quarkus.annotation.processor.documentation.config.model.Extension; +import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule; public class Config { - private final Extension extension; + private final ExtensionModule extensionModule; private final boolean useConfigMapping; private final boolean debug; - public Config(Extension extension, boolean useConfigMapping, boolean debug) { - this.extension = extension; + public Config(ExtensionModule extensionModule, boolean useConfigMapping, boolean debug) { + this.extensionModule = extensionModule; this.useConfigMapping = useConfigMapping; this.debug = debug; } + public ExtensionModule getExtensionModule() { + return extensionModule; + } + public Extension getExtension() { - return extension; + return extensionModule.extension(); } public boolean useConfigMapping() { 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 f1d6f434c8855..81b203a1085f8 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 @@ -20,10 +20,12 @@ import io.quarkus.annotation.processor.documentation.config.model.Extension; import io.quarkus.annotation.processor.documentation.config.model.Extension.NameSource; +import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule; +import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule.ExtensionModuleType; public final class ExtensionUtil { - private static final String RUNTIME_MARKER_FILE = "META-INF/quarkus.properties"; + private static final String RUNTIME_MARKER_FILE = "META-INF/quarkus-extension.properties"; private static final String ARTIFACT_DEPLOYMENT_SUFFIX = "-deployment"; private static final String NAME_QUARKUS_PREFIX = "Quarkus - "; @@ -42,11 +44,11 @@ public final class ExtensionUtil { * This is not exactly pretty but it's actually not easy to get the artifact id of the current artifact. * One option would be to pass it through the annotation processor but it's not exactly ideal. */ - public Extension getExtension() { + public ExtensionModule getExtensionModule() { Optional pom = filerUtil.getPomPath(); if (pom.isEmpty()) { - return Extension.createNotDetected(); + return ExtensionModule.createNotDetected(); } Document doc; @@ -61,10 +63,10 @@ public Extension getExtension() { throw new IllegalStateException("Unable to parse pom file: " + pom, e); } - return getExtensionFromPom(pom.get(), doc); + return getExtensionModuleFromPom(pom.get(), doc); } - private Extension getExtensionFromPom(Path pom, Document doc) { + private ExtensionModule getExtensionModuleFromPom(Path pom, Document doc) { String parentGroupId = null; String artifactId = null; String groupId = null; @@ -111,40 +113,45 @@ private Extension getExtensionFromPom(Path pom, Document doc) { if (groupId == null || groupId.isBlank() || artifactId == null || artifactId.isBlank()) { processingEnv.getMessager().printMessage(Kind.WARNING, "Unable to determine artifact coordinates from: " + pom); - return Extension.createNotDetected(); + return ExtensionModule.createNotDetected(); } - boolean runtime = isRuntime(); + ExtensionModuleType moduleType = detectExtensionModuleType(artifactId); - if (!runtime && artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) { - artifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_DEPLOYMENT_SUFFIX.length()); + String extensionArtifactId; + if (moduleType == ExtensionModuleType.DEPLOYMENT) { + extensionArtifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_DEPLOYMENT_SUFFIX.length()); + } else { + extensionArtifactId = artifactId; } - NameSource nameSource; + NameSource extensionNameSource; Optional extensionMetadata = getExtensionMetadata(); if (extensionMetadata.isPresent()) { name = extensionMetadata.get().name(); - nameSource = NameSource.EXTENSION_METADATA; + extensionNameSource = NameSource.EXTENSION_METADATA; guideUrl = extensionMetadata.get().guideUrl(); } else if (name != null) { - nameSource = NameSource.POM_XML; + extensionNameSource = NameSource.POM_XML; } else { - nameSource = NameSource.NONE; + extensionNameSource = NameSource.NONE; } - if (name != null) { - if (name.startsWith(NAME_QUARKUS_PREFIX)) { - name = name.substring(NAME_QUARKUS_PREFIX.length()).trim(); + String extensionName = name; + if (extensionName != null) { + if (extensionName.startsWith(NAME_QUARKUS_PREFIX)) { + extensionName = extensionName.substring(NAME_QUARKUS_PREFIX.length()).trim(); } - if (!runtime && name.endsWith(NAME_DEPLOYMENT_SUFFIX)) { - name = name.substring(0, name.length() - NAME_DEPLOYMENT_SUFFIX.length()); + if (moduleType == ExtensionModuleType.DEPLOYMENT && extensionName.endsWith(NAME_DEPLOYMENT_SUFFIX)) { + extensionName = extensionName.substring(0, extensionName.length() - NAME_DEPLOYMENT_SUFFIX.length()); } - if (runtime && name.endsWith(NAME_RUNTIME_SUFFIX)) { - name = name.substring(0, name.length() - NAME_RUNTIME_SUFFIX.length()); + if (moduleType == ExtensionModuleType.RUNTIME && extensionName.endsWith(NAME_RUNTIME_SUFFIX)) { + extensionName = extensionName.substring(0, extensionName.length() - NAME_RUNTIME_SUFFIX.length()); } } - return Extension.of(groupId, artifactId, name, nameSource, guideUrl); + return ExtensionModule.of(groupId, artifactId, moduleType, + Extension.of(groupId, extensionArtifactId, extensionName, extensionNameSource, guideUrl)); } private Optional getExtensionMetadata() { @@ -179,13 +186,21 @@ private Optional getExtensionMetadata() { private record ExtensionMetadata(String name, String guideUrl) { } - private boolean isRuntime() { + private ExtensionModuleType detectExtensionModuleType(String artifactId) { try { Path runtimeMarkerFile = Paths .get(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", RUNTIME_MARKER_FILE).toUri()); - return Files.exists(runtimeMarkerFile); + if (Files.exists(runtimeMarkerFile)) { + return ExtensionModuleType.RUNTIME; + } } catch (IOException e) { - return false; + // ignore, the file doesn't exist } + + if (artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) { + return ExtensionModuleType.DEPLOYMENT; + } + + return ExtensionModuleType.UNKNOWN; } }