use of org.springframework.core.type.filter.AssignableTypeFilter in project spring-boot by spring-projects.
the class AnnotationCustomizableTypeExcludeFilter method isTypeOrAnnotated.
@SuppressWarnings("unchecked")
protected final boolean isTypeOrAnnotated(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory, Class<?> type) throws IOException {
AnnotationTypeFilter annotationFilter = new AnnotationTypeFilter((Class<? extends Annotation>) type);
AssignableTypeFilter typeFilter = new AssignableTypeFilter(type);
return annotationFilter.match(metadataReader, metadataReaderFactory) || typeFilter.match(metadataReader, metadataReaderFactory);
}
use of org.springframework.core.type.filter.AssignableTypeFilter in project gocd by gocd.
the class MagicalMaterialAndMaterialConfigConversionTest method failIfNewTypeOfMaterialIsNotAddedInTheAboveTest.
@Test
public void failIfNewTypeOfMaterialIsNotAddedInTheAboveTest() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(MaterialConfig.class));
Set<BeanDefinition> candidateComponents = provider.findCandidateComponents("com/thoughtworks");
List<Class> reflectionsSubTypesOf = candidateComponents.stream().map(beanDefinition -> beanDefinition.getBeanClassName()).map(s -> {
try {
return Class.forName(s);
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
}).collect(Collectors.toList());
reflectionsSubTypesOf.removeIf(this::isNotAConcrete_NonTest_MaterialConfigImplementation);
List<Class> allExpectedMaterialConfigImplementations = testMaterials().map(MaterialConfig::getClass).collect(Collectors.toList());
assertThatAllMaterialConfigsInCodeAreTestedHere(reflectionsSubTypesOf, allExpectedMaterialConfigImplementations);
}
use of org.springframework.core.type.filter.AssignableTypeFilter in project eventapis by kloiasoft.
the class AutomaticTopicConfiguration method init.
@PostConstruct
public void init() {
AdminClient adminClient = adminClient();
try {
StopWatch stopWatch = new StopWatch("CheckAndCreateTopics");
stopWatch.start("CheckAndCreateTopics");
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(PublishedEvent.class));
// provider.addExcludeFilter(new AssignableTypeFilter(ReceivedEvent.class));
Set<BeanDefinition> candidateComponents = provider.findCandidateComponents(eventApisConfiguration.getBaseEventsPackage());
int numberOfNodes = 1;
try {
Collection<Node> nodes = adminClient.describeCluster().nodes().get();
numberOfNodes = nodes.size();
} catch (InterruptedException | ExecutionException e) {
log.warn("Error while finding number of Nodes:" + e.getMessage(), e);
}
for (BeanDefinition candidateComponent : candidateComponents) {
Class<PublishedEvent> beanClass;
try {
beanClass = (Class<PublishedEvent>) Class.forName(candidateComponent.getBeanClassName());
String topicName = beanClass.getSimpleName();
log.info("Candidate {} to Create Topic:", topicName);
try {
adminClient.describeTopics(Collections.singleton(topicName)).all().get();
} catch (UnknownTopicOrPartitionException | ExecutionException exception) {
if (!(exception.getCause() instanceof UnknownTopicOrPartitionException))
throw exception;
log.warn("Topic {} does not exists, trying to create", topicName);
try {
adminClient.createTopics(Collections.singleton(new NewTopic(topicName, numberOfNodes, (short) 1)));
log.info("Topic {} is Created Successfully:", topicName);
} catch (Exception topicCreationEx) {
log.warn("Error while creating Topic:" + topicCreationEx.getMessage(), topicCreationEx);
}
}
} catch (ClassNotFoundException | InterruptedException | ExecutionException exception) {
log.warn("Error while checking Topic:" + candidateComponent.toString() + " message: " + exception.getMessage(), exception);
}
}
stopWatch.stop();
log.debug(stopWatch.prettyPrint());
} finally {
adminClient.close();
}
}
use of org.springframework.core.type.filter.AssignableTypeFilter in project spring-framework by spring-projects.
the class ClassPathScanningCandidateComponentProviderTests method testWithInterfaceType.
@Test
public void testWithInterfaceType() {
ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
assertThat(candidates.size()).isEqualTo(1);
assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
}
use of org.springframework.core.type.filter.AssignableTypeFilter in project spring-framework by spring-projects.
the class ClassPathScanningCandidateComponentProviderTests method testCustomAssignableTypeIncludeFilter.
private void testCustomAssignableTypeIncludeFilter(ClassPathScanningCandidateComponentProvider provider) {
provider.addIncludeFilter(new AssignableTypeFilter(FooService.class));
Set<BeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
// Interfaces/Abstract class are filtered out automatically.
assertThat(containsBeanClass(candidates, AutowiredQualifierFooService.class)).isTrue();
assertThat(containsBeanClass(candidates, FooServiceImpl.class)).isTrue();
assertThat(containsBeanClass(candidates, ScopedProxyTestBean.class)).isTrue();
assertThat(candidates.size()).isEqualTo(3);
assertBeanDefinitionType(candidates);
}
Aggregations