Skip to content

Commit d1c3ae8

Browse files
authored
Merge pull request #44388 from gsmet/fix-config-generation
Fix some invalid configuration cases for doc generation and fail the build if some description are missing
2 parents 7603085 + 1813c5a commit d1c3ae8

File tree

10 files changed

+132
-57
lines changed

10 files changed

+132
-57
lines changed

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/GenerateConfigDocMojo.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
import io.quarkus.annotation.processor.documentation.config.model.Extension;
3838
import io.quarkus.maven.config.doc.generator.Format;
3939
import io.quarkus.maven.config.doc.generator.Formatter;
40+
import io.quarkus.maven.config.doc.generator.GenerationReport;
41+
import io.quarkus.maven.config.doc.generator.GenerationReport.GenerationViolation;
4042
import io.quarkus.qute.Engine;
4143
import io.quarkus.qute.ReflectionValueResolver;
4244
import io.quarkus.qute.UserTagSectionHelper;
@@ -91,13 +93,14 @@ public void execute() throws MojoExecutionException, MojoFailureException {
9193

9294
List<Path> targetDirectories = findTargetDirectories(resolvedScanDirectory);
9395

96+
GenerationReport generationReport = new GenerationReport();
9497
JavadocRepository javadocRepository = JavadocMerger.mergeJavadocElements(targetDirectories);
9598
MergedModel mergedModel = ModelMerger.mergeModel(javadocRepository, targetDirectories, true);
9699

97100
Format normalizedFormat = Format.normalizeFormat(format);
98101

99102
String normalizedTheme = normalizedFormat.normalizeTheme(theme);
100-
Formatter formatter = Formatter.getFormatter(javadocRepository, enableEnumTooltips, normalizedFormat);
103+
Formatter formatter = Formatter.getFormatter(generationReport, javadocRepository, enableEnumTooltips, normalizedFormat);
101104
Engine quteEngine = initializeQuteEngine(formatter, normalizedFormat, normalizedTheme);
102105

103106
// we generate a file per extension + top level prefix
@@ -168,6 +171,21 @@ public void execute() throws MojoExecutionException, MojoFailureException {
168171
}
169172
}
170173

174+
if (!generationReport.getViolations().isEmpty()) {
175+
StringBuilder report = new StringBuilder(
176+
"One or more errors happened during the configuration documentation generation. Here is a full report:\n\n");
177+
for (Entry<String, List<GenerationViolation>> violationsEntry : generationReport.getViolations().entrySet()) {
178+
report.append("- ").append(violationsEntry.getKey()).append("\n");
179+
for (GenerationViolation violation : violationsEntry.getValue()) {
180+
report.append(" . ").append(violation.sourceElement()).append(" - ").append(violation.message())
181+
.append("\n");
182+
}
183+
report.append("\n----\n\n");
184+
}
185+
186+
throw new IllegalStateException(report.toString());
187+
}
188+
171189
// we generate files for generated sections
172190
for (Entry<Extension, List<ConfigSection>> extensionConfigSectionsEntry : mergedModel.getGeneratedConfigSections()
173191
.entrySet()) {

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AbstractFormatter.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,16 @@
1515
import io.quarkus.annotation.processor.documentation.config.model.JavadocFormat;
1616
import io.quarkus.annotation.processor.documentation.config.util.Types;
1717
import io.quarkus.maven.config.doc.GenerateConfigDocMojo.Context;
18+
import io.quarkus.maven.config.doc.generator.GenerationReport.ConfigPropertyGenerationViolation;
1819

1920
abstract class AbstractFormatter implements Formatter {
2021

22+
protected final GenerationReport generationReport;
2123
protected final JavadocRepository javadocRepository;
2224
protected final boolean enableEnumTooltips;
2325

24-
AbstractFormatter(JavadocRepository javadocRepository, boolean enableEnumTooltips) {
26+
AbstractFormatter(GenerationReport generationReport, JavadocRepository javadocRepository, boolean enableEnumTooltips) {
27+
this.generationReport = generationReport;
2528
this.javadocRepository = javadocRepository;
2629
this.enableEnumTooltips = enableEnumTooltips;
2730
}
@@ -41,12 +44,17 @@ public String formatDescription(ConfigProperty configProperty) {
4144
configProperty.getSourceElementName());
4245

4346
if (javadocElement.isEmpty()) {
47+
generationReport.addError(new ConfigPropertyGenerationViolation(configProperty.getSourceType(),
48+
configProperty.getSourceElementName(), configProperty.getSourceElementType(), "Missing Javadoc"));
4449
return null;
4550
}
4651

4752
String description = JavadocTransformer.transform(javadocElement.get().description(), javadocElement.get().format(),
4853
javadocFormat());
4954
if (description == null || description.isBlank()) {
55+
generationReport.addError(new ConfigPropertyGenerationViolation(configProperty.getSourceType(),
56+
configProperty.getSourceElementName(), configProperty.getSourceElementType(),
57+
"Transformed Javadoc is empty"));
5058
return null;
5159
}
5260

@@ -204,17 +212,20 @@ public String formatSectionTitle(ConfigSection configSection) {
204212
configSection.getSourceElementName());
205213

206214
if (javadocElement.isEmpty()) {
207-
throw new IllegalStateException(
208-
"Couldn't find section title for: " + configSection.getSourceType() + "#"
209-
+ configSection.getSourceElementName());
215+
generationReport.addError(new ConfigPropertyGenerationViolation(configSection.getSourceType(),
216+
configSection.getSourceElementName(), configSection.getSourceElementType(), "Missing Javadoc"));
217+
218+
return null;
210219
}
211220

212221
String javadoc = JavadocTransformer.transform(javadocElement.get().description(), javadocElement.get().format(),
213222
javadocFormat());
214223
if (javadoc == null || javadoc.isBlank()) {
215-
throw new IllegalStateException(
216-
"Couldn't find section title for: " + configSection.getSourceType() + "#"
217-
+ configSection.getSourceElementName());
224+
generationReport.addError(new ConfigPropertyGenerationViolation(configSection.getSourceType(),
225+
configSection.getSourceElementName(), configSection.getSourceElementType(),
226+
"Transformed Javadoc is empty"));
227+
228+
return null;
218229
}
219230

220231
return trimFinalDot(javadoc);

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/AsciidocFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ final class AsciidocFormatter extends AbstractFormatter {
2424
private static final Pattern ANGLE_BRACKETS_WITH_DESCRIPTION_PATTERN = Pattern.compile("<<([a-z0-9_\\-#\\.]+?),([^>]+?)>>",
2525
Pattern.CASE_INSENSITIVE);
2626

27-
AsciidocFormatter(JavadocRepository javadocRepository, boolean enableEnumTooltips) {
28-
super(javadocRepository, enableEnumTooltips);
27+
AsciidocFormatter(GenerationReport generationReport, JavadocRepository javadocRepository, boolean enableEnumTooltips) {
28+
super(generationReport, javadocRepository, enableEnumTooltips);
2929
}
3030

3131
@Override

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/Formatter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,13 @@ default String formatDescription(ConfigProperty configProperty, Extension extens
3131

3232
String formatName(Extension extension);
3333

34-
static Formatter getFormatter(JavadocRepository javadocRepository, boolean enableEnumTooltips, Format format) {
34+
static Formatter getFormatter(GenerationReport generationReport, JavadocRepository javadocRepository,
35+
boolean enableEnumTooltips, Format format) {
3536
switch (format) {
3637
case asciidoc:
37-
return new AsciidocFormatter(javadocRepository, enableEnumTooltips);
38+
return new AsciidocFormatter(generationReport, javadocRepository, enableEnumTooltips);
3839
case markdown:
39-
return new MarkdownFormatter(javadocRepository);
40+
return new MarkdownFormatter(generationReport, javadocRepository);
4041
default:
4142
throw new IllegalArgumentException("Unsupported format: " + format);
4243
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.quarkus.maven.config.doc.generator;
2+
3+
import java.util.ArrayList;
4+
import java.util.LinkedHashMap;
5+
import java.util.List;
6+
import java.util.Map;
7+
8+
import io.quarkus.annotation.processor.documentation.config.model.SourceElementType;
9+
10+
public class GenerationReport {
11+
12+
private Map<String, List<GenerationViolation>> violations = new LinkedHashMap<>();
13+
14+
void addError(GenerationViolation error) {
15+
this.violations.computeIfAbsent(error.sourceType(), k -> new ArrayList<>()).add(error);
16+
}
17+
18+
public Map<String, List<GenerationViolation>> getViolations() {
19+
return violations;
20+
}
21+
22+
public record ConfigPropertyGenerationViolation(String sourceType, String sourceElement,
23+
SourceElementType sourceElementType, String message) implements GenerationViolation {
24+
25+
@Override
26+
public String sourceElement() {
27+
return sourceElement + (sourceElementType == SourceElementType.METHOD ? "()" : "");
28+
}
29+
}
30+
31+
public interface GenerationViolation {
32+
33+
String sourceType();
34+
35+
String sourceElement();
36+
37+
String message();
38+
}
39+
}

devtools/config-doc-maven-plugin/src/main/java/io/quarkus/maven/config/doc/generator/MarkdownFormatter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ final class MarkdownFormatter extends AbstractFormatter {
99

1010
private static final String MORE_INFO_ABOUT_TYPE_FORMAT = "[🛈](#%s)";
1111

12-
MarkdownFormatter(JavadocRepository javadocRepository) {
13-
super(javadocRepository, false);
12+
MarkdownFormatter(GenerationReport generationReport, JavadocRepository javadocRepository) {
13+
super(generationReport, javadocRepository, false);
1414
}
1515

1616
@Override

extensions/container-image/container-image-docker-common/deployment/src/main/java/io/quarkus/container/image/docker/common/deployment/CommonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66

77
import io.quarkus.runtime.annotations.ConfigDocDefault;
88
import io.quarkus.runtime.annotations.ConfigDocMapKey;
9+
import io.quarkus.runtime.annotations.ConfigGroup;
910

11+
@ConfigGroup
1012
public interface CommonConfig {
1113
/**
1214
* Path to the JVM Dockerfile.

extensions/narayana-jta/runtime/src/main/java/io/quarkus/narayana/jta/runtime/TransactionManagerConfiguration.java

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -72,47 +72,47 @@ public final class TransactionManagerConfiguration {
7272
*/
7373
@ConfigItem
7474
public ObjectStoreConfig objectStore;
75-
}
76-
77-
@ConfigGroup
78-
class ObjectStoreConfig {
79-
/**
80-
* The name of the directory where the transaction logs will be stored when using the {@code file-system} object store.
81-
* If the value is not absolute then the directory is relative
82-
* to the <em>user.dir</em> system property.
83-
*/
84-
@ConfigItem(defaultValue = "ObjectStore")
85-
public String directory;
86-
87-
/**
88-
* The type of object store.
89-
*/
90-
@ConfigItem(defaultValue = "file-system")
91-
public ObjectStoreType type;
92-
93-
/**
94-
* The name of the datasource where the transaction logs will be stored when using the {@code jdbc} object store.
95-
* <p>
96-
* If undefined, it will use the default datasource.
97-
*/
98-
@ConfigItem
99-
public Optional<String> datasource = Optional.empty();
10075

101-
/**
102-
* Whether to create the table if it does not exist.
103-
*/
104-
@ConfigItem(defaultValue = "false")
105-
public boolean createTable;
106-
107-
/**
108-
* Whether to drop the table on startup.
109-
*/
110-
@ConfigItem(defaultValue = "false")
111-
public boolean dropTable;
112-
113-
/**
114-
* The prefix to apply to the table.
115-
*/
116-
@ConfigItem(defaultValue = "quarkus_")
117-
public String tablePrefix;
76+
@ConfigGroup
77+
public static class ObjectStoreConfig {
78+
/**
79+
* The name of the directory where the transaction logs will be stored when using the {@code file-system} object store.
80+
* If the value is not absolute then the directory is relative
81+
* to the <em>user.dir</em> system property.
82+
*/
83+
@ConfigItem(defaultValue = "ObjectStore")
84+
public String directory;
85+
86+
/**
87+
* The type of object store.
88+
*/
89+
@ConfigItem(defaultValue = "file-system")
90+
public ObjectStoreType type;
91+
92+
/**
93+
* The name of the datasource where the transaction logs will be stored when using the {@code jdbc} object store.
94+
* <p>
95+
* If undefined, it will use the default datasource.
96+
*/
97+
@ConfigItem
98+
public Optional<String> datasource = Optional.empty();
99+
100+
/**
101+
* Whether to create the table if it does not exist.
102+
*/
103+
@ConfigItem(defaultValue = "false")
104+
public boolean createTable;
105+
106+
/**
107+
* Whether to drop the table on startup.
108+
*/
109+
@ConfigItem(defaultValue = "false")
110+
public boolean dropTable;
111+
112+
/**
113+
* The prefix to apply to the table.
114+
*/
115+
@ConfigItem(defaultValue = "quarkus_")
116+
public String tablePrefix;
117+
}
118118
}

extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/config/OidcClientCommonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import java.util.Optional;
55

66
import io.quarkus.runtime.annotations.ConfigDocMapKey;
7+
import io.quarkus.runtime.annotations.ConfigGroup;
78
import io.smallrye.config.WithDefault;
89

10+
@ConfigGroup
911
public interface OidcClientCommonConfig extends OidcCommonConfig {
1012
/**
1113
* The OIDC token endpoint that issues access and refresh tokens;

extensions/oidc-common/runtime/src/main/java/io/quarkus/oidc/common/runtime/config/OidcCommonConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import java.util.OptionalInt;
77

88
import io.quarkus.runtime.annotations.ConfigDocDefault;
9+
import io.quarkus.runtime.annotations.ConfigGroup;
910
import io.smallrye.config.WithDefault;
1011

12+
@ConfigGroup
1113
public interface OidcCommonConfig {
1214
/**
1315
* The base URL of the OpenID Connect (OIDC) server, for example, `https://host:port/auth`.

0 commit comments

Comments
 (0)