From df6feb3e2a796e09997cc6660a787b741d719c70 Mon Sep 17 00:00:00 2001 From: artsiom Date: Wed, 25 Jul 2018 23:39:18 +0300 Subject: [PATCH] Make SpringBootConfigurationFinder public and usable with other annotations See gh-13904 --- .../SpringBootConfigurationFinder.java | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootConfigurationFinder.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootConfigurationFinder.java index 54f07aaa49..728669bc5f 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootConfigurationFinder.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/SpringBootConfigurationFinder.java @@ -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> 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 annotationType) { this.scanner = new ClassPathScanningCandidateComponentProvider(false); this.scanner.addIncludeFilter( - new AnnotationTypeFilter(SpringBootConfiguration.class)); + new AnnotationTypeFilter(annotationType)); this.scanner.setResourcePattern("*.class"); }