Skip to content

Commit

Permalink
Merge pull request #12547 from gytis/use-naming-strategy-in-spring-pr…
Browse files Browse the repository at this point in the history
…operties

Check naming strategy in Spring Boot properties #12483
  • Loading branch information
geoand authored Oct 7, 2020
2 parents d63751e + 02d78ae commit cd50f5b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.springframework.boot.context.properties.ConfigurationProperties;

import io.quarkus.arc.config.ConfigProperties;
import io.quarkus.arc.deployment.ArcConfig;
import io.quarkus.arc.deployment.configproperties.ConfigPropertiesMetadataBuildItem;
import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
Expand All @@ -15,44 +16,47 @@

public class ConfigurationPropertiesProcessor {

private static final DotName CONFIGURATION_PROPERTIES_ANNOTATION = DotName
.createSimple(ConfigurationProperties.class.getName());
private static final DotName CONFIGURATION_PROPERTIES = DotName.createSimple(ConfigurationProperties.class.getName());

@BuildStep
public FeatureBuildItem registerFeature() {
return new FeatureBuildItem(Feature.SPRING_BOOT_PROPERTIES);
}

@BuildStep
public void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex,
public void produceConfigPropertiesMetadata(CombinedIndexBuildItem combinedIndex, ArcConfig arcConfig,
BuildProducer<ConfigPropertiesMetadataBuildItem> configPropertiesMetadataProducer) {
combinedIndex.getIndex()
.getAnnotations(CONFIGURATION_PROPERTIES_ANNOTATION)
.stream()
.map(annotation -> createConfigPropertiesMetadata(annotation, combinedIndex.getIndex()))
.forEach(configPropertiesMetadataProducer::produce);
ConfigProperties.NamingStrategy namingStrategy = arcConfig.configPropertiesDefaultNamingStrategy;
for (AnnotationInstance annotation : combinedIndex.getIndex().getAnnotations(CONFIGURATION_PROPERTIES)) {
configPropertiesMetadataProducer.produce(
createConfigPropertiesMetadata(annotation, combinedIndex.getIndex(), namingStrategy));
}
}

private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadata(AnnotationInstance annotation, IndexView index) {
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadata(AnnotationInstance annotation,
IndexView index, ConfigProperties.NamingStrategy namingStrategy) {
switch (annotation.target().kind()) {
case CLASS:
return createConfigPropertiesMetadataFromClass(annotation);
return createConfigPropertiesMetadataFromClass(annotation, namingStrategy);
case METHOD:
return createConfigPropertiesMetadataFromMethod(annotation, index);
return createConfigPropertiesMetadataFromMethod(annotation, index, namingStrategy);
default:
throw new IllegalArgumentException("Unsupported annotation target kind " + annotation.target().kind().name());
throw new IllegalArgumentException(
"Unsupported annotation target kind " + annotation.target().kind().name());
}
}

private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromClass(AnnotationInstance annotation) {
private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromClass(AnnotationInstance annotation,
ConfigProperties.NamingStrategy namingStrategy) {
return new ConfigPropertiesMetadataBuildItem(annotation.target().asClass(), getPrefix(annotation),
ConfigProperties.NamingStrategy.VERBATIM, true, false);
namingStrategy, true, false);
}

private ConfigPropertiesMetadataBuildItem createConfigPropertiesMetadataFromMethod(AnnotationInstance annotation,
IndexView index) {
return new ConfigPropertiesMetadataBuildItem(index.getClassByName(annotation.target().asMethod().returnType().name()),
getPrefix(annotation), ConfigProperties.NamingStrategy.VERBATIM, true, false);
IndexView index, ConfigProperties.NamingStrategy namingStrategy) {
return new ConfigPropertiesMetadataBuildItem(
index.getClassByName(annotation.target().asMethod().returnType().name()), getPrefix(annotation),
namingStrategy, true, false);
}

private String getPrefix(AnnotationInstance annotation) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cl.value=class-value
cl.anotherClass.value=true
cl.another-class.value=true
bean.value=1
bean.innerClass.value=inner-class-value
interface.value=interface-value
bean.inner-class.value=inner-class-value
interface.value=interface-value

0 comments on commit cd50f5b

Please sign in to comment.