tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1490645 - in /tomee/tomee/trunk: container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
Date Fri, 07 Jun 2013 13:40:45 GMT
Author: rmannibucau
Date: Fri Jun  7 13:40:45 2013
New Revision: 1490645

URL: http://svn.apache.org/r1490645
Log:
TOMEE-964 tolerating slf4j-api in web-inf/lib

Modified:
    tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
    tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java

Modified: tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java?rev=1490645&r1=1490644&r2=1490645&view=diff
==============================================================================
--- tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
(original)
+++ tomee/tomee/trunk/container/openejb-core/src/main/java/org/apache/openejb/util/classloader/URLClassLoaderFirst.java
Fri Jun  7 13:40:45 2013
@@ -45,6 +45,8 @@ public class URLClassLoaderFirst extends
         reloadConfig();
     }
 
+    public static final String SLF4J_BINDER_CLASS = "org/slf4j/impl/StaticLoggerBinder.class";
+
     public static void reloadConfig() {
         list(FORCED_SKIP, "openejb.classloader.forced-skip");
         list(FORCED_LOAD, "openejb.classloader.forced-load");
@@ -102,7 +104,7 @@ public class URLClassLoaderFirst extends
         }
 
         // look for it in this classloader
-        boolean ok = !(shouldSkip(name) || (name.startsWith("javax.faces.") && URLClassLoaderFirst.shouldSkipJsf(this,
name)));
+        boolean ok = !(shouldSkip(name) || shouldDelegateToTheContainer(this, name));
         if (ok) {
             clazz = loadInternal(name, resolve);
             if (clazz != null) {
@@ -126,6 +128,10 @@ public class URLClassLoaderFirst extends
         throw new ClassNotFoundException(name);
     }
 
+    public static boolean shouldDelegateToTheContainer(final ClassLoader loader, final String
name) {
+        return shouldSkipJsf(loader, name) || shouldSkipSlf4j(loader, name);
+    }
+
     private Class<?> loadFromParent(final String name, final boolean resolve) {
         ClassLoader parent = getParent();
         if (parent == null) {
@@ -331,10 +337,11 @@ public class URLClassLoaderFirst extends
     }
 
     public static boolean shouldSkipJsf(final ClassLoader loader, final String name) {
-        ClassLoader parentLoader = loader.getParent();
-        while (parentLoader != null && TempClassLoader.class.isInstance(parentLoader)
&& URLClassLoaderFirst.class.getClassLoader() != parentLoader) {
-            parentLoader = parentLoader.getParent();
+        if (!name.startsWith("javax.faces.")) {
+            return false;
         }
+
+        final ClassLoader parentLoader = findParent(loader);
         if (parentLoader == null) {
             return true;
         }
@@ -357,6 +364,14 @@ public class URLClassLoaderFirst extends
 
     }
 
+    private static ClassLoader findParent(final ClassLoader loader) {
+        ClassLoader parentLoader = loader.getParent();
+        while (parentLoader != null && TempClassLoader.class.isInstance(parentLoader)
&& URLClassLoaderFirst.class.getClassLoader() != parentLoader) {
+            parentLoader = parentLoader.getParent();
+        }
+        return parentLoader;
+    }
+
     // in org.apache.openejb.
     private static boolean isWebAppEnrichment(final String openejb) {
         return openejb.startsWith("hibernate.") || openejb.startsWith("jpa.integration.")
@@ -374,7 +389,12 @@ public class URLClassLoaderFirst extends
         return name != null
                 && ("META-INF/services/javax.validation.spi.ValidationProvider".equals(name)
                 || name.startsWith("META-INF/services/org.apache.myfaces.spi")
-                || "org/slf4j/impl/StaticLoggerBinder.class".equals(name));
+                || SLF4J_BINDER_CLASS.equals(name));
+    }
+
+    public static boolean shouldSkipSlf4j(final ClassLoader loader, final String name) {
+        return name != null && name.startsWith("org.slf4j.")
+                && loader.getResource(SLF4J_BINDER_CLASS).equals(findParent(loader).getResource(SLF4J_BINDER_CLASS));
     }
 
     // useful method for SPI

Modified: tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
URL: http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java?rev=1490645&r1=1490644&r2=1490645&view=diff
==============================================================================
--- tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
(original)
+++ tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
Fri Jun  7 13:40:45 2013
@@ -86,7 +86,7 @@ public class LazyStopWebappClassLoader e
         }
 
         // avoid to redefine classes from server in this classloader is it not already loaded
-        if (name.startsWith("javax.faces.") && URLClassLoaderFirst.shouldSkipJsf(this,
name)) {
+        if (URLClassLoaderFirst.shouldDelegateToTheContainer(this, name)) { // dynamic validation
handling overriding
             try {
                 return OpenEJB.class.getClassLoader().loadClass(name);
             } catch (ClassNotFoundException e) {
@@ -99,7 +99,7 @@ public class LazyStopWebappClassLoader e
     }
 
     @Override
-    protected boolean validate(final String name) {
+    protected boolean validate(final String name) { // static validation, mainly container
stuff
         return !URLClassLoaderFirst.shouldSkip(name);
     }
 



Mime
View raw message