diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java index 3086400e7762..c2c59a549c10 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptor.java @@ -36,6 +36,8 @@ class LombokPropertyDescriptor extends PropertyDescriptor { private static final String LOMBOK_DATA_ANNOTATION = "lombok.Data"; + private static final String LOMBOK_VALUE_ANNOTATION = "lombok.Value"; + private static final String LOMBOK_GETTER_ANNOTATION = "lombok.Getter"; private static final String LOMBOK_SETTER_ANNOTATION = "lombok.Setter"; @@ -100,7 +102,11 @@ private boolean hasLombokPublicAccessor(MetadataGenerationEnvironment env, boole if (lombokMethodAnnotationOnElement != null) { return isAccessLevelPublic(env, lombokMethodAnnotationOnElement); } - return (env.getAnnotation(getOwnerElement(), LOMBOK_DATA_ANNOTATION) != null); + return (hasAnnotation(env, LOMBOK_DATA_ANNOTATION) || hasAnnotation(env, LOMBOK_VALUE_ANNOTATION)); + } + + private boolean hasAnnotation(MetadataGenerationEnvironment env, String lombokAnnotation) { + return (env.getAnnotation(getOwnerElement(), lombokAnnotation) != null); } private boolean isAccessLevelPublic(MetadataGenerationEnvironment env, AnnotationMirror lombokAnnotation) { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokMetadataGenerationTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokMetadataGenerationTests.java index 943fcd1c4331..af75dedbc969 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokMetadataGenerationTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokMetadataGenerationTests.java @@ -29,6 +29,7 @@ import org.springframework.boot.configurationsample.lombok.LombokInnerClassWithGetterProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleProperties; +import org.springframework.boot.configurationsample.lombok.LombokSimpleValueProperties; import org.springframework.boot.configurationsample.lombok.SimpleLombokPojo; import static org.assertj.core.api.Assertions.assertThat; @@ -46,6 +47,12 @@ void lombokDataProperties() { assertSimpleLombokProperties(metadata, LombokSimpleDataProperties.class, "data"); } + @Test + void lombokValueProperties() { + ConfigurationMetadata metadata = compile(LombokSimpleValueProperties.class); + assertSimpleLombokProperties(metadata, LombokSimpleValueProperties.class, "value"); + } + @Test void lombokSimpleProperties() { ConfigurationMetadata metadata = compile(LombokSimpleProperties.class); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java index 21bddfaaaf2e..2512010f7755 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokPropertyDescriptorTests.java @@ -30,6 +30,7 @@ import org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleProperties; +import org.springframework.boot.configurationsample.lombok.LombokSimpleValueProperties; import org.springframework.boot.configurationsample.simple.SimpleProperties; import org.springframework.boot.configurationsample.specific.InnerClassProperties; @@ -114,6 +115,16 @@ void lombokSimplePropertyWithOnlyGetterOnDataClassShouldNotBeExposed() throws IO }); } + @Test + void lombokSimplePropertyWithOnlyGetterOnValueClassShouldNotBeExposed() throws IOException { + process(LombokSimpleValueProperties.class, (roundEnv, metadataEnv) -> { + TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleValueProperties.class); + LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignored"); + assertThat(property.isProperty(metadataEnv)).isFalse(); + assertThat(property.isNested(metadataEnv)).isFalse(); + }); + } + @Test void lombokSimplePropertyWithOnlyGetterOnFieldShouldNotBeExposed() throws IOException { process(LombokExplicitProperties.class, (roundEnv, metadataEnv) -> { diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolverTests.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolverTests.java index 6e3bb6312c63..93dc9504c189 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolverTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/PropertyDescriptorResolverTests.java @@ -41,6 +41,7 @@ import org.springframework.boot.configurationsample.lombok.LombokExplicitProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties; import org.springframework.boot.configurationsample.lombok.LombokSimpleProperties; +import org.springframework.boot.configurationsample.lombok.LombokSimpleValueProperties; import org.springframework.boot.configurationsample.simple.HierarchicalProperties; import org.springframework.boot.configurationsample.simple.HierarchicalPropertiesGrandparent; import org.springframework.boot.configurationsample.simple.HierarchicalPropertiesParent; @@ -104,6 +105,12 @@ void propertiesWithLombokDataClass() throws IOException { (stream) -> assertThat(stream).containsExactly("name", "description", "counter", "number", "items"))); } + @Test + void propertiesWithLombokValueClass() throws IOException { + process(LombokSimpleValueProperties.class, propertyNames( + (stream) -> assertThat(stream).containsExactly("name", "description", "counter", "number", "items"))); + } + @Test void propertiesWithConstructorWithConstructorBinding() throws IOException { process(ImmutableSimpleProperties.class, propertyNames( diff --git a/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokSimpleValueProperties.java b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokSimpleValueProperties.java new file mode 100644 index 000000000000..6f6a77987b58 --- /dev/null +++ b/spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/lombok/LombokSimpleValueProperties.java @@ -0,0 +1,54 @@ +/* + * Copyright 2012-2019 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.configurationsample.lombok; + +import java.util.ArrayList; +import java.util.List; + +import lombok.Value; + +import org.springframework.boot.configurationsample.ConfigurationProperties; + +/** + * Configuration properties using lombok @Value. + * + * @author Mark Jeffrey + */ +@Value +@ConfigurationProperties(prefix = "value") +@SuppressWarnings("unused") +public class LombokSimpleValueProperties { + + private final String id = "super-id"; + + /** + * Name description. + */ + private String name; + + private String description; + + private Integer counter; + + @Deprecated + private Integer number = 0; + + private final List items = new ArrayList<>(); + + private final String ignored = "foo"; + +}