Repository: tomee Updated Branches: refs/heads/master 1485c13bb -> e60f92340
inhibiting owb jsf integration is cdi is off Project: http://git-wip-us.apache.org/repos/asf/tomee/repo Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e677d4d5 Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e677d4d5 Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e677d4d5 Branch: refs/heads/master Commit: e677d4d5c25f8514b357478f7e94ff832731e5e4 Parents: 1485c13 Author: Romain Manni-Bucau <rmannibu...@apache.org> Authored: Tue Jun 16 18:03:40 2015 +0200 Committer: Romain Manni-Bucau <rmannibu...@apache.org> Committed: Tue Jun 16 18:03:40 2015 +0200 ---------------------------------------------------------------------- .../TomEEFacesConfigResourceProvider.java | 28 +++++++++++++++----- .../TomEEMyFacesContainerInitializer.java | 10 +++++-- 2 files changed, 30 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/tomee/blob/e677d4d5/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java index cbac3a6..7053c7a 100644 --- a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java +++ b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEFacesConfigResourceProvider.java @@ -21,6 +21,7 @@ import org.apache.myfaces.shared.util.ClassUtils; import org.apache.openejb.config.NewLoaderLogic; import org.apache.openejb.loader.Files; import org.apache.openejb.util.URLs; +import org.apache.webbeans.config.WebBeansContext; import org.apache.xbean.finder.UrlSet; import javax.faces.context.ExternalContext; @@ -33,6 +34,7 @@ import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; @@ -47,7 +49,7 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource private static final String META_INF_PREFIX = "META-INF/"; private static final String FACES_CONFIG_SUFFIX = ".faces-config.xml"; private static final String FACES_CONFIG_IMPLICIT = "META-INF/faces-config.xml"; - private static final Map<ClassLoader, Collection<URL>> CACHED_RESOURCES = new HashMap<ClassLoader, Collection<URL>>(); + private static final Map<ClassLoader, Collection<URL>> CACHED_RESOURCES = new HashMap<>(); @Override public Collection<URL> getMetaInfConfigurationResources(final ExternalContext notUsedNullIsPassedFromInitializer) throws IOException { @@ -55,10 +57,10 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource Collection<URL> urlSet = CACHED_RESOURCES.get(loader); if (urlSet != null) { - return new HashSet<URL>(urlSet); // copy it since it can be modified then + return new HashSet<>(urlSet); // copy it since it can be modified then } - urlSet = new HashSet<URL>(); + urlSet = new HashSet<>(); final Enumeration<URL> resources = loader.getResources(FACES_CONFIG_IMPLICIT); while (resources.hasMoreElements()) { @@ -68,7 +70,7 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource 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()); + final Collection<Future<Set<URL>>> futures = new ArrayList<>(urls.size()); // Scan files inside META-INF ending with .faces-config.xml for (final URL url : urls) { @@ -80,7 +82,7 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource futures.add(es.submit(new Callable<Set<URL>>() { @Override public Set<URL> call() throws Exception { - final Set<URL> currentSet = new HashSet<URL>(); + final Set<URL> currentSet = new HashSet<>(); if (!file.isDirectory()) { // browse all entries to see if we have a matching file final Enumeration<JarEntry> e = new JarFile(file).entries(); @@ -123,8 +125,22 @@ public class TomEEFacesConfigResourceProvider extends DefaultFacesConfigResource } } + try { + if (WebBeansContext.currentInstance() == null) { + final Iterator<URL> toFilter = urlSet.iterator(); + while (toFilter.hasNext()) { + final URL url = toFilter.next(); + if (TomEEMyFacesContainerInitializer.isOwb(url)) { + toFilter.remove(); + } + } + } + } catch (final Throwable th) { + // no-op + } + CACHED_RESOURCES.put(loader, urlSet); - return new HashSet<URL>(urlSet); + return new HashSet<>(urlSet); } private ClassLoader getClassLoader() { http://git-wip-us.apache.org/repos/asf/tomee/blob/e677d4d5/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java ---------------------------------------------------------------------- diff --git a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java index 851ef6e..a7631be 100644 --- a/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java +++ b/tomee/tomee-myfaces/src/main/java/org/apache/tomee/myfaces/TomEEMyFacesContainerInitializer.java @@ -27,6 +27,7 @@ import org.apache.myfaces.webapp.AbstractFacesInitializer; import org.apache.myfaces.webapp.StartupServletContextListener; import org.apache.openejb.loader.SystemInstance; import org.apache.openejb.log.RemoveLogMessage; +import org.apache.openejb.util.URLs; import javax.faces.webapp.FacesServlet; import javax.servlet.ServletContainerInitializer; @@ -166,8 +167,8 @@ public class TomEEMyFacesContainerInitializer implements ServletContainerInitial // remove our internal faces-config.xml final Iterator<URL> it = metaInfFacesConfigUrls.iterator(); while (it.hasNext()) { - final String next = it.next().toExternalForm().replace(File.separator, "/"); - if (next.contains("/openwebbeans-jsf-") || next.contains("/openwebbeans-el22-")) { + final URL next = it.next(); + if (isOwb(next)) { it.remove(); } } @@ -178,6 +179,11 @@ public class TomEEMyFacesContainerInitializer implements ServletContainerInitial } } + public static boolean isOwb(final URL url) { + final String jar = URLs.toFile(url).getName(); + return jar.startsWith("openwebbeans-jsf-") || jar.startsWith("openwebbeans-el22-"); + } + private static Object get(final Class<?> clazz, final Object facade) throws Exception { final Field field = clazz.getDeclaredField("context"); final boolean acc = field.isAccessible();