Search in sources :

Example 6 with Reflections

use of org.reflections.Reflections in project Smack by igniterealtime.

the class SmackIntegrationTestFramework method run.

public synchronized TestRunResult run() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException {
    testRunResult = new TestRunResult();
    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting");
    if (config.debug) {
        // 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) {
        AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);
    }
    // TODO print effective configuration
    String[] testPackages;
    if (config.testPackages == null) {
        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);
    Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(inttestClasses.size() + lowLevelInttestClasses.size());
    classes.addAll(inttestClasses);
    classes.addAll(lowLevelInttestClasses);
    if (classes.isEmpty()) {
        throw new IllegalStateException("No test classes found");
    }
    LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + "]: Finished scanning for tests, preparing environment");
    environment = prepareEnvironment();
    try {
        runTests(classes);
    } finally {
        // Ensure that the accounts are deleted and disconnected before we continue
        disconnectAndMaybeDelete(environment.conOne);
        disconnectAndMaybeDelete(environment.conTwo);
        disconnectAndMaybeDelete(environment.conThree);
    }
    return testRunResult;
}
Also used : MethodParameterScanner(org.reflections.scanners.MethodParameterScanner) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) SubTypesScanner(org.reflections.scanners.SubTypesScanner) TypeAnnotationsScanner(org.reflections.scanners.TypeAnnotationsScanner) BeforeClass(org.junit.BeforeClass) AfterClass(org.junit.AfterClass) Reflections(org.reflections.Reflections) HashSet(java.util.HashSet)

Example 7 with Reflections

use of org.reflections.Reflections in project disconf by knightliao.

the class ReflectionScanStatic method scanBasicInfo.

/**
     * 扫描基本信息
     */
private ScanStaticModel scanBasicInfo(List<String> packNameList) {
    ScanStaticModel scanModel = new ScanStaticModel();
    //
    // 扫描对象
    //
    Reflections reflections = getReflection(packNameList);
    scanModel.setReflections(reflections);
    //
    // 获取DisconfFile class
    //
    Set<Class<?>> classdata = reflections.getTypesAnnotatedWith(DisconfFile.class);
    scanModel.setDisconfFileClassSet(classdata);
    //
    // 获取DisconfFileItem method
    //
    Set<Method> af1 = reflections.getMethodsAnnotatedWith(DisconfFileItem.class);
    scanModel.setDisconfFileItemMethodSet(af1);
    //
    // 获取DisconfItem method
    //
    af1 = reflections.getMethodsAnnotatedWith(DisconfItem.class);
    scanModel.setDisconfItemMethodSet(af1);
    //
    // 获取DisconfActiveBackupService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfActiveBackupService.class);
    scanModel.setDisconfActiveBackupServiceClassSet(classdata);
    //
    // 获取DisconfUpdateService
    //
    classdata = reflections.getTypesAnnotatedWith(DisconfUpdateService.class);
    scanModel.setDisconfUpdateService(classdata);
    // update pipeline
    Set<Class<? extends IDisconfUpdatePipeline>> iDisconfUpdatePipeline = reflections.getSubTypesOf(IDisconfUpdatePipeline.class);
    if (iDisconfUpdatePipeline != null && iDisconfUpdatePipeline.size() != 0) {
        scanModel.setiDisconfUpdatePipeline((Class<IDisconfUpdatePipeline>) iDisconfUpdatePipeline.toArray()[0]);
    }
    return scanModel;
}
Also used : DisconfActiveBackupService(com.baidu.disconf.client.common.annotations.DisconfActiveBackupService) IDisconfUpdatePipeline(com.baidu.disconf.client.common.update.IDisconfUpdatePipeline) ScanStaticModel(com.baidu.disconf.client.scan.inner.statically.model.ScanStaticModel) Method(java.lang.reflect.Method) DisconfUpdateService(com.baidu.disconf.client.common.annotations.DisconfUpdateService) Reflections(org.reflections.Reflections) DisconfItem(com.baidu.disconf.client.common.annotations.DisconfItem)

Example 8 with Reflections

use of org.reflections.Reflections 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 9 with Reflections

use of org.reflections.Reflections 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));
    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));
        }
    }
    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 10 with Reflections

use of org.reflections.Reflections 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)

Aggregations

Reflections (org.reflections.Reflections)47 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)20 SubTypesScanner (org.reflections.scanners.SubTypesScanner)14 Test (org.junit.Test)9 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)9 URL (java.net.URL)8 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)5 HashSet (java.util.HashSet)5 ResourcesScanner (org.reflections.scanners.ResourcesScanner)5 FilterBuilder (org.reflections.util.FilterBuilder)4 Method (java.lang.reflect.Method)3 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)3 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)3 File (java.io.File)2 Annotation (java.lang.annotation.Annotation)2 IResultTypeComputer (org.apache.asterix.om.typecomputer.base.IResultTypeComputer)2 DTO (org.eclipse.che.dto.shared.DTO)2 FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)2 FileSystem (alluxio.client.file.FileSystem)1