Merge branch '2.7.x'

This commit is contained in:
Phillip Webb 2022-02-23 23:02:59 -08:00
commit 5454e2e26a
15 changed files with 81 additions and 83 deletions

View File

@ -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.

View File

@ -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

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -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.

View File

@ -76,31 +76,35 @@ public class AutoConfigureAnnotationProcessor extends AbstractProcessor {
protected List<PropertyGenerator> getPropertyGenerators() {
List<PropertyGenerator> 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<PropertyGenerator> 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<PropertyGenerator> 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<String, ValueExtractor> valueExtractors;
private PropertyGenerator(String keyName, boolean omitEmptyValues,
private PropertyGenerator(String annotationPackage, String propertyName, boolean omitEmptyValues,
Map<String, ValueExtractor> 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<String, ValueExtractor> valueExtractors = new LinkedHashMap<>(this.valueExtractors);
valueExtractors.put(this.annotationPackage + "." + name, ValueExtractor);
return new PropertyGenerator(this.annotationPackage, this.propertyName, this.omitEmptyValues,
valueExtractors);
}
Set<String> 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<String, String> 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<String, ValueExtractor> 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());
}
}

View File

@ -49,22 +49,23 @@ public class TestAutoConfigureAnnotationProcessor extends AutoConfigureAnnotatio
@Override
protected List<PropertyGenerator> getPropertyGenerators() {
List<PropertyGenerator> 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;
}

View File

@ -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.

View File

@ -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.
@ -89,12 +89,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);
}
}

View File

@ -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.

View File

@ -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.

View File

@ -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.