Search in sources :

Example 11 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project pwm by pwm-project.

the class RestServletTest method getClasses.

private Set<Class<? extends RestServlet>> getClasses() {
    Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("password.pwm")).setScanners(new SubTypesScanner(), new TypeAnnotationsScanner(), new FieldAnnotationsScanner()));
    Set<Class<? extends RestServlet>> classes = reflections.getSubTypesOf(RestServlet.class);
    return Collections.unmodifiableSet(classes);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) RestServlet(password.pwm.ws.server.RestServlet) Reflections(org.reflections.Reflections)

Example 12 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project xian by happyyangyuan.

the class TraverseClasspath method getNonAbstractSubClasses.

/**
 * reflection is not thread-safe scanning the jars files in the classpath,
 * must be synchronized otherwise a "java.lang.IllegalStateException: zip file closed" is thrown.
 * by happyyangyuan at 2017-01-22
 */
public static synchronized <T> Set<Class<? extends T>> getNonAbstractSubClasses(Class<T> parentClass, String... packages) {
    try {
        Reflections reflections = new Reflections(new ConfigurationBuilder().forPackages(packages).setScanners(new SubTypesScanner()));
        Set<Class<? extends T>> subClasses = reflections.getSubTypesOf(parentClass);
        Iterator<Class<? extends T>> it = subClasses.iterator();
        while (it.hasNext()) {
            Class subClass = it.next();
            if (!Reflection.canInitiate(subClass)) {
                // here is in danger of class loading deadlock if you use LOG.java to print the log.
                SystemOutLogger.singleton.warn(subClass + " can not be initiated, ignored!", null, TraverseClasspath.class.getSimpleName());
                it.remove();
            }
        }
        return subClasses;
    } catch (Throwable e) {
        throw new RuntimeException(e);
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) Reflections(org.reflections.Reflections)

Example 13 with SubTypesScanner

use of org.reflections.scanners.SubTypesScanner in project newton by muoncore.

the class MuonLookupUtils method init.

static void init(String[] packages) {
    List<URL> urls = new ArrayList<>();
    urls.addAll(ClasspathHelper.forPackage("io.muoncore.newton", MuonLookupUtils.class.getClassLoader()));
    for (String aPackage : packages) {
        log.info("Adding package {}", aPackage);
        Collection<URL> urls1 = ClasspathHelper.forPackage(aPackage, MuonLookupUtils.class.getClassLoader());
        log.info("Got {}", urls1);
        urls.addAll(urls1);
    }
    log.info("Booting Reflections with urls {}", urls);
    Reflections reflections = new Reflections(new ConfigurationBuilder().addScanners(new SubTypesScanner()).addScanners(new TypeAnnotationsScanner()).setUrls(urls));
    final Set<Class<? extends NewtonEvent>> eventTypes = reflections.getSubTypesOf(NewtonEvent.class);
    eventTypeMappings = new HashMap<>();
    for (Class<? extends NewtonEvent> newtonEvent : eventTypes) {
        eventTypeMappings.put(newtonEvent.getSimpleName(), newtonEvent);
    }
    final Set<Class<? extends AggregateRoot>> aggregateRootTypes = reflections.getSubTypesOf(AggregateRoot.class);
    aggregateRootMappings = new HashMap<>();
    for (Class<? extends AggregateRoot> root : aggregateRootTypes) {
        aggregateRootMappings.put(root.getSimpleName(), root);
    }
    final Set<Class<? extends Saga>> sagaTypes = reflections.getSubTypesOf(Saga.class);
    sagaTypeMappings = new HashMap<>();
    for (Class<? extends Saga> root : sagaTypes) {
        sagaTypeMappings.put(root.getSimpleName(), root);
    }
    ready.countDown();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) NewtonEvent(io.muoncore.newton.NewtonEvent) URL(java.net.URL) Saga(io.muoncore.newton.saga.Saga) AggregateRoot(io.muoncore.newton.AggregateRoot) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Reflections(org.reflections.Reflections)

Example 14 with SubTypesScanner

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

the class OpsMappingTests method getOperations.

protected List<Operation> getOperations(@NonNull Op.Type type) {
    val list = new ArrayList<Operation>();
    Reflections f = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().include(FilterBuilder.prefix("org.nd4j.*")).exclude("^(?!.*\\.class$).*$")).setUrls(ClasspathHelper.forPackage("org.nd4j")).setScanners(new SubTypesScanner()));
    switch(type) {
        case SUMMARYSTATS:
            {
                Set<Class<? extends Variance>> clazzes = f.getSubTypesOf(Variance.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case RANDOM:
            {
                Set<Class<? extends BaseRandomOp>> clazzes = f.getSubTypesOf(BaseRandomOp.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case INDEXREDUCE:
            {
                Set<Class<? extends BaseIndexAccumulation>> clazzes = f.getSubTypesOf(BaseIndexAccumulation.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case REDUCE3:
        case REDUCE:
            {
                Set<Class<? extends BaseAccumulation>> clazzes = f.getSubTypesOf(BaseAccumulation.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case BROADCAST:
            {
                Set<Class<? extends BaseBroadcastOp>> clazzes = f.getSubTypesOf(BaseBroadcastOp.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case SCALAR:
            {
                Set<Class<? extends BaseScalarOp>> clazzes = f.getSubTypesOf(BaseScalarOp.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case PAIRWISE:
        case TRANSFORM:
            {
                Set<Class<? extends BaseTransformOp>> clazzes = f.getSubTypesOf(BaseTransformOp.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) addOperation(clazz, list);
            }
            break;
        case CUSTOM:
            {
                Set<Class<? extends DynamicCustomOp>> clazzes = f.getSubTypesOf(DynamicCustomOp.class);
                for (Class<? extends DifferentialFunction> clazz : clazzes) {
                    if (clazz.getSimpleName().equalsIgnoreCase("dynamiccustomop"))
                        continue;
                    addOperation(clazz, list);
                }
            }
            break;
    }
    log.info("Group: {}; List size: {}", type, list.size());
    return list;
}
Also used : lombok.val(lombok.val) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Set(java.util.Set) ArrayList(java.util.ArrayList) BaseRandomOp(org.nd4j.linalg.api.ops.random.BaseRandomOp) Variance(org.nd4j.linalg.api.ops.impl.accum.Variance) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) DifferentialFunction(org.nd4j.autodiff.functions.DifferentialFunction) Reflections(org.reflections.Reflections)

Example 15 with SubTypesScanner

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

the class TestforBaseTestInheritance method verifyInheritance.

@Test
@Category(UnlikelyTest.class)
public void verifyInheritance() {
    // Get all BaseTest inheritors
    Reflections reflections = new Reflections("org.apache.drill", new SubTypesScanner(false));
    Set<Class<? extends BaseTest>> baseTestInheritors = reflections.getSubTypesOf(BaseTest.class);
    // Get all tests that are not inherited from BaseTest
    Set<String> testClasses = reflections.getSubTypesOf(Object.class).stream().filter(c -> !c.isInterface()).filter(c -> c.getSimpleName().toLowerCase().contains("test")).filter(c -> Arrays.stream(c.getDeclaredMethods()).anyMatch(m -> m.getAnnotation(Test.class) != null)).filter(c -> !baseTestInheritors.contains(c)).map(Class::getName).collect(Collectors.toSet());
    Assert.assertEquals("Found test classes that are not inherited from BaseTest:", Collections.emptySet(), testClasses);
}
Also used : BaseTest(org.apache.drill.test.BaseTest) Arrays(java.util.Arrays) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) Set(java.util.Set) Test(org.junit.Test) Reflections(org.reflections.Reflections) Assert(org.junit.Assert) Category(org.junit.experimental.categories.Category) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) SubTypesScanner(org.reflections.scanners.SubTypesScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) BaseTest(org.apache.drill.test.BaseTest) Reflections(org.reflections.Reflections) Category(org.junit.experimental.categories.Category) BaseTest(org.apache.drill.test.BaseTest) UnlikelyTest(org.apache.drill.categories.UnlikelyTest) Test(org.junit.Test)

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