Skip to content

Commit

Permalink
Improve compatibility of the model with ZipPath and deserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 22, 2024
1 parent 0ee5a29 commit bdc25a7
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,29 +1,24 @@
package io.quarkus.annotation.processor;

import java.nio.file.Path;

/**
* Define the output here so that they are clearly identified.
* Define the outputs here so that they are clearly identified.
* <p>
* Paths are resolved from target/classes.
* DO NOT use Path as we need maximum compatibility with the filer API and the ZipPath API.
*/
public final class Outputs {

public static final String META_INF_QUARKUS_BUILD_STEPS = "META-INF/quarkus-build-steps.list";
public static final String META_INF_QUARKUS_CONFIG_ROOTS = "META-INF/quarkus-config-roots.list";

public static final String META_INF_QUARKUS_CONFIG = "META-INF/quarkus-config";
public static final String META_INF_QUARKUS_CONFIG_JAVADOC = META_INF_QUARKUS_CONFIG + "/quarkus-config-javadoc.json";
public static final String META_INF_QUARKUS_CONFIG_MODEL = META_INF_QUARKUS_CONFIG + "/quarkus-config-model.json";
private static final String QUARKUS_CONFIG_DOC = "quarkus-config-doc";
public static final String QUARKUS_CONFIG_DOC_JAVADOC = QUARKUS_CONFIG_DOC + "/quarkus-config-javadoc.yaml";
public static final String QUARKUS_CONFIG_DOC_MODEL = QUARKUS_CONFIG_DOC + "/quarkus-config-model.yaml";

/**
* This directory is specific and written directly into target/ as it's not a file we want to package.
* <p>
* It is not written by the annotation processor Filer API so we can use proper Paths.
*/
private static final Path QUARKUS_CONFIG_DOC = Path.of("quarkus-config-doc");
public static final Path QUARKUS_CONFIG_DOC_JAVADOC = QUARKUS_CONFIG_DOC.resolve("quarkus-config-javadoc.yaml");
public static final Path QUARKUS_CONFIG_DOC_MODEL = QUARKUS_CONFIG_DOC.resolve("quarkus-config-model.yaml");
public static final String META_INF_QUARKUS_CONFIG = "META-INF/" + QUARKUS_CONFIG_DOC;
public static final String META_INF_QUARKUS_CONFIG_JAVADOC_JSON = META_INF_QUARKUS_CONFIG + "/quarkus-config-javadoc.json";
public static final String META_INF_QUARKUS_CONFIG_MODEL_JSON = META_INF_QUARKUS_CONFIG + "/quarkus-config-model.json";
public static final String META_INF_QUARKUS_CONFIG_JAVADOC_YAML = META_INF_QUARKUS_CONFIG + "/quarkus-config-javadoc.yaml";
public static final String META_INF_QUARKUS_CONFIG_MODEL_YAML = META_INF_QUARKUS_CONFIG + "/quarkus-config-model.yaml";

/**
* Ideally, we should remove this file at some point.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,5 @@ public void finalizeProcessing() {
}
}
}

}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.annotation.processor.documentation.config.merger;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
Expand All @@ -26,8 +27,8 @@ public static JavadocRepository mergeJavadocElements(List<Path> buildOutputDirec
continue;
}

try {
JavadocElements javadocElements = JacksonMappers.yamlObjectReader().readValue(javadocPath.toFile(),
try (InputStream javadocIs = Files.newInputStream(javadocPath)) {
JavadocElements javadocElements = JacksonMappers.yamlObjectReader().readValue(javadocIs,
JavadocElements.class);

if (javadocElements.elements() == null || javadocElements.elements().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,8 @@ public Map<String, ConfigRoot> getConfigRootsInSpecificFile() {
public Map<Extension, List<ConfigSection>> getGeneratedConfigSections() {
return generatedConfigSections;
}

public boolean isEmpty() {
return configRoots.isEmpty();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.annotation.processor.documentation.config.merger;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -44,8 +45,8 @@ public static MergedModel mergeModel(List<Path> buildOutputDirectories) {
continue;
}

try {
ResolvedModel resolvedModel = JacksonMappers.yamlObjectReader().readValue(resolvedModelPath.toFile(),
try (InputStream resolvedModelIs = Files.newInputStream(resolvedModelPath)) {
ResolvedModel resolvedModel = JacksonMappers.yamlObjectReader().readValue(resolvedModelIs,
ResolvedModel.class);

if (resolvedModel.getConfigRoots() == null || resolvedModel.getConfigRoots().isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public ConfigProperty(ConfigPhase phase, String sourceClass, String sourceName,
boolean deprecated) {
super(sourceClass, sourceName, path, type, deprecated);
this.phase = phase;
this.additionalPaths = additionalPaths;
this.additionalPaths = additionalPaths != null ? additionalPaths : List.of();
this.environmentVariable = environmentVariable;
this.typeDescription = typeDescription;
this.map = map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,33 @@ public void writeJson(String filePath, Object value) {
}
}

/**
* This method uses the annotation processor Filer API and we shouldn't use a Path as paths containing \ are not supported.
*/
public void writeYaml(String filePath, Object value) {
if (value == null) {
return;
}

try {
final FileObject yamlResource = processingEnv.getFiler().createResource(StandardLocation.CLASS_OUTPUT, "",
filePath.toString());

try (OutputStream os = yamlResource.openOutputStream()) {
JacksonMappers.yamlObjectWriter().writeValue(os, value);
}
} catch (IOException e) {
processingEnv.getMessager().printMessage(Diagnostic.Kind.ERROR, "Failed to write " + filePath + ": " + e);
return;
}
}

/**
* The model files are written outside of target/classes as we don't want to include them in the jar.
* <p>
* They are not written by the annotation processor Filer API so we can use proper Paths.
*/
public Path writeModel(Path filePath, Object value) {
public Path writeModel(String filePath, Object value) {
Path yamlModelPath = getTargetPath().resolve(filePath);
try {
Files.createDirectories(yamlModelPath.getParent());
Expand Down

0 comments on commit bdc25a7

Please sign in to comment.