|
|
@ -24,13 +24,18 @@ import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
|
|
import org.springframework.core.annotation.AnnotationAttributes;
|
|
|
|
import org.springframework.core.annotation.AnnotationAttributes;
|
|
|
|
import org.springframework.core.annotation.AnnotationUtils;
|
|
|
|
import org.springframework.core.annotation.AnnotationUtils;
|
|
|
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
|
|
|
import org.springframework.core.io.support.SpringFactoriesLoader;
|
|
|
|
import org.springframework.core.type.AnnotationMetadata;
|
|
|
|
import org.springframework.core.type.AnnotationMetadata;
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
|
|
import org.springframework.util.MultiValueMap;
|
|
|
|
|
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Variant of {@link EnableAutoConfigurationImportSelector} for
|
|
|
|
* Variant of {@link EnableAutoConfigurationImportSelector} for
|
|
|
@ -59,47 +64,27 @@ class ImportAutoConfigurationImportSelector
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
|
|
|
|
protected List<String> getCandidateConfigurations(AnnotationMetadata metadata,
|
|
|
|
AnnotationAttributes attributes) {
|
|
|
|
AnnotationAttributes attributes) {
|
|
|
|
try {
|
|
|
|
List<String> candidates = new ArrayList<String>();
|
|
|
|
return getCandidateConfigurations(
|
|
|
|
Map<Class<?>, List<Annotation>> annotations = getAnnotations(metadata);
|
|
|
|
ClassUtils.forName(metadata.getClassName(), null));
|
|
|
|
for (Map.Entry<Class<?>, List<Annotation>> entry : annotations.entrySet()) {
|
|
|
|
}
|
|
|
|
collectCandidateConfigurations(entry.getKey(), entry.getValue(), candidates);
|
|
|
|
catch (Exception ex) {
|
|
|
|
|
|
|
|
throw new IllegalStateException(ex);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getCandidateConfigurations(Class<?> source) {
|
|
|
|
|
|
|
|
Set<String> candidates = new LinkedHashSet<String>();
|
|
|
|
|
|
|
|
collectCandidateConfigurations(source, candidates, new HashSet<Class<?>>());
|
|
|
|
|
|
|
|
return new ArrayList<String>(candidates);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void collectCandidateConfigurations(Class<?> source, Set<String> candidates,
|
|
|
|
|
|
|
|
Set<Class<?>> seen) {
|
|
|
|
|
|
|
|
if (source != null && seen.add(source)) {
|
|
|
|
|
|
|
|
for (Annotation annotation : source.getDeclaredAnnotations()) {
|
|
|
|
|
|
|
|
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
|
|
|
|
|
|
|
|
collectCandidateConfigurations(source, annotation, candidates, seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
collectCandidateConfigurations(source.getSuperclass(), candidates, seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return candidates;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void collectCandidateConfigurations(Class<?> source, Annotation annotation,
|
|
|
|
private void collectCandidateConfigurations(Class<?> source,
|
|
|
|
Set<String> candidates, Set<Class<?>> seen) {
|
|
|
|
List<Annotation> annotations, List<String> candidates) {
|
|
|
|
if (ANNOTATION_NAMES.contains(annotation.annotationType().getName())) {
|
|
|
|
for (Annotation annotation : annotations) {
|
|
|
|
candidates.addAll(getConfigurationsForAnnotation(source, annotation));
|
|
|
|
candidates.addAll(getConfigurationsForAnnotation(source, annotation));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
collectCandidateConfigurations(annotation.annotationType(), candidates, seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Collection<String> getConfigurationsForAnnotation(Class<?> source,
|
|
|
|
private Collection<String> getConfigurationsForAnnotation(Class<?> source,
|
|
|
|
Annotation annotation) {
|
|
|
|
Annotation annotation) {
|
|
|
|
String[] value = (String[]) AnnotationUtils
|
|
|
|
String[] classes = (String[]) AnnotationUtils
|
|
|
|
.getAnnotationAttributes(annotation, true).get("value");
|
|
|
|
.getAnnotationAttributes(annotation, true).get("classes");
|
|
|
|
if (value.length > 0) {
|
|
|
|
if (classes.length > 0) {
|
|
|
|
return Arrays.asList(value);
|
|
|
|
return Arrays.asList(classes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return SpringFactoriesLoader.loadFactoryNames(source,
|
|
|
|
return SpringFactoriesLoader.loadFactoryNames(source,
|
|
|
|
getClass().getClassLoader());
|
|
|
|
getClass().getClassLoader());
|
|
|
@ -108,7 +93,52 @@ class ImportAutoConfigurationImportSelector
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
protected Set<String> getExclusions(AnnotationMetadata metadata,
|
|
|
|
protected Set<String> getExclusions(AnnotationMetadata metadata,
|
|
|
|
AnnotationAttributes attributes) {
|
|
|
|
AnnotationAttributes attributes) {
|
|
|
|
return Collections.emptySet();
|
|
|
|
Set<String> exclusions = new LinkedHashSet<String>();
|
|
|
|
|
|
|
|
Class<?> source = ClassUtils.resolveClassName(metadata.getClassName(), null);
|
|
|
|
|
|
|
|
for (String annotationName : ANNOTATION_NAMES) {
|
|
|
|
|
|
|
|
AnnotationAttributes merged = AnnotatedElementUtils
|
|
|
|
|
|
|
|
.getMergedAnnotationAttributes(source, annotationName);
|
|
|
|
|
|
|
|
Class<?>[] exclude = (merged == null ? null
|
|
|
|
|
|
|
|
: merged.getClassArray("exclude"));
|
|
|
|
|
|
|
|
if (exclude != null) {
|
|
|
|
|
|
|
|
for (Class<?> excludeClass : exclude) {
|
|
|
|
|
|
|
|
exclusions.add(excludeClass.getName());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (List<Annotation> annotations : getAnnotations(metadata).values()) {
|
|
|
|
|
|
|
|
for (Annotation annotation : annotations) {
|
|
|
|
|
|
|
|
String[] exclude = (String[]) AnnotationUtils
|
|
|
|
|
|
|
|
.getAnnotationAttributes(annotation, true).get("exclude");
|
|
|
|
|
|
|
|
if (!ObjectUtils.isEmpty(exclude)) {
|
|
|
|
|
|
|
|
exclusions.addAll(Arrays.asList(exclude));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return exclusions;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Map<Class<?>, List<Annotation>> getAnnotations(AnnotationMetadata metadata) {
|
|
|
|
|
|
|
|
MultiValueMap<Class<?>, Annotation> annotations = new LinkedMultiValueMap<Class<?>, Annotation>();
|
|
|
|
|
|
|
|
Class<?> source = ClassUtils.resolveClassName(metadata.getClassName(), null);
|
|
|
|
|
|
|
|
collectAnnotations(source, annotations, new HashSet<Class<?>>());
|
|
|
|
|
|
|
|
return Collections.unmodifiableMap(annotations);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void collectAnnotations(Class<?> source,
|
|
|
|
|
|
|
|
MultiValueMap<Class<?>, Annotation> annotations, HashSet<Class<?>> seen) {
|
|
|
|
|
|
|
|
if (source != null && seen.add(source)) {
|
|
|
|
|
|
|
|
for (Annotation annotation : source.getDeclaredAnnotations()) {
|
|
|
|
|
|
|
|
if (!AnnotationUtils.isInJavaLangAnnotationPackage(annotation)) {
|
|
|
|
|
|
|
|
if (ANNOTATION_NAMES
|
|
|
|
|
|
|
|
.contains(annotation.annotationType().getName())) {
|
|
|
|
|
|
|
|
annotations.add(source, annotation);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
collectAnnotations(annotation.annotationType(), annotations, seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
collectAnnotations(source.getSuperclass(), annotations, seen);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|