Skip to content

Commit

Permalink
Merge pull request quarkusio#42708 from gsmet/extension-annotation-pr…
Browse files Browse the repository at this point in the history
…ocessor-improvements

Extension annotation processor improvements
  • Loading branch information
gsmet authored Aug 27, 2024
2 parents d815152 + bdc25a7 commit fae59c9
Show file tree
Hide file tree
Showing 13 changed files with 84 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 @@ -51,4 +51,6 @@ public boolean isDeprecated() {

@JsonIgnore
public abstract boolean hasMemorySizeType();

protected abstract void walk(ConfigItemVisitor visitor);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.quarkus.annotation.processor.documentation.config.model;

public interface ConfigItemVisitor {

public void visit(AbstractConfigItem configItem);
}
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 Expand Up @@ -145,4 +145,9 @@ public boolean hasDurationType() {
public boolean hasMemorySizeType() {
return Types.MEMORY_SIZE_TYPE.equals(type);
}

@Override
protected void walk(ConfigItemVisitor visitor) {
visitor.visit(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,10 @@ private static String buildTopLevelPrefix(String prefix) {

return prefixSegments[0] + Markers.DOT + prefixSegments[1];
}

public void walk(ConfigItemVisitor visitor) {
for (AbstractConfigItem item : items) {
item.walk(visitor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,12 @@ public boolean hasMemorySizeType() {
}
return false;
}

@Override
protected void walk(ConfigItemVisitor visitor) {
visitor.visit(this);
for (AbstractConfigItem item : items) {
item.walk(visitor);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public record JavadocElements(Extension extension, Map<String, JavadocElement> e

public record JavadocElement(String description, String since, @JsonIgnore String rawJavadoc) {
}

public boolean isEmpty() {
return elements.isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,14 @@ public ResolvedModel(List<ConfigRoot> configRoots) {
public List<ConfigRoot> getConfigRoots() {
return configRoots;
}

public void walk(ConfigItemVisitor visitor) {
for (ConfigRoot configRoot : configRoots) {
configRoot.walk(visitor);
}
}

public boolean isEmpty() {
return configRoots.isEmpty();
}
}
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 fae59c9

Please sign in to comment.