Skip to content

Commit a4d7e2f

Browse files
committed
Fix runtime/deployment detection and propagate it
That way, we can assert if the module is a deployment module later in the process. Related to quarkusio#43513
1 parent 30d733f commit a4d7e2f

File tree

4 files changed

+74
-33
lines changed

4 files changed

+74
-33
lines changed

core/processor/src/main/java/io/quarkus/annotation/processor/ExtensionAnnotationProcessor.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import org.jboss.jdeparser.JDeparser;
2222

2323
import io.quarkus.annotation.processor.documentation.config.ConfigDocExtensionProcessor;
24-
import io.quarkus.annotation.processor.documentation.config.model.Extension;
24+
import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule;
2525
import io.quarkus.annotation.processor.documentation.config.util.Types;
2626
import io.quarkus.annotation.processor.extension.ExtensionBuildProcessor;
2727
import io.quarkus.annotation.processor.util.Config;
@@ -45,11 +45,12 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
4545
.parseBoolean(utils.processingEnv().getOptions().getOrDefault(Options.LEGACY_CONFIG_ROOT, "false"));
4646
boolean debug = Boolean.getBoolean(DEBUG);
4747

48-
Extension extension = utils.extension().getExtension();
49-
Config config = new Config(extension, useConfigMapping, debug);
48+
ExtensionModule extensionModule = utils.extension().getExtensionModule();
49+
50+
Config config = new Config(extensionModule, useConfigMapping, debug);
5051

5152
if (!useConfigMapping) {
52-
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Extension " + extension.artifactId()
53+
processingEnv.getMessager().printMessage(Diagnostic.Kind.WARNING, "Extension module " + extensionModule.artifactId()
5354
+ " config implementation is deprecated. Please migrate to use @ConfigMapping: https://quarkus.io/guides/writing-extensions#configuration");
5455
}
5556

@@ -61,7 +62,7 @@ public synchronized void init(ProcessingEnvironment processingEnv) {
6162

6263
// for now, we generate the old config doc by default but we will change this behavior soon
6364
if (generateDoc) {
64-
if (extension.detected()) {
65+
if (extensionModule.detected()) {
6566
extensionProcessors.add(new ConfigDocExtensionProcessor());
6667
} else {
6768
processingEnv.getMessager().printMessage(Kind.WARNING,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.quarkus.annotation.processor.documentation.config.model;
2+
3+
public record ExtensionModule(String groupId, String artifactId, ExtensionModuleType type, Extension extension,
4+
boolean detected) {
5+
6+
public static ExtensionModule createNotDetected() {
7+
return new ExtensionModule("not.detected", "not.detected", ExtensionModuleType.UNKNOWN, Extension.createNotDetected(),
8+
false);
9+
}
10+
11+
public static ExtensionModule of(String groupId, String artifactId, ExtensionModuleType type, Extension extension) {
12+
return new ExtensionModule(groupId, artifactId, type, extension, true);
13+
}
14+
15+
public enum ExtensionModuleType {
16+
RUNTIME,
17+
DEPLOYMENT,
18+
UNKNOWN;
19+
}
20+
}

core/processor/src/main/java/io/quarkus/annotation/processor/util/Config.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,26 @@
11
package io.quarkus.annotation.processor.util;
22

33
import io.quarkus.annotation.processor.documentation.config.model.Extension;
4+
import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule;
45

56
public class Config {
67

7-
private final Extension extension;
8+
private final ExtensionModule extensionModule;
89
private final boolean useConfigMapping;
910
private final boolean debug;
1011

11-
public Config(Extension extension, boolean useConfigMapping, boolean debug) {
12-
this.extension = extension;
12+
public Config(ExtensionModule extensionModule, boolean useConfigMapping, boolean debug) {
13+
this.extensionModule = extensionModule;
1314
this.useConfigMapping = useConfigMapping;
1415
this.debug = debug;
1516
}
1617

18+
public ExtensionModule getExtensionModule() {
19+
return extensionModule;
20+
}
21+
1722
public Extension getExtension() {
18-
return extension;
23+
return extensionModule.extension();
1924
}
2025

2126
public boolean useConfigMapping() {

core/processor/src/main/java/io/quarkus/annotation/processor/util/ExtensionUtil.java

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020

2121
import io.quarkus.annotation.processor.documentation.config.model.Extension;
2222
import io.quarkus.annotation.processor.documentation.config.model.Extension.NameSource;
23+
import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule;
24+
import io.quarkus.annotation.processor.documentation.config.model.ExtensionModule.ExtensionModuleType;
2325

2426
public final class ExtensionUtil {
2527

26-
private static final String RUNTIME_MARKER_FILE = "META-INF/quarkus.properties";
28+
private static final String RUNTIME_MARKER_FILE = "META-INF/quarkus-extension.properties";
2729

2830
private static final String ARTIFACT_DEPLOYMENT_SUFFIX = "-deployment";
2931
private static final String NAME_QUARKUS_PREFIX = "Quarkus - ";
@@ -42,11 +44,11 @@ public final class ExtensionUtil {
4244
* This is not exactly pretty but it's actually not easy to get the artifact id of the current artifact.
4345
* One option would be to pass it through the annotation processor but it's not exactly ideal.
4446
*/
45-
public Extension getExtension() {
47+
public ExtensionModule getExtensionModule() {
4648
Optional<Path> pom = filerUtil.getPomPath();
4749

4850
if (pom.isEmpty()) {
49-
return Extension.createNotDetected();
51+
return ExtensionModule.createNotDetected();
5052
}
5153

5254
Document doc;
@@ -61,10 +63,10 @@ public Extension getExtension() {
6163
throw new IllegalStateException("Unable to parse pom file: " + pom, e);
6264
}
6365

64-
return getExtensionFromPom(pom.get(), doc);
66+
return getExtensionModuleFromPom(pom.get(), doc);
6567
}
6668

67-
private Extension getExtensionFromPom(Path pom, Document doc) {
69+
private ExtensionModule getExtensionModuleFromPom(Path pom, Document doc) {
6870
String parentGroupId = null;
6971
String artifactId = null;
7072
String groupId = null;
@@ -111,40 +113,45 @@ private Extension getExtensionFromPom(Path pom, Document doc) {
111113

112114
if (groupId == null || groupId.isBlank() || artifactId == null || artifactId.isBlank()) {
113115
processingEnv.getMessager().printMessage(Kind.WARNING, "Unable to determine artifact coordinates from: " + pom);
114-
return Extension.createNotDetected();
116+
return ExtensionModule.createNotDetected();
115117
}
116118

117-
boolean runtime = isRuntime();
119+
ExtensionModuleType moduleType = detectExtensionModuleType(artifactId);
118120

119-
if (!runtime && artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) {
120-
artifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_DEPLOYMENT_SUFFIX.length());
121+
String extensionArtifactId;
122+
if (moduleType == ExtensionModuleType.DEPLOYMENT) {
123+
extensionArtifactId = artifactId.substring(0, artifactId.length() - ARTIFACT_DEPLOYMENT_SUFFIX.length());
124+
} else {
125+
extensionArtifactId = artifactId;
121126
}
122127

123-
NameSource nameSource;
128+
NameSource extensionNameSource;
124129
Optional<ExtensionMetadata> extensionMetadata = getExtensionMetadata();
125130
if (extensionMetadata.isPresent()) {
126131
name = extensionMetadata.get().name();
127-
nameSource = NameSource.EXTENSION_METADATA;
132+
extensionNameSource = NameSource.EXTENSION_METADATA;
128133
guideUrl = extensionMetadata.get().guideUrl();
129134
} else if (name != null) {
130-
nameSource = NameSource.POM_XML;
135+
extensionNameSource = NameSource.POM_XML;
131136
} else {
132-
nameSource = NameSource.NONE;
137+
extensionNameSource = NameSource.NONE;
133138
}
134139

135-
if (name != null) {
136-
if (name.startsWith(NAME_QUARKUS_PREFIX)) {
137-
name = name.substring(NAME_QUARKUS_PREFIX.length()).trim();
140+
String extensionName = name;
141+
if (extensionName != null) {
142+
if (extensionName.startsWith(NAME_QUARKUS_PREFIX)) {
143+
extensionName = extensionName.substring(NAME_QUARKUS_PREFIX.length()).trim();
138144
}
139-
if (!runtime && name.endsWith(NAME_DEPLOYMENT_SUFFIX)) {
140-
name = name.substring(0, name.length() - NAME_DEPLOYMENT_SUFFIX.length());
145+
if (moduleType == ExtensionModuleType.DEPLOYMENT && extensionName.endsWith(NAME_DEPLOYMENT_SUFFIX)) {
146+
extensionName = extensionName.substring(0, extensionName.length() - NAME_DEPLOYMENT_SUFFIX.length());
141147
}
142-
if (runtime && name.endsWith(NAME_RUNTIME_SUFFIX)) {
143-
name = name.substring(0, name.length() - NAME_RUNTIME_SUFFIX.length());
148+
if (moduleType == ExtensionModuleType.RUNTIME && extensionName.endsWith(NAME_RUNTIME_SUFFIX)) {
149+
extensionName = extensionName.substring(0, extensionName.length() - NAME_RUNTIME_SUFFIX.length());
144150
}
145151
}
146152

147-
return Extension.of(groupId, artifactId, name, nameSource, guideUrl);
153+
return ExtensionModule.of(groupId, artifactId, moduleType,
154+
Extension.of(groupId, extensionArtifactId, extensionName, extensionNameSource, guideUrl));
148155
}
149156

150157
private Optional<ExtensionMetadata> getExtensionMetadata() {
@@ -179,13 +186,21 @@ private Optional<ExtensionMetadata> getExtensionMetadata() {
179186
private record ExtensionMetadata(String name, String guideUrl) {
180187
}
181188

182-
private boolean isRuntime() {
189+
private ExtensionModuleType detectExtensionModuleType(String artifactId) {
183190
try {
184191
Path runtimeMarkerFile = Paths
185192
.get(processingEnv.getFiler().getResource(StandardLocation.CLASS_OUTPUT, "", RUNTIME_MARKER_FILE).toUri());
186-
return Files.exists(runtimeMarkerFile);
193+
if (Files.exists(runtimeMarkerFile)) {
194+
return ExtensionModuleType.RUNTIME;
195+
}
187196
} catch (IOException e) {
188-
return false;
197+
// ignore, the file doesn't exist
189198
}
199+
200+
if (artifactId.endsWith(ARTIFACT_DEPLOYMENT_SUFFIX)) {
201+
return ExtensionModuleType.DEPLOYMENT;
202+
}
203+
204+
return ExtensionModuleType.UNKNOWN;
190205
}
191206
}

0 commit comments

Comments
 (0)