Skip to content

Commit

Permalink
Work around Quarkus Core and Quarkus Messaging mixing two approaches
Browse files Browse the repository at this point in the history
Both use traditional config roots AND config mappings at the same time,
which won't be supported in the future.
For now, we try to be lenient as it's going to be a long and bumpy road
to fix it.
  • Loading branch information
gsmet committed Jul 31, 2024
1 parent 3f659a6 commit 83a7a98
Show file tree
Hide file tree
Showing 11 changed files with 111 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

public final class DiscoveryConfigGroup extends DiscoveryRootElement {

public DiscoveryConfigGroup(Extension extension, String binaryName, String qualifiedName) {
super(extension, binaryName, qualifiedName);
public DiscoveryConfigGroup(Extension extension, String binaryName, String qualifiedName, boolean configMapping) {
super(extension, binaryName, qualifiedName, configMapping);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public final class DiscoveryConfigRoot extends DiscoveryRootElement {
private final String overriddenDocFileName;

public DiscoveryConfigRoot(Extension extension, String prefix, String binaryName, String qualifiedName,
ConfigPhase configPhase, String overriddenDocFileName) {
super(extension, binaryName, qualifiedName);
ConfigPhase configPhase, String overriddenDocFileName, boolean configMapping) {
super(extension, binaryName, qualifiedName, configMapping);

this.prefix = prefix;
this.phase = configPhase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@ public sealed abstract class DiscoveryRootElement permits DiscoveryConfigRoot, D
private final List<String> unresolvedInterfaces = new ArrayList<>();
private final Map<String, DiscoveryConfigProperty> properties = new LinkedHashMap<>();

DiscoveryRootElement(Extension extension, String binaryName, String qualifiedName) {
// TODO #42114 remove once fixed
// this is an approximation, we can't fully detect that in the case of config groups
@Deprecated(forRemoval = true)
private final boolean configMapping;

DiscoveryRootElement(Extension extension, String binaryName, String qualifiedName, boolean configMapping) {
this.extension = extension;
this.binaryName = binaryName;
this.qualifiedName = qualifiedName;
this.configMapping = configMapping;
}

public Extension getExtension() {
Expand Down Expand Up @@ -59,6 +65,11 @@ public Map<String, DiscoveryConfigProperty> getProperties() {
return Collections.unmodifiableMap(properties);
}

@Deprecated(forRemoval = true)
public boolean isConfigMapping() {
return configMapping;
}

public String toString() {
return toString("");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
package io.quarkus.annotation.processor.documentation.config.model;

import com.fasterxml.jackson.annotation.JsonIgnore;

public record Extension(String groupId, String artifactId, String name) {

// TODO #42114 remove once fixed
@Deprecated(forRemoval = true)
@JsonIgnore
public boolean isMixedModule() {
return "io.quarkus".equals(groupId) && ("quarkus-core".equals(artifactId) || "quarkus-messaging".equals(artifactId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ protected AbstractConfigListener(Config config, Utils utils, ConfigCollector con
public Optional<DiscoveryConfigGroup> onConfigGroup(TypeElement configGroup) {
DiscoveryConfigGroup discoveryConfigGroup = new DiscoveryConfigGroup(config.getExtension(),
utils.element().getBinaryName(configGroup),
configGroup.getQualifiedName().toString());
configGroup.getQualifiedName().toString(),
// interface config groups are considered config mappings, let's hope it's enough
configGroup.getKind() == ElementKind.INTERFACE);
configCollector.addResolvedConfigGroup(discoveryConfigGroup);
return Optional.of(discoveryConfigGroup);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,26 @@ public ConfigAnnotationScanner(Config config, Utils utils) {
this.configCollector = new ConfigCollector();

List<ConfigAnnotationListener> listeners = new ArrayList<>();
if (config.useConfigMapping()) {
listeners.add(new JavadocConfigMappingListener(config, utils, configCollector));
listeners.add(new ConfigMappingListener(config, utils, configCollector));
if (!config.getExtension().isMixedModule()) {
// This is what we aim for. We have an exception for Quarkus Core and Quarkus Messaging though.
if (config.useConfigMapping()) {
listeners.add(new JavadocConfigMappingListener(config, utils, configCollector));
listeners.add(new ConfigMappingListener(config, utils, configCollector));
} else {
listeners.add(new JavadocLegacyConfigRootListener(config, utils, configCollector));
listeners.add(new LegacyConfigListener(config, utils, configCollector));
}
} else {
listeners.add(new JavadocLegacyConfigRootListener(config, utils, configCollector));
listeners.add(new LegacyConfigListener(config, utils, configCollector));
// TODO #42114 remove once fixed
// we handle both traditional config roots and config mappings
if (config.getExtension().isMixedModule()) {
listeners.add(new JavadocConfigMappingListener(config, utils, configCollector));
listeners.add(new JavadocLegacyConfigRootListener(config, utils, configCollector));
listeners.add(new ConfigMappingListener(config, utils, configCollector));
listeners.add(new LegacyConfigListener(config, utils, configCollector));
}
}

this.listeners = Collections.unmodifiableList(listeners);
}

Expand Down Expand Up @@ -408,7 +421,8 @@ private <T extends DiscoveryRootElement> T applyRootListeners(
Optional<T> discoveryRootElementCandidate = listenerFunction.apply(listener);
if (discoveryRootElementCandidate.isPresent()) {
if (discoveryRootElement != null) {
throw new IllegalStateException("Multiple listeners returned discovery root elements");
throw new IllegalStateException("Multiple listeners returned discovery root elements for: " +
discoveryRootElement.getQualifiedName());
}

discoveryRootElement = discoveryRootElementCandidate.get();
Expand All @@ -425,7 +439,9 @@ private <T extends DiscoveryRootElement> T applyRootListeners(
private void checkConfigRootAnnotationConsistency(TypeElement configRoot) {
// for now quarkus-core is a mix of both @ConfigRoot and @ConfigMapping
// see https://github.com/quarkusio/quarkus/issues/42114
if ("quarkus-core".equals(config.getExtension().artifactId())) {
// same for Quarkus Messaging
// TODO #42114 remove once fixed
if (config.getExtension().isMixedModule()) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;

import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigGroup;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigProperty;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigRoot;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement;
Expand All @@ -30,6 +32,10 @@ public class ConfigMappingListener extends AbstractConfigListener {

@Override
public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
if (config.getExtension().isMixedModule() && configRoot.getKind() != ElementKind.INTERFACE) {
return Optional.empty();
}

String prefix = Markers.DEFAULT_PREFIX;
ConfigPhase configPhase = ConfigPhase.BUILD_TIME;

Expand Down Expand Up @@ -89,19 +95,27 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
String binaryName = utils.element().getBinaryName(configRoot);

DiscoveryConfigRoot discoveryConfigRoot = new DiscoveryConfigRoot(config.getExtension(), rootPrefix,
binaryName, configRoot.getQualifiedName().toString(), configPhase, overriddenDocFileName);
binaryName, configRoot.getQualifiedName().toString(), configPhase, overriddenDocFileName, true);
configCollector.addConfigRoot(discoveryConfigRoot);
return Optional.of(discoveryConfigRoot);
}

@Override
public void onUnresolvedInterface(DiscoveryRootElement discoveryRootElement, TypeElement interfaze) {
if (config.getExtension().isMixedModule() && !discoveryRootElement.isConfigMapping()) {
return;
}

discoveryRootElement.addUnresolvedInterfaces(interfaze.getQualifiedName().toString());
}

@Override
public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElement clazz, ExecutableElement method,
ResolvedType resolvedType) {
if (config.getExtension().isMixedModule() && !discoveryRootElement.isConfigMapping()) {
return;
}

Map<String, AnnotationMirror> methodAnnotations = utils.element().getAnnotations(method);

String sourceName = method.getSimpleName().toString();
Expand Down Expand Up @@ -169,4 +183,14 @@ public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElem

discoveryRootElement.addProperty(builder.build());
}

@Deprecated(forRemoval = true)
@Override
public Optional<DiscoveryConfigGroup> onConfigGroup(TypeElement configGroup) {
if (config.getExtension().isMixedModule() && configGroup.getKind() != ElementKind.INTERFACE) {
return Optional.empty();
}

return super.onConfigGroup(configGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class JavadocConfigMappingListener extends AbstractJavadocConfigListener
@Override
public void onEnclosedMethod(DiscoveryRootElement discoveryRootElement, TypeElement clazz, ExecutableElement method,
ResolvedType resolvedType) {
if (config.getExtension().isMixedModule() && !discoveryRootElement.isConfigMapping()) {
return;
}

String docComment = utils.element().getRequiredJavadoc(method);
configCollector.addJavadocProperty(
clazz.getQualifiedName().toString() + Markers.DOT + method.getSimpleName().toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public class JavadocLegacyConfigRootListener extends AbstractJavadocConfigListen
@Override
public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeElement clazz, VariableElement field,
ResolvedType resolvedType) {
if (config.getExtension().isMixedModule() && discoveryRootElement.isConfigMapping()) {
return;
}

configCollector.addJavadocProperty(clazz.getQualifiedName().toString() + Markers.DOT + field.getSimpleName()
.toString(), utils.element().getRequiredJavadoc(field));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;

import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigGroup;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigProperty;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryConfigRoot;
import io.quarkus.annotation.processor.documentation.config.discovery.DiscoveryRootElement;
Expand All @@ -32,6 +34,10 @@ public class LegacyConfigListener extends AbstractConfigListener {

@Override
public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {
if (config.getExtension().isMixedModule() && configRoot.getKind() == ElementKind.INTERFACE) {
return Optional.empty();
}

String prefix = Markers.DEFAULT_PREFIX;
ConfigPhase configPhase = ConfigPhase.BUILD_TIME;

Expand Down Expand Up @@ -87,19 +93,27 @@ public Optional<DiscoveryConfigRoot> onConfigRoot(TypeElement configRoot) {

DiscoveryConfigRoot discoveryConfigRoot = new DiscoveryConfigRoot(config.getExtension(), rootPrefix,
binaryName, configRoot.getQualifiedName().toString(),
configPhase, overriddenDocFileName);
configPhase, overriddenDocFileName, false);
configCollector.addConfigRoot(discoveryConfigRoot);
return Optional.of(discoveryConfigRoot);
}

@Override
public void onUnresolvedSuperclass(DiscoveryRootElement discoveryRootElement, TypeElement superclass) {
if (config.getExtension().isMixedModule() && discoveryRootElement.isConfigMapping()) {
return;
}

discoveryRootElement.setUnresolvedSuperclass(superclass.getQualifiedName().toString());
}

@Override
public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeElement clazz, VariableElement field,
ResolvedType resolvedType) {
if (config.getExtension().isMixedModule() && discoveryRootElement.isConfigMapping()) {
return;
}

Map<String, AnnotationMirror> fieldAnnotations = utils.element().getAnnotations(field);

String sourceName = field.getSimpleName().toString();
Expand Down Expand Up @@ -171,4 +185,14 @@ public void onEnclosedField(DiscoveryRootElement discoveryRootElement, TypeEleme

discoveryRootElement.addProperty(builder.build());
}

@Deprecated(forRemoval = true)
@Override
public Optional<DiscoveryConfigGroup> onConfigGroup(TypeElement configGroup) {
if (config.getExtension().isMixedModule() && configGroup.getKind() == ElementKind.INTERFACE) {
return Optional.empty();
}

return super.onConfigGroup(configGroup);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ private void processConfigRoot(RoundEnvironment roundEnv, TypeElement annotation
private void processConfigGroup(RoundEnvironment roundEnv, TypeElement annotation) {
for (TypeElement configGroup : typesIn(roundEnv.getElementsAnnotatedWith(annotation))) {
// TODO for config groups, we generate an accessor only if we don't use @ConfigMapping
// and for core which is still a mess
if (!config.useConfigMapping() || "quarkus-core".equals(config.getExtension().artifactId())) {
// and for core and messaging which are still a mess
if (!config.useConfigMapping() || config.getExtension().isMixedModule()) {
utils.accessorGenerator().generateAccessor(configGroup);
}
}
Expand Down

0 comments on commit 83a7a98

Please sign in to comment.