use of org.apache.xbean.finder.filter.PrefixFilter in project component-runtime by Talend.
the class FilterFactory method and.
public static Filter and(final Filter first, final Filter second) {
if (Stream.of(first, second).anyMatch(f -> !FilterList.class.isInstance(f) || !FilterList.class.cast(f).getFilters().stream().allMatch(PrefixFilter.class::isInstance))) {
// for optims
throw new IllegalArgumentException("And only works with filter list of prefix filters");
}
final FilterList list1 = FilterList.class.cast(first);
final FilterList list2 = FilterList.class.cast(second);
return Filters.prefixes(Stream.of(list1.getFilters(), list2.getFilters()).flatMap(Collection::stream).map(PrefixFilter.class::cast).map(PrefixFilter::getPrefix).distinct().toArray(String[]::new));
}
use of org.apache.xbean.finder.filter.PrefixFilter in project stdlib by petergeneric.
the class ClassScannerFactory method getArchivesForPackage.
private static CompositeArchive getArchivesForPackage(final ClassLoader classloader, final String... packages) {
try {
final List<Archive> archives = new ArrayList<>();
for (String pkg : packages) {
if (!pkg.endsWith("."))
// Add a trailing dot for easier package matching
pkg += ".";
final String baseFolder = pkg.replace('.', '/');
final Enumeration<URL> urls = classloader.getResources(baseFolder);
while (urls.hasMoreElements()) {
final URL url = urls.nextElement();
if (log.isTraceEnabled())
log.trace("Found source: " + url);
if (url.getProtocol() != null && (url.getProtocol().equals("zip") || url.getProtocol().equals("jar")))
archives.add(new FilteredArchive(new JarArchive(classloader, url), new PrefixFilter(pkg)));
else
archives.add(new FileArchive(classloader, url, pkg));
}
}
return new CompositeArchive(archives);
} catch (IOException e) {
throw new IllegalArgumentException("Error loading archives for packages: " + Arrays.asList(packages), e);
}
}
Aggregations