@Override public Enumeration<URL> getResources(final String name) throws IOException { if (!getState().isAvailable()) { return null; } if ("META-INF/services/javax.servlet.ServletContainerInitializer".equals(name)) { final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final URL next = it.next(); final File file = Files.toFile(next); if (!file.isFile() && NewLoaderLogic.skip(next)) { it.remove(); } } return Collections.enumeration(list); } if ("META-INF/services/javax.websocket.ContainerProvider".equals(name)) { final Collection<URL> list = new ArrayList<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final URL next = it.next(); final File file = Files.toFile(next); if (!file.isFile() && NewLoaderLogic.skip(next)) { it.remove(); } } return Collections.enumeration(list); } if ("META-INF/faces-config.xml".equals(name)) { // mojarra workaround try { if (WebBeansContext.currentInstance() == null && Boolean.parseBoolean( SystemInstance.get().getProperty("tomee.jsf.ignore-owb", "true"))) { final Collection<URL> list = new HashSet<>(Collections.list(super.getResources(name))); final Iterator<URL> it = list.iterator(); while (it.hasNext()) { final String fileName = Files.toFile(it.next()).getName(); if (fileName.startsWith("openwebbeans-" /*jsf|el22*/) && fileName.endsWith(".jar")) { it.remove(); } } return Collections.enumeration(list); } } catch (final Throwable th) { // no-op } } return URLClassLoaderFirst.filterResources(name, super.getResources(name)); }
@Override public Collection<URL> getMetaInfConfigurationResources( final ExternalContext notUsedNullIsPassedFromInitializer) throws IOException { final ClassLoader loader = getClassLoader(); Collection<URL> urlSet = CACHED_RESOURCES.get(loader); if (urlSet != null) { return new HashSet<URL>(urlSet); // copy it since it can be modified then } urlSet = new HashSet<URL>(); final Enumeration<URL> resources = loader.getResources(FACES_CONFIG_IMPLICIT); while (resources.hasMoreElements()) { urlSet.add(resources.nextElement()); } final List<URL> urls = NewLoaderLogic.applyBuiltinExcludes(new UrlSet(loader)).getUrls(); final ExecutorService es = Executors.newFixedThreadPool(2 * Runtime.getRuntime().availableProcessors() + 1); final Collection<Future<Set<URL>>> futures = new ArrayList<Future<Set<URL>>>(urls.size()); // Scan files inside META-INF ending with .faces-config.xml for (final URL url : urls) { final File file = URLs.toFile(url); if (!file.exists()) { continue; } futures.add( es.submit( new Callable<Set<URL>>() { @Override public Set<URL> call() throws Exception { final Set<URL> currentSet = new HashSet<URL>(); if (!file.isDirectory()) { // browse all entries to see if we have a matching file final Enumeration<JarEntry> e = new JarFile(file).entries(); while (e.hasMoreElements()) { try { final String name = e.nextElement().getName(); if (name.startsWith(META_INF_PREFIX) && name.endsWith(FACES_CONFIG_SUFFIX)) { final Enumeration<URL> e2 = loader.getResources(name); while (e2.hasMoreElements()) { currentSet.add(e2.nextElement()); } } } catch (final Throwable ignored) { // no-op } } } else { final File metaInf = new File(file, META_INF_PREFIX); if (metaInf.exists() && metaInf.isDirectory()) { for (final File f : Files.collect(metaInf, FacesConfigSuffixFilter.INSTANCE)) { if (!f.isDirectory()) { currentSet.add(f.toURI().toURL()); } } } } return currentSet; } })); } es.shutdown(); for (final Future<Set<URL>> set : futures) { try { urlSet.addAll(set.get()); } catch (final Exception e) { // no-op } } CACHED_RESOURCES.put(loader, urlSet); return new HashSet<URL>(urlSet); }