Skip to content

Commit

Permalink
Make the name of the configuration adoc file configurable fix quarkus…
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Oct 5, 2023
1 parent 7ae8e29 commit 001782e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ final public class Constants {
public static final String ANNOTATION_CONFIG_DOC_SECTION = "io.quarkus.runtime.annotations.ConfigDocSection";
public static final String ANNOTATION_CONFIG_DOC_ENUM_VALUE = "io.quarkus.runtime.annotations.ConfigDocEnumValue";
public static final String ANNOTATION_CONFIG_DOC_DEFAULT = "io.quarkus.runtime.annotations.ConfigDocDefault";
public static final String ANNOTATION_CONFIG_DOC_FILE_NAME = "io.quarkus.runtime.annotations.ConfigDocFilename";

public static final String ANNOTATION_CONFIG_WITH_NAME = "io.smallrye.config.WithName";
public static final String ANNOTATION_CONFIG_WITH_PARENT_NAME = "io.smallrye.config.WithParentName";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,21 +97,36 @@ public void addConfigRoot(final PackageElement pkg, TypeElement clazz) {
}
}

String docFileName = null;
for (AnnotationMirror mirror : clazz.getAnnotationMirrors()) {
if (mirror.getAnnotationType().toString().equals(Constants.ANNOTATION_CONFIG_DOC_FILE_NAME)) {
for (Entry<? extends ExecutableElement, ? extends AnnotationValue> entry : mirror.getElementValues()
.entrySet()) {
if ("value()".equals(entry.getKey().toString())) {
docFileName = entry.getValue().getValue().toString();
break;
}
}
break;
}
}

name = getName(prefix, name, clazz.getSimpleName().toString(), configPhase);
if (name.endsWith(Constants.DOT + Constants.PARENT)) {
// take into account the root case which would contain characters that can't be used to create the final file
name = name.replace(Constants.DOT + Constants.PARENT, "");
}

final Matcher pkgMatcher = Constants.PKG_PATTERN.matcher(pkg.toString());
final String fileName;
if (pkgMatcher.find()) {
fileName = DocGeneratorUtil.computeExtensionDocFileName(clazz.toString());
} else {
fileName = name.replace(Constants.DOT, Constants.DASH.charAt(0)) + Constants.ADOC_EXTENSION;
if (docFileName == null || docFileName.isEmpty()) {
final Matcher pkgMatcher = Constants.PKG_PATTERN.matcher(pkg.toString());
if (pkgMatcher.find()) {
docFileName = DocGeneratorUtil.computeExtensionDocFileName(clazz.toString());
} else {
docFileName = name.replace(Constants.DOT, Constants.DASH.charAt(0))
+ Constants.ADOC_EXTENSION;
}
}

ConfigRootInfo configRootInfo = new ConfigRootInfo(name, clazz, configPhase, fileName);
ConfigRootInfo configRootInfo = new ConfigRootInfo(name, clazz, configPhase, docFileName);
configRoots.add(configRootInfo);
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.runtime.annotations;

import static java.lang.annotation.RetentionPolicy.SOURCE;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;

import io.smallrye.config.ConfigMapping;



/**
* Specifies the file name where {@code quarkus-extension-processor} will output the documentation in AsciiDoc format.
* If not specified, the effective file name is derived either from the class name or {@link ConfigMapping#prefix()}.
*/
@Documented
@Retention(SOURCE)
@Target({ ElementType.TYPE })
public @interface ConfigDocFilename {

String value();
}

0 comments on commit 001782e

Please sign in to comment.