|
|
|
@ -16,19 +16,20 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.actuate.autoconfigure; |
|
|
|
package org.springframework.boot.actuate.autoconfigure; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.LinkedHashSet; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
|
|
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
|
|
import org.springframework.context.annotation.DeferredImportSelector; |
|
|
|
import org.springframework.context.annotation.DeferredImportSelector; |
|
|
|
|
|
|
|
import org.springframework.core.OrderComparator; |
|
|
|
import org.springframework.core.Ordered; |
|
|
|
import org.springframework.core.Ordered; |
|
|
|
import org.springframework.core.annotation.AnnotationAwareOrderComparator; |
|
|
|
|
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
import org.springframework.core.annotation.Order; |
|
|
|
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.core.type.classreading.MetadataReader; |
|
|
|
|
|
|
|
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Selects configuration classes for the management context configuration. Entries are |
|
|
|
* Selects configuration classes for the management context configuration. Entries are |
|
|
|
@ -38,6 +39,7 @@ import org.springframework.util.ClassUtils; |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
* @author Phillip Webb |
|
|
|
* @author Phillip Webb |
|
|
|
|
|
|
|
* @author Andy Wilkinson |
|
|
|
* @see ManagementContextConfiguration |
|
|
|
* @see ManagementContextConfiguration |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Order(Ordered.LOWEST_PRECEDENCE) |
|
|
|
@Order(Ordered.LOWEST_PRECEDENCE) |
|
|
|
@ -48,27 +50,41 @@ class ManagementContextConfigurationsImportSelector |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public String[] selectImports(AnnotationMetadata metadata) { |
|
|
|
public String[] selectImports(AnnotationMetadata metadata) { |
|
|
|
// Find all possible auto configuration classes, filtering duplicates
|
|
|
|
// Find all management context configuration classes, filtering duplicates
|
|
|
|
List<String> names = loadFactoryNames(); |
|
|
|
List<ManagementConfiguration> configurations = getConfigurations(); |
|
|
|
Set<Class<?>> classes = new LinkedHashSet<Class<?>>(); |
|
|
|
OrderComparator.sort(configurations); |
|
|
|
for (String factoryName : names) { |
|
|
|
List<String> names = new ArrayList<String>(); |
|
|
|
classes.add(ClassUtils.resolveClassName(factoryName, this.classLoader)); |
|
|
|
for (ManagementConfiguration configuration : configurations) { |
|
|
|
|
|
|
|
names.add(configuration.getClassName()); |
|
|
|
} |
|
|
|
} |
|
|
|
return getSortedClassNames(new ArrayList<Class<?>>(classes)); |
|
|
|
return names.toArray(new String[names.size()]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected List<String> loadFactoryNames() { |
|
|
|
private List<ManagementConfiguration> getConfigurations() { |
|
|
|
return SpringFactoriesLoader |
|
|
|
SimpleMetadataReaderFactory readerFactory = new SimpleMetadataReaderFactory( |
|
|
|
.loadFactoryNames(ManagementContextConfiguration.class, this.classLoader); |
|
|
|
this.classLoader); |
|
|
|
|
|
|
|
List<ManagementConfiguration> configurations = new ArrayList<ManagementConfiguration>(); |
|
|
|
|
|
|
|
for (String className : loadFactoryNames()) { |
|
|
|
|
|
|
|
getConfiguration(readerFactory, configurations, className); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return configurations; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private String[] getSortedClassNames(List<Class<?>> classes) { |
|
|
|
private void getConfiguration(SimpleMetadataReaderFactory readerFactory, |
|
|
|
AnnotationAwareOrderComparator.sort(classes); |
|
|
|
List<ManagementConfiguration> configurations, String className) { |
|
|
|
List<String> names = new ArrayList<String>(); |
|
|
|
try { |
|
|
|
for (Class<?> sourceClass : classes) { |
|
|
|
MetadataReader metadataReader = readerFactory.getMetadataReader(className); |
|
|
|
names.add(sourceClass.getName()); |
|
|
|
configurations.add(new ManagementConfiguration(metadataReader)); |
|
|
|
} |
|
|
|
} |
|
|
|
return names.toArray(new String[names.size()]); |
|
|
|
catch (IOException ex) { |
|
|
|
|
|
|
|
throw new RuntimeException( |
|
|
|
|
|
|
|
"Failed to read annotation metadata for '" + className + "'", ex); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected List<String> loadFactoryNames() { |
|
|
|
|
|
|
|
return SpringFactoriesLoader |
|
|
|
|
|
|
|
.loadFactoryNames(ManagementContextConfiguration.class, this.classLoader); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@ -76,4 +92,39 @@ class ManagementContextConfigurationsImportSelector |
|
|
|
this.classLoader = classLoader; |
|
|
|
this.classLoader = classLoader; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* A management configuration class which can be sorted according to {@code @Order}. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private static final class ManagementConfiguration implements Ordered { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final String className; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final int order; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ManagementConfiguration(MetadataReader metadataReader) { |
|
|
|
|
|
|
|
AnnotationMetadata annotationMetadata = metadataReader |
|
|
|
|
|
|
|
.getAnnotationMetadata(); |
|
|
|
|
|
|
|
this.order = readOrder(annotationMetadata); |
|
|
|
|
|
|
|
this.className = metadataReader.getClassMetadata().getClassName(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int readOrder(AnnotationMetadata annotationMetadata) { |
|
|
|
|
|
|
|
Map<String, Object> attributes = annotationMetadata |
|
|
|
|
|
|
|
.getAnnotationAttributes(Order.class.getName()); |
|
|
|
|
|
|
|
Integer order = (attributes == null ? null |
|
|
|
|
|
|
|
: (Integer) attributes.get("value")); |
|
|
|
|
|
|
|
return (order == null ? Ordered.LOWEST_PRECEDENCE : order); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String getClassName() { |
|
|
|
|
|
|
|
return this.className; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public int getOrder() { |
|
|
|
|
|
|
|
return this.order; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|