Search in sources :

Example 1 with PrefixFilter

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));
}
Also used : PrefixFilter(org.apache.xbean.finder.filter.PrefixFilter) FilterList(org.apache.xbean.finder.filter.FilterList)

Example 2 with PrefixFilter

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);
    }
}
Also used : JarArchive(org.apache.xbean.finder.archive.JarArchive) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) Archive(org.apache.xbean.finder.archive.Archive) PrefixFilter(org.apache.xbean.finder.filter.PrefixFilter) ArrayList(java.util.ArrayList) FilteredArchive(org.apache.xbean.finder.archive.FilteredArchive) IOException(java.io.IOException) URL(java.net.URL) CompositeArchive(org.apache.xbean.finder.archive.CompositeArchive) JarArchive(org.apache.xbean.finder.archive.JarArchive) FileArchive(org.apache.xbean.finder.archive.FileArchive)

Aggregations

PrefixFilter (org.apache.xbean.finder.filter.PrefixFilter)2 IOException (java.io.IOException)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Archive (org.apache.xbean.finder.archive.Archive)1 CompositeArchive (org.apache.xbean.finder.archive.CompositeArchive)1 FileArchive (org.apache.xbean.finder.archive.FileArchive)1 FilteredArchive (org.apache.xbean.finder.archive.FilteredArchive)1 JarArchive (org.apache.xbean.finder.archive.JarArchive)1 FilterList (org.apache.xbean.finder.filter.FilterList)1