Skip to content

Commit ea95c24

Browse files
committed
Config doc - Write the model as JSON in jars
It comes with a version marker.
1 parent b1c2c06 commit ea95c24

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public final class Outputs {
1717
public static final String META_INF_QUARKUS_CONFIG = "META-INF/" + QUARKUS_CONFIG_DOC;
1818
public static final String META_INF_QUARKUS_CONFIG_JAVADOC_JSON = META_INF_QUARKUS_CONFIG + "/quarkus-config-javadoc.json";
1919
public static final String META_INF_QUARKUS_CONFIG_MODEL_JSON = META_INF_QUARKUS_CONFIG + "/quarkus-config-model.json";
20-
public static final String META_INF_QUARKUS_CONFIG_JAVADOC_YAML = META_INF_QUARKUS_CONFIG + "/quarkus-config-javadoc.yaml";
21-
public static final String META_INF_QUARKUS_CONFIG_MODEL_YAML = META_INF_QUARKUS_CONFIG + "/quarkus-config-model.yaml";
20+
public static final String META_INF_QUARKUS_CONFIG_MODEL_VERSION = META_INF_QUARKUS_CONFIG
21+
+ "/quarkus-config-model-version";
2222

2323
/**
2424
* Ideally, we should remove this file at some point.

core/processor/src/main/java/io/quarkus/annotation/processor/documentation/config/ConfigDocExtensionProcessor.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private Optional<TypeElement> findAnnotation(Set<? extends TypeElement> annotati
6969
public void finalizeProcessing() {
7070
ConfigCollector configCollector = configAnnotationScanner.finalizeProcessing();
7171

72+
// TODO radcortez drop this once we don't need them anymore
73+
// we will still need to read the quarkus-javadoc.properties in the Dev UI for now to allow for extensions built with older Quarkus versions
7274
Properties javadocProperties = new Properties();
7375
for (Entry<String, JavadocElement> javadocElementEntry : configCollector.getJavadocElements().entrySet()) {
7476
if (javadocElementEntry.getValue().description() == null
@@ -84,12 +86,12 @@ public void finalizeProcessing() {
8486

8587
// the model is not written in the jar file
8688
JavadocElements javadocElements = configResolver.resolveJavadoc();
87-
if (!javadocElements.elements().isEmpty()) {
89+
if (!javadocElements.isEmpty()) {
8890
utils.filer().writeModel(Outputs.QUARKUS_CONFIG_DOC_JAVADOC, javadocElements);
8991
}
9092

9193
ResolvedModel resolvedModel = configResolver.resolveModel();
92-
if (!resolvedModel.getConfigRoots().isEmpty()) {
94+
if (!resolvedModel.isEmpty()) {
9395
Path resolvedModelPath = utils.filer().writeModel(Outputs.QUARKUS_CONFIG_DOC_MODEL, resolvedModel);
9496

9597
if (config.isDebug()) {
@@ -101,5 +103,17 @@ public void finalizeProcessing() {
101103
}
102104
}
103105
}
106+
107+
// Generate files that will be stored in the jar and can be consumed freely.
108+
// We generate JSON files to avoid requiring an additional dependency to the YAML mapper
109+
if (!javadocElements.isEmpty()) {
110+
utils.filer().writeJson(Outputs.META_INF_QUARKUS_CONFIG_JAVADOC_JSON, javadocElements);
111+
}
112+
if (!resolvedModel.isEmpty()) {
113+
utils.filer().writeJson(Outputs.META_INF_QUARKUS_CONFIG_MODEL_JSON, resolvedModel);
114+
}
115+
if (!javadocElements.isEmpty() || !resolvedModel.isEmpty()) {
116+
utils.filer().write(Outputs.META_INF_QUARKUS_CONFIG_MODEL_VERSION, "1");
117+
}
104118
}
105119
}

core/processor/src/main/java/io/quarkus/annotation/processor/util/FilerUtil.java

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ public class FilerUtil {
3434
this.processingEnv = processingEnv;
3535
}
3636

37+
/**
38+
* This method uses the annotation processor Filer API and we shouldn't use a Path as paths containing \ are not supported.
39+
*/
40+
public void write(String filePath, String value) {
41+
if (value == null || value.isBlank()) {
42+
return;
43+
}
44+
45+
try {
46+
final FileObject listResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
47+
filePath);
48+
49+
try (BufferedWriter writer = new BufferedWriter(
50+
new OutputStreamWriter(listResource.openOutputStream(), StandardCharsets.UTF_8))) {
51+
writer.write(value);
52+
}
53+
} catch (IOException e) {
54+
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to write " + filePath + ": " + e);
55+
return;
56+
}
57+
}
58+
3759
/**
3860
* This method uses the annotation processor Filer API and we shouldn't use a Path as paths containing \ are not supported.
3961
*/
@@ -44,7 +66,7 @@ public void write(String filePath, Set<String> set) {
4466

4567
try {
4668
final FileObject listResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
47-
filePath.toString());
69+
filePath);
4870

4971
try (BufferedWriter writer = new BufferedWriter(
5072
new OutputStreamWriter(listResource.openOutputStream(), StandardCharsets.UTF_8))) {
@@ -69,7 +91,7 @@ public void write(String filePath, Properties properties) {
6991

7092
try {
7193
final FileObject propertiesResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
72-
filePath.toString());
94+
filePath);
7395

7496
try (BufferedWriter writer = new BufferedWriter(
7597
new OutputStreamWriter(propertiesResource.openOutputStream(), StandardCharsets.UTF_8))) {
@@ -91,7 +113,7 @@ public void writeJson(String filePath, Object value) {
91113

92114
try {
93115
final FileObject jsonResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
94-
filePath.toString());
116+
filePath);
95117

96118
try (OutputStream os = jsonResource.openOutputStream()) {
97119
JacksonMappers.jsonObjectWriter().writeValue(os, value);
@@ -112,7 +134,7 @@ public void writeYaml(String filePath, Object value) {
112134

113135
try {
114136
final FileObject yamlResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
115-
filePath.toString());
137+
filePath);
116138

117139
try (OutputStream os = yamlResource.openOutputStream()) {
118140
JacksonMappers.yamlObjectWriter().writeValue(os, value);

0 commit comments

Comments
 (0)