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

Do not require @ConfigGroup to generate mappings documentation #32085

Merged
merged 1 commit into from
Mar 28, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.quarkus.annotation.processor;

import static io.quarkus.annotation.processor.Constants.ANNOTATION_CONFIG_MAPPING;
import static javax.lang.model.util.ElementFilter.constructorsIn;
import static javax.lang.model.util.ElementFilter.fieldsIn;
import static javax.lang.model.util.ElementFilter.methodsIn;
Expand Down Expand Up @@ -415,7 +416,7 @@ private void recordConfigJavadoc(TypeElement clazz) {
String className = clazz.getQualifiedName().toString();
if (!generatedJavaDocs.add(className))
return;
final Properties javadocProps = new Properties();
Properties javadocProps = new Properties();
for (Element e : clazz.getEnclosedElements()) {
switch (e.getKind()) {
case FIELD: {
Expand Down Expand Up @@ -455,7 +456,12 @@ private void recordMappingJavadoc(TypeElement clazz) {
String className = clazz.getQualifiedName().toString();
if (!generatedJavaDocs.add(className))
return;
final Properties javadocProps = new Properties();
if (!isAnnotationPresent(clazz, ANNOTATION_CONFIG_MAPPING)) {
if (generateDocs) {
configDocItemScanner.addConfigGroups(clazz);
}
}
Properties javadocProps = new Properties();
recordMappingJavadoc(clazz, javadocProps);
writeJavadocProperties(clazz, javadocProps);
}
Expand All @@ -478,6 +484,20 @@ private void recordMappingJavadoc(final TypeElement clazz, final Properties java
}
}

private boolean isEnclosedByMapping(Element clazz) {
if (clazz.getKind().equals(ElementKind.INTERFACE)) {
Element enclosingElement = clazz.getEnclosingElement();
if (enclosingElement.getKind().equals(ElementKind.INTERFACE)) {
if (isAnnotationPresent(enclosingElement, ANNOTATION_CONFIG_MAPPING)) {
return true;
} else {
isEnclosedByMapping(enclosingElement);
}
}
}
return false;
}

private void writeJavadocProperties(final TypeElement clazz, final Properties javadocProps) {
if (javadocProps.isEmpty())
return;
Expand Down Expand Up @@ -535,7 +555,11 @@ private void processConfigGroup(RoundEnvironment roundEnv, TypeElement annotatio
for (TypeElement i : typesIn(roundEnv.getElementsAnnotatedWith(annotation))) {
if (groupClassNames.add(i.getQualifiedName().toString())) {
generateAccessor(i);
recordConfigJavadoc(i);
if (isEnclosedByMapping(i) || i.getKind().equals(ElementKind.INTERFACE)) {
recordMappingJavadoc(i);
} else {
recordConfigJavadoc(i);
}
if (generateDocs) {
configDocItemScanner.addConfigGroups(i);
}
Expand All @@ -561,7 +585,7 @@ private void processConfigRoot(RoundEnvironment roundEnv, TypeElement annotation
final String binaryName = processingEnv.getElementUtils().getBinaryName(clazz).toString();
if (rootClassNames.add(binaryName)) {
// new class
if (isAnnotationPresent(clazz, Constants.ANNOTATION_CONFIG_MAPPING)) {
if (isAnnotationPresent(clazz, ANNOTATION_CONFIG_MAPPING)) {
recordMappingJavadoc(clazz);
} else if (isAnnotationPresent(clazz, Constants.ANNOTATION_CONFIG_ROOT)) {
recordConfigJavadoc(clazz);
Expand All @@ -572,7 +596,7 @@ private void processConfigRoot(RoundEnvironment roundEnv, TypeElement annotation
final FileObject itemResource = processingEnv.getFiler().createResource(
StandardLocation.SOURCE_OUTPUT,
pkg.getQualifiedName().toString(),
rbn.toString() + ".cr",
rbn + ".cr",
clazz);
writeResourceFile(binaryName, itemResource);
} catch (IOException e1) {
Expand Down
11 changes: 3 additions & 8 deletions docs/src/main/asciidoc/writing-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,6 @@ IMPORTANT: _Bootstrap_ configuration steps are executed during runtime-init *bef

[source%nowrap,java]
----
import io.quarkus.runtime.annotations.ConfigGroup;
import io.quarkus.runtime.annotations.ConfigPhase;
import io.quarkus.runtime.annotations.ConfigRoot;
import io.smallrye.config.ConfigMapping;
Expand All @@ -1135,7 +1134,6 @@ public interface LogConfiguration {
*/
FileConfig file();

@ConfigGroup // <3>
interface FileConfig {
/**
* Enable logging to a file.
Expand Down Expand Up @@ -1172,7 +1170,7 @@ public class LoggingProcessor {
/*
* Logging configuration.
*/
LogConfiguration config; // <4>
LogConfiguration config; // <3>
}
----

Expand All @@ -1182,15 +1180,12 @@ A configuration property name can be split into segments. For example, a propert
* `quarkus` - a namespace claimed by Quarkus which is a prefix for `@ConfigMapping` interfaces,
* `log` - a name segment which corresponds to the prefix set in the interface annotated with `@ConfigMapping`,
* `file` - a name segment which corresponds to the `file` field in this class,
* `enabled` - a name segment which corresponds to `enable` field in `FileConfig` class annotated with `@ConfigGroup`.
* `enable` - a name segment which corresponds to `enable` field in `FileConfig`.

<1> The `@ConfigMapping` annotation indicates that the interface is a configuration mapping, in this case one which
corresponds to a `quarkus.log` segment.
<2> The `@ConfigRoot` annotation indicated to which Config phase, the configuration applies to.
<3> The `FileConfig` class is annotated with `@ConfigGroup` to indicate that this is an aggregate
configuration object containing a collection of configurable properties, rather than being a simple configuration
key type.
<4> Here the `LoggingProcessor` injects a `LogConfiguration` instance automatically by detecting the `@ConfigRoot`
<3> Here the `LoggingProcessor` injects a `LogConfiguration` instance automatically by detecting the `@ConfigRoot`
annotation.

A corresponding `application.properties` for the above example could be:
Expand Down