Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix runtime/deployment detection and propagate it #44390

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
}

Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a dumb mistake on my side. It had no consequences until now but we need it to actually work from now on :).


private static final String ARTIFACT_DEPLOYMENT_SUFFIX = "-deployment";
private static final String NAME_QUARKUS_PREFIX = "Quarkus - ";
Expand All @@ -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<Path> pom = filerUtil.getPomPath();

if (pom.isEmpty()) {
return Extension.createNotDetected();
return ExtensionModule.createNotDetected();
}

Document doc;
Expand All @@ -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;
Expand Down Expand Up @@ -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> 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<ExtensionMetadata> getExtensionMetadata() {
Expand Down Expand Up @@ -179,13 +186,21 @@ private Optional<ExtensionMetadata> 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;
}
}
Loading