forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#6269 from gytis/spring-boot-properties
Spring Boot properties extension
- Loading branch information
Showing
33 changed files
with
723 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...in/java/io/quarkus/arc/deployment/configproperties/ConfigPropertiesMetadataBuildItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package io.quarkus.arc.deployment.configproperties; | ||
|
||
import static io.quarkus.runtime.util.StringUtil.camelHumpsIterator; | ||
import static io.quarkus.runtime.util.StringUtil.join; | ||
import static io.quarkus.runtime.util.StringUtil.lowerCase; | ||
import static io.quarkus.runtime.util.StringUtil.withoutSuffix; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.AnnotationValue; | ||
import org.jboss.jandex.ClassInfo; | ||
import org.jboss.jandex.DotName; | ||
|
||
import io.quarkus.arc.config.ConfigProperties; | ||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
public final class ConfigPropertiesMetadataBuildItem extends MultiBuildItem { | ||
|
||
private static final DotName CONFIG_PROPERTIES_ANNOTATION = DotName.createSimple(ConfigProperties.class.getName()); | ||
|
||
private final ClassInfo classInfo; | ||
|
||
private final String prefix; | ||
|
||
public ConfigPropertiesMetadataBuildItem(AnnotationInstance annotation) { | ||
if (!CONFIG_PROPERTIES_ANNOTATION.equals(annotation.name())) { | ||
throw new IllegalArgumentException(annotation + " is not an instance of " + ConfigProperties.class.getSimpleName()); | ||
} | ||
|
||
this.classInfo = annotation.target().asClass(); | ||
this.prefix = extractPrefix(annotation); | ||
} | ||
|
||
public ConfigPropertiesMetadataBuildItem(ClassInfo classInfo, String prefix) { | ||
this.classInfo = classInfo; | ||
this.prefix = sanitisePrefix(prefix); | ||
} | ||
|
||
public ClassInfo getClassInfo() { | ||
return classInfo; | ||
} | ||
|
||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
private String extractPrefix(AnnotationInstance annotationInstance) { | ||
AnnotationValue value = annotationInstance.value("prefix"); | ||
return sanitisePrefix(value == null ? null : value.asString()); | ||
} | ||
|
||
private String sanitisePrefix(String prefix) { | ||
if (isPrefixUnset(prefix)) { | ||
return getPrefixFromClassName(classInfo.name()); | ||
} | ||
return prefix; | ||
} | ||
|
||
private boolean isPrefixUnset(String prefix) { | ||
return prefix == null || "".equals(prefix.trim()) || ConfigProperties.UNSET_PREFIX.equals(prefix.trim()); | ||
} | ||
|
||
private String getPrefixFromClassName(DotName className) { | ||
String simpleName = className.isInner() ? className.local() : className.withoutPackagePrefix(); | ||
return join("-", | ||
withoutSuffix(lowerCase(camelHumpsIterator(simpleName)), "config", "configuration", | ||
"properties", "props")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>quarkus-spring-boot-properties-parent</artifactId> | ||
<groupId>io.quarkus</groupId> | ||
<version>999-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>quarkus-spring-boot-properties-deployment</artifactId> | ||
<name>Quarkus - Spring Boot - Properties - Deployment</name> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-spring-boot-properties</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-arc-deployment</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<annotationProcessorPaths> | ||
<path> | ||
<groupId>io.quarkus</groupId> | ||
<artifactId>quarkus-extension-processor</artifactId> | ||
<version>${project.version}</version> | ||
</path> | ||
</annotationProcessorPaths> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
64 changes: 64 additions & 0 deletions
64
...n/java/io/quarkus/spring/boot/properties/deployment/ConfigurationPropertiesProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.spring.boot.properties.deployment; | ||
|
||
import org.jboss.jandex.AnnotationInstance; | ||
import org.jboss.jandex.DotName; | ||
import org.jboss.jandex.IndexView; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import io.quarkus.arc.deployment.configproperties.ConfigPropertiesMetadataBuildItem; | ||
import io.quarkus.deployment.annotations.BuildProducer; | ||
import io.quarkus.deployment.annotations.BuildStep; | ||
import io.quarkus.deployment.builditem.CombinedIndexBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
|
||
public class ConfigurationPropertiesProcessor { | ||
|
||
private static final DotName CONFIGURATION_PROPERTIES_ANNOTATION = DotName | ||
.createSimple(ConfigurationProperties.class.getName()); | ||
|
||
@BuildStep | ||
public FeatureBuildItem registerFeature() { | ||
return new FeatureBuildItem(FeatureBuildItem.SPRING_BOOT_PROPERTIES); | ||
} | ||
|
||
@BuildStep | ||
public void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex, | ||
BuildProducer<ConfigPropertiesMetadataBuildItem> configPropertiesMetadataProducer) { | ||
combinedIndex.getIndex() | ||
.getAnnotations(CONFIGURATION_PROPERTIES_ANNOTATION) | ||
.stream() | ||
.map(annotation -> createConfigPropertiesMetadata(annotation, combinedIndex.getIndex())) | ||
.forEach(configPropertiesMetadataProducer::produce); | ||
} | ||
|
||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadata(AnnotationInstance annotation, IndexView index) { | ||
switch (annotation.target().kind()) { | ||
case CLASS: | ||
return createConfigPropertiesMetadataFromClass(annotation); | ||
case METHOD: | ||
return createConfigPropertiesMetadataFromMethod(annotation, index); | ||
default: | ||
throw new IllegalArgumentException("Unsupported annotation target kind " + annotation.target().kind().name()); | ||
} | ||
} | ||
|
||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromClass(AnnotationInstance annotation) { | ||
return new ConfigPropertiesMetadataBuildItem(annotation.target().asClass(), getPrefix(annotation)); | ||
} | ||
|
||
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromMethod(AnnotationInstance annotation, | ||
IndexView index) { | ||
return new ConfigPropertiesMetadataBuildItem(index.getClassByName(annotation.target().asMethod().returnType().name()), | ||
getPrefix(annotation)); | ||
} | ||
|
||
private String getPrefix(AnnotationInstance annotation) { | ||
if (annotation.value() != null) { | ||
return annotation.value().asString(); | ||
} else if (annotation.value("prefix") != null) { | ||
return annotation.value("prefix").asString(); | ||
} | ||
|
||
return null; | ||
} | ||
} |
Oops, something went wrong.