Skip to content

Commit

Permalink
Experiment with generating config files for the IDEs
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet committed Aug 21, 2024
1 parent 53831b7 commit 17e8476
Show file tree
Hide file tree
Showing 14 changed files with 204 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Properties;
Expand All @@ -14,6 +16,11 @@

import io.quarkus.annotation.processor.ExtensionProcessor;
import io.quarkus.annotation.processor.Outputs;
import io.quarkus.annotation.processor.documentation.config.ide.IdeConfigJavadocElements;
import io.quarkus.annotation.processor.documentation.config.ide.IdeConfigModel;
import io.quarkus.annotation.processor.documentation.config.model.AbstractConfigItem;
import io.quarkus.annotation.processor.documentation.config.model.ConfigItemVisitor;
import io.quarkus.annotation.processor.documentation.config.model.ConfigProperty;
import io.quarkus.annotation.processor.documentation.config.model.JavadocElements;
import io.quarkus.annotation.processor.documentation.config.model.JavadocElements.JavadocElement;
import io.quarkus.annotation.processor.documentation.config.model.ResolvedModel;
Expand Down Expand Up @@ -79,12 +86,12 @@ public void finalizeProcessing() {

// the model is not written in the jar file
JavadocElements javadocElements = configResolver.resolveJavadoc();
if (!javadocElements.elements().isEmpty()) {
if (!javadocElements.isEmpty()) {
utils.filer().writeModel(Outputs.QUARKUS_CONFIG_DOC_JAVADOC, javadocElements);
}

ResolvedModel resolvedModel = configResolver.resolveModel();
if (!resolvedModel.getConfigRoots().isEmpty()) {
if (!resolvedModel.isEmpty()) {
Path resolvedModelPath = utils.filer().writeModel(Outputs.QUARKUS_CONFIG_DOC_MODEL, resolvedModel);

if (config.isDebug()) {
Expand All @@ -97,5 +104,25 @@ public void finalizeProcessing() {
}
}

// Generate files for IDE consumption
if (!javadocElements.isEmpty()) {
IdeConfigJavadocElements ideConfigJavadocElements = IdeConfigJavadocElements.of(javadocElements);
utils.filer().writeJson(Outputs.META_INF_QUARKUS_CONFIG_JAVADOC, ideConfigJavadocElements);
}

if (!resolvedModel.isEmpty()) {
List<ConfigProperty> configProperties = new ArrayList<>();
resolvedModel.walk(new ConfigItemVisitor() {

@Override
public void visit(AbstractConfigItem configItem) {
if (configItem instanceof ConfigProperty configProperty) {
configProperties.add(configProperty);
}
}
});
IdeConfigModel ideConfigProperties = IdeConfigModel.of(config.getExtension(), configProperties);
utils.filer().writeJson(Outputs.META_INF_QUARKUS_CONFIG_MODEL, ideConfigProperties);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import java.util.List;

import io.quarkus.annotation.processor.documentation.config.model.JavadocElements;

public record IdeConfigJavadocElements(IdeExtension extension, List<IdeConfigJavadocElement> elements) {

public record IdeConfigJavadocElement(String key, String description, String since) {
}

public static IdeConfigJavadocElements of(JavadocElements javadocElements) {
return new IdeConfigJavadocElements(IdeExtension.of(javadocElements.extension()),
javadocElements.elements().entrySet().stream()
.map(e -> new IdeConfigJavadocElement(e.getKey(), e.getValue().description(), e.getValue().since()))
.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import java.util.List;

import io.quarkus.annotation.processor.documentation.config.model.ConfigProperty;
import io.quarkus.annotation.processor.documentation.config.model.Extension;

public record IdeConfigModel(IdeExtension extension, List<IdeConfigProperty> properties) {

public static IdeConfigModel of(Extension extension, List<ConfigProperty> properties) {
return new IdeConfigModel(IdeExtension.of(extension),
properties.stream().map(p -> IdeConfigProperty.of(p)).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import io.quarkus.annotation.processor.documentation.config.model.ConfigPhase;

public enum IdeConfigPhase {

RUN_TIME,
BUILD_TIME,
BUILD_AND_RUN_TIME_FIXED;

public static IdeConfigPhase of(ConfigPhase phase) {
switch (phase) {
case BUILD_AND_RUN_TIME_FIXED:
return IdeConfigPhase.BUILD_AND_RUN_TIME_FIXED;
case BUILD_TIME:
return IdeConfigPhase.BUILD_TIME;
case RUN_TIME:
return IdeConfigPhase.RUN_TIME;
default:
throw new IllegalStateException("Phase " + phase + " not supported in " + IdeConfigPhase.class.getSimpleName());
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import java.util.List;

import io.quarkus.annotation.processor.documentation.config.model.ConfigProperty;

public record IdeConfigProperty(
IdeConfigPhase phase,
String path,
List<String> additionalPaths,
String environmentVariable,
String sourceClass,
String sourceName,
String type,
String typeDescription,
String javadocLink,
String defaultValue,
boolean optional,
boolean isEnum,
IdeEnumAcceptedValues enumAcceptedValues,
boolean deprecated) {

public static IdeConfigProperty of(ConfigProperty configProperty) {
return new IdeConfigProperty(IdeConfigPhase.of(configProperty.getPhase()),
configProperty.getPath(),
configProperty.getAdditionalPaths(),
configProperty.getEnvironmentVariable(),
configProperty.getSourceClass(),
configProperty.getSourceName(),
configProperty.getType(),
configProperty.getTypeDescription(),
configProperty.getJavadocSiteLink(),
configProperty.getDefaultValue(),
configProperty.isOptional(),
configProperty.isEnum(),
IdeEnumAcceptedValues.of(configProperty.getEnumAcceptedValues()),
configProperty.isDeprecated());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;

import io.quarkus.annotation.processor.documentation.config.model.EnumAcceptedValues;
import io.quarkus.annotation.processor.documentation.config.model.EnumAcceptedValues.EnumAcceptedValue;

public record IdeEnumAcceptedValues(String qualifiedName, Map<String, IdeEnumAcceptedValue> values) {

public record IdeEnumAcceptedValue(String configValue) {

public static IdeEnumAcceptedValue of(EnumAcceptedValue enumAcceptedValue) {
return new IdeEnumAcceptedValue(enumAcceptedValue.configValue());
}
}

public static IdeEnumAcceptedValues of(EnumAcceptedValues enumAcceptedValues) {
if (enumAcceptedValues == null) {
return null;
}

return new IdeEnumAcceptedValues(enumAcceptedValues.qualifiedName(),
enumAcceptedValues.values().entrySet().stream()
.collect(Collectors.toMap(Entry::getKey, v -> IdeEnumAcceptedValue.of(v.getValue()))));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.quarkus.annotation.processor.documentation.config.ide;

import io.quarkus.annotation.processor.documentation.config.model.Extension;

public record IdeExtension(String groupId, String artifactId) {

public static IdeExtension of(Extension extension) {
return new IdeExtension(extension.groupId(), extension.artifactId());
}
}
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 @@ -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();
}
}

0 comments on commit 17e8476

Please sign in to comment.