tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1196093 - in /openejb/trunk/openejb: arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/ assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ container/openejb-core/src/...
Date Tue, 01 Nov 2011 16:18:33 GMT
Author: rmannibucau
Date: Tue Nov  1 16:18:32 2011
New Revision: 1196093

URL: http://svn.apache.org/viewvc?rev=1196093&view=rev
Log:
TOMEE-42 TOMEE-43 TOMEE-47 using app classloader as parent classloader of the webapp classloader
with delegation. It allows scanned class to be managed by cdi. adding a customee tomee classloader
to avoid duplicated classes when calling getresources

Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesListener.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
    openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesListener.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesListener.java?rev=1196093&r1=1196092&r2=1196093&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesListener.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesListener.java
Tue Nov  1 16:18:32 2011
@@ -18,7 +18,7 @@ public class GetResourcesListener implem
         GetResourcesHolder.RESOURCE_NUMBER = 0;
         try {
             ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
-            Enumeration<URL> urls = classLoader.getResources("test.getresources");
+            Enumeration<URL> urls = classLoader.getResources("config/test.getresources2");
             while (urls.hasMoreElements()) {
                 urls.nextElement();
                 GetResourcesHolder.RESOURCE_NUMBER++;

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java?rev=1196093&r1=1196092&r2=1196093&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
(original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-tests/src/test/java/org/apache/openejb/arquillian/tests/getresources/GetResourcesTest.java
Tue Nov  1 16:18:32 2011
@@ -30,6 +30,7 @@ import static org.apache.openejb.arquill
                 .addClass(GetResourcesListener.class)
                 .addClass(GetResourcesHolder.class)
                 .addAsWebResource(Thread.currentThread().getContextClassLoader().getResource("test.getresources"),
"/config/test.getresources")
+                .addAsWebResource(Thread.currentThread().getContextClassLoader().getResource("test.getresources"),
"/config/test.getresources2")
                 .addAsLibraries(new File("target/test-libs/junit.jar"))
                 .setWebXML(new StringAsset(
                       Descriptors.create(WebAppDescriptor.class)

Modified: openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java?rev=1196093&r1=1196092&r2=1196093&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomEEWebappLoader.java
Tue Nov  1 16:18:32 2011
@@ -3,34 +3,67 @@ package org.apache.tomee.catalina;
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.loader.WebappLoader;
 import org.apache.naming.resources.DirContextURLStreamHandler;
+import org.apache.openejb.util.ArrayEnumeration;
 import org.apache.tomcat.util.ExceptionUtils;
 
+import java.io.IOException;
+import java.net.URL;
+import java.util.Collection;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
+
 /**
- * simply override getClassLoader().
- *
- * Note: internally it still uses a webappclassloader.
- *
  * @author rmannibucau
  */
 public class TomEEWebappLoader extends WebappLoader {
     private ClassLoader appClassLoader;
+    private ClassLoader tomEEClassLoader;
 
-    public TomEEWebappLoader(ClassLoader classLoader) {
+    public TomEEWebappLoader(final ClassLoader classLoader) {
         appClassLoader = classLoader;
     }
 
     @Override public ClassLoader getClassLoader() {
-        return appClassLoader;
+        return tomEEClassLoader;
     }
 
     @Override protected void startInternal() throws LifecycleException {
         super.startInternal();
+        tomEEClassLoader = new TomEEClassLoader(appClassLoader, super.getClassLoader());
         try {
-            // override the webappclassloader by the app classloader
-            DirContextURLStreamHandler.bind(appClassLoader, getContainer().getResources());
+             DirContextURLStreamHandler.bind(tomEEClassLoader, getContainer().getResources());
         } catch (Throwable t) {
             ExceptionUtils.handleThrowable(t);
             throw new LifecycleException("start: ", t);
         }
     }
+
+    public static class TomEEClassLoader extends ClassLoader {
+        private ClassLoader app;
+        private ClassLoader webapp;
+
+        public TomEEClassLoader(final ClassLoader appCl, final ClassLoader webappCl) {
+            app = appCl;
+            webapp = webappCl;
+        }
+
+        @Override public Enumeration<URL> getResources(final String name) throws IOException
{
+            Enumeration<URL> appClassLoaderResources = app.getResources(name);
+            Enumeration<URL> webappClassLoaderResources = webapp.getResources(name);
+
+            Set<URL> urls = new HashSet<URL>();
+            // /!\ order is important here
+            add(urls, webappClassLoaderResources);
+            add(urls, appClassLoaderResources);
+
+            return new ArrayEnumeration(urls);
+        }
+
+        private static void add(Collection<URL> urls, Enumeration<URL> enumUrls)
{
+            while (enumUrls.hasMoreElements()) {
+                urls.add(enumUrls.nextElement());
+            }
+        }
+    }
 }

Modified: openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java?rev=1196093&r1=1196092&r2=1196093&view=diff
==============================================================================
--- openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
(original)
+++ openejb/trunk/openejb/assembly/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
Tue Nov  1 16:18:32 2011
@@ -322,6 +322,18 @@ public class TomcatWebAppBuilder impleme
                 if (standardContext.getDocBase() != null && standardContext.getDocBase().endsWith(".war"))
{
                     standardContext.setDocBase(standardContext.getDocBase().substring(0,
standardContext.getDocBase().length() - 4));
                 }
+
+                // add classloader which is an URLClassLoader created by openejb
+                // {@see Assembler}
+                //
+                // we add it as parent classloader since we scanned classes with this classloader
+                // that's why we force delegate to true.
+                //
+                // However since this classloader and the webappclassloader will have a lot
+                // of common classes/resources we have to avoid duplicated resources
+                // so we contribute a custom loader.
+                standardContext.setParentClassLoader(classLoader);
+                standardContext.setDelegate(true);
                 standardContext.setLoader(new TomEEWebappLoader(classLoader));
 
                 String host = webApp.host;

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java?rev=1196093&r1=1196092&r2=1196093&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java
(original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/ArrayEnumeration.java
Tue Nov  1 16:18:32 2011
@@ -22,6 +22,7 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import java.util.Enumeration;
 import java.util.NoSuchElementException;
+import java.util.Set;
 import java.util.Vector;
 
 public final class ArrayEnumeration implements Enumeration, Externalizable {
@@ -40,6 +41,11 @@ public final class ArrayEnumeration impl
         list.toArray(this.elements);
     }
 
+    public ArrayEnumeration(Set<?> set) {
+        this.elements = new Object[set.size()];
+        set.toArray(this.elements);
+    }
+
     public ArrayEnumeration() {
     }
 



Mime
View raw message