Generate auto-configuration OnWebApplication data
Update the auto-configuration annotation processor to generate properties for `@OnWebApplication`. See gh-13328
This commit is contained in:
parent
c2f8398c06
commit
75bde00334
|
@ -53,6 +53,7 @@ import javax.tools.StandardLocation;
|
|||
"org.springframework.boot.autoconfigure.condition.ConditionalOnClass",
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnBean",
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate",
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication",
|
||||
"org.springframework.boot.autoconfigure.AutoConfigureBefore",
|
||||
"org.springframework.boot.autoconfigure.AutoConfigureAfter",
|
||||
"org.springframework.boot.autoconfigure.AutoConfigureOrder" })
|
||||
|
@ -85,6 +86,8 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
|
|||
"org.springframework.boot.autoconfigure.condition.ConditionalOnBean");
|
||||
annotations.put("ConditionalOnSingleCandidate",
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnSingleCandidate");
|
||||
annotations.put("ConditionalOnWebApplication",
|
||||
"org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication");
|
||||
annotations.put("AutoConfigureBefore",
|
||||
"org.springframework.boot.autoconfigure.AutoConfigureBefore");
|
||||
annotations.put("AutoConfigureAfter",
|
||||
|
@ -99,6 +102,7 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
|
|||
attributes.put("ConditionalOnBean", new OnBeanConditionValueExtractor());
|
||||
attributes.put("ConditionalOnSingleCandidate",
|
||||
new OnBeanConditionValueExtractor());
|
||||
attributes.put("ConditionalOnWebApplication", ValueExtractor.allFrom("type"));
|
||||
attributes.put("AutoConfigureBefore", ValueExtractor.allFrom("value", "name"));
|
||||
attributes.put("AutoConfigureAfter", ValueExtractor.allFrom("value", "name"));
|
||||
attributes.put("AutoConfigureOrder", ValueExtractor.allFrom("value"));
|
||||
|
|
|
@ -50,7 +50,7 @@ public class AutoConfigureAnnotationProcessorTests {
|
|||
@Test
|
||||
public void annotatedClass() throws Exception {
|
||||
Properties properties = compile(TestClassConfiguration.class);
|
||||
assertThat(properties).hasSize(5);
|
||||
assertThat(properties).hasSize(6);
|
||||
assertThat(properties).containsEntry(
|
||||
"org.springframework.boot.autoconfigureprocessor."
|
||||
+ "TestClassConfiguration.ConditionalOnClass",
|
||||
|
@ -73,6 +73,10 @@ public class AutoConfigureAnnotationProcessorTests {
|
|||
"org.springframework.boot.autoconfigureprocessor."
|
||||
+ "TestClassConfiguration.ConditionalOnSingleCandidate",
|
||||
"java.io.OutputStream");
|
||||
assertThat(properties).containsEntry(
|
||||
"org.springframework.boot.autoconfigureprocessor."
|
||||
+ "TestClassConfiguration.ConditionalOnWebApplication",
|
||||
"SERVLET");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -124,7 +128,7 @@ public class AutoConfigureAnnotationProcessorTests {
|
|||
}
|
||||
|
||||
private Properties compile(Class<?>... types) throws IOException {
|
||||
TestConditionMetadataAnnotationProcessor processor = new TestConditionMetadataAnnotationProcessor(
|
||||
TestAutoConfigureAnnotationProcessor processor = new TestAutoConfigureAnnotationProcessor(
|
||||
this.compiler.getOutputLocation());
|
||||
this.compiler.getTask(types).call(processor);
|
||||
return processor.getWrittenProperties();
|
||||
|
|
|
@ -34,15 +34,16 @@ import javax.annotation.processing.SupportedAnnotationTypes;
|
|||
"org.springframework.boot.autoconfigureprocessor.TestConditionalOnClass",
|
||||
"org.springframework.boot.autoconfigure.condition.TestConditionalOnBean",
|
||||
"org.springframework.boot.autoconfigure.condition.TestConditionalOnSingleCandidate",
|
||||
"org.springframework.boot.autoconfigure.condition.TestConditionalOnWebApplication",
|
||||
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureBefore",
|
||||
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureAfter",
|
||||
"org.springframework.boot.autoconfigureprocessor.TestAutoConfigureOrder" })
|
||||
public class TestConditionMetadataAnnotationProcessor
|
||||
public class TestAutoConfigureAnnotationProcessor
|
||||
extends AutoConfigureAnnotationProcessor {
|
||||
|
||||
private final File outputLocation;
|
||||
|
||||
public TestConditionMetadataAnnotationProcessor(File outputLocation) {
|
||||
public TestAutoConfigureAnnotationProcessor(File outputLocation) {
|
||||
this.outputLocation = outputLocation;
|
||||
}
|
||||
|
||||
|
@ -53,6 +54,8 @@ public class TestConditionMetadataAnnotationProcessor
|
|||
put(annotations, "ConditionalOnBean", TestConditionalOnBean.class);
|
||||
put(annotations, "ConditionalOnSingleCandidate",
|
||||
TestConditionalOnSingleCandidate.class);
|
||||
put(annotations, "ConditionalOnWebApplication",
|
||||
TestConditionalOnWebApplication.class);
|
||||
put(annotations, "AutoConfigureBefore", TestAutoConfigureBefore.class);
|
||||
put(annotations, "AutoConfigureAfter", TestAutoConfigureAfter.class);
|
||||
put(annotations, "AutoConfigureOrder", TestAutoConfigureOrder.class);
|
|
@ -16,6 +16,8 @@
|
|||
|
||||
package org.springframework.boot.autoconfigureprocessor;
|
||||
|
||||
import org.springframework.boot.autoconfigureprocessor.TestConditionalOnWebApplication.Type;
|
||||
|
||||
/**
|
||||
* Test configuration with an annotated class.
|
||||
*
|
||||
|
@ -25,6 +27,7 @@ package org.springframework.boot.autoconfigureprocessor;
|
|||
@TestConditionalOnClass(name = "java.io.InputStream", value = TestClassConfiguration.Nested.class)
|
||||
@TestConditionalOnBean(type = "java.io.OutputStream")
|
||||
@TestConditionalOnSingleCandidate(type = "java.io.OutputStream")
|
||||
@TestConditionalOnWebApplication(type = Type.SERVLET)
|
||||
public class TestClassConfiguration {
|
||||
|
||||
@TestAutoConfigureOrder
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* Copyright 2012-2018 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
|
||||
*
|
||||
* http://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 Boot's {@code @ConditionalOnWebApplication} for testing (removes
|
||||
* the need for a dependency on the real annotation).
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface TestConditionalOnWebApplication {
|
||||
|
||||
Type type() default Type.ANY;
|
||||
|
||||
enum Type {
|
||||
|
||||
ANY, SERVLET, REACTIVE
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue