org.apache.xbean.finder.filter.Filter Java Examples
The following examples show how to use
org.apache.xbean.finder.filter.Filter.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationComposers.java From tomee with Apache License 2.0 | 6 votes |
private static IAnnotationFinder finderFromClasses(final DeploymentModule module, final Class<?>[] value, final Collection<File> others, final String[] excludes) { final Collection<Archive> archives = new ArrayList<>(1 + (others == null ? 0 : others.size())); final Filter filter = excludes == null || excludes.length == 0 ? null : Filters.invert(Filters.prefixes(excludes)); final Collection<Class<?>> classes = new ArrayList<>(asList(FinderFactory.ensureMinimalClasses(module))); if (value != null) { classes.addAll(asList(value)); } final ClassesArchive classesArchive = new ClassesArchive(classes); archives.add(filter == null ? classesArchive : new FilteredArchive(classesArchive, filter)); if (others != null) { final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); for (final File f : others) { try { final Archive archive = f.isDirectory() ? new FileArchive(classLoader, f) : new JarArchive(classLoader, f.toURI().toURL()); archives.add(filter == null ? archive : new FilteredArchive(archive, filter)); } catch (final MalformedURLException e) { throw new IllegalArgumentException(e); } } } return new FinderFactory.OpenEJBAnnotationFinder(new CompositeArchive(archives)).link(); }
Example #2
Source File: ComponentManager.java From component-runtime with Apache License 2.0 | 6 votes |
private Filter createScanningFilter(final Properties config) { final String includes = config.getProperty("classloader.includes"); final String excludes = config.getProperty("classloader.excludes"); if (includes == null && excludes == null) { return KnownClassesFilter.INSTANCE; } final Filter accept = ofNullable(includes) .map(String::trim) .filter(v -> !v.isEmpty()) .map(s -> s.split(",")) .map(Filters::patterns) .orElseGet(() -> name -> true); final Filter reject = ofNullable(excludes) .map(String::trim) .filter(v -> !v.isEmpty()) .map(s -> s.split(",")) .map(Filters::patterns) .orElseGet(() -> name -> false); if ("include-exclude".equals(config.getProperty("classloader.filter.strategy"))) { return new IncludeExcludeFilter(accept, reject); } return new ExcludeIncludeFilter(accept, reject); }
Example #3
Source File: ScanTask.java From component-runtime with Apache License 2.0 | 6 votes |
private Stream<String> scanList() { final AnnotationFinder finder = newFinder(); final Filter filter = newFilter(); return Stream .concat(Stream .of(PartitionMapper.class, Processor.class, Emitter.class, Service.class, Internationalized.class) .flatMap(it -> finder.findAnnotatedClasses(it).stream()), Stream .of(Request.class) .flatMap(it -> finder.findAnnotatedMethods(it).stream()) .map(Method::getDeclaringClass)) .distinct() .map(Class::getName) .sorted() .filter(filter::accept); }
Example #4
Source File: ScanTask.java From component-runtime with Apache License 2.0 | 6 votes |
private Filter newFilter() { final Filter accept = ofNullable(includes) .filter(it -> it.size() > 0) .map(i -> i.toArray(new String[0])) .map(Filters::patterns) .orElseGet(() -> name -> true); final Filter reject = ofNullable(excludes) .filter(it -> it.size() > 0) .map(i -> i.toArray(new String[0])) .map(Filters::patterns) .orElseGet(() -> name -> false); if ("include-exclude".equals(filterStrategy)) { return new IncludeExcludeFilter(accept, reject); } return new ExcludeIncludeFilter(accept, reject); }
Example #5
Source File: FilterFactory.java From component-runtime with Apache License 2.0 | 6 votes |
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))) { throw new IllegalArgumentException("And only works with filter list of prefix filters"); // for optims } 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)); }
Example #6
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 6 votes |
public static boolean skip(final URL url, final Filter includeFilter, final Filter excludeFilter) { if ("archive".equals(url.getProtocol())) { return true; } try { final File file = URLs.toFile(url); final String name = NameFiltering.filter(file).getName(); if (skip(includeFilter, excludeFilter, name)) { return true; } } catch (final IllegalArgumentException iae) { // no-op } return false; }
Example #7
Source File: OWBTomcatWebScannerService.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
public void setFilter(final JarScanFilter filter, final ServletContext ctx) { this.filter = filter; super.init(ctx); final Configuration config = Configuration.class.cast(ServletContext.class.cast(ctx).getAttribute("meecrowave.configuration")); if (this.filter == null) { this.filter = new KnownJarsFilter(config); } final Filter userFilter = webBeansContext().getService(Filter.class); if (KnownClassesFilter.class.isInstance(userFilter)) { KnownClassesFilter.class.cast(userFilter).init(config); } }
Example #8
Source File: WebappAggregatedArchive.java From tomee with Apache License 2.0 | 5 votes |
private List<Archive> doScan(final ClassLoader loader, final Iterable<URL> urls, final Filter filter) { final List<Archive> archives = new ArrayList<>(); for (final URL url : urls) { final List<String> classes = new ArrayList<>(); final Archive archive = new FilteredArchive( new ConfigurableClasspathArchive(loader, singletonList(url)), new ScanXmlSaverFilter(scanXmlExists, handler, classes, filter)); map.put(url, classes); archives.add(archive); } return archives; }
Example #9
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 5 votes |
private static boolean skip(final Filter includeFilter, final Filter excludeFilter, final String name) { if (includeFilter == null || !includeFilter.accept(name)) { if (filter != null && filter.accept(name)) { return true; } else if (excludeFilter != null && excludeFilter.accept(name)) { return true; } } return false; }
Example #10
Source File: MeecrowaveSeContainerInitializer.java From openwebbeans-meecrowave with Apache License 2.0 | 5 votes |
@Override protected void addCustomServices(final Map<String, Object> services) { final Set<String> forced = this.scannerService.configuredClasses().stream().map(Class::getName).collect(toSet()); services.put(Filter.class.getName(), new KnownClassesFilter() { // override it to make programmatic configuration working OOTB @Override public boolean accept(final String name) { return forced.contains(name) || super.accept(name); } }); }
Example #11
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 5 votes |
public static UrlSet applyBuiltinExcludes(final UrlSet urlSet, final Filter includeFilter, final Filter excludeFilter) throws MalformedURLException { getExclusions(); // force init final List<URL> urls = urlSet.getUrls(); urls.removeIf(url -> skip(url, includeFilter, excludeFilter)); return new UrlSet(urls); }
Example #12
Source File: BaseComponentsHandler.java From component-runtime with Apache License 2.0 | 5 votes |
public EmbeddedComponentManager start() { final EmbeddedComponentManager embeddedComponentManager = new EmbeddedComponentManager(packageName) { @Override protected boolean isContainerClass(final Filter filter, final String name) { if (name == null) { return super.isContainerClass(filter, null); } return (isolatedPackages == null || isolatedPackages.stream().noneMatch(name::startsWith)) && super.isContainerClass(filter, name); } @Override public void close() { try { final State state = STATE.get(); if (state.jsonb != null) { try { state.jsonb.close(); } catch (final Exception e) { // no-op: not important } } STATE.remove(); initState.remove(); } finally { super.close(); } } }; STATE .set(new State(embeddedComponentManager, new CopyOnWriteArrayList<>(), initState.get().emitter, null, null, null, null)); return embeddedComponentManager; }
Example #13
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public static Filter getFilter() { if (filter == null) { synchronized (NewLoaderLogic.class) { if (filter == null) { filter = new OptimizedExclusionFilter(getExclusions()); } } } return filter; }
Example #14
Source File: NativeWrappedIOTest.java From component-runtime with Apache License 2.0 | 5 votes |
public EmbeddedComponentManager start() { final EmbeddedComponentManager embeddedComponentManager = new EmbeddedComponentManager(packageName) { @Override protected boolean isContainerClass(final Filter filter, final String name) { if (name == null) { return super.isContainerClass(filter, null); } return (isolatedPackages == null || isolatedPackages.stream().noneMatch(name::startsWith)) && super.isContainerClass(filter, name); } @Override public void close() { try { final State state = STATE.get(); if (state.jsonb != null) { try { state.jsonb.close(); } catch (final Exception e) { // no-op: not important } } STATE.remove(); initState.remove(); } finally { super.close(); } } }; STATE .set(new State(embeddedComponentManager, new ArrayList<>(), initState.get().emitter, null, null, null, null)); return embeddedComponentManager; }
Example #15
Source File: Configuration.java From tomee with Apache License 2.0 | 4 votes |
public Filter getClassesFilter() { return classesFilter; }
Example #16
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 4 votes |
public static UrlSet applyBuiltinExcludes(final UrlSet urlSet, final Filter includeFilter) throws MalformedURLException { return applyBuiltinExcludes(urlSet, includeFilter, null); }
Example #17
Source File: NewLoaderLogic.java From tomee with Apache License 2.0 | 4 votes |
public static UrlSet filterArchives(final Filter filter, final ClassLoader classLoader, UrlSet urlSet) { for (final URL url : urlSet.getUrls()) { for (final Archive archive : ClasspathArchive.archives(classLoader, url)) { final FilteredArchive filtered = new FilteredArchive(archive, filter); if (!filtered.iterator().hasNext()) { urlSet = urlSet.exclude(url); } } } return urlSet; }
Example #18
Source File: DeploymentsResolver.java From tomee with Apache License 2.0 | 4 votes |
public ClasspathSearcher loadUrls(final ClassLoader classLoader) { try { final UrlSet original = cleanUpUrlSet(new UrlSet(classLoader)); urlSet = URLs.cullSystemJars(original); // save the prefiltered list of jars before excluding system apps // so that we can choose not to filter modules with descriptors on the full list prefiltered = urlSet; Filter includeFilter = Filters.patterns(include); // we should exclude system apps before and apply user properties after if (!".*".equals(include) || !"".equals(exclude)) { // if we are using default this will not do anything // the next line should probably replaced by: // final Filter filter = new ExcludeIncludeFilter(includeFilter, Filters.patterns(exclude)); final Filter filter; if (EXCLUDE_INCLUDE_ORDER.startsWith("include")) { // this test should be simply enough filter = new IncludeExcludeFilter(includeFilter, Filters.patterns(exclude)); } else { filter = new ExcludeIncludeFilter(includeFilter, Filters.patterns(exclude)); } // filter using user parameters urlSet = urlSet.filter(filter); } else { includeFilter = null; } if (prefiltered.size() == urlSet.size()) { urlSet = NewLoaderLogic.applyBuiltinExcludes(urlSet, includeFilter); if (filterSystemApps) { urlSet = urlSet.exclude(".*/openejb-[^/]+(.(jar|ear|war)(!/)?|/target/(test-)?classes/?)"); } } final boolean isWindows = JavaSecurityManagers.getSystemProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH).startsWith("windows"); if (!isWindows || !Boolean.parseBoolean(SystemInstance.get().getProperty("openejb.resolver.windows.lowercase-urls", "true"))) { urls = urlSet.getUrls(); } else { urls = new ArrayList<>(); for (final URL url : urlSet.getUrls()) { final String ef = url.toExternalForm().toLowerCase(); final URL u = new URL(ef); if (!urls.contains(u)) { urls.add(u); } } } return this; } catch (final IOException e1) { logger.warning("Unable to search classpath", e1); } return this; }
Example #19
Source File: DeploymentLoader.java From tomee with Apache License 2.0 | 4 votes |
public Filter getCustomerFilter() { return customerFilter; }
Example #20
Source File: DeploymentLoader.java From tomee with Apache License 2.0 | 4 votes |
public ExternalConfiguration(final String[] classpath, final Filter customerFilter) { this.classpath = classpath; this.customerFilter = customerFilter; }
Example #21
Source File: DeploymentLoader.java From tomee with Apache License 2.0 | 4 votes |
private Class<? extends DeploymentModule> checkAnnotations(final URL urls, final ClassLoader classLoader, final boolean scanPotentialEjbModules, final boolean scanPotentialClientModules) { Class<? extends DeploymentModule> cls = null; if (scanPotentialEjbModules || scanPotentialClientModules) { final AnnotationFinder classFinder = new AnnotationFinder(classLoader, urls); final Set<Class<? extends DeploymentModule>> otherTypes = new LinkedHashSet<>(); final AnnotationFinder.Filter filter = new AnnotationFinder.Filter() { final String packageName = LocalClient.class.getName().replace("LocalClient", ""); @Override public boolean accept(final String annotationName) { if (scanPotentialClientModules && annotationName.startsWith(packageName)) { if (LocalClient.class.getName().equals(annotationName)) { otherTypes.add(ClientModule.class); } if (RemoteClient.class.getName().equals(annotationName)) { otherTypes.add(ClientModule.class); } } else if (scanPotentialEjbModules) { if (annotationName.startsWith("javax.ejb.")) { if ("javax.ejb.Stateful".equals(annotationName)) { return true; } if ("javax.ejb.Stateless".equals(annotationName)) { return true; } if ("javax.ejb.Singleton".equals(annotationName)) { return true; } if ("javax.ejb.MessageDriven".equals(annotationName)) { return true; } } else if (scanManagedBeans && "javax.annotation.ManagedBean".equals(annotationName)) { return true; } } return false; } }; if (classFinder.find(filter)) { cls = EjbModule.class; // if it is a war just throw an error try { if(LOGGER.isWarningEnabled()) { final File ar = URLs.toFile(urls); if (!ar.isDirectory() && !ar.getName().endsWith("ar")) { // guess no archive extension, check it is not a hidden war try (JarFile war = new JarFile(ar)) { final ZipEntry entry = war.getEntry("WEB-INF/"); if (entry != null) { LOGGER.warning("you deployed " + urls.toExternalForm() + ", it seems it is a war with no extension, please rename it"); } } } } } catch (final Exception ignored) { // no-op } } if (otherTypes.size() > 0) { // We may want some ordering/sorting if we add more type scanning cls = otherTypes.iterator().next(); } } return cls; }
Example #22
Source File: WebappAggregatedArchive.java From tomee with Apache License 2.0 | 4 votes |
public ScanXmlSaverFilter(final boolean scanXmlExists, final ScanUtil.ScanHandler handler, final List<String> classes, final Filter otherFilter) { this.scanXmlExists = scanXmlExists; this.handler = handler; this.classes = classes; this.otherFilter = otherFilter; }
Example #23
Source File: Configuration.java From tomee with Apache License 2.0 | 4 votes |
public Configuration classesFilter(final Filter filter) { setClassesFilter(filter); return this; }
Example #24
Source File: Configuration.java From tomee with Apache License 2.0 | 4 votes |
public void setClassesFilter(final Filter filter) { this.classesFilter = filter; }
Example #25
Source File: BaseComponentsHandler.java From component-runtime with Apache License 2.0 | 4 votes |
@Override protected boolean isContainerClass(final Filter filter, final String name) { // embedded mode (no plugin structure) so just run with all classes in parent classloader return true; }
Example #26
Source File: NativeWrappedIOTest.java From component-runtime with Apache License 2.0 | 4 votes |
@Override protected boolean isContainerClass(final Filter filter, final String name) { // embedded mode (no plugin structure) so just run with all classes in parent classloader return true; }
Example #27
Source File: ComponentManager.java From component-runtime with Apache License 2.0 | 4 votes |
protected boolean isContainerClass(final Filter filter, final String name) { return name != null && filter.accept(name); }