Skip to content

Commit 8302f5c

Browse files
committed
Make the name of the configuration adoc file configurable fix quarkusio#36189
1 parent 7ae8e29 commit 8302f5c

File tree

3 files changed

+46
-8
lines changed

3 files changed

+46
-8
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ final public class Constants {
6363
public static final String ANNOTATION_CONFIG_DOC_SECTION = "io.quarkus.runtime.annotations.ConfigDocSection";
6464
public static final String ANNOTATION_CONFIG_DOC_ENUM_VALUE = "io.quarkus.runtime.annotations.ConfigDocEnumValue";
6565
public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault";
66+
public static final String ANNOTATION_CONFIG_DOC_FILE_NAME = "io.quarkus.runtime.annotations.ConfigDocFilename";
6667

6768
public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName";
6869
public static final String ANNOTATION_CONFIG_WITH_PARENT_NAME = "io.smallrye.config.WithParentName";

core/processor/src/main/java/io/quarkus/annotation/processor/generate_doc/ConfigDocItemScanner.java

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,36 @@ public void addConfigRoot(final PackageElement pkg, TypeElement clazz) {
9797
}
9898
}
9999

100+
String docFileName = null;
101+
for (AnnotationMirror mirror : clazz.getAnnotationMirrors()) {
102+
if (mirror.getAnnotationType().toString().equals(Constants.ANNOTATION_CONFIG_DOC_FILE_NAME)) {
103+
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues()
104+
.entrySet()) {
105+
if ("value()".equals(entry.getKey().toString())) {
106+
docFileName = entry.getValue().getValue().toString();
107+
break;
108+
}
109+
}
110+
break;
111+
}
112+
}
113+
100114
name = getName(prefix, name, clazz.getSimpleName().toString(), configPhase);
101115
if (name.endsWith(Constants.DOT + Constants.PARENT)) {
102116
// take into account the root case which would contain characters that can't be used to create the final file
103117
name = name.replace(Constants.DOT + Constants.PARENT, "");
104118
}
105119

106-
final Matcher pkgMatcher = Constants.PKG_PATTERN.matcher(pkg.toString());
107-
final String fileName;
108-
if (pkgMatcher.find()) {
109-
fileName = DocGeneratorUtil.computeExtensionDocFileName(clazz.toString());
110-
} else {
111-
fileName = name.replace(Constants.DOT, Constants.DASH.charAt(0)) + Constants.ADOC_EXTENSION;
120+
if (docFileName == null || docFileName.isEmpty()) {
121+
final Matcher pkgMatcher = Constants.PKG_PATTERN.matcher(pkg.toString());
122+
if (pkgMatcher.find()) {
123+
docFileName = DocGeneratorUtil.computeExtensionDocFileName(clazz.toString());
124+
} else {
125+
docFileName = name.replace(Constants.DOT, Constants.DASH.charAt(0))
126+
+ Constants.ADOC_EXTENSION;
127+
}
112128
}
113-
114-
ConfigRootInfo configRootInfo = new ConfigRootInfo(name, clazz, configPhase, fileName);
129+
ConfigRootInfo configRootInfo = new ConfigRootInfo(name, clazz, configPhase, docFileName);
115130
configRoots.add(configRootInfo);
116131
break;
117132
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package io.quarkus.runtime.annotations;
2+
3+
import static java.lang.annotation.RetentionPolicy.SOURCE;
4+
5+
import java.lang.annotation.Documented;
6+
import java.lang.annotation.ElementType;
7+
import java.lang.annotation.Retention;
8+
import java.lang.annotation.Target;
9+
10+
import io.smallrye.config.ConfigMapping;
11+
12+
/**
13+
* Specifies the file name where {@code quarkus-extension-processor} will output the documentation in AsciiDoc format.
14+
* If not specified, the effective file name is derived either from the class name or {@link ConfigMapping#prefix()}.
15+
*/
16+
@Documented
17+
@Retention(SOURCE)
18+
@Target({ ElementType.TYPE })
19+
public @interface ConfigDocFilename {
20+
21+
String value();
22+
}

0 commit comments

Comments
 (0)