mirror of
https://github.com/spring-projects/spring-boot.git
synced 2026-09-17 12:09:16 +00:00
Merge branch '3.5.x'
Closes gh-48355
This commit is contained in:
+14
-20
@@ -26,7 +26,6 @@ import java.nio.file.StandardOpenOption;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
@@ -74,27 +73,26 @@ import org.gradle.api.tasks.VerificationException;
|
||||
*/
|
||||
public abstract class ArchitectureCheck extends DefaultTask {
|
||||
|
||||
static final String CONDITIONAL_ON_CLASS = "ConditionalOnClass";
|
||||
|
||||
static final String DEPRECATED_CONFIGURATION_PROPERTY = "DeprecatedConfigurationProperty";
|
||||
|
||||
private static final String CONDITIONAL_ON_CLASS_ANNOTATION = "org.springframework.boot.autoconfigure.condition.ConditionalOnClass";
|
||||
|
||||
private static final String DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION = "org.springframework.boot.context.properties.DeprecatedConfigurationProperty";
|
||||
|
||||
private FileCollection classes;
|
||||
|
||||
public ArchitectureCheck() {
|
||||
getOutputDirectory().convention(getProject().getLayout().getBuildDirectory().dir(getName()));
|
||||
getAnnotationClasses().convention(Map.of(CONDITIONAL_ON_CLASS, CONDITIONAL_ON_CLASS_ANNOTATION,
|
||||
DEPRECATED_CONFIGURATION_PROPERTY, DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION));
|
||||
getAnnotationClasses().convention(ArchitectureCheckAnnotation.asMap());
|
||||
getRules().addAll(getProhibitObjectsRequireNonNull().convention(true)
|
||||
.map(whenTrue(ArchitectureRules::noClassesShouldCallObjectsRequireNonNull)));
|
||||
getRules().addAll(ArchitectureRules.standard());
|
||||
getRules().addAll(whenMainSources(() -> ArchitectureRules
|
||||
.beanMethods(annotationClassFor(CONDITIONAL_ON_CLASS, CONDITIONAL_ON_CLASS_ANNOTATION))));
|
||||
getRules().addAll(whenMainSources(() -> ArchitectureRules.configurationProperties(
|
||||
annotationClassFor(DEPRECATED_CONFIGURATION_PROPERTY, DEPRECATED_CONFIGURATION_PROPERTY_ANNOTATION))));
|
||||
getRules().addAll(whenMainSources(() -> ArchitectureRules.beanMethods(ArchitectureCheckAnnotation
|
||||
.classFor(getAnnotationClasses().get(), ArchitectureCheckAnnotation.CONDITIONAL_ON_CLASS))));
|
||||
getRules().addAll(whenMainSources(() -> ArchitectureRules.conditionalOnMissingBean(ArchitectureCheckAnnotation
|
||||
.classFor(getAnnotationClasses().get(), ArchitectureCheckAnnotation.CONDITIONAL_ON_MISSING_BEAN))));
|
||||
getRules().addAll(whenMainSources(() -> ArchitectureRules.configurationProperties(ArchitectureCheckAnnotation
|
||||
.classFor(getAnnotationClasses().get(), ArchitectureCheckAnnotation.CONFIGURATION_PROPERTIES))));
|
||||
getRules().addAll(whenMainSources(
|
||||
() -> ArchitectureRules.configurationPropertiesBinding(ArchitectureCheckAnnotation.classFor(
|
||||
getAnnotationClasses().get(), ArchitectureCheckAnnotation.CONFIGURATION_PROPERTIES_BINDING))));
|
||||
getRules().addAll(whenMainSources(
|
||||
() -> ArchitectureRules.configurationPropertiesDeprecation(ArchitectureCheckAnnotation.classFor(
|
||||
getAnnotationClasses().get(), ArchitectureCheckAnnotation.DEPRECATED_CONFIGURATION_PROPERTY))));
|
||||
getRules().addAll(and(getNullMarkedEnabled(), isMainSourceSet()).map(whenTrue(() -> Collections.singletonList(
|
||||
ArchitectureRules.packagesShouldBeAnnotatedWithNullMarked(getNullMarkedIgnoredPackages().get())))));
|
||||
getRuleDescriptions().set(getRules().map(this::asDescriptions));
|
||||
@@ -120,10 +118,6 @@ public abstract class ArchitectureCheck extends DefaultTask {
|
||||
return rules.stream().map(ArchRule::getDescription).toList();
|
||||
}
|
||||
|
||||
private String annotationClassFor(String name, String defaultValue) {
|
||||
return getAnnotationClasses().get().getOrDefault(name, defaultValue);
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void checkArchitecture() throws Exception {
|
||||
withCompileClasspath(() -> {
|
||||
@@ -223,7 +217,7 @@ public abstract class ArchitectureCheck extends DefaultTask {
|
||||
@Internal
|
||||
abstract SetProperty<String> getNullMarkedIgnoredPackages();
|
||||
|
||||
@Input
|
||||
@Internal
|
||||
abstract MapProperty<String, String> getAnnotationClasses();
|
||||
|
||||
}
|
||||
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Annotations used in architecture checks, which can be overridden in architecture rule
|
||||
* tests.
|
||||
*
|
||||
* @author Scott Frederick
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public enum ArchitectureCheckAnnotation {
|
||||
|
||||
/**
|
||||
* Condition on class check.
|
||||
*/
|
||||
CONDITIONAL_ON_CLASS,
|
||||
|
||||
/**
|
||||
* Condition on missing bean check.
|
||||
*/
|
||||
CONDITIONAL_ON_MISSING_BEAN,
|
||||
|
||||
/**
|
||||
* Configuration properties bean.
|
||||
*/
|
||||
CONFIGURATION_PROPERTIES,
|
||||
|
||||
/**
|
||||
* Deprecated configuration property.
|
||||
*/
|
||||
DEPRECATED_CONFIGURATION_PROPERTY,
|
||||
|
||||
/**
|
||||
* Custom implementation to bind configuration properties.
|
||||
*/
|
||||
CONFIGURATION_PROPERTIES_BINDING;
|
||||
|
||||
private static final Map<String, String> annotationNameToClassName = Map.of(CONDITIONAL_ON_CLASS.name(),
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnClass", CONDITIONAL_ON_MISSING_BEAN.name(),
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean",
|
||||
CONFIGURATION_PROPERTIES.name(), "org.springframework.boot.context.properties.ConfigurationProperties",
|
||||
DEPRECATED_CONFIGURATION_PROPERTY.name(),
|
||||
"org.springframework.boot.context.properties.DeprecatedConfigurationProperty",
|
||||
CONFIGURATION_PROPERTIES_BINDING.name(),
|
||||
"org.springframework.boot.context.properties.ConfigurationPropertiesBinding");
|
||||
|
||||
static Map<String, String> asMap() {
|
||||
return annotationNameToClassName;
|
||||
}
|
||||
|
||||
static String classFor(Map<String, String> annotationProperty, ArchitectureCheckAnnotation annotation) {
|
||||
String name = annotation.name();
|
||||
return annotationProperty.getOrDefault(name, asMap().get(name));
|
||||
}
|
||||
|
||||
}
|
||||
+46
-31
@@ -104,25 +104,35 @@ final class ArchitectureRules {
|
||||
rules.add(noClassesShouldLoadResourcesUsingResourceUtils());
|
||||
rules.add(noClassesShouldCallStringToUpperCaseWithoutLocale());
|
||||
rules.add(noClassesShouldCallStringToLowerCaseWithoutLocale());
|
||||
rules.add(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType());
|
||||
rules.add(enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter());
|
||||
rules.add(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
|
||||
rules.add(methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute());
|
||||
rules.add(conditionsShouldNotBePublic());
|
||||
rules.add(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic());
|
||||
rules.add(autoConfigurationClassesShouldBePublicAndFinal());
|
||||
rules.add(autoConfigurationClassesShouldHaveNoPublicMembers());
|
||||
rules.add(testAutoConfigurationClassesShouldBePackagePrivateAndFinal());
|
||||
return List.copyOf(rules);
|
||||
}
|
||||
|
||||
static List<ArchRule> beanMethods(String annotationName) {
|
||||
static List<ArchRule> beanMethods(String annotationClass) {
|
||||
return List.of(allBeanMethodsShouldReturnNonPrivateType(),
|
||||
allBeanMethodsShouldNotHaveConditionalOnClassAnnotation(annotationName));
|
||||
allBeanMethodsShouldNotHaveConditionalOnClassAnnotation(annotationClass));
|
||||
}
|
||||
|
||||
static List<ArchRule> configurationProperties(String annotationName) {
|
||||
return List.of(allDeprecatedConfigurationPropertiesShouldIncludeSince(annotationName));
|
||||
static List<ArchRule> conditionalOnMissingBean(String annotationClass) {
|
||||
return List
|
||||
.of(conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType(annotationClass));
|
||||
}
|
||||
|
||||
static List<ArchRule> configurationProperties(String annotationClass) {
|
||||
return List.of(classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute(annotationClass),
|
||||
methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute(annotationClass));
|
||||
}
|
||||
|
||||
static List<ArchRule> configurationPropertiesBinding(String annotationClass) {
|
||||
return List.of(allConfigurationPropertiesBindingBeanMethodsShouldBeStatic(annotationClass));
|
||||
}
|
||||
|
||||
static List<ArchRule> configurationPropertiesDeprecation(String annotationClass) {
|
||||
return List.of(allDeprecatedConfigurationPropertiesShouldIncludeSince(annotationClass));
|
||||
}
|
||||
|
||||
private static ArchRule allBeanMethodsShouldReturnNonPrivateType() {
|
||||
@@ -267,9 +277,10 @@ final class ArchitectureRules {
|
||||
.because(shouldUse("String.toLowerCase(Locale.ROOT)"));
|
||||
}
|
||||
|
||||
private static ArchRule conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType() {
|
||||
return methodsThatAreAnnotatedWith("org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean")
|
||||
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodReturnType())
|
||||
private static ArchRule conditionalOnMissingBeanShouldNotSpecifyOnlyATypeThatIsTheSameAsMethodReturnType(
|
||||
String annotation) {
|
||||
return methodsThatAreAnnotatedWith(annotation)
|
||||
.should(notSpecifyOnlyATypeThatIsTheSameAsTheMethodReturnType(annotation))
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
@@ -279,10 +290,10 @@ final class ArchitectureRules {
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodReturnType() {
|
||||
private static ArchCondition<? super JavaMethod> notSpecifyOnlyATypeThatIsTheSameAsTheMethodReturnType(
|
||||
String annotation) {
|
||||
return check("not specify only a type that is the same as the method's return type", (item, events) -> {
|
||||
JavaAnnotation<JavaMethod> conditionalAnnotation = item
|
||||
.getAnnotationOfType("org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean");
|
||||
JavaAnnotation<JavaMethod> conditionalAnnotation = item.getAnnotationOfType(annotation);
|
||||
Map<String, Object> properties = conditionalAnnotation.getProperties();
|
||||
if (!hasProperty("type", properties) && !hasProperty("name", properties)) {
|
||||
conditionalAnnotation.get("value").ifPresent((value) -> {
|
||||
@@ -300,7 +311,7 @@ final class ArchitectureRules {
|
||||
if (property == null) {
|
||||
return false;
|
||||
}
|
||||
return !property.getClass().isArray() || ((Object[]) property).length > 0;
|
||||
return (property.getClass().isArray()) ? ((Object[]) property).length > 0 : !property.toString().isEmpty();
|
||||
}
|
||||
|
||||
private static ArchRule enumSourceShouldNotHaveValueThatIsTheSameAsTypeOfMethodsFirstParameter() {
|
||||
@@ -329,33 +340,37 @@ final class ArchitectureRules {
|
||||
});
|
||||
}
|
||||
|
||||
private static ArchRule classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute() {
|
||||
private static ArchRule classLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute(
|
||||
String annotationClass) {
|
||||
return ArchRuleDefinition.classes()
|
||||
.that()
|
||||
.areAnnotatedWith("org.springframework.boot.context.properties.ConfigurationProperties")
|
||||
.should(notSpecifyOnlyPrefixAttributeOfConfigurationProperties())
|
||||
.areAnnotatedWith(annotationClass)
|
||||
.should(notSpecifyOnlyPrefixAttributeOfConfigurationProperties(annotationClass))
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
private static ArchRule methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute() {
|
||||
private static ArchRule methodLevelConfigurationPropertiesShouldNotSpecifyOnlyPrefixAttribute(
|
||||
String annotationClass) {
|
||||
return ArchRuleDefinition.methods()
|
||||
.that()
|
||||
.areAnnotatedWith("org.springframework.boot.context.properties.ConfigurationProperties")
|
||||
.should(notSpecifyOnlyPrefixAttributeOfConfigurationProperties())
|
||||
.areAnnotatedWith(annotationClass)
|
||||
.should(notSpecifyOnlyPrefixAttributeOfConfigurationProperties(annotationClass))
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
private static ArchCondition<? super HasAnnotations<?>> notSpecifyOnlyPrefixAttributeOfConfigurationProperties() {
|
||||
return check("not specify only prefix attribute of @ConfigurationProperties",
|
||||
ArchitectureRules::notSpecifyOnlyPrefixAttributeOfConfigurationProperties);
|
||||
private static ArchCondition<? super HasAnnotations<?>> notSpecifyOnlyPrefixAttributeOfConfigurationProperties(
|
||||
String annotationClass) {
|
||||
return check("not specify only prefix attribute of @ConfigurationProperties", (item,
|
||||
events) -> notSpecifyOnlyPrefixAttributeOfConfigurationProperties(annotationClass, item, events));
|
||||
}
|
||||
|
||||
private static void notSpecifyOnlyPrefixAttributeOfConfigurationProperties(HasAnnotations<?> item,
|
||||
ConditionEvents events) {
|
||||
JavaAnnotation<?> configurationPropertiesAnnotation = item
|
||||
.getAnnotationOfType("org.springframework.boot.context.properties.ConfigurationProperties");
|
||||
private static void notSpecifyOnlyPrefixAttributeOfConfigurationProperties(String annotationClass,
|
||||
HasAnnotations<?> item, ConditionEvents events) {
|
||||
JavaAnnotation<?> configurationPropertiesAnnotation = item.getAnnotationOfType(annotationClass);
|
||||
Map<String, Object> properties = configurationPropertiesAnnotation.getProperties();
|
||||
if (properties.size() == 1 && properties.containsKey("prefix")) {
|
||||
if (hasProperty("prefix", properties) && !hasProperty("value", properties)
|
||||
&& properties.get("ignoreInvalidFields").equals(false)
|
||||
&& properties.get("ignoreUnknownFields").equals(true)) {
|
||||
addViolation(events, item, configurationPropertiesAnnotation.getDescription()
|
||||
+ " should specify implicit 'value' attribute other than explicit 'prefix' attribute");
|
||||
}
|
||||
@@ -375,9 +390,9 @@ final class ArchitectureRules {
|
||||
.allowEmptyShould(true);
|
||||
}
|
||||
|
||||
private static ArchRule allConfigurationPropertiesBindingBeanMethodsShouldBeStatic() {
|
||||
private static ArchRule allConfigurationPropertiesBindingBeanMethodsShouldBeStatic(String annotationClass) {
|
||||
return methodsThatAreAnnotatedWith("org.springframework.context.annotation.Bean").and()
|
||||
.areAnnotatedWith("org.springframework.boot.context.properties.ConfigurationPropertiesBinding")
|
||||
.areAnnotatedWith(annotationClass)
|
||||
.should()
|
||||
.beStatic()
|
||||
.allowEmptyShould(true);
|
||||
|
||||
+135
-16
@@ -44,6 +44,9 @@ import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConditionalOnClass;
|
||||
import org.springframework.boot.build.architecture.annotations.TestConditionalOnMissingBean;
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationPropertiesBinding;
|
||||
import org.springframework.boot.build.architecture.annotations.TestDeprecatedConfigurationProperty;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
@@ -205,6 +208,29 @@ class ArchitectureCheckTests {
|
||||
build(this.gradleBuild.withProhibitObjectsRequireNonNull(false), task);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenClassCallsCollectorsToListShouldFailAndWriteReport(Task task) throws IOException {
|
||||
prepareTask(task, "collectors/toList");
|
||||
buildAndFail(this.gradleBuild, task, "because java.util.stream.Stream.toList() should be used instead");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenClassCallsUrlEncoderWithStringEncodingShouldFailAndWriteReport(Task task) throws IOException {
|
||||
prepareTask(task, "url/encode");
|
||||
buildAndFail(this.gradleBuild, task,
|
||||
"because java.net.URLEncoder.encode(String s, Charset charset) should be used instead");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenClassCallsUrlDecoderWithStringEncodingShouldFailAndWriteReport(Task task) throws IOException {
|
||||
prepareTask(task, "url/decode");
|
||||
buildAndFail(this.gradleBuild, task,
|
||||
"because java.net.URLDecoder.decode(String s, Charset charset) should be used instead");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenClassCallsStringToUpperCaseWithoutLocaleShouldFailAndWriteReport(Task task) throws IOException {
|
||||
@@ -233,6 +259,81 @@ class ArchitectureCheckTests {
|
||||
build(this.gradleBuild, task);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenConditionalOnMissingBeanWithTypeSameAsMethodReturnTypeShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "conditionalonmissingbean/valueonly", "annotations");
|
||||
buildAndFail(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConditionalOnMissingBeanAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN,
|
||||
"should not specify only a value that is the same as the method's return type");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenConditionalOnMissingBeanWithTypeAttributeShouldSucceedAndWriteEmptyReport(Task task) throws IOException {
|
||||
prepareTask(task, "conditionalonmissingbean/withtype", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT), task);
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenConditionalOnMissingBeanWithNameAttributeShouldSucceedAndWriteEmptyReport(Task task) throws IOException {
|
||||
prepareTask(task, "conditionalonmissingbean/withname", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT), task);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenClassLevelConfigurationPropertiesContainsOnlyPrefixShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/classprefixonly", "annotations");
|
||||
buildAndFail(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN,
|
||||
"should specify implicit 'value' attribute other than explicit 'prefix' attribute");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenClassLevelConfigurationPropertiesContainsPrefixAndIgnoreShouldSucceedAndWriteEmptyReport()
|
||||
throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/classprefixandignore", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenClassLevelConfigurationPropertiesContainsOnlyValueShouldSucceedAndWriteEmptyReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/classvalueonly", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenMethodLevelConfigurationPropertiesContainsOnlyPrefixShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/methodprefixonly", "annotations");
|
||||
buildAndFail(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN,
|
||||
"should specify implicit 'value' attribute other than explicit 'prefix' attribute");
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenMethodLevelConfigurationPropertiesContainsPrefixAndIgnoreShouldSucceedAndWriteEmptyReport()
|
||||
throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/methodprefixandignore", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenMethodLevelConfigurationPropertiesContainsOnlyValueShouldSucceedAndWriteEmptyReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/methodvalueonly", "annotations");
|
||||
build(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenConfigurationPropertiesBindingBeanMethodIsNotStaticShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/bindingnonstatic", "annotations");
|
||||
buildAndFail(this.gradleBuild.withDependencies(SPRING_CONTEXT).withConfigurationPropertiesBindingAnnotation(),
|
||||
Task.CHECK_ARCHITECTURE_MAIN, "does not have modifier STATIC");
|
||||
}
|
||||
|
||||
@ParameterizedTest(name = "{0}")
|
||||
@EnumSource(Task.class)
|
||||
void whenBeanPostProcessorBeanMethodIsNotStaticWithExternalClassShouldFailAndWriteReport(Task task)
|
||||
@@ -327,8 +428,7 @@ class ArchitectureCheckTests {
|
||||
@Test
|
||||
void whenConditionalOnClassUsedOnBeanMethodsWithMainSourcesShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "conditionalonclass", "annotations");
|
||||
GradleBuild gradleBuild = this.gradleBuild.withDependencies(SPRING_CONTEXT)
|
||||
.withConditionalOnClassAnnotation(TestConditionalOnClass.class.getName());
|
||||
GradleBuild gradleBuild = this.gradleBuild.withDependencies(SPRING_CONTEXT).withConditionalOnClassAnnotation();
|
||||
buildAndFail(gradleBuild, Task.CHECK_ARCHITECTURE_MAIN,
|
||||
"because @ConditionalOnClass on @Bean methods is ineffective - it doesn't prevent"
|
||||
+ " the method signature from being loaded. Such condition need to be placed"
|
||||
@@ -338,16 +438,15 @@ class ArchitectureCheckTests {
|
||||
@Test
|
||||
void whenConditionalOnClassUsedOnBeanMethodsWithTestSourcesShouldSucceedAndWriteEmptyReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_TEST, "conditionalonclass", "annotations");
|
||||
GradleBuild gradleBuild = this.gradleBuild.withDependencies(SPRING_CONTEXT)
|
||||
.withConditionalOnClassAnnotation(TestConditionalOnClass.class.getName());
|
||||
GradleBuild gradleBuild = this.gradleBuild.withDependencies(SPRING_CONTEXT).withConditionalOnClassAnnotation();
|
||||
build(gradleBuild, Task.CHECK_ARCHITECTURE_TEST);
|
||||
}
|
||||
|
||||
@Test
|
||||
void whenDeprecatedConfigurationPropertyIsMissingSinceShouldFailAndWriteReport() throws IOException {
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties", "annotations");
|
||||
prepareTask(Task.CHECK_ARCHITECTURE_MAIN, "configurationproperties/deprecatedsince", "annotations");
|
||||
GradleBuild gradleBuild = this.gradleBuild.withDependencies(SPRING_CONTEXT)
|
||||
.withDeprecatedConfigurationPropertyAnnotation(TestDeprecatedConfigurationProperty.class.getName());
|
||||
.withDeprecatedConfigurationPropertyAnnotation();
|
||||
buildAndFail(gradleBuild, Task.CHECK_ARCHITECTURE_MAIN,
|
||||
"should include a non-empty 'since' attribute of @DeprecatedConfigurationProperty",
|
||||
"DeprecatedConfigurationPropertySince.getProperty");
|
||||
@@ -454,19 +553,33 @@ class ArchitectureCheckTests {
|
||||
return this;
|
||||
}
|
||||
|
||||
GradleBuild withConditionalOnClassAnnotation(String annotationClass) {
|
||||
for (Task task : Task.values()) {
|
||||
configureTask(task, (configuration) -> configuration
|
||||
.withAnnotation(ArchitectureCheck.CONDITIONAL_ON_CLASS, annotationClass));
|
||||
}
|
||||
GradleBuild withConditionalOnClassAnnotation() {
|
||||
configureTasks(ArchitectureCheckAnnotation.CONDITIONAL_ON_CLASS.name(),
|
||||
TestConditionalOnClass.class.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
GradleBuild withDeprecatedConfigurationPropertyAnnotation(String annotationClass) {
|
||||
for (Task task : Task.values()) {
|
||||
configureTask(task, (configuration) -> configuration
|
||||
.withAnnotation(ArchitectureCheck.DEPRECATED_CONFIGURATION_PROPERTY, annotationClass));
|
||||
}
|
||||
GradleBuild withConditionalOnMissingBeanAnnotation() {
|
||||
configureTasks(ArchitectureCheckAnnotation.CONDITIONAL_ON_MISSING_BEAN.name(),
|
||||
TestConditionalOnMissingBean.class.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
GradleBuild withConfigurationPropertiesAnnotation() {
|
||||
configureTasks(ArchitectureCheckAnnotation.CONFIGURATION_PROPERTIES.name(),
|
||||
TestConfigurationProperties.class.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
GradleBuild withConfigurationPropertiesBindingAnnotation() {
|
||||
configureTasks(ArchitectureCheckAnnotation.CONFIGURATION_PROPERTIES_BINDING.name(),
|
||||
TestConfigurationPropertiesBinding.class.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
GradleBuild withDeprecatedConfigurationPropertyAnnotation() {
|
||||
configureTasks(ArchitectureCheckAnnotation.DEPRECATED_CONFIGURATION_PROPERTY.name(),
|
||||
TestDeprecatedConfigurationProperty.class.getName());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -480,6 +593,12 @@ class ArchitectureCheckTests {
|
||||
return this;
|
||||
}
|
||||
|
||||
private void configureTasks(String annotationName, String annotationClass) {
|
||||
for (Task task : Task.values()) {
|
||||
configureTask(task, (configuration) -> configuration.withAnnotation(annotationName, annotationClass));
|
||||
}
|
||||
}
|
||||
|
||||
private void configureTask(Task task, UnaryOperator<TaskConfiguration> configurer) {
|
||||
this.taskConfigurations.computeIfAbsent(task, (key) -> new TaskConfiguration(null, null));
|
||||
this.taskConfigurations.compute(task, (key, value) -> configurer.apply(value));
|
||||
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.annotations;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* {@code @ConditionalOnMissingBean} analogue for architecture checks.
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TestConditionalOnMissingBean {
|
||||
|
||||
Class<?>[] value() default {};
|
||||
|
||||
String[] type() default {};
|
||||
|
||||
Class<?>[] ignored() default {};
|
||||
|
||||
String[] ignoredType() default {};
|
||||
|
||||
Class<? extends Annotation>[] annotation() default {};
|
||||
|
||||
String[] name() default {};
|
||||
|
||||
Class<?>[] parameterizedContainer() default {};
|
||||
|
||||
}
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.stereotype.Indexed;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Indexed
|
||||
public @interface TestConfigurationProperties {
|
||||
|
||||
@AliasFor("prefix")
|
||||
String value() default "";
|
||||
|
||||
@AliasFor("value")
|
||||
String prefix() default "";
|
||||
|
||||
boolean ignoreInvalidFields() default false;
|
||||
|
||||
boolean ignoreUnknownFields() default true;
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.annotations;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface TestConfigurationPropertiesBinding {
|
||||
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.collectors.toList;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
class CollectorsToList {
|
||||
|
||||
void exampleMethod() {
|
||||
List<String> strings = Stream.of("a", "b", "c").collect(Collectors.toList());
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.conditionalonmissingbean.valueonly;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
class TypeSameAsMethodReturnType {
|
||||
|
||||
@Bean
|
||||
@TestConditionalOnMissingBean(String.class)
|
||||
String helloWorld() {
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.conditionalonmissingbean.withname;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
class WithNameAttribute {
|
||||
|
||||
@Bean
|
||||
@TestConditionalOnMissingBean(name = "myBean")
|
||||
String helloWorld() {
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.conditionalonmissingbean.withtype;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConditionalOnMissingBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
class WithTypeAttribute {
|
||||
|
||||
@Bean
|
||||
@TestConditionalOnMissingBean(type = "String")
|
||||
String helloWorld() {
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.bindingnonstatic;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationPropertiesBinding;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
public class BindingMethodNonStatic {
|
||||
|
||||
@Bean
|
||||
@TestConfigurationPropertiesBinding
|
||||
public List<String> binder() {
|
||||
return List.of("hello", "world");
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.classprefixandignore;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
@TestConfigurationProperties(prefix = "testing", ignoreUnknownFields = false)
|
||||
public class ConfigurationPropertiesWithPrefixAndIgnore {
|
||||
|
||||
private String property;
|
||||
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.classprefixonly;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
@TestConfigurationProperties(prefix = "testing")
|
||||
public class ConfigurationPropertiesWithPrefixOnly {
|
||||
|
||||
private String property;
|
||||
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.classvalueonly;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
@TestConfigurationProperties("testing")
|
||||
public class ConfigurationPropertiesWithValueOnly {
|
||||
|
||||
private String property;
|
||||
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.architecture.configurationproperties;
|
||||
package org.springframework.boot.build.architecture.configurationproperties.deprecatedsince;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestDeprecatedConfigurationProperty;
|
||||
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.methodprefixandignore;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
public class ConfigurationPropertiesWithPrefixAndIgnore {
|
||||
|
||||
private String property;
|
||||
|
||||
@TestConfigurationProperties(prefix = "testing", ignoreInvalidFields = true)
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.methodprefixonly;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
public class ConfigurationPropertiesWithPrefixOnly {
|
||||
|
||||
private String property;
|
||||
|
||||
@TestConfigurationProperties(prefix = "testing")
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.configurationproperties.methodvalueonly;
|
||||
|
||||
import org.springframework.boot.build.architecture.annotations.TestConfigurationProperties;
|
||||
|
||||
public class ConfigurationPropertiesWithValueOnly {
|
||||
|
||||
private String property;
|
||||
|
||||
@TestConfigurationProperties("testing")
|
||||
public String getProperty() {
|
||||
return this.property;
|
||||
}
|
||||
|
||||
public void setProperty(String property) {
|
||||
this.property = property;
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.url.decode;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
|
||||
class UrlDecodeWithStringEncoding {
|
||||
|
||||
void exampleMethod() throws UnsupportedEncodingException {
|
||||
URLDecoder.decode("https://example.com", "UTF-8");
|
||||
}
|
||||
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2012-present 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.build.architecture.url.encode;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
class UrlEncodeWithStringEncoding {
|
||||
|
||||
void exampleMethod() throws UnsupportedEncodingException {
|
||||
URLEncoder.encode("https://example.com", "UTF-8");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user