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"));
}
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"));
}
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();
}
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)));
}
}
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"));
}
Aggregations