|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2022 the original author or authors.
|
|
|
|
|
* Copyright 2012-2023 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.
|
|
|
|
@ -25,6 +25,7 @@ import java.util.HashSet;
|
|
|
|
|
import java.util.LinkedHashSet;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.annotation.DeterminableImports;
|
|
|
|
@ -32,6 +33,7 @@ import org.springframework.boot.context.annotation.ImportCandidates;
|
|
|
|
|
import org.springframework.core.annotation.AnnotatedElementUtils;
|
|
|
|
|
import org.springframework.core.annotation.AnnotationAttributes;
|
|
|
|
|
import org.springframework.core.annotation.AnnotationUtils;
|
|
|
|
|
import org.springframework.core.io.ClassPathResource;
|
|
|
|
|
import org.springframework.core.type.AnnotationMetadata;
|
|
|
|
|
import org.springframework.util.ClassUtils;
|
|
|
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
@ -49,6 +51,8 @@ import org.springframework.util.ObjectUtils;
|
|
|
|
|
*/
|
|
|
|
|
class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelector implements DeterminableImports {
|
|
|
|
|
|
|
|
|
|
private static final String OPTIONAL_PREFIX = "optional:";
|
|
|
|
|
|
|
|
|
|
private static final Set<String> ANNOTATION_NAMES;
|
|
|
|
|
|
|
|
|
|
static {
|
|
|
|
@ -92,13 +96,27 @@ class ImportAutoConfigurationImportSelector extends AutoConfigurationImportSelec
|
|
|
|
|
if (classes.length > 0) {
|
|
|
|
|
return Arrays.asList(classes);
|
|
|
|
|
}
|
|
|
|
|
return loadFactoryNames(source);
|
|
|
|
|
Collection<String> factoryNames = loadFactoryNames(source);
|
|
|
|
|
return factoryNames.stream().map((name) -> {
|
|
|
|
|
if (name.startsWith(OPTIONAL_PREFIX)) {
|
|
|
|
|
name = name.substring(OPTIONAL_PREFIX.length());
|
|
|
|
|
if (!present(name)) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return name;
|
|
|
|
|
}).filter(Objects::nonNull).toList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Collection<String> loadFactoryNames(Class<?> source) {
|
|
|
|
|
return ImportCandidates.load(source, getBeanClassLoader()).getCandidates();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean present(String className) {
|
|
|
|
|
String resourcePath = ClassUtils.convertClassNameToResourcePath(className) + ".class";
|
|
|
|
|
return new ClassPathResource(resourcePath).exists();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected Set<String> getExclusions(AnnotationMetadata metadata, AnnotationAttributes attributes) {
|
|
|
|
|
Set<String> exclusions = new LinkedHashSet<>();
|
|
|
|
|