resolved package dependency tangles
This commit is contained in:
parent
686ae8f7b3
commit
d6d169ac56
|
|
@ -16,9 +16,9 @@
|
||||||
|
|
||||||
package org.springframework.context.annotation;
|
package org.springframework.context.annotation;
|
||||||
|
|
||||||
import static org.springframework.context.annotation.ConfigurationClassUtils.isConfigurationCandidate;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.lang.annotation.Annotation;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -35,11 +35,10 @@ import org.springframework.beans.factory.parsing.Location;
|
||||||
import org.springframework.beans.factory.parsing.Problem;
|
import org.springframework.beans.factory.parsing.Problem;
|
||||||
import org.springframework.beans.factory.parsing.ProblemReporter;
|
import org.springframework.beans.factory.parsing.ProblemReporter;
|
||||||
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
|
||||||
import org.springframework.core.annotation.AnnotationUtils;
|
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
import org.springframework.core.io.ResourceLoader;
|
import org.springframework.core.io.ResourceLoader;
|
||||||
import org.springframework.core.io.ResourcePropertySource;
|
import org.springframework.core.io.support.ResourcePropertySource;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
import org.springframework.core.type.AnnotationMetadata;
|
||||||
import org.springframework.core.type.MethodMetadata;
|
import org.springframework.core.type.MethodMetadata;
|
||||||
import org.springframework.core.type.StandardAnnotationMetadata;
|
import org.springframework.core.type.StandardAnnotationMetadata;
|
||||||
|
|
@ -167,7 +166,7 @@ class ConfigurationClassParser {
|
||||||
for (String memberClassName : metadata.getMemberClassNames()) {
|
for (String memberClassName : metadata.getMemberClassNames()) {
|
||||||
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(memberClassName);
|
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(memberClassName);
|
||||||
AnnotationMetadata memberClassMetadata = reader.getAnnotationMetadata();
|
AnnotationMetadata memberClassMetadata = reader.getAnnotationMetadata();
|
||||||
if (isConfigurationCandidate(memberClassMetadata)) {
|
if (ConfigurationClassUtils.isConfigurationCandidate(memberClassMetadata)) {
|
||||||
processConfigurationClass(new ConfigurationClass(reader, null));
|
processConfigurationClass(new ConfigurationClass(reader, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -204,7 +203,7 @@ class ConfigurationClassParser {
|
||||||
|
|
||||||
// process any @Import annotations
|
// process any @Import annotations
|
||||||
List<Map<String, Object>> allImportAttribs =
|
List<Map<String, Object>> allImportAttribs =
|
||||||
AnnotationUtils.findAllAnnotationAttributes(Import.class, metadata.getClassName(), true, metadataReaderFactory);
|
findAllAnnotationAttributes(Import.class, metadata.getClassName(), true);
|
||||||
for (Map<String, Object> importAttribs : allImportAttribs) {
|
for (Map<String, Object> importAttribs : allImportAttribs) {
|
||||||
processImport(configClass, (String[]) importAttribs.get("value"), true);
|
processImport(configClass, (String[]) importAttribs.get("value"), true);
|
||||||
}
|
}
|
||||||
|
|
@ -229,6 +228,48 @@ class ConfigurationClassParser {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a list of attribute maps for all declarations of the given annotation
|
||||||
|
* on the given annotated class using the given MetadataReaderFactory to introspect
|
||||||
|
* annotation metadata. Meta-annotations are ordered first in the list, and if the
|
||||||
|
* target annotation is declared directly on the class, its map of attributes will be
|
||||||
|
* ordered last in the list.
|
||||||
|
* @param targetAnnotation the annotation to search for, both locally and as a meta-annotation
|
||||||
|
* @param annotatedClassName the class to inspect
|
||||||
|
* @param classValuesAsString whether class attributes should be returned as strings
|
||||||
|
*/
|
||||||
|
private List<Map<String, Object>> findAllAnnotationAttributes(
|
||||||
|
Class<? extends Annotation> targetAnnotation, String annotatedClassName,
|
||||||
|
boolean classValuesAsString) throws IOException {
|
||||||
|
|
||||||
|
List<Map<String, Object>> allAttribs = new ArrayList<Map<String, Object>>();
|
||||||
|
|
||||||
|
MetadataReader reader = this.metadataReaderFactory.getMetadataReader(annotatedClassName);
|
||||||
|
AnnotationMetadata metadata = reader.getAnnotationMetadata();
|
||||||
|
String targetAnnotationType = targetAnnotation.getName();
|
||||||
|
|
||||||
|
for (String annotationType : metadata.getAnnotationTypes()) {
|
||||||
|
if (annotationType.equals(targetAnnotationType)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
MetadataReader metaReader = this.metadataReaderFactory.getMetadataReader(annotationType);
|
||||||
|
Map<String, Object> targetAttribs =
|
||||||
|
metaReader.getAnnotationMetadata().getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
||||||
|
if (targetAttribs != null) {
|
||||||
|
allAttribs.add(targetAttribs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, Object> localAttribs =
|
||||||
|
metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
||||||
|
if (localAttribs != null) {
|
||||||
|
allAttribs.add(localAttribs);
|
||||||
|
}
|
||||||
|
|
||||||
|
return allAttribs;
|
||||||
|
}
|
||||||
|
|
||||||
private void processImport(ConfigurationClass configClass, String[] classesToImport, boolean checkForCircularImports) throws IOException {
|
private void processImport(ConfigurationClass configClass, String[] classesToImport, boolean checkForCircularImports) throws IOException {
|
||||||
if (checkForCircularImports && this.importStack.contains(configClass)) {
|
if (checkForCircularImports && this.importStack.contains(configClass)) {
|
||||||
this.problemReporter.error(new CircularImportProblem(configClass, this.importStack, configClass.getMetadata()));
|
this.problemReporter.error(new CircularImportProblem(configClass, this.importStack, configClass.getMetadata()));
|
||||||
|
|
|
||||||
|
|
@ -28,10 +28,6 @@ import java.util.Map;
|
||||||
import java.util.WeakHashMap;
|
import java.util.WeakHashMap;
|
||||||
|
|
||||||
import org.springframework.core.BridgeMethodResolver;
|
import org.springframework.core.BridgeMethodResolver;
|
||||||
import org.springframework.core.type.AnnotationMetadata;
|
|
||||||
import org.springframework.core.type.classreading.MetadataReader;
|
|
||||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
|
||||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
|
||||||
import org.springframework.util.Assert;
|
import org.springframework.util.Assert;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -354,49 +350,6 @@ public abstract class AnnotationUtils {
|
||||||
return attrs;
|
return attrs;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a list of attribute maps for all declarations of the given annotation
|
|
||||||
* on the given annotated class using the given MetadataReaderFactory to introspect
|
|
||||||
* annotation metadata. Meta-annotations are ordered first in the list, and if the
|
|
||||||
* target annotation is declared directly on the class, its map of attributes will be
|
|
||||||
* ordered last in the list.
|
|
||||||
* @param targetAnnotation the annotation to search for, both locally and as a meta-annotation
|
|
||||||
* @param annotatedClassName the class to inspect
|
|
||||||
* @param classValuesAsString whether class attributes should be returned as strings
|
|
||||||
* @param metadataReaderFactory factory used to create metadata readers for each type
|
|
||||||
* @since 3.1
|
|
||||||
*/
|
|
||||||
public static List<Map<String, Object>> findAllAnnotationAttributes(
|
|
||||||
Class<? extends Annotation> targetAnnotation, String annotatedClassName,
|
|
||||||
boolean classValuesAsString, MetadataReaderFactory metadataReaderFactory) throws IOException {
|
|
||||||
|
|
||||||
List<Map<String, Object>> allAttribs = new ArrayList<Map<String, Object>>();
|
|
||||||
|
|
||||||
MetadataReader reader = metadataReaderFactory.getMetadataReader(annotatedClassName);
|
|
||||||
AnnotationMetadata metadata = reader.getAnnotationMetadata();
|
|
||||||
String targetAnnotationType = targetAnnotation.getName();
|
|
||||||
|
|
||||||
for (String annotationType : metadata.getAnnotationTypes()) {
|
|
||||||
if (annotationType.equals(targetAnnotationType)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MetadataReader metaReader = metadataReaderFactory.getMetadataReader(annotationType);
|
|
||||||
Map<String, Object> targetAttribs =
|
|
||||||
metaReader.getAnnotationMetadata().getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
|
||||||
if (targetAttribs != null) {
|
|
||||||
allAttribs.add(targetAttribs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Object> localAttribs =
|
|
||||||
metadata.getAnnotationAttributes(targetAnnotationType, classValuesAsString);
|
|
||||||
if (localAttribs != null) {
|
|
||||||
allAttribs.add(localAttribs);
|
|
||||||
}
|
|
||||||
|
|
||||||
return allAttribs;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the <em>value</em> of the <code>"value"</code> attribute of a
|
* Retrieve the <em>value</em> of the <code>"value"</code> attribute of a
|
||||||
* single-element Annotation, given an annotation instance.
|
* single-element Annotation, given an annotation instance.
|
||||||
|
|
|
||||||
|
|
@ -14,20 +14,20 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.core.io;
|
package org.springframework.core.io.support;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.springframework.core.env.PropertiesPropertySource;
|
import org.springframework.core.env.PropertiesPropertySource;
|
||||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
import org.springframework.core.io.Resource;
|
||||||
import org.springframework.util.ClassUtils;
|
import org.springframework.util.ClassUtils;
|
||||||
import org.springframework.util.StringUtils;
|
import org.springframework.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Subclass of {@link PropertiesPropertySource} that loads a {@link Properties}
|
* Subclass of {@link PropertiesPropertySource} that loads a {@link Properties}
|
||||||
* object from a given {@link Resource} or resource location such as
|
* object from a given {@link org.springframework.core.io.Resource} or resource location such as
|
||||||
* {@code "classpath:/com/myco/foo.properties"} or {@code "file:/path/to/file.properties"}.
|
* {@code "classpath:/com/myco/foo.properties"} or {@code "file:/path/to/file.properties"}.
|
||||||
*
|
*
|
||||||
* @author Chris Beams
|
* @author Chris Beams
|
||||||
|
|
@ -219,21 +219,6 @@ public class AnnotationUtilsTests {
|
||||||
assertNotNull(order);
|
assertNotNull(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void findAllComponentAnnotationAttributes() throws IOException {
|
|
||||||
List<Map<String,Object>> allAttribs =
|
|
||||||
AnnotationUtils.findAllAnnotationAttributes(Component.class,
|
|
||||||
HasLocalAndMetaComponentAnnotation.class.getName(), false,
|
|
||||||
new SimpleMetadataReaderFactory());
|
|
||||||
|
|
||||||
Object value = null;
|
|
||||||
for (Map<String, Object> attribs : allAttribs) {
|
|
||||||
value = attribs.get("value");
|
|
||||||
}
|
|
||||||
|
|
||||||
assertThat(allAttribs.size(), is(3));
|
|
||||||
assertEquals("local", value);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Component(value="meta1")
|
@Component(value="meta1")
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.core.io;
|
package org.springframework.core.io.support;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.easymock.internal.matchers.StartsWith;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import org.springframework.core.env.PropertySource;
|
import org.springframework.core.env.PropertySource;
|
||||||
|
import org.springframework.core.io.ByteArrayResource;
|
||||||
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.*;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unit tests for {@link ResourcePropertySource}.
|
* Unit tests for {@link ResourcePropertySource}.
|
||||||
Loading…
Reference in New Issue