Search in sources :

Example 26 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project asterixdb by apache.

the class TypeComputerTest method test.

@Test
public void test() throws Exception {
    // Several exceptional type computers.
    Set<String> exceptionalTypeComputers = new HashSet<>();
    exceptionalTypeComputers.add("InjectFailureTypeComputer");
    exceptionalTypeComputers.add("RecordAddFieldsTypeComputer");
    exceptionalTypeComputers.add("OpenRecordConstructorResultType");
    exceptionalTypeComputers.add("RecordRemoveFieldsTypeComputer");
    exceptionalTypeComputers.add("ClosedRecordConstructorResultType");
    exceptionalTypeComputers.add("LocalAvgTypeComputer");
    exceptionalTypeComputers.add("BooleanOnlyTypeComputer");
    exceptionalTypeComputers.add("AMissingTypeComputer");
    exceptionalTypeComputers.add("NullableDoubleTypeComputer");
    exceptionalTypeComputers.add("RecordMergeTypeComputer");
    exceptionalTypeComputers.add("BooleanOrMissingTypeComputer");
    // Tests all usual type computers.
    Reflections reflections = new Reflections("org.apache.asterix.om.typecomputer", new SubTypesScanner(false));
    Set<Class<? extends IResultTypeComputer>> classes = reflections.getSubTypesOf(IResultTypeComputer.class);
    for (Class<? extends IResultTypeComputer> c : classes) {
        if (exceptionalTypeComputers.contains(c.getSimpleName()) || Modifier.isAbstract(c.getModifiers())) {
            continue;
        }
        System.out.println("Test type computer: " + c.getName());
        Assert.assertTrue(testTypeComputer(c));
    }
}
Also used : IResultTypeComputer(org.apache.asterix.om.typecomputer.base.IResultTypeComputer) SubTypesScanner(org.reflections.scanners.SubTypesScanner) HashSet(java.util.HashSet) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 27 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project cas by apereo.

the class ConfigurationMetadataGenerator method locatePropertiesClassForType.

private Class locatePropertiesClassForType(final ClassOrInterfaceType type) {
    if (cachedPropertiesClasses.containsKey(type.getNameAsString())) {
        return cachedPropertiesClasses.get(type.getNameAsString());
    }
    final Predicate<String> filterInputs = s -> s.contains(type.getNameAsString());
    final Predicate<String> filterResults = s -> s.endsWith(type.getNameAsString());
    final String packageName = ConfigurationMetadataGenerator.class.getPackage().getName();
    final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filterInputs).setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new TypeElementsScanner().includeFields(false).includeMethods(false).includeAnnotations(false).filterResultsBy(filterResults), new SubTypesScanner(false)));
    final Class clz = reflections.getSubTypesOf(Serializable.class).stream().filter(c -> c.getSimpleName().equalsIgnoreCase(type.getNameAsString())).findFirst().orElseThrow(() -> new IllegalArgumentException("Cant locate class for " + type.getNameAsString()));
    cachedPropertiesClasses.put(type.getNameAsString(), clz);
    return clz;
}
Also used : ClassOrInterfaceType(com.github.javaparser.ast.type.ClassOrInterfaceType) Arrays(java.util.Arrays) SneakyThrows(lombok.SneakyThrows) VoidVisitorAdapter(com.github.javaparser.ast.visitor.VoidVisitorAdapter) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) LiteralStringValueExpr(com.github.javaparser.ast.expr.LiteralStringValueExpr) ClassUtils(org.apache.commons.lang3.ClassUtils) QueryType(org.apereo.services.persondir.support.QueryType) Matcher(java.util.regex.Matcher) Map(java.util.Map) Expression(com.github.javaparser.ast.expr.Expression) CompilationUnit(com.github.javaparser.ast.CompilationUnit) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Resource(org.springframework.core.io.Resource) ValueHint(org.springframework.boot.configurationmetadata.ValueHint) Unchecked(org.jooq.lambda.Unchecked) Collection(java.util.Collection) Set(java.util.Set) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) ConfigurationMetadataProperty(org.springframework.boot.configurationmetadata.ConfigurationMetadataProperty) Collectors(java.util.stream.Collectors) PasswordPolicyProperties(org.apereo.cas.configuration.model.core.authentication.PasswordPolicyProperties) ClasspathHelper(org.reflections.util.ClasspathHelper) Modifier(com.github.javaparser.ast.Modifier) Serializable(java.io.Serializable) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Stream(java.util.stream.Stream) Predicate(com.google.common.base.Predicate) Pattern(java.util.regex.Pattern) ClassOrInterfaceDeclaration(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) RequiresModule(org.apereo.cas.configuration.support.RequiresModule) HashMap(java.util.HashMap) PrincipalTransformationProperties(org.apereo.cas.configuration.model.core.authentication.PrincipalTransformationProperties) VariableDeclarator(com.github.javaparser.ast.body.VariableDeclarator) HashSet(java.util.HashSet) DefaultPrettyPrinter(com.fasterxml.jackson.core.util.DefaultPrettyPrinter) StreamSupport(java.util.stream.StreamSupport) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) LinkedHashSet(java.util.LinkedHashSet) RelaxedNames(org.springframework.boot.bind.RelaxedNames) BooleanLiteralExpr(com.github.javaparser.ast.expr.BooleanLiteralExpr) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileInputStream(java.io.FileInputStream) RequiredProperty(org.apereo.cas.configuration.support.RequiredProperty) CaseCanonicalizationMode(org.apereo.services.persondir.util.CaseCanonicalizationMode) File(java.io.File) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FieldDeclaration(com.github.javaparser.ast.body.FieldDeclaration) ReflectionUtils(org.springframework.util.ReflectionUtils) LdapSearchEntryHandlersProperties(org.apereo.cas.configuration.model.support.ldap.LdapSearchEntryHandlersProperties) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) PrettyPrinter(com.fasterxml.jackson.core.PrettyPrinter) JavaParser(com.github.javaparser.JavaParser) InputStream(java.io.InputStream) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeElementsScanner(org.reflections.scanners.TypeElementsScanner) Reflections(org.reflections.Reflections)

Example 28 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project cas by apereo.

the class JpaServiceRegistryConfiguration method jpaServicePackagesToScan.

@Bean
public List<String> jpaServicePackagesToScan() {
    final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(CentralAuthenticationService.NAMESPACE)).setScanners(new SubTypesScanner(false)));
    final Set<Class<? extends AbstractRegisteredService>> subTypes = reflections.getSubTypesOf(AbstractRegisteredService.class);
    return subTypes.stream().map(t -> t.getPackage().getName()).collect(Collectors.toList());
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Autowired(org.springframework.beans.factory.annotation.Autowired) Reflections(org.reflections.Reflections) EnableTransactionManagement(org.springframework.transaction.annotation.EnableTransactionManagement) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) ServiceRegistryExecutionPlan(org.apereo.cas.services.ServiceRegistryExecutionPlan) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) JpaServiceRegistry(org.apereo.cas.services.JpaServiceRegistry) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSource(javax.sql.DataSource) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) JpaConfigDataHolder(org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder) Set(java.util.Set) Collectors(java.util.stream.Collectors) ServiceRegistry(org.apereo.cas.services.ServiceRegistry) ClasspathHelper(org.reflections.util.ClasspathHelper) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) HibernateJpaVendorAdapter(org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter) EntityManagerFactory(javax.persistence.EntityManagerFactory) Lazy(org.springframework.context.annotation.Lazy) Bean(org.springframework.context.annotation.Bean) ServiceRegistryExecutionPlanConfigurer(org.apereo.cas.services.ServiceRegistryExecutionPlanConfigurer) JpaBeans(org.apereo.cas.configuration.support.JpaBeans) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) AbstractRegisteredService(org.apereo.cas.services.AbstractRegisteredService) Reflections(org.reflections.Reflections) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 29 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project sldeditor by robward-scisys.

the class RegisterClasses method registerRenderers.

/**
 * Register renderer converters.
 *
 * @param classLoadersList the class loaders list
 * @param data the data
 */
private static void registerRenderers(List<ClassLoader> classLoadersList, ConversionData data) {
    logger.info("Renderers supported:");
    Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.renderer"))));
    Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
    for (Class<? extends Object> claszz : allClasses) {
        try {
            if (validClass(claszz, EsriRendererInterface.class)) {
                EsriRendererInterface rendererObj = (EsriRendererInterface) claszz.newInstance();
                logger.info(rendererObj.getRendererClass().getName());
                data.addRenderer(rendererObj);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FilterBuilder(org.reflections.util.FilterBuilder) EsriRendererInterface(com.sldeditor.importdata.esri.renderer.EsriRendererInterface) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 30 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project sldeditor by robward-scisys.

the class RegisterClasses method registerTextBackground.

/**
 * Register text background converters.
 *
 * @param classLoadersList the class loaders list
 * @param data the data
 */
private static void registerTextBackground(List<ClassLoader> classLoadersList, ConversionData data) {
    logger.info("Text backgrounds supported:");
    Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new SubTypesScanner(false), new ResourcesScanner()).setUrls(ClasspathHelper.forClassLoader(classLoadersList.toArray(new ClassLoader[0]))).filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("com.sldeditor.importdata.esri.textbackground"))));
    Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
    for (Class<? extends Object> claszz : allClasses) {
        try {
            if (validClass(claszz, EsriTextBackgroundInterface.class)) {
                EsriTextBackgroundInterface textBackgroundObj = (EsriTextBackgroundInterface) claszz.newInstance();
                logger.info(textBackgroundObj.getBackgroundClass().getName());
                data.addTextBackground(textBackgroundObj);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FilterBuilder(org.reflections.util.FilterBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) EsriTextBackgroundInterface(com.sldeditor.importdata.esri.textbackground.EsriTextBackgroundInterface) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)41 SubTypesScanner (org.reflections.scanners.SubTypesScanner)41 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)29 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 HashSet (java.util.HashSet)9 FilterBuilder (org.reflections.util.FilterBuilder)9 ResourcesScanner (org.reflections.scanners.ResourcesScanner)8 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)6 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 File (java.io.File)4 List (java.util.List)4 Bean (org.springframework.context.annotation.Bean)4 HashMap (java.util.HashMap)3 Slf4j (lombok.extern.slf4j.Slf4j)3 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)3 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)3 IOException (java.io.IOException)2