Make SpringBootConfigurationFinder public and usable with other annotations

See gh-13904
This commit is contained in:
artsiom 2018-07-25 23:39:18 +03:00 committed by Stephane Nicoll
parent e60af7240d
commit df6feb3e2a
1 changed files with 18 additions and 4 deletions

View File

@ -16,6 +16,7 @@
package org.springframework.boot.test.context;
import java.lang.annotation.Annotation;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
@ -29,21 +30,34 @@ import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
/**
* Internal utility class to scan for a {@link SpringBootConfiguration} class.
* Utility class to scan for a {@link SpringBootConfiguration} or custom annotation.
*
* @author Phillip Webb
* @author Artsiom Yudovin
* @since 2.1.0
*/
final class SpringBootConfigurationFinder {
public final class SpringBootConfigurationFinder {
private static final Map<String, Class<?>> cache = Collections
.synchronizedMap(new Cache(40));
private final ClassPathScanningCandidateComponentProvider scanner;
SpringBootConfigurationFinder() {
/**
* Default constructor initializing finder to scan for a {@link SpringBootConfiguration} annotation.
*/
public SpringBootConfigurationFinder() {
this(SpringBootConfiguration.class);
}
/**
* Customiable constructor allow to provide the custom annotation to scan for.
* @param annotationType Annotation to scan for.
*/
public SpringBootConfigurationFinder(Class<? extends Annotation> annotationType) {
this.scanner = new ClassPathScanningCandidateComponentProvider(false);
this.scanner.addIncludeFilter(
new AnnotationTypeFilter(SpringBootConfiguration.class));
new AnnotationTypeFilter(annotationType));
this.scanner.setResourcePattern("*.class");
}