From 61873fbf42c11a333a5834eac5fb87a54b0bfcc5 Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Wed, 2 Oct 2019 20:52:54 -0700 Subject: [PATCH] Don't generate @Configuration metadata Update `AutoConfigureAnnotationProcessor` to no longer store `@Configuration.value` in the meta-data JSON since we never actually read it. Closes gh-16608 --- .../AutoConfigureAnnotationProcessor.java | 5 +-- ...AutoConfigureAnnotationProcessorTests.java | 18 ++------- .../TestAutoConfigureAnnotationProcessor.java | 10 ++--- .../TestClassConfiguration.java | 1 - .../TestConfiguration.java | 38 ------------------- .../TestMethodConfiguration.java | 1 - .../TestOnBeanWithNameClassConfiguration.java | 1 - 7 files changed, 8 insertions(+), 66 deletions(-) delete mode 100644 spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java 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 efefc3c2bd..5656396a1b 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 @@ -51,8 +51,7 @@ import javax.tools.StandardLocation; * @author Phillip Webb * @since 1.5.0 */ -@SupportedAnnotationTypes({ "org.springframework.context.annotation.Configuration", - "org.springframework.boot.autoconfigure.condition.ConditionalOnClass", +@SupportedAnnotationTypes({ "org.springframework.boot.autoconfigure.condition.ConditionalOnClass", "org.springframework.boot.autoconfigure.condition.ConditionalOnBean", "org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate", "org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication", @@ -79,7 +78,6 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { } protected void addAnnotations(Map annotations) { - annotations.put("Configuration", "org.springframework.context.annotation.Configuration"); annotations.put("ConditionalOnClass", "org.springframework.boot.autoconfigure.condition.ConditionalOnClass"); annotations.put("ConditionalOnBean", "org.springframework.boot.autoconfigure.condition.ConditionalOnBean"); annotations.put("ConditionalOnSingleCandidate", @@ -92,7 +90,6 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor { } private void addValueExtractors(Map attributes) { - attributes.put("Configuration", ValueExtractor.allFrom("value")); attributes.put("ConditionalOnClass", new OnClassConditionValueExtractor()); attributes.put("ConditionalOnBean", new OnBeanConditionValueExtractor()); attributes.put("ConditionalOnSingleCandidate", new OnBeanConditionValueExtractor()); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java index 39ae4e9478..ea6a7c1d97 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/AutoConfigureAnnotationProcessorTests.java @@ -18,8 +18,6 @@ package org.springframework.boot.autoconfigureprocessor; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.Properties; import org.junit.jupiter.api.BeforeEach; @@ -50,14 +48,12 @@ class AutoConfigureAnnotationProcessorTests { @Test void annotatedClass() throws Exception { Properties properties = compile(TestClassConfiguration.class); - assertThat(properties).hasSize(6); + assertThat(properties).hasSize(5); assertThat(properties).containsEntry( "org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.ConditionalOnClass", "java.io.InputStream,org.springframework.boot.autoconfigureprocessor." + "TestClassConfiguration$Nested,org.springframework.foo"); assertThat(properties).containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration"); - assertThat(properties) - .containsKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration.Configuration"); assertThat(properties) .doesNotContainKey("org.springframework.boot.autoconfigureprocessor.TestClassConfiguration$Nested"); assertThat(properties).containsEntry( @@ -72,7 +68,7 @@ class AutoConfigureAnnotationProcessorTests { @Test void annotatedClassWithOnBeanThatHasName() throws Exception { Properties properties = compile(TestOnBeanWithNameClassConfiguration.class); - assertThat(properties).hasSize(3); + assertThat(properties).hasSize(2); assertThat(properties).containsEntry( "org.springframework.boot.autoconfigureprocessor.TestOnBeanWithNameClassConfiguration.ConditionalOnBean", ""); @@ -81,15 +77,7 @@ class AutoConfigureAnnotationProcessorTests { @Test void annotatedMethod() throws Exception { Properties properties = compile(TestMethodConfiguration.class); - List matching = new ArrayList<>(); - for (Object key : properties.keySet()) { - if (key.toString().startsWith("org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration")) { - matching.add(key.toString()); - } - } - assertThat(matching).hasSize(2) - .contains("org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration") - .contains("org.springframework.boot.autoconfigureprocessor.TestMethodConfiguration.Configuration"); + assertThat(properties).isNull(); } @Test 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 556fb97828..b87627701e 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 @@ -29,11 +29,10 @@ import javax.annotation.processing.SupportedAnnotationTypes; * * @author Madhura Bhave */ -@SupportedAnnotationTypes({ "org.springframework.boot.autoconfigureprocessor.TestConfiguration", - "org.springframework.boot.autoconfigureprocessor.TestConditionalOnClass", - "org.springframework.boot.autoconfigure.condition.TestConditionalOnBean", - "org.springframework.boot.autoconfigure.condition.TestConditionalOnSingleCandidate", - "org.springframework.boot.autoconfigure.condition.TestConditionalOnWebApplication", +@SupportedAnnotationTypes({ "org.springframework.boot.autoconfigureprocessor.TestConditionalOnClass", + "org.springframework.boot.autoconfigureprocessor.TestConditionalOnBean", + "org.springframework.boot.autoconfigureprocessor.TestConditionalOnSingleCandidate", + "org.springframework.boot.autoconfigureprocessor.TestConditionalOnWebApplication", "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureBefore", "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureAfter", "org.springframework.boot.autoconfigureprocessor.TestAutoConfigureOrder" }) @@ -47,7 +46,6 @@ public class TestAutoConfigureAnnotationProcessor extends AutoConfigureAnnotatio @Override protected void addAnnotations(Map annotations) { - put(annotations, "Configuration", TestConfiguration.class); put(annotations, "ConditionalOnClass", TestConditionalOnClass.class); put(annotations, "ConditionalOnBean", TestConditionalOnBean.class); put(annotations, "ConditionalOnSingleCandidate", TestConditionalOnSingleCandidate.class); diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java index be4d11f944..2f48c3e75d 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestClassConfiguration.java @@ -23,7 +23,6 @@ import org.springframework.boot.autoconfigureprocessor.TestConditionalOnWebAppli * * @author Madhura Bhave */ -@TestConfiguration @TestConditionalOnClass(name = { "org.springframework.foo", "java.io.InputStream" }, value = TestClassConfiguration.Nested.class) @TestConditionalOnBean(type = "java.io.OutputStream") diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java deleted file mode 100644 index 499830ee9e..0000000000 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestConfiguration.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.autoconfigureprocessor; - -import java.lang.annotation.Documented; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Alternative to Spring's {@code @Configuration} for testing (removes the need for a - * dependency on the real annotation). - * - * @author Phillip Webb - */ -@Target(ElementType.TYPE) -@Retention(RetentionPolicy.RUNTIME) -@Documented -public @interface TestConfiguration { - - String value() default ""; - -} diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java index 6def2025e3..1b90ccf2d9 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestMethodConfiguration.java @@ -23,7 +23,6 @@ import java.io.OutputStream; * * @author Madhura Bhave */ -@TestConfiguration public class TestMethodConfiguration { @TestConditionalOnClass(name = "java.io.InputStream", value = OutputStream.class) diff --git a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOnBeanWithNameClassConfiguration.java b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOnBeanWithNameClassConfiguration.java index f169a3e30b..fae92de2d0 100644 --- a/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOnBeanWithNameClassConfiguration.java +++ b/spring-boot-project/spring-boot-tools/spring-boot-autoconfigure-processor/src/test/java/org/springframework/boot/autoconfigureprocessor/TestOnBeanWithNameClassConfiguration.java @@ -21,7 +21,6 @@ package org.springframework.boot.autoconfigureprocessor; * * @author Phillip Webb */ -@TestConfiguration @TestConditionalOnBean(name = "test", type = "java.io.OutputStream") public class TestOnBeanWithNameClassConfiguration {