Search in sources :

Example 1 with ClassPathScanningCandidateComponentProvider

use of cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider in project today-infrastructure by TAKETODAY.

the class ConfigurationPropertiesScanRegistrar method scan.

private void scan(BootstrapContext context, Set<String> packages) {
    var registrar = new ConfigurationPropertiesBeanRegistrar(context);
    ClassPathScanningCandidateComponentProvider scanner = getScanner(context);
    for (String basePackage : packages) {
        try {
            scanner.scanCandidateComponents(basePackage, (metadataReader, factory) -> register(registrar, metadataReader));
        } catch (IOException e) {
            throw new IllegalStateException("ConfigurationProperties scanning failed", e);
        }
    }
}
Also used : ClassPathScanningCandidateComponentProvider(cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider) IOException(java.io.IOException)

Example 2 with ClassPathScanningCandidateComponentProvider

use of cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider in project today-infrastructure by TAKETODAY.

the class ClassPathScanningCandidateComponentProviderTests method customFiltersFollowedByResetUseIndex.

@Test
public void customFiltersFollowedByResetUseIndex() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
    provider.addIncludeFilter(new AnnotationTypeFilter(Component.class));
    provider.resetFilters(true);
    Set<AnnotatedBeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
    assertBeanDefinitionType(candidates);
}
Also used : AnnotationTypeFilter(cn.taketoday.core.type.filter.AnnotationTypeFilter) AnnotatedBeanDefinition(cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition) ClassPathScanningCandidateComponentProvider(cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider) Component(cn.taketoday.lang.Component) ProfileMetaAnnotatedComponent(example.profilescan.ProfileMetaAnnotatedComponent) NamedComponent(example.scannable.NamedComponent) ProfileAnnotatedComponent(example.profilescan.ProfileAnnotatedComponent) BarComponent(example.scannable.sub.BarComponent) AnnotatedComponent(cn.taketoday.context.annotation.gh24375.AnnotatedComponent) DevComponent(example.profilescan.DevComponent) DefaultNamedComponent(example.scannable.DefaultNamedComponent) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) Test(org.junit.jupiter.api.Test)

Example 3 with ClassPathScanningCandidateComponentProvider

use of cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider in project today-infrastructure by TAKETODAY.

the class ClassPathScanningCandidateComponentProviderTests method customSupportedIncludeAndExcludedFilterWithScan.

@Test
public void customSupportedIncludeAndExcludedFilterWithScan() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.setResourceLoader(new DefaultResourceLoader(CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
    testCustomSupportedIncludeAndExcludeFilter(provider);
}
Also used : ClassPathScanningCandidateComponentProvider(cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) Test(org.junit.jupiter.api.Test)

Example 4 with ClassPathScanningCandidateComponentProvider

use of cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider in project today-infrastructure by TAKETODAY.

the class ClassPathScanningCandidateComponentProviderTests method customNotSupportedIncludeFilterUseScan.

@Test
public void customNotSupportedIncludeFilterUseScan() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.setResourceLoader(new DefaultResourceLoader(TEST_BASE_CLASSLOADER));
    provider.addIncludeFilter(new AssignableTypeFilter(FooDao.class));
    Set<AnnotatedBeanDefinition> candidates = provider.findCandidateComponents(TEST_BASE_PACKAGE);
    assertThat(containsBeanClass(candidates, StubFooDao.class)).isTrue();
    assertThat(candidates.size()).isEqualTo(1);
    assertBeanDefinitionType(candidates);
}
Also used : AnnotatedBeanDefinition(cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition) ClassPathScanningCandidateComponentProvider(cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider) StubFooDao(example.scannable.StubFooDao) FooDao(example.scannable.FooDao) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) AssignableTypeFilter(cn.taketoday.core.type.filter.AssignableTypeFilter) Test(org.junit.jupiter.api.Test)

Example 5 with ClassPathScanningCandidateComponentProvider

use of cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider in project today-infrastructure by TAKETODAY.

the class ClassPathScanningCandidateComponentProviderTests method customAssignableTypeIncludeFilterWithScan.

@Test
public void customAssignableTypeIncludeFilterWithScan() {
    ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider(false);
    provider.setResourceLoader(new DefaultResourceLoader(CandidateComponentsTestClassLoader.disableIndex(getClass().getClassLoader())));
    testCustomAssignableTypeIncludeFilter(provider);
}
Also used : ClassPathScanningCandidateComponentProvider(cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider) DefaultResourceLoader(cn.taketoday.core.io.DefaultResourceLoader) Test(org.junit.jupiter.api.Test)

Aggregations

ClassPathScanningCandidateComponentProvider (cn.taketoday.context.loader.ClassPathScanningCandidateComponentProvider)65 Test (org.junit.jupiter.api.Test)56 AnnotatedBeanDefinition (cn.taketoday.beans.factory.annotation.AnnotatedBeanDefinition)36 DefaultResourceLoader (cn.taketoday.core.io.DefaultResourceLoader)34 AnnotationTypeFilter (cn.taketoday.core.type.filter.AnnotationTypeFilter)14 AssignableTypeFilter (cn.taketoday.core.type.filter.AssignableTypeFilter)14 AnnotatedComponent (cn.taketoday.context.annotation.gh24375.AnnotatedComponent)10 ProfileAnnotatedComponent (example.profilescan.ProfileAnnotatedComponent)10 ProfileMetaAnnotatedComponent (example.profilescan.ProfileMetaAnnotatedComponent)10 RegexPatternTypeFilter (cn.taketoday.core.type.filter.RegexPatternTypeFilter)8 Component (cn.taketoday.lang.Component)8 DevComponent (example.profilescan.DevComponent)8 DefaultNamedComponent (example.scannable.DefaultNamedComponent)8 NamedComponent (example.scannable.NamedComponent)8 BarComponent (example.scannable.sub.BarComponent)8 BeanDefinition (cn.taketoday.beans.factory.config.BeanDefinition)4 ConfigurableEnvironment (cn.taketoday.core.env.ConfigurableEnvironment)4 StandardEnvironment (cn.taketoday.core.env.StandardEnvironment)4 AutowiredQualifierFooService (example.scannable.AutowiredQualifierFooService)4 FooDao (example.scannable.FooDao)4