From 57009d562391c9b1b388a67f7f1961289f87c519 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 23 Feb 2022 19:00:19 -0800 Subject: [PATCH 1/3] Polish --- .../autoconfigure/security/SecurityProperties.java | 2 +- .../boot/SpringApplicationShutdownHook.java | 10 +++------- .../boot/context/properties/bind/DefaultValue.java | 2 +- 3 files changed, 5 insertions(+), 9 deletions(-) diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java index e84faa7bc45..aa2b859c5a8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/SecurityProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationShutdownHook.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationShutdownHook.java index 090462ac620..274ca9d476b 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationShutdownHook.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/SpringApplicationShutdownHook.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. @@ -95,12 +95,8 @@ class SpringApplicationShutdownHook implements Runnable { void deregisterFailedApplicationContext(ConfigurableApplicationContext applicationContext) { synchronized (SpringApplicationShutdownHook.class) { - if (!applicationContext.isActive()) { - SpringApplicationShutdownHook.this.contexts.remove(applicationContext); - } - else { - throw new IllegalStateException("Cannot unregister active application context"); - } + Assert.state(!applicationContext.isActive(), "Cannot unregister active application context"); + SpringApplicationShutdownHook.this.contexts.remove(applicationContext); } } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultValue.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultValue.java index d17eb605eec..257b37514c9 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultValue.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/DefaultValue.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. From 1a3841f74e9efb13c24f9c63d6c59c1ca9ceb5ec Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 23 Feb 2022 19:02:54 -0800 Subject: [PATCH 2/3] Polish --- .../boot/testsupport/gradle/testkit/GradleBuild.java | 2 +- .../springframework/boot/image/paketo/PaketoBuilderTests.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java index bec4ca13549..e080e0fc9c4 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-gradle-test-support/src/main/java/org/springframework/boot/testsupport/gradle/testkit/GradleBuild.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java index 6e378d91a0a..5b06954f6dd 100644 --- a/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java +++ b/spring-boot-system-tests/spring-boot-image-tests/src/systemTest/java/org/springframework/boot/image/paketo/PaketoBuilderTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. From 9f00c3acf5e70569874de790ab46df36c6fc7e7f Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 23 Feb 2022 20:40:13 -0800 Subject: [PATCH 3/3] Polish --- .../boot/build/JavaConventions.java | 2 +- .../test/autoconfigure/TestSliceMetadata.java | 1 - ...stractEndpointRequestIntegrationTests.java | 2 +- ...mentWebSecurityAutoConfigurationTests.java | 2 +- .../security/DefaultWebSecurityCondition.java | 2 +- .../SpringBootWebSecurityConfiguration.java | 2 +- .../OAuth2WebSecurityConfigurationTests.java | 2 +- ...ml2RelyingPartyAutoConfigurationTests.java | 2 +- .../SecurityAutoConfigurationTests.java | 2 +- .../RemoteDevtoolsSecurityConfiguration.java | 2 +- .../RemoteDevToolsAutoConfigurationTests.java | 2 +- .../developing-auto-configuration.adoc | 2 + .../servlet/WebMvcTypeExcludeFilterTests.java | 2 +- .../AutoConfigureAnnotationProcessor.java | 98 +++++++++---------- .../TestAutoConfigureAnnotationProcessor.java | 33 ++++--- .../context/annotation/ImportCandidates.java | 2 +- 16 files changed, 80 insertions(+), 78 deletions(-) diff --git a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java index d82ba98cec5..30a8acf602a 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/JavaConventions.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java b/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java index f135490547b..598ed899548 100644 --- a/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java +++ b/buildSrc/src/main/java/org/springframework/boot/build/test/autoconfigure/TestSliceMetadata.java @@ -117,7 +117,6 @@ public class TestSliceMetadata extends DefaultTask { /** * Reads files from the given directory and puts them in springFactories. The key is * the file name, the value is the file contents, split by line, delimited with comma. - * * This is done to mimic the spring.factories structure. * @param springFactories spring.factories parsed as properties * @param directory directory to scan diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java index a7539d91352..9d9e26e41b6 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/AbstractEndpointRequestIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java index f980d13ae6b..d4b067c9009 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/security/servlet/ManagementWebSecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/DefaultWebSecurityCondition.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/DefaultWebSecurityCondition.java index cdd146da771..1317f19cf91 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/DefaultWebSecurityCondition.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/DefaultWebSecurityCondition.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java index cbbe3d5a0d8..a15d22efaf6 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/security/servlet/SpringBootWebSecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2020 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfigurationTests.java index 53f1371691d..390c2780c34 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/oauth2/client/servlet/OAuth2WebSecurityConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java index f5e36cd4d77..c939eb810a9 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/saml2/Saml2RelyingPartyAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java index 5501ab9999d..b62cdca5231 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/security/servlet/SecurityAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevtoolsSecurityConfiguration.java b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevtoolsSecurityConfiguration.java index 5d0461e05d1..53247b595af 100644 --- a/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevtoolsSecurityConfiguration.java +++ b/spring-boot-project/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/autoconfigure/RemoteDevtoolsSecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java index 059060996f2..ff32ce4db4f 100644 --- a/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/autoconfigure/RemoteDevToolsAutoConfigurationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc index 5b2220638a4..7ba8f3912d0 100644 --- a/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc +++ b/spring-boot-project/spring-boot-docs/src/docs/asciidoc/features/developing-auto-configuration.adoc @@ -44,6 +44,8 @@ Specific ``@Import``s should be used instead. You can use the {spring-boot-autoconfigure-module-code}/AutoConfigureAfter.java[`@AutoConfigureAfter`] or {spring-boot-autoconfigure-module-code}/AutoConfigureBefore.java[`@AutoConfigureBefore`] annotations if your configuration needs to be applied in a specific order. For example, if you provide web-specific configuration, your class may need to be applied after `WebMvcAutoConfiguration`. +TIP: If you are using the {spring-boot-autoconfigure-module-code}/AutoConfiguration.java[`@AutoConfiguration`] annotation, you can use the `before`, `beforeName`, `after` and `afterName` attribute aliases instead of the dedicated annotations. + If you want to order certain auto-configurations that should not have any direct knowledge of each other, you can also use `@AutoConfigureOrder`. That annotation has the same semantic as the regular `@Order` annotation but provides a dedicated order for auto-configuration classes. diff --git a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java index 25315dbff6c..2c1599ccf58 100644 --- a/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-test-autoconfigure/src/test/java/org/springframework/boot/test/autoconfigure/web/servlet/WebMvcTypeExcludeFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2022 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. diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java index 53f5b97cbd4..68cedc92b0c 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/main/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessor.java @@ -76,31 +76,35 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { protected List getPropertyGenerators() { List generators = new ArrayList<>(); - generators.add(PropertyGenerator.of("ConditionalOnClass", - "org.springframework.boot.autoconfigure.condition.ConditionalOnClass", - new OnClassConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnBean", - "org.springframework.boot.autoconfigure.condition.ConditionalOnBean", - new OnBeanConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnSingleCandidate", - "org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate", - new OnBeanConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnWebApplication", - "org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication", - ValueExtractor.allFrom("type"))); - generators.add(PropertyGenerator.of("AutoConfigureBefore", true, - "org.springframework.boot.autoconfigure.AutoConfigureBefore", ValueExtractor.allFrom("value", "name"), - "org.springframework.boot.autoconfigure.AutoConfiguration", - ValueExtractor.allFrom("before", "beforeName"))); - generators.add(PropertyGenerator.of("AutoConfigureAfter", true, - "org.springframework.boot.autoconfigure.AutoConfigureAfter", ValueExtractor.allFrom("value", "name"), - "org.springframework.boot.autoconfigure.AutoConfiguration", - ValueExtractor.allFrom("after", "afterName"))); - generators.add(PropertyGenerator.of("AutoConfigureOrder", - "org.springframework.boot.autoconfigure.AutoConfigureOrder", ValueExtractor.allFrom("value"))); + addConditionPropertyGenerators(generators); + addAutoConfigurePropertyGenerators(generators); return generators; } + private void addConditionPropertyGenerators(List generators) { + String annotationPackage = "org.springframework.boot.autoconfigure.condition"; + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnClass") + .withAnnotation(new OnClassConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnBean") + .withAnnotation(new OnBeanConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnSingleCandidate") + .withAnnotation(new OnBeanConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnWebApplication") + .withAnnotation(ValueExtractor.allFrom("type"))); + } + + private void addAutoConfigurePropertyGenerators(List generators) { + String annotationPackage = "org.springframework.boot.autoconfigure"; + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureBefore", true) + .withAnnotation(ValueExtractor.allFrom("value", "name")) + .withAnnotation("AutoConfiguration", ValueExtractor.allFrom("before", "beforeName"))); + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureAfter", true) + .withAnnotation(ValueExtractor.allFrom("value", "name")) + .withAnnotation("AutoConfiguration", ValueExtractor.allFrom("after", "afterName"))); + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureOrder") + .withAnnotation(ValueExtractor.allFrom("value"))); + } + @Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latestSupported(); @@ -282,24 +286,35 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { static final class PropertyGenerator { - private final String keyName; + private final String annotationPackage; + + private final String propertyName; private final boolean omitEmptyValues; - /** - * Maps from annotation class name -> {@link ValueExtractor}. - */ private final Map valueExtractors; - private PropertyGenerator(String keyName, boolean omitEmptyValues, + private PropertyGenerator(String annotationPackage, String propertyName, boolean omitEmptyValues, Map valueExtractors) { - this.keyName = keyName; + this.annotationPackage = annotationPackage; + this.propertyName = propertyName; this.omitEmptyValues = omitEmptyValues; this.valueExtractors = valueExtractors; } + PropertyGenerator withAnnotation(ValueExtractor valueExtractor) { + return withAnnotation(this.propertyName, valueExtractor); + } + + PropertyGenerator withAnnotation(String name, ValueExtractor ValueExtractor) { + Map valueExtractors = new LinkedHashMap<>(this.valueExtractors); + valueExtractors.put(this.annotationPackage + "." + name, ValueExtractor); + return new PropertyGenerator(this.annotationPackage, this.propertyName, this.omitEmptyValues, + valueExtractors); + } + Set getSupportedAnnotations() { - return Collections.unmodifiableSet(this.valueExtractors.keySet()); + return this.valueExtractors.keySet(); } ValueExtractor getValueExtractor(String annotation) { @@ -310,7 +325,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { if (this.omitEmptyValues && annotationValues.isEmpty()) { return; } - mergeProperties(properties, className + "." + this.keyName, toCommaDelimitedString(annotationValues)); + mergeProperties(properties, className + "." + this.propertyName, toCommaDelimitedString(annotationValues)); } private void mergeProperties(Map properties, String key, String value) { @@ -335,27 +350,12 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { return result.toString(); } - static PropertyGenerator of(String keyName, String annotation, ValueExtractor valueExtractor) { - return of(keyName, false, annotation, valueExtractor); + static PropertyGenerator of(String annotationPackage, String propertyName) { + return of(annotationPackage, propertyName, false); } - static PropertyGenerator of(String keyName, boolean omitEmptyValues, String annotation, - ValueExtractor valueExtractor) { - return new PropertyGenerator(keyName, omitEmptyValues, - Collections.singletonMap(annotation, valueExtractor)); - } - - static PropertyGenerator of(String keyName, String annotation1, ValueExtractor valueExtractor1, - String annotation2, ValueExtractor valueExtractor2) { - return of(keyName, false, annotation1, valueExtractor1, annotation2, valueExtractor2); - } - - static PropertyGenerator of(String keyName, boolean omitEmptyValues, String annotation1, - ValueExtractor valueExtractor1, String annotation2, ValueExtractor valueExtractor2) { - Map valueExtractors = new LinkedHashMap<>(); - valueExtractors.put(annotation1, valueExtractor1); - valueExtractors.put(annotation2, valueExtractor2); - return new PropertyGenerator(keyName, omitEmptyValues, valueExtractors); + static PropertyGenerator of(String annotationPackage, String propertyName, boolean omitEmptyValues) { + return new PropertyGenerator(annotationPackage, propertyName, omitEmptyValues, Collections.emptyMap()); } } diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAnnotationProcessor.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAnnotationProcessor.java index cd1314922c4..36cfba8ab90 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAnnotationProcessor.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestAutoConfigureAnnotationProcessor.java @@ -49,22 +49,23 @@ public class TestAutoConfigureAnnotationProcessor extends AutoConfigureAnnotatio @Override protected List getPropertyGenerators() { List generators = new ArrayList<>(); - generators.add(PropertyGenerator.of("ConditionalOnClass", TestConditionalOnClass.class.getName(), - new OnClassConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnBean", TestConditionalOnBean.class.getName(), - new OnBeanConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnSingleCandidate", - TestConditionalOnSingleCandidate.class.getName(), new OnBeanConditionValueExtractor())); - generators.add(PropertyGenerator.of("ConditionalOnWebApplication", - TestConditionalOnWebApplication.class.getName(), ValueExtractor.allFrom("type"))); - generators.add(PropertyGenerator.of("AutoConfigureBefore", true, TestAutoConfigureBefore.class.getName(), - ValueExtractor.allFrom("value", "name"), TestAutoConfiguration.class.getName(), - ValueExtractor.allFrom("before", "beforeName"))); - generators.add(PropertyGenerator.of("AutoConfigureAfter", true, TestAutoConfigureAfter.class.getName(), - ValueExtractor.allFrom("value", "name"), TestAutoConfiguration.class.getName(), - ValueExtractor.allFrom("after", "afterName"))); - generators.add(PropertyGenerator.of("AutoConfigureOrder", TestAutoConfigureOrder.class.getName(), - ValueExtractor.allFrom("value"))); + String annotationPackage = "org.springframework.boot.autoconfigureprocessor"; + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnClass") + .withAnnotation("TestConditionalOnClass", new OnClassConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnBean") + .withAnnotation("TestConditionalOnBean", new OnBeanConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnSingleCandidate") + .withAnnotation("TestConditionalOnSingleCandidate", new OnBeanConditionValueExtractor())); + generators.add(PropertyGenerator.of(annotationPackage, "ConditionalOnWebApplication") + .withAnnotation("TestConditionalOnWebApplication", ValueExtractor.allFrom("type"))); + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureBefore", true) + .withAnnotation("TestAutoConfigureBefore", ValueExtractor.allFrom("value", "name")) + .withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("before", "beforeName"))); + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureAfter", true) + .withAnnotation("TestAutoConfigureAfter", ValueExtractor.allFrom("value", "name")) + .withAnnotation("TestAutoConfiguration", ValueExtractor.allFrom("after", "afterName"))); + generators.add(PropertyGenerator.of(annotationPackage, "AutoConfigureOrder") + .withAnnotation("TestAutoConfigureOrder", ValueExtractor.allFrom("value"))); return generators; } diff --git a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java index 817cf40f53c..efecb9bfc2a 100644 --- a/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java +++ b/spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/annotation/ImportCandidates.java @@ -33,7 +33,7 @@ import org.springframework.core.io.UrlResource; import org.springframework.util.Assert; /** - * Contains import candidates, usually auto-configurations. + * Contains {@code @Configuration} import candidates, usually auto-configurations. * * The {@link #load(Class, ClassLoader)} method can be used to discover the import * candidates.