Search in sources :

Example 11 with FilterBuilder

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

the class FilterBuilderTest method test_parse_include_notRegex.

@Test
public void test_parse_include_notRegex() {
    FilterBuilder filter = FilterBuilder.parse("+org.reflections");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertFalse(filter.apply("org.foobar.Reflections"));
    assertFalse(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 12 with FilterBuilder

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

the class FilterBuilderTest method test_parsePackages_include_trailingDot.

@Test
public void test_parsePackages_include_trailingDot() {
    FilterBuilder filter = FilterBuilder.parsePackages("+org.reflections.");
    assertTrue(filter.apply("org.reflections.Reflections"));
    assertTrue(filter.apply("org.reflections.foo.Reflections"));
    assertFalse(filter.apply("org.foobar.Reflections"));
    assertFalse(filter.apply("org.reflectionsplus.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Example 13 with FilterBuilder

use of org.reflections.util.FilterBuilder in project cas by apereo.

the class CasEmbeddedContainerUtils method getCasBannerInstance.

/**
     * Gets cas banner instance.
     *
     * @return the cas banner instance
     */
public static Banner getCasBannerInstance() {
    final String packageName = CasEmbeddedContainerUtils.class.getPackage().getName();
    final Reflections reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(new FilterBuilder().includePackage(packageName)).setUrls(ClasspathHelper.forPackage(packageName)).setScanners(new SubTypesScanner(true)));
    final Set<Class<? extends AbstractCasBanner>> subTypes = reflections.getSubTypesOf(AbstractCasBanner.class);
    subTypes.remove(DefaultCasBanner.class);
    if (subTypes.isEmpty()) {
        return new DefaultCasBanner();
    }
    try {
        final Class<? extends AbstractCasBanner> clz = subTypes.iterator().next();
        LOGGER.debug("Created banner [{}]", clz);
        return clz.newInstance();
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return new DefaultCasBanner();
}
Also used : ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) AbstractCasBanner(org.apereo.cas.util.spring.boot.AbstractCasBanner) FilterBuilder(org.reflections.util.FilterBuilder) SubTypesScanner(org.reflections.scanners.SubTypesScanner) DefaultCasBanner(org.apereo.cas.util.spring.boot.DefaultCasBanner) Reflections(org.reflections.Reflections)

Example 14 with FilterBuilder

use of org.reflections.util.FilterBuilder 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 15 with FilterBuilder

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

the class FilterBuilderTest method test_excludePackage.

@Test
public void test_excludePackage() {
    FilterBuilder filter = new FilterBuilder().excludePackage("org.reflections");
    assertFalse(filter.apply("org.reflections.Reflections"));
    assertFalse(filter.apply("org.reflections.foo.Reflections"));
    assertTrue(filter.apply("org.foobar.Reflections"));
}
Also used : FilterBuilder(org.reflections.util.FilterBuilder) Test(org.junit.Test)

Aggregations

FilterBuilder (org.reflections.util.FilterBuilder)23 Test (org.junit.Test)17 ConfigurationBuilder (org.reflections.util.ConfigurationBuilder)6 Reflections (org.reflections.Reflections)4 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 BeforeClass (org.junit.BeforeClass)2 SubTypesScanner (org.reflections.scanners.SubTypesScanner)2 Stopwatch (com.google.common.base.Stopwatch)1 AnnotatedClassDescriptor (org.apache.drill.common.scanner.persistence.AnnotatedClassDescriptor)1 ParentClassDescriptor (org.apache.drill.common.scanner.persistence.ParentClassDescriptor)1 ScanResult (org.apache.drill.common.scanner.persistence.ScanResult)1 AbstractCasBanner (org.apereo.cas.util.spring.boot.AbstractCasBanner)1 DefaultCasBanner (org.apereo.cas.util.spring.boot.DefaultCasBanner)1 DL4JSubTypesScanner (org.deeplearning4j.util.reflections.DL4JSubTypesScanner)1 AnnotatedClass (org.nd4j.shade.jackson.databind.introspect.AnnotatedClass)1 NamedType (org.nd4j.shade.jackson.databind.jsontype.NamedType)1 FieldAnnotationsScanner (org.reflections.scanners.FieldAnnotationsScanner)1 MethodAnnotationsScanner (org.reflections.scanners.MethodAnnotationsScanner)1 MethodParameterScanner (org.reflections.scanners.MethodParameterScanner)1