use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.
the class AssignableTypeFilterTests method interfaceThroughSuperClassMatch.
@Test
public void interfaceThroughSuperClassMatch() throws Exception {
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory();
String classUnderTest = "org.springframework.core.type.AssignableTypeFilterTests$SomeDaoLikeImpl";
MetadataReader metadataReader = metadataReaderFactory.getMetadataReader(classUnderTest);
AssignableTypeFilter filter = new AssignableTypeFilter(JdbcDaoSupport.class);
assertTrue(filter.match(metadataReader, metadataReaderFactory));
ClassloadingAssertions.assertClassNotLoaded(classUnderTest);
}
use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.
the class CachingMetadataReaderLeakTests method testSignificantLoad.
@Test
public void testSignificantLoad() throws Exception {
Assume.group(TestGroup.LONG_RUNNING);
// the biggest public class in the JDK (>60k)
URL url = getClass().getResource("/java/awt/Component.class");
assertThat(url, notNullValue());
// look at a LOT of items
for (int i = 0; i < ITEMS_TO_LOAD; i++) {
Resource resource = new UrlResource(url) {
@Override
public boolean equals(Object obj) {
return (obj == this);
}
@Override
public int hashCode() {
return System.identityHashCode(this);
}
};
MetadataReader reader = mrf.getMetadataReader(resource);
assertThat(reader, notNullValue());
}
// useful for profiling to take snapshots
// System.in.read();
}
use of org.springframework.core.type.classreading.MetadataReader in project spring-framework by spring-projects.
the class DefaultPersistenceUnitManager method scanPackage.
private void scanPackage(SpringPersistenceUnitInfo scannedUnit, String pkg) {
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + ClassUtils.convertClassNameToResourcePath(pkg) + CLASS_RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
URL url = resource.getURL();
if (ResourceUtils.isJarURL(url)) {
scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
}
}
} else if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
scannedUnit.addManagedPackage(className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
}
}
}
} catch (IOException ex) {
throw new PersistenceException("Failed to scan classpath for unlisted entity classes", ex);
}
}
use of org.springframework.core.type.classreading.MetadataReader in project spring-boot by spring-projects.
the class ManagementContextConfigurationsImportSelector method getConfiguration.
private void getConfiguration(SimpleMetadataReaderFactory readerFactory, List<ManagementConfiguration> configurations, String className) {
try {
MetadataReader metadataReader = readerFactory.getMetadataReader(className);
configurations.add(new ManagementConfiguration(metadataReader));
} catch (IOException ex) {
throw new RuntimeException("Failed to read annotation metadata for '" + className + "'", ex);
}
}
use of org.springframework.core.type.classreading.MetadataReader in project spring-boot by spring-projects.
the class ConcurrentReferenceCachingMetadataReaderFactoryTests method getMetadataReaderUsesCache.
@Test
public void getMetadataReaderUsesCache() throws Exception {
TestConcurrentReferenceCachingMetadataReaderFactory factory = spy(new TestConcurrentReferenceCachingMetadataReaderFactory());
MetadataReader metadataReader1 = factory.getMetadataReader(getClass().getName());
MetadataReader metadataReader2 = factory.getMetadataReader(getClass().getName());
assertThat(metadataReader1).isSameAs(metadataReader2);
verify(factory, times(1)).createMetadataReader((Resource) any());
}
Aggregations