Search in sources :

Example 6 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project deeplearning4j by deeplearning4j.

the class DefaultI18N method loadLanguageResources.

private synchronized void loadLanguageResources(String languageCode) {
    if (loadedLanguages.contains(languageCode))
        return;
    //Scan classpath for resources in the /dl4j_i18n/ directory...
    URL url = this.getClass().getResource("/" + DEFAULT_I8N_RESOURCES_DIR + "/");
    Reflections reflections = new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(url));
    String pattern = ".*" + languageCode;
    Set<String> resources = reflections.getResources(Pattern.compile(pattern));
    Map<String, String> messages = new HashMap<>();
    for (String s : resources) {
        if (!s.endsWith(languageCode))
            continue;
        log.trace("Attempting to parse file: {}", s);
        parseFile(s, messages);
    }
    messagesByLanguage.put(languageCode, messages);
    loadedLanguages.add(languageCode);
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ResourcesScanner(org.reflections.scanners.ResourcesScanner) URL(java.net.URL) Reflections(org.reflections.Reflections)

Example 7 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project graylog2-server by Graylog2.

the class AuditCoverageTest method testAuditCoverage.

@Test
public void testAuditCoverage() throws Exception {
    final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder().setUrls(ClasspathHelper.forPackage("org.graylog2")).setScanners(new MethodAnnotationsScanner());
    final Set<String> auditEventTypes = new AuditEventTypes().auditEventTypes();
    final Reflections reflections = new Reflections(configurationBuilder);
    final ImmutableSet.Builder<Method> methods = ImmutableSet.builder();
    final ImmutableSet.Builder<Method> missing = ImmutableSet.builder();
    final ImmutableSet.Builder<Method> unregisteredAction = ImmutableSet.builder();
    methods.addAll(reflections.getMethodsAnnotatedWith(POST.class));
    methods.addAll(reflections.getMethodsAnnotatedWith(PUT.class));
    methods.addAll(reflections.getMethodsAnnotatedWith(DELETE.class));
    for (Method method : methods.build()) {
        if (!method.isAnnotationPresent(AuditEvent.class) && !method.isAnnotationPresent(NoAuditEvent.class)) {
            missing.add(method);
        } else {
            if (method.isAnnotationPresent(AuditEvent.class)) {
                final AuditEvent annotation = method.getAnnotation(AuditEvent.class);
                if (!auditEventTypes.contains(annotation.type())) {
                    unregisteredAction.add(method);
                }
            }
        }
    }
    assertThat(missing.build()).describedAs("Check that there are no POST, PUT and DELETE resources which do not have the @AuditEvent annotation").isEmpty();
    assertThat(unregisteredAction.build()).describedAs("Check that there are no @AuditEvent annotations with unregistered event types").isEmpty();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) POST(javax.ws.rs.POST) Method(java.lang.reflect.Method) PUT(javax.ws.rs.PUT) DELETE(javax.ws.rs.DELETE) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) ImmutableSet(com.google.common.collect.ImmutableSet) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) AuditEvent(org.graylog2.audit.jersey.AuditEvent) Reflections(org.reflections.Reflections) Test(org.junit.Test)

Example 8 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project reflections by ronmamo.

the class ReflectionsExpandSupertypesTest method testExpandSupertypes.

@Test
public void testExpandSupertypes() throws Exception {
    Reflections refExpand = new Reflections(new ConfigurationBuilder().setUrls(ClasspathHelper.forClass(TestModel.ScannedScope.C.class)).filterInputsBy(inputsFilter));
    Assert.assertTrue(refExpand.getConfiguration().shouldExpandSuperTypes());
    Set<Class<? extends TestModel.A>> subTypesOf = refExpand.getSubTypesOf(TestModel.A.class);
    Assert.assertTrue("expanded", subTypesOf.contains(TestModel.B.class));
    Assert.assertTrue("transitivity", subTypesOf.containsAll(refExpand.getSubTypesOf(TestModel.B.class)));
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) Test(org.junit.Test)

Example 9 with ConfigurationBuilder

use of org.reflections.util.ConfigurationBuilder in project drill by apache.

the class ClassPathScanner method scan.

/**
   *
   * @param pathsToScan the locations to scan for .class files
   * @param packagePrefixes the whitelist of package prefixes to scan
   * @param parentResult if there was a prescan, its result
   * @return the merged scan
   */
static ScanResult scan(Collection<URL> pathsToScan, Collection<String> packagePrefixes, Collection<String> scannedClasses, Collection<String> scannedAnnotations, ScanResult parentResult) {
    Stopwatch watch = Stopwatch.createStarted();
    try {
        AnnotationScanner annotationScanner = new AnnotationScanner(scannedAnnotations);
        SubTypesScanner subTypesScanner = new SubTypesScanner(parentResult.getImplementations());
        if (packagePrefixes.size() > 0) {
            final FilterBuilder filter = new FilterBuilder();
            for (String prefix : packagePrefixes) {
                filter.include(FilterBuilder.prefix(prefix));
            }
            ConfigurationBuilder conf = new ConfigurationBuilder().setUrls(pathsToScan).setMetadataAdapter(// Scanners depend on this
            METADATA_ADAPTER).filterInputsBy(filter).setScanners(annotationScanner, subTypesScanner);
            // scans stuff, but don't use the funky storage layer
            new Reflections(conf);
        }
        List<ParentClassDescriptor> implementations = new ArrayList<>();
        for (String baseTypeName : scannedClasses) {
            implementations.add(new ParentClassDescriptor(baseTypeName, new ArrayList<>(subTypesScanner.getChildrenOf(baseTypeName))));
        }
        List<AnnotatedClassDescriptor> annotated = annotationScanner.getAnnotatedClasses();
        verifyClassUnicity(annotated, pathsToScan);
        return new ScanResult(packagePrefixes, scannedClasses, scannedAnnotations, annotated, implementations);
    } finally {
        logger.info(format("Scanning packages %s in locations %s took %dms", packagePrefixes, pathsToScan, watch.elapsed(MILLISECONDS)));
    }
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) ScanResult(org.apache.drill.common.scanner.persistence.ScanResult) Stopwatch(com.google.common.base.Stopwatch) ArrayList(java.util.ArrayList) AnnotatedClassDescriptor(org.apache.drill.common.scanner.persistence.AnnotatedClassDescriptor) FilterBuilder(org.reflections.util.FilterBuilder) ParentClassDescriptor(org.apache.drill.common.scanner.persistence.ParentClassDescriptor) Reflections(org.reflections.Reflections)

Example 10 with ConfigurationBuilder

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

Aggregations

ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)29 Reflections (org.reflections.Reflections)26 SubTypesScanner (org.reflections.scanners.SubTypesScanner)16 URL (java.net.URL)7 ArrayList (java.util.ArrayList)7 TypeAnnotationsScanner (org.reflections.scanners.TypeAnnotationsScanner)7 FilterBuilder (org.reflections.util.FilterBuilder)7 HashSet (java.util.HashSet)5 List (java.util.List)5 Set (java.util.Set)5 Collectors (java.util.stream.Collectors)5 Slf4j (lombok.extern.slf4j.Slf4j)5 CasConfigurationProperties (org.apereo.cas.configuration.CasConfigurationProperties)4 ResourcesScanner (org.reflections.scanners.ResourcesScanner)4 ClasspathHelper (org.reflections.util.ClasspathHelper)4 Bean (org.springframework.context.annotation.Bean)4 File (java.io.File)3 Map (java.util.Map)3 CentralAuthenticationService (org.apereo.cas.CentralAuthenticationService)3 IOException (java.io.IOException)2