tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1357871 - in /openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina: LazyStopWebappClassLoader.java TomEEClassLoaderHelper.java TomEEWebappLoader.java
Date Thu, 05 Jul 2012 20:21:15 GMT
Author: rmannibucau
Date: Thu Jul  5 20:21:15 2012
New Revision: 1357871

URL: http://svn.apache.org/viewvc?rev=1357871&view=rev
Log:
TOMEE-261 better filtering to enrich webapps to avoid to have multipe time the same classes

Modified:
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderHelper.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java?rev=1357871&r1=1357870&r2=1357871&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
(original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/LazyStopWebappClassLoader.java
Thu Jul  5 20:21:15 2012
@@ -71,10 +71,10 @@ public class LazyStopWebappClassLoader e
     // will be in the webapp
     @Override
     public void start() throws LifecycleException {
-        for (URL url : TomEEClassLoaderHelper.tomEEWebappIntegrationLibraries())  {
+        super.start(); // do it first otherwise we can't use this as classloader
+        for (URL url : TomEEClassLoaderHelper.tomEEWebappIntegrationLibraries(this))  {
             addURL(url);
         }
-        super.start();
     }
 
     @Override

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderHelper.java?rev=1357871&r1=1357870&r2=1357871&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderHelper.java
(original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEClassLoaderHelper.java
Thu Jul  5 20:21:15 2012
@@ -49,18 +49,16 @@ public final class TomEEClassLoaderHelpe
     public static final String TOMEE_WEBAPP_CLASSLOADER_ENRICHMENT_CLASSES = "tomee.webapp.classloader.enrichment.classes";
     public static final String TOMEE_WEBAPP_CLASSLOADER_ENRICHMENT_PREFIXES = "tomee.webapp.classloader.enrichment.prefixes";
 
-    private static final String[] DEFAULT_JAR_TO_ADD_CLASS_HELPERS = new String[]{
+    private static final String[] DEFAULT_JAR_TO_ADD_CLASS_HELPERS = new String[] { // put
here only classes which needs classloading check
             // openejb-jsf and openwebbeans-jsf to be able to embedded the jsf impl keeping
CDI features
             "org.apache.openejb.jsf.CustomApplicationFactory",
-            "org.apache.webbeans.jsf.OwbApplicationFactory",
-
-            // JPA integration: mainly JTA integration
-            "org.apache.openejb.jpa.integration.MakeTxLookup",
+            "org.apache.webbeans.jsf.OwbApplicationFactory"
     };
     private static final String[] JAR_TO_ADD_CLASS_HELPERS;
 
-    private static final String[] DEFAULT_PREFIXES_TO_ADD = new String[]{
-            "tomee-mojarra"
+    private static final String[] DEFAULT_PREFIXES_TO_ADD = new String[] { // always added
+            "tomee-mojarra",
+            "openejb-jpa-integration"
     };
     private static final String[] PREFIXES_TO_ADD;
 
@@ -88,26 +86,61 @@ public final class TomEEClassLoaderHelpe
         PREFIXES_TO_ADD = prefixes.toArray(new String[prefixes.size()]);
     }
 
-    public static URL[] tomEEWebappIntegrationLibraries() {
+    public static URL[] tomEEWebappIntegrationLibraries(final ClassLoader appCl) { // TODO:
refactor with an interface: isActive(), addJar(List<URL>)
         final Collection<URL> urls = new ArrayList<URL>();
 
         // from class
         final ClassLoader cl = TomEEClassLoaderHelper.class.getClassLoader(); // reference
classloader = standardclassloader
-        for (String name : JAR_TO_ADD_CLASS_HELPERS) {
-            try {
-                final Class<?> clazz = cl.loadClass(name);
-                if (!clazz.getClassLoader().equals(OpenEJB.class.getClassLoader())) { //
already provided?
-                    continue;
-                }
+        if (cl != appCl && appCl != null) {
+            for (String name : JAR_TO_ADD_CLASS_HELPERS) {
+                try {
+                    final Class<?> clazz = cl.loadClass(name);
+                    if (!clazz.getClassLoader().equals(OpenEJB.class.getClassLoader())) {
// already provided?
+                        continue;
+                    }
+
+                    // don't create a list here to loop only once to avoid to allocate memory
for nothing
+
+                    boolean add = false;
+                    for (Class<?> itf : clazz.getInterfaces()) {
+                        try {
+                            final Class<?> tcclLoaded = appCl.loadClass(itf.getName());
+                            if (!tcclLoaded.getClassLoader().equals(cl)) {
+                                add = true;
+                                break;
+                            }
+                        } catch (Exception e) {
+                            // ignored
+                        }
+                    }
+
+                    Class<?> current = clazz.getSuperclass();
+                    while (current != null && !Object.class.equals(current)) {
+                        try {
+                            final Class<?> tcclLoaded = appCl.loadClass(current.getName());
+                            if (!tcclLoaded.getClassLoader().equals(cl)) {
+                                add = true;
+                                break;
+                            }
+                        } catch (Exception cnfe) {
+                            // ignored
+                        }
+                        current = current.getSuperclass();
+                    }
+
+                    if (!add) {
+                        continue;
+                    }
+
+                    final URL url = JarLocation.jarLocation(clazz).toURI().toURL();
+                    if (url == null) {
+                        continue;
+                    }
 
-                final URL url = JarLocation.jarLocation(clazz).toURI().toURL();
-                if (url == null) {
-                    continue;
+                    urls.add(url);
+                } catch (Exception e) {
+                    // ignore
                 }
-
-                urls.add(url);
-            } catch (Exception e) {
-                // ignore
             }
         }
 

Modified: openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java?rev=1357871&r1=1357870&r2=1357871&view=diff
==============================================================================
--- openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
(original)
+++ openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
Thu Jul  5 20:21:15 2012
@@ -123,13 +123,13 @@ public class TomEEWebappLoader extends W
         private String appPath;
 
         public TomEEClassLoader(final String appId, final ClassLoader appCl, final WebappClassLoader
webappCl) {
-            super(enrichedUrls(webappCl.getURLs()), webappCl); // in fact this classloader
= webappclassloader since we add nothing to this
+            super(enrichedUrls(webappCl.getURLs(), webappCl), webappCl); // in fact this
classloader = webappclassloader since we add nothing to this
             this.appPath = appId;
             this.app = appCl; // only used to manage resources since webapp.getParent() should
be app
             this.webapp = webappCl;
         }
 
-        private static URL[] enrichedUrls(final URL[] urLs) {
+        private static URL[] enrichedUrls(final URL[] urLs, final ClassLoader cl) {
             final List<Integer> skipped = new ArrayList<Integer>();
 
             // while we are here validate the urls regading tomee rules
@@ -150,7 +150,7 @@ public class TomEEWebappLoader extends W
                 }
             }
 
-            final URL[] additional = TomEEClassLoaderHelper.tomEEWebappIntegrationLibraries();
+            final URL[] additional = TomEEClassLoaderHelper.tomEEWebappIntegrationLibraries(cl);
             final URL[] urls = new URL[urLs.length + additional.length - skipped.size()];
             for (int i = 0; i < urLs.length; i++) {
                 if (!skipped.contains(i)) {



Mime
View raw message