20
20
21
21
import io .quarkus .annotation .processor .documentation .config .model .Extension ;
22
22
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 ;
23
25
24
26
public final class ExtensionUtil {
25
27
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" ;
27
29
28
30
private static final String ARTIFACT_DEPLOYMENT_SUFFIX = "-deployment" ;
29
31
private static final String NAME_QUARKUS_PREFIX = "Quarkus - " ;
@@ -42,11 +44,11 @@ public final class ExtensionUtil {
42
44
* This is not exactly pretty but it's actually not easy to get the artifact id of the current artifact.
43
45
* One option would be to pass it through the annotation processor but it's not exactly ideal.
44
46
*/
45
- public Extension getExtension () {
47
+ public ExtensionModule getExtensionModule () {
46
48
Optional <Path > pom = filerUtil .getPomPath ();
47
49
48
50
if (pom .isEmpty ()) {
49
- return Extension .createNotDetected ();
51
+ return ExtensionModule .createNotDetected ();
50
52
}
51
53
52
54
Document doc ;
@@ -61,10 +63,10 @@ public Extension getExtension() {
61
63
throw new IllegalStateException ("Unable to parse pom file: " + pom , e );
62
64
}
63
65
64
- return getExtensionFromPom (pom .get (), doc );
66
+ return getExtensionModuleFromPom (pom .get (), doc );
65
67
}
66
68
67
- private Extension getExtensionFromPom (Path pom , Document doc ) {
69
+ private ExtensionModule getExtensionModuleFromPom (Path pom , Document doc ) {
68
70
String parentGroupId = null ;
69
71
String artifactId = null ;
70
72
String groupId = null ;
@@ -111,40 +113,45 @@ private Extension getExtensionFromPom(Path pom, Document doc) {
111
113
112
114
if (groupId == null || groupId .isBlank () || artifactId == null || artifactId .isBlank ()) {
113
115
processingEnv .getMessager ().printMessage (Kind .WARNING , "Unable to determine artifact coordinates from: " + pom );
114
- return Extension .createNotDetected ();
116
+ return ExtensionModule .createNotDetected ();
115
117
}
116
118
117
- boolean runtime = isRuntime ( );
119
+ ExtensionModuleType moduleType = detectExtensionModuleType ( artifactId );
118
120
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 ;
121
126
}
122
127
123
- NameSource nameSource ;
128
+ NameSource extensionNameSource ;
124
129
Optional <ExtensionMetadata > extensionMetadata = getExtensionMetadata ();
125
130
if (extensionMetadata .isPresent ()) {
126
131
name = extensionMetadata .get ().name ();
127
- nameSource = NameSource .EXTENSION_METADATA ;
132
+ extensionNameSource = NameSource .EXTENSION_METADATA ;
128
133
guideUrl = extensionMetadata .get ().guideUrl ();
129
134
} else if (name != null ) {
130
- nameSource = NameSource .POM_XML ;
135
+ extensionNameSource = NameSource .POM_XML ;
131
136
} else {
132
- nameSource = NameSource .NONE ;
137
+ extensionNameSource = NameSource .NONE ;
133
138
}
134
139
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 ();
138
144
}
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 ());
141
147
}
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 ());
144
150
}
145
151
}
146
152
147
- return Extension .of (groupId , artifactId , name , nameSource , guideUrl );
153
+ return ExtensionModule .of (groupId , artifactId , moduleType ,
154
+ Extension .of (groupId , extensionArtifactId , extensionName , extensionNameSource , guideUrl ));
148
155
}
149
156
150
157
private Optional <ExtensionMetadata > getExtensionMetadata () {
@@ -179,13 +186,21 @@ private Optional<ExtensionMetadata> getExtensionMetadata() {
179
186
private record ExtensionMetadata (String name , String guideUrl ) {
180
187
}
181
188
182
- private boolean isRuntime ( ) {
189
+ private ExtensionModuleType detectExtensionModuleType ( String artifactId ) {
183
190
try {
184
191
Path runtimeMarkerFile = Paths
185
192
.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
+ }
187
196
} catch (IOException e ) {
188
- return false ;
197
+ // ignore, the file doesn't exist
189
198
}
199
+
200
+ if (artifactId .endsWith (ARTIFACT_DEPLOYMENT_SUFFIX )) {
201
+ return ExtensionModuleType .DEPLOYMENT ;
202
+ }
203
+
204
+ return ExtensionModuleType .UNKNOWN ;
190
205
}
191
206
}
0 commit comments