Search in sources :

Example 31 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project kanonizo by kanonizo.

the class Util method getReflections.

public static Reflections getReflections() {
    if (r == null) {
        Set<URL> packages = new HashSet<>(ClasspathHelper.forPackage("org.kanonizo"));
        packages.addAll(ClasspathHelper.forPackage("com.scythe"));
        r = new Reflections(new ConfigurationBuilder().setUrls(packages).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
    }
    return r;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) URL(java.net.URL) HashSet(java.util.HashSet) Reflections(org.reflections.Reflections)

Example 32 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project nd4j by deeplearning4j.

the class BasicNDArrayCompressor method loadCompressors.

protected void loadCompressors() {
    /*
            We scan classpath for NDArrayCompressor implementations and add them one by one to codecs map
         */
    codecs = new ConcurrentHashMap<>();
    Set<Class<? extends NDArrayCompressor>> classes = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j")).exclude(// Consider only .class files (to avoid debug messages etc. on .dlls, etc
    "^(?!.*\\.class$).*$")).setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner())).getSubTypesOf(NDArrayCompressor.class);
    for (Class<? extends NDArrayCompressor> impl : classes) {
        if (Modifier.isAbstract(impl.getModifiers()) || impl.isInterface())
            continue;
        try {
            NDArrayCompressor compressor = impl.newInstance();
            codecs.put(compressor.getDescriptor().toUpperCase(), compressor);
        } catch (InstantiationException i) {
            // we need catch there, to avoid exceptions at abstract classes
            ;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections)

Example 33 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project serenity-jbehave by serenity-bdd.

the class ClassFinder method annotatedClassesInPackage.

public List<Class<?>> annotatedClassesInPackage(String packageName) {
    Reflections reflections = new Reflections(packageName, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new ResourcesScanner(), getClassLoader());
    Set<Class<?>> matchingClasses = new HashSet<>();
    for (Class<? extends Annotation> expectedAnnotation : expectedAnnotations) {
        matchingClasses.addAll(reflections.getTypesAnnotatedWith(expectedAnnotation));
        matchingClasses.addAll(classesFrom(reflections.getMethodsAnnotatedWith(expectedAnnotation)));
    }
    return ImmutableList.copyOf(matchingClasses);
}
Also used : MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) ResourcesScanner(org.reflections.scanners.ResourcesScanner) Reflections(org.reflections.Reflections)

Example 34 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project motech by motech.

the class ReflectionsUtil method getMdsInterfaces.

/**
 * Finds all interfaces that extend the {@link MotechDataService} interface.
 *
 * @param bundle A bundle to look in.
 * @return a list of classes that extend the MotechDataService interface.
 */
public static List<Class<? extends MotechDataService>> getMdsInterfaces(Bundle bundle) {
    LOGGER.debug("Looking for MDS interfaces in bundle: {}", bundle.getSymbolicName());
    Reflections reflections = configureReflection(bundle, new WrappedBundleClassLoader(bundle), new SubTypesScanner());
    Set<Class<? extends MotechDataService>> set = reflections.getSubTypesOf(MotechDataService.class);
    return new ArrayList<>(set);
}
Also used : SubTypesScanner(org.reflections.scanners.SubTypesScanner) ArrayList(java.util.ArrayList) MotechDataService(org.motechproject.mds.service.MotechDataService) Reflections(org.reflections.Reflections)

Example 35 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project apache-kafka-on-k8s by banzaicloud.

the class DelegatingClassLoader method scanPluginPath.

private PluginScanResult scanPluginPath(ClassLoader loader, URL[] urls) throws InstantiationException, IllegalAccessException {
    ConfigurationBuilder builder = new ConfigurationBuilder();
    builder.setClassLoaders(new ClassLoader[] { loader });
    builder.addUrls(urls);
    builder.setScanners(new SubTypesScanner());
    builder.useParallelExecutor();
    Reflections reflections = new InternalReflections(builder);
    return new PluginScanResult(getPluginDesc(reflections, Connector.class, loader), getPluginDesc(reflections, Converter.class, loader), getPluginDesc(reflections, HeaderConverter.class, loader), getPluginDesc(reflections, Transformation.class, loader));
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Connector(org.apache.kafka.connect.connector.Connector) Transformation(org.apache.kafka.connect.transforms.Transformation) SubTypesScanner(org.reflections.scanners.SubTypesScanner) HeaderConverter(org.apache.kafka.connect.storage.HeaderConverter) Converter(org.apache.kafka.connect.storage.Converter) HeaderConverter(org.apache.kafka.connect.storage.HeaderConverter) 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