Search in sources :

Example 1 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project che by eclipse.

the class DynaProviderGenerator method findDynaObjects.

private void findDynaObjects() throws IOException {
    ConfigurationBuilder configuration = new ConfigurationBuilder();
    List<URL> urls = new ArrayList<>();
    for (String element : classpath) {
        urls.add(new File(element).toURI().toURL());
    }
    ClassLoader contextClassLoader = URLClassLoader.newInstance(urls.toArray(new URL[urls.size()]), Thread.currentThread().getContextClassLoader());
    Thread.currentThread().setContextClassLoader(contextClassLoader);
    configuration.setUrls(ClasspathHelper.forClassLoader(contextClassLoader));
    configuration.setScanners(new SubTypesScanner(), new TypeAnnotationsScanner());
    Reflections reflection = new Reflections(configuration);
    Set<Class<?>> classes = reflection.getTypesAnnotatedWith(DynaObject.class);
    for (Class clazz : classes) {
        //accept only classes
        if (clazz.isEnum() || clazz.isInterface() || clazz.isAnnotation()) {
            continue;
        }
        dynaClasses.add(new ClassModel(clazz));
        System.out.println(String.format("New Dyna Object Found: %s", clazz.getCanonicalName()));
    }
    System.out.println(String.format("Found: %d Dyna Objects", dynaClasses.size()));
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ArrayList(java.util.ArrayList) URL(java.net.URL) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) URLClassLoader(java.net.URLClassLoader) File(java.io.File) Reflections(org.reflections.Reflections)

Example 2 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project swagger-core by swagger-api.

the class BeanConfig method classes.

@Override
public Set<Class<?>> classes() {
    ConfigurationBuilder config = new ConfigurationBuilder();
    Set<String> acceptablePackages = new HashSet<String>();
    boolean allowAllPackages = false;
    if (resourcePackage != null && !"".equals(resourcePackage)) {
        String[] parts = resourcePackage.split(",");
        for (String pkg : parts) {
            if (!"".equals(pkg)) {
                acceptablePackages.add(pkg);
                config.addUrls(ClasspathHelper.forPackage(pkg));
            }
        }
    } else {
        allowAllPackages = true;
    }
    config.setScanners(new ResourcesScanner(), new TypeAnnotationsScanner(), new SubTypesScanner());
    final Reflections reflections = new Reflections(config);
    Set<Class<?>> classes = reflections.getTypesAnnotatedWith(javax.ws.rs.Path.class);
    Set<Class<?>> typesAnnotatedWith = reflections.getTypesAnnotatedWith(SwaggerDefinition.class);
    classes.addAll(typesAnnotatedWith);
    /*
         * Find concrete types annotated with @Api, but with a supertype annotated with @Path.
         * This would handle split resources where the interface has jax-rs annotations
         * and the implementing class has Swagger annotations 
         */
    for (Class<?> cls : reflections.getTypesAnnotatedWith(Api.class)) {
        for (Class<?> intfc : TypeToken.of(cls).getTypes().interfaces().rawTypes()) {
            Annotation ann = intfc.getAnnotation(javax.ws.rs.Path.class);
            if (ann != null) {
                classes.add(cls);
                break;
            }
        }
    }
    Set<Class<?>> output = new HashSet<Class<?>>();
    for (Class<?> cls : classes) {
        if (allowAllPackages) {
            output.add(cls);
        } else {
            for (String pkg : acceptablePackages) {
                if (cls.getPackage().getName().startsWith(pkg)) {
                    output.add(cls);
                }
            }
        }
    }
    return output;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Annotation(java.lang.annotation.Annotation) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) HashSet(java.util.HashSet) Reflections(org.reflections.Reflections)

Example 3 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project ocvn by devgateway.

the class ReflectionsConfiguration method reflections.

@Bean
public Reflections reflections() {
    logger.debug("Starting reflections scanners...");
    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.devgateway.ocds.persistence.mongo")).setScanners(new SubTypesScanner(), new FieldAnnotationsScanner(), new MethodParameterScanner()));
    logger.debug("Configured reflections bean.");
    return reflections;
}
Also used : MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) Bean(org.springframework.context.annotation.Bean)

Example 4 with SubTypesScanner

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

the class JpaTicketRegistryConfiguration method ticketPackagesToScan.

@Bean
public List<String> ticketPackagesToScan() {
    final Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage(CentralAuthenticationService.NAMESPACE)).setScanners(new SubTypesScanner(false)));
    final Set<Class<?>> subTypes = (Set) reflections.getSubTypesOf(AbstractTicket.class);
    final List<String> packages = subTypes.stream().map(t -> t.getPackage().getName()).collect(Collectors.toList());
    return packages;
}
Also used : CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) JpaLockingStrategy(org.apereo.cas.ticket.registry.support.JpaLockingStrategy) CentralAuthenticationService(org.apereo.cas.CentralAuthenticationService) Autowired(org.springframework.beans.factory.annotation.Autowired) Beans(org.apereo.cas.configuration.support.Beans) Reflections(org.reflections.Reflections) TicketRegistryProperties(org.apereo.cas.configuration.model.core.ticket.registry.TicketRegistryProperties) StringUtils(org.apache.commons.lang3.StringUtils) EnableTransactionManagement(org.springframework.transaction.annotation.EnableTransactionManagement) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) TicketRegistry(org.apereo.cas.ticket.registry.TicketRegistry) LockingStrategy(org.apereo.cas.ticket.registry.support.LockingStrategy) JpaTransactionManager(org.springframework.orm.jpa.JpaTransactionManager) EnableConfigurationProperties(org.springframework.boot.context.properties.EnableConfigurationProperties) Qualifier(org.springframework.beans.factory.annotation.Qualifier) DataSource(javax.sql.DataSource) InetAddressUtils(org.apereo.cas.util.InetAddressUtils) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) TicketCatalog(org.apereo.cas.ticket.TicketCatalog) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) JpaTicketRegistryProperties(org.apereo.cas.configuration.model.support.jpa.ticketregistry.JpaTicketRegistryProperties) JpaConfigDataHolder(org.apereo.cas.configuration.model.support.jpa.JpaConfigDataHolder) Set(java.util.Set) CoreTicketUtils(org.apereo.cas.util.CoreTicketUtils) Collectors(java.util.stream.Collectors) ClasspathHelper(org.reflections.util.ClasspathHelper) SubTypesScanner(org.reflections.scanners.SubTypesScanner) JpaTicketRegistry(org.apereo.cas.ticket.registry.JpaTicketRegistry) Configuration(org.springframework.context.annotation.Configuration) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) EntityManagerFactory(javax.persistence.EntityManagerFactory) Lazy(org.springframework.context.annotation.Lazy) AbstractTicket(org.apereo.cas.ticket.AbstractTicket) Bean(org.springframework.context.annotation.Bean) JpaBeans(org.apereo.cas.configuration.support.JpaBeans) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Set(java.util.Set) AbstractTicket(org.apereo.cas.ticket.AbstractTicket) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean) LocalContainerEntityManagerFactoryBean(org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)

Example 5 with SubTypesScanner

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

the class RegisterClasses method registerLabelRenderers.

/**
 * Register label converters.
 *
 * @param classLoadersList the class loaders list
 * @param data the data
 */
private static void registerLabelRenderers(List<ClassLoader> classLoadersList, ConversionData data) {
    logger.info("Label 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.label"))));
    Set<Class<? extends Object>> allClasses = reflections.getSubTypesOf(Object.class);
    for (Class<? extends Object> claszz : allClasses) {
        try {
            if (validClass(claszz, EsriLabelRendererInterface.class)) {
                EsriLabelRendererInterface rendererObj = (EsriLabelRendererInterface) claszz.newInstance();
                logger.info(rendererObj.getRendererClass().getName());
                data.addLabelRenderer(rendererObj);
            }
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) EsriLabelRendererInterface(com.sldeditor.importdata.esri.label.EsriLabelRendererInterface) SubTypesScanner(org.reflections.scanners.SubTypesScanner) FilterBuilder(org.reflections.util.FilterBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Aggregations

Reflections (org.reflections.Reflections)43 SubTypesScanner (org.reflections.scanners.SubTypesScanner)43 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)31 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 Collectors (java.util.stream.Collectors)6 FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)6 Set (java.util.Set)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 ClasspathHelper (org.reflections.util.ClasspathHelper)3