Search in sources :

Example 6 with TypeAnnotationsScanner

use of org.reflections.scanners.TypeAnnotationsScanner 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 7 with TypeAnnotationsScanner

use of org.reflections.scanners.TypeAnnotationsScanner in project ninja by ninjaframework.

the class JaxyRoutes method findControllerMethods.

/**
 * Searches for Methods that have either a Path Annotation or a HTTP-Method Annotation
 */
@SuppressWarnings("unchecked")
private Set<Method> findControllerMethods() {
    Set<Method> methods = Sets.newLinkedHashSet();
    methods.addAll(reflections.getMethodsAnnotatedWith(Path.class));
    boolean enableCustomHttpMethods = ninjaProperties.getBooleanWithDefault(NINJA_CUSTOM_HTTP_METHODS, false);
    if (enableCustomHttpMethods) {
        Reflections annotationReflections = new Reflections("", new TypeAnnotationsScanner(), new SubTypesScanner());
        for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) {
            if (httpMethod.isAnnotation()) {
                methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod));
            }
        }
    } else {
        // Only look for standard HTTP methods annotations
        Reflections annotationReflections = new Reflections("ninja.jaxy", new TypeAnnotationsScanner(), new SubTypesScanner());
        for (Class<?> httpMethod : annotationReflections.getTypesAnnotatedWith(HttpMethod.class)) {
            if (httpMethod.isAnnotation()) {
                methods.addAll(reflections.getMethodsAnnotatedWith((Class<? extends Annotation>) httpMethod));
            }
        }
    }
    return methods;
}
Also used : SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Method(java.lang.reflect.Method) Annotation(java.lang.annotation.Annotation) Reflections(org.reflections.Reflections)

Example 8 with TypeAnnotationsScanner

use of org.reflections.scanners.TypeAnnotationsScanner in project hazelcast by hazelcast.

the class ReflectionUtils method getReflectionsForTestPackage.

public static Reflections getReflectionsForTestPackage(String forPackage) {
    try {
        URL testClassesURL = new File("target/test-classes").toURI().toURL();
        URLClassLoader classLoader = newInstance(new URL[] { testClassesURL }, ClasspathHelper.staticClassLoader());
        return new Reflections(new ConfigurationBuilder().addUrls(ClasspathHelper.forPackage(forPackage, classLoader)).addClassLoader(classLoader).filterInputsBy(new FilterBuilder().includePackage(forPackage)).setScanners(new SubTypesScanner(false), new TypeAnnotationsScanner(), new MethodAnnotationsScanner()));
    } catch (MalformedURLException e) {
        throw new IllegalArgumentException(e);
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) MalformedURLException(java.net.MalformedURLException) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) URLClassLoader(java.net.URLClassLoader) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) File(java.io.File) URL(java.net.URL) Reflections(org.reflections.Reflections)

Example 9 with TypeAnnotationsScanner

use of org.reflections.scanners.TypeAnnotationsScanner in project disconf by knightliao.

the class ReflectionScanStatic method getReflection.

/**
 * 通过扫描,获取反射对象
 */
private Reflections getReflection(List<String> packNameList) {
    // 
    // filter
    // 
    FilterBuilder filterBuilder = new FilterBuilder().includePackage(Constants.DISCONF_PACK_NAME);
    for (String packName : packNameList) {
        filterBuilder = filterBuilder.includePackage(packName);
    }
    Predicate<String> filter = filterBuilder;
    // 
    // urls
    // 
    Collection<URL> urlTotals = new ArrayList<URL>();
    for (String packName : packNameList) {
        Set<URL> urls = ClasspathHelper.forPackage(packName);
        urlTotals.addAll(urls);
    }
    // 
    Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(filter).setScanners(new SubTypesScanner().filterResultsBy(filter), new TypeAnnotationsScanner().filterResultsBy(filter), new FieldAnnotationsScanner().filterResultsBy(filter), new MethodAnnotationsScanner().filterResultsBy(filter), new MethodParameterScanner()).setUrls(urlTotals));
    return reflections;
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ArrayList(java.util.ArrayList) URL(java.net.URL) MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) FieldAnnotationsScanner(org.reflections.scanners.FieldAnnotationsScanner) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Reflections(org.reflections.Reflections)

Example 10 with TypeAnnotationsScanner

use of org.reflections.scanners.TypeAnnotationsScanner in project Smack by igniterealtime.

the class SmackIntegrationTestFramework method run.

public synchronized TestRunResult run() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    // it is a global setting, but we treat it like a per sinttest run setting.
    switch(config.dnsResolver) {
        case minidns:
            MiniDnsResolver.setup();
            break;
        case javax:
            JavaxResolver.setup();
            break;
        case dnsjava:
            DNSJavaResolver.setup();
            break;
    }
    testRunResult = new TestRunResult();
    // Create a connection manager *after* we created the testRunId (in testRunResult).
    this.connectionManager = new XmppConnectionManager(this);
    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion());
    if (config.debugger != Configuration.Debugger.none) {
        // JUL Debugger will not print any information until configured to print log messages of
        // level FINE
        // TODO configure JUL for log?
        SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.debugger.JulDebugger");
        SmackConfiguration.DEBUG = true;
    }
    if (config.replyTimeout > 0) {
        SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
    }
    if (config.securityMode != SecurityMode.required && config.accountRegistration == AccountRegistration.inBandRegistration) {
        AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);
    }
    // TODO print effective configuration
    String[] testPackages;
    if (config.testPackages == null || config.testPackages.isEmpty()) {
        testPackages = new String[] { "org.jivesoftware.smackx", "org.jivesoftware.smack" };
    } else {
        testPackages = config.testPackages.toArray(new String[config.testPackages.size()]);
    }
    Reflections reflections = new Reflections(testPackages, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterScanner());
    Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
    Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);
    final int builtInTestCount = inttestClasses.size() + lowLevelInttestClasses.size();
    Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(builtInTestCount);
    classes.addAll(inttestClasses);
    classes.addAll(lowLevelInttestClasses);
    {
        // Remove all abstract classes.
        // TODO: This may be a good candidate for Java stream filtering once Smack is Android API 24 or higher.
        Iterator<Class<? extends AbstractSmackIntTest>> it = classes.iterator();
        while (it.hasNext()) {
            Class<? extends AbstractSmackIntTest> clazz = it.next();
            if (Modifier.isAbstract(clazz.getModifiers())) {
                it.remove();
            }
        }
    }
    if (classes.isEmpty()) {
        throw new IllegalStateException("No test classes in " + Arrays.toString(testPackages) + " found");
    }
    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + "]: Finished scanning for tests, preparing environment");
    environment = prepareEnvironment();
    try {
        runTests(classes);
    } catch (Throwable t) {
        // Log the thrown Throwable to prevent it being shadowed in case the finally block below also throws.
        LOGGER.log(Level.SEVERE, "Unexpected abort because runTests() threw throwable", t);
        throw t;
    } finally {
        // Ensure that the accounts are deleted and disconnected before we continue
        connectionManager.disconnectAndCleanup();
    }
    return testRunResult;
}
Also used : MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) Iterator(java.util.Iterator) BeforeClass(org.igniterealtime.smack.inttest.annotations.BeforeClass) AfterClass(org.igniterealtime.smack.inttest.annotations.AfterClass) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Aggregations

Reflections (org.reflections.Reflections)18 SubTypesScanner (org.reflections.scanners.SubTypesScanner)18 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)18 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)13 URL (java.net.URL)7 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)4 FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)4 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)4 File (java.io.File)3 ResourcesScanner (org.reflections.scanners.ResourcesScanner)3 IOException (java.io.IOException)2 Annotation (java.lang.annotation.Annotation)2 Method (java.lang.reflect.Method)2 URLClassLoader (java.net.URLClassLoader)2 DTO (org.eclipse.che.dto.shared.DTO)2 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)2 FilterBuilder (org.reflections.util.FilterBuilder)2 Resources (com.google.common.io.Resources)1 AggregateRoot (io.muoncore.newton.AggregateRoot)1