/** return urls that are in the current class path. * attempts to load the jar manifest, if any, and adds to the result any dependencies it finds. */ public static Set<URL> forManifest() { return forManifest(forClassLoader()); }
public boolean isBlacklisted(final MetaClass type) { final SimplePackageFilter blacklistFilter = new SimplePackageFilter(blacklist); final String fullName = type.getFullyQualifiedName(); return blacklistFilter.apply(fullName); }
ContraintScanner() { super(new ConfigurationBuilder() .setUrls(ClasspathHelper.forClassLoader()) .setScanners( new FieldAnnotationsScanner(), new TypeAnnotationsScanner())); scan(); } }
/** * collect saved Reflection xml resources and merge it into a Reflections instance * <p>by default, resources are collected from all urls that contains the package META-INF/reflections * and includes files matching the pattern .*-reflections.xml */ public static Reflections collect() { return new Reflections(new ConfigurationBuilder()). collect("META-INF/reflections", new FilterBuilder().include(".*-reflections.xml")); }
/** * a convenient constructor for scanning within a package prefix * <p>this actually create a {@link Configuration} with: * <br> - urls that contain resources with name {@code prefix} * <br> - acceptsInput where name starts with the given {@code prefix} * <br> - scanners set to the given {@code scanners}, otherwise defaults to {@link TypeAnnotationsScanner} and {@link SubTypesScanner}. * <br> - scanner results filter is set to accept results matching given {@code prefix} */ public Reflections(final String prefix, final Scanner... scanners) { this(new ConfigurationBuilder() { { final Predicate<String> filter = new FilterBuilder.Include(FilterBuilder.prefix(prefix)); setUrls(ClasspathHelper.forPackage(prefix)); filterInputsBy(filter); if (scanners != null && scanners.length != 0) { for (Scanner scanner : scanners) { scanner.filterResultsBy(Predicates.<String>and(filter, scanner.getResultFilter())); } setScanners(scanners); } else { setScanners( new TypeAnnotationsScanner().filterResultsBy(filter), new SubTypesScanner().filterResultsBy(filter)); } } }); }
/** include a package of a given class */ public FilterBuilder includePackage(final Class<?> aClass) {return add(new Include(packageNameRegex(aClass)));} /** exclude a package of a given class */
/** exclude a package of a given class */ public FilterBuilder excludePackage(final Class<?> aClass) {return add(new Exclude(packageNameRegex(aClass)));}
/** sets the executor service used for scanning to ThreadPoolExecutor with core size as the given availableProcessors parameter * <p>default is ThreadPoolExecutor with a single core */ public ConfigurationBuilder useParallelExecutor(final int availableProcessors) { setExecutorService(Executors.newFixedThreadPool(availableProcessors)); return this; }
/** add urls to be scanned * <p>use {@link org.jboss.errai.reflections.util.ClasspathHelper} convenient methods to get the relevant urls * */ public ConfigurationBuilder addUrls(final Collection<URL>... urlss) { for (Collection<URL> urls : urlss) { addUrls(urls); } return this; }
@Override public boolean apply(String input) { return !matches(input); } }
@Override public boolean apply(final String input) { return matches(input); }
public BasePackageFilter(final Collection<String> filters) { this.filters = processFilters(filters); }
@Override public String toString() {return "+" + super.toString();} }
/** sets the executor service used for scanning to ThreadPoolExecutor with core size as {@link java.lang.Runtime#availableProcessors()} * <p>default is ThreadPoolExecutor with a single core */ public ConfigurationBuilder useParallelExecutor() { return useParallelExecutor(Runtime.getRuntime().availableProcessors()); }
/** get the urls that are specified in the manifest of the given urls. * attempts to load the jar manifest, if any, and adds to the result any dependencies it finds. */ public static Set<URL> forManifest(final Iterable<URL> urls) { Set<URL> result = Sets.newHashSet(); // determine if any of the URLs are JARs, and get any dependencies for (URL url : urls) { result.addAll(forManifest(url)); } return result; }
public boolean isBlacklisted(final MetaClass type) { final SimplePackageFilter blacklistFilter = new SimplePackageFilter(blacklist); final String fullName = type.getFullyQualifiedName(); return blacklistFilter.apply(fullName); }
/** set the urls to be scanned * <p>use {@link org.jboss.errai.reflections.util.ClasspathHelper} convenient methods to get the relevant urls * */ public ConfigurationBuilder setUrls(final Collection<URL>... urlss) { urls.clear(); addUrls(urlss); return this; }
public boolean isWhitelisted(final MetaClass type) { if (whitelist.isEmpty()) { return true; } final SimplePackageFilter implicitFilter = new SimplePackageFilter(Arrays.asList(implicitWhitelist)); final SimplePackageFilter whitelistFilter = new SimplePackageFilter(whitelist); final String fullName = type.getFullyQualifiedName(); return implicitFilter.apply(fullName) || whitelistFilter.apply(fullName); }