[jboss-cvs] JBossAS SVN: r69524 - in trunk: tomcat and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Feb 1 02:54:28 EST 2008


Author: scott.stark at jboss.org
Date: 2008-02-01 02:54:28 -0500 (Fri, 01 Feb 2008)
New Revision: 69524

Modified:
   trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
   trunk/tomcat/.classpath
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebAppLoader.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebCtxLoader.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
   trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/WarClassLoaderDeployer.java
   trunk/tomcat/src/resources/war-deployers-beans.xml
Log:
JBAS-5153, move the war class loader creation to WarClassLoaderDeployer

Modified: trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java
===================================================================
--- trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/server/src/main/org/jboss/web/deployers/AbstractWarDeployment.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -310,9 +310,12 @@
       {
          // Create a classloader for the war to ensure a unique ENC
          // TODO: this should be handled by the WarClassLoaderDeployer
+         /*
          VirtualFile root = unit.getRoot();
          URL[] empty = {root.toURL()};
          URLClassLoader warLoader = URLClassLoader.newInstance(empty, unit.getClassLoader());
+         */
+         ClassLoader warLoader = unit.getClassLoader();
          thread.setContextClassLoader(warLoader);
          String webContext = metaData.getContextRoot();
    

Modified: trunk/tomcat/.classpath
===================================================================
--- trunk/tomcat/.classpath	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/.classpath	2008-02-01 07:54:28 UTC (rev 69524)
@@ -64,5 +64,6 @@
 		</accessrules>
 	</classpathentry>
 	<classpathentry kind="lib" path="/thirdparty/sun-jaxb/lib/jaxb-api.jar"/>
+	<classpathentry kind="lib" path="/thirdparty/jboss/microcontainer/lib/jboss-classloader.jar" sourcepath="/thirdparty/jboss/microcontainer/lib/jboss-classloader-sources.jar"/>
 	<classpathentry kind="output" path="output/eclipse-classes"/>
 </classpath>

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -160,9 +160,13 @@
       return webDD.getJndiEnvironmentRefsGroup();
    }
 
-   public Object newInstance(String className) throws IllegalAccessException, InvocationTargetException, NamingException, InstantiationException, ClassNotFoundException {
-       Class<?> clazz = catalinaContext.getLoader().getClassLoader().loadClass(className);
-       Object instance = clazz.newInstance();
+   public Object newInstance(String className)
+      throws IllegalAccessException, InvocationTargetException, NamingException,
+      InstantiationException, ClassNotFoundException
+   {
+      ClassLoader loader = catalinaContext.getLoader().getClassLoader();
+      Class<?> clazz = loader.loadClass(className);
+      Object instance = clazz.newInstance();
 	   if (!catalinaContext.getIgnoreAnnotations())
 	   {
 		   processAnnotations(instance);

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebAppLoader.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebAppLoader.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebAppLoader.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -23,6 +23,7 @@
 
 import java.net.URL;
 import java.util.List;
+import java.util.Set;
 
 import org.apache.catalina.LifecycleException;
 import org.apache.catalina.loader.WebappLoader;
@@ -52,10 +53,21 @@
       setLoaderClass(WebAppClassLoader.class.getName());
    }
 
-   public WebAppLoader(ClassLoader parent, String[] filteredPackages)
+   public WebAppLoader(ClassLoader parent, Set<String> filteredPackages)
    {
       this(parent, filteredPackages, null);
    }
+   public WebAppLoader(ClassLoader parent, Set<String> filteredPackages, TomcatInjectionContainer container)
+   {
+      super(parent);
+      setLoaderClass(WebAppClassLoader.class.getName());
+      if(filteredPackages != null)
+      {
+         this.filteredPackages = new String[filteredPackages.size()];
+         filteredPackages.toArray(this.filteredPackages);
+      }
+      injectionContainer = container;
+   }
    public WebAppLoader(ClassLoader parent, String[] filteredPackages, TomcatInjectionContainer container)
    {
       super(parent);

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebCtxLoader.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebCtxLoader.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/WebCtxLoader.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -40,7 +40,6 @@
 import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.Loader;
 import org.apache.naming.resources.DirContextURLStreamHandler;
-import org.jboss.mx.loading.RepositoryClassLoader;
 import org.jboss.logging.Logger;
 
 /**
@@ -61,10 +60,6 @@
     * The ClassLoader returned from getClassLoader
     */
    protected ENCLoader ctxLoader;
-   /**
-    * The war UCL used to load the war classes
-    */
-   protected RepositoryClassLoader delegate;
    protected Container webContainer;
    protected URL warURL;
    protected TomcatInjectionContainer injectionContainer;
@@ -87,13 +82,6 @@
    {
       this.encLoader = encLoader;
       this.ctxLoader = new ENCLoader(encLoader);
-      ClassLoader parent = encLoader;
-      while ((parent instanceof RepositoryClassLoader) == false && parent != null)
-         parent = parent.getParent();
-      // Fail if a parent could not be found
-      if(parent == null)
-         throw new IllegalStateException("No RepositoryClassLoader parent found, encLoader: "+encLoader);
-      this.delegate = (RepositoryClassLoader) parent;
       injectionContainer = container;
    }
 
@@ -106,7 +94,6 @@
    {
       for(URL path : classpath)
       {
-         delegate.addURL(path);
          ctxLoader.addURLInternal(path);
       }
    }
@@ -124,7 +111,6 @@
       File classesDir = new File(path, "WEB-INF/classes");
       if (classesDir.exists())
       {
-         delegate.addURL(classesDir.toURL());
          ctxLoader.addURLInternal(classesDir.toURL());
       }
       File libDir = new File(path, "WEB-INF/lib");
@@ -137,7 +123,6 @@
             File jar = jars[j];
             if(jar.getAbsolutePath().endsWith(".jar"))
             {
-               delegate.addURL(jar.toURL());
                ctxLoader.addURLInternal(jar.toURL());
             }
          }
@@ -185,7 +170,6 @@
       org.apache.commons.logging.LogFactory.release(encLoader);
       this.encLoader = null;
       this.ctxLoader = null;
-      this.delegate = null;
       this.repositories.clear();
       this.warURL = null;
       this.webContainer = null;

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -583,7 +583,11 @@
          }
       }
 
-      ClassLoadingMetaData classLoading = metaData.getClassLoading();
+      WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
+      if (classpath != null)
+         jbossLoader.setClasspath(classpath);
+      webLoader = jbossLoader;
+      /*
       if (classLoading != null && classLoading.isJava2ClassLoadingCompliance())
       {
          WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
@@ -600,6 +604,7 @@
             jbossLoader.setClasspath(classpath);
          webLoader = jbossLoader;
       }
+      */
       return webLoader;
    }
 

Modified: trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/WarClassLoaderDeployer.java
===================================================================
--- trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/WarClassLoaderDeployer.java	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/main/org/jboss/web/tomcat/service/deployers/WarClassLoaderDeployer.java	2008-02-01 07:54:28 UTC (rev 69524)
@@ -23,47 +23,50 @@
 
 import java.net.URL;
 import java.util.ArrayList;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import java.util.jar.Attributes;
+import java.util.jar.Manifest;
 
-import org.apache.catalina.Loader;
+import org.jboss.classloader.spi.ClassLoaderPolicy;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderSystemDeployer;
+import org.jboss.deployers.plugins.classloading.Module;
 import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderPolicy;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.logging.Logger;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
+import org.jboss.virtual.VFSUtils;
 import org.jboss.virtual.VirtualFile;
-import org.jboss.web.tomcat.service.TomcatInjectionContainer;
-import org.jboss.web.tomcat.service.WebAppLoader;
-import org.jboss.web.tomcat.service.WebCtxLoader;
 
 /**
- * A class loader deployer for wars that handles installing a war first class
- * loader unless the WebMetaData indicates otherwise.
- * AbstractClassLoaderDeployer
+ * The war deployment class loader deployer.
+ * TODO: this deployer should not exist. Metadata should be
+ * driving the existing top-level class loader deployer.
  * 
  * @author Scott.Stark at jboss.org
  * @author adrian at jboss.org
  * @version $Revision:$
  */
-public class WarClassLoaderDeployer extends AbstractDeployer implements ClassLoaderFactory
+public class WarClassLoaderDeployer extends AbstractClassLoaderSystemDeployer
 {
    /** The parent class loader first model flag */
    private boolean java2ClassLoadingCompliance = false;
-   private boolean useJBossWebLoader;
+   private boolean includeWebInfInClasspath;
    /** Package names that should be ignored for class loading */
-   private String[] filteredPackages;
+   private Set<String> filteredPackages;
 
    /**
     * Create a new WarClassLoaderDeployer.
     */
    public WarClassLoaderDeployer()
    {
-      setStage(DeploymentStages.CLASSLOADER);
-      setOutput(ClassLoaderFactory.class);
+      super();
+      setInput(JBossWebMetaData.class);
    }
 
    public boolean isJava2ClassLoadingCompliance()
@@ -75,117 +78,121 @@
       this.java2ClassLoadingCompliance = flag;
    }
 
-   public String[] getFilteredPackages()
+   public Set<String> getFilteredPackages()
    {
       return filteredPackages;
    }
-   public void setFilteredPackages(String[] pkgs)
+   public void setFilteredPackages(Set<String> pkgs)
    {
       this.filteredPackages = pkgs;
    }
 
-   public boolean isUseJBossWebLoader()
+   public boolean isIncludeWebInfInClasspath()
    {
-      return useJBossWebLoader;
+      return includeWebInfInClasspath;
    }
-   public void setUseJBossWebLoader(boolean useJBossWebLoader)
+   public void setIncludeWebInfInClasspath(boolean includeWebInfInClasspath)
    {
-      this.useJBossWebLoader = useJBossWebLoader;
+      this.includeWebInfInClasspath = includeWebInfInClasspath;
    }
 
    
+   @Override
    public void deploy(DeploymentUnit unit) throws DeploymentException
    {
-      if (unit instanceof VFSDeploymentUnit)
-         return;
-      
-      JBossWebMetaData metaData = unit.getAttachment(JBossWebMetaData.class);
-      if( metaData != null )
-      {
-         unit.addAttachment(ClassLoaderFactory.class, this);
-      }
+      if(unit.isAttachmentPresent(JBossWebMetaData.class))
+         super.deploy(unit);
    }
 
-   public ClassLoader createClassLoader(DeploymentContext context) throws Exception
+   @Override
+   public void undeploy(DeploymentUnit unit)
    {
-      ClassLoader loader = null;
+      if(unit.isAttachmentPresent(JBossWebMetaData.class))
+         super.undeploy(unit);
+   }
+
+   @Override
+   protected ClassLoaderPolicy createClassLoaderPolicy(DeploymentContext context, Module module)
+      throws Exception
+   {
+      VFSClassLoaderPolicy policy = null;
       try
       {
-         DeploymentUnit unit = context.getDeploymentUnit();
-         JBossWebMetaData metaData = unit.getAttachment(JBossWebMetaData.class);
-         loader = createClassLoader(metaData, (VFSDeploymentContext) context);
-         if( loader != null )
-            context.setClassLoader(loader);
+         if(context instanceof VFSDeploymentContext)
+         {
+            VFSDeploymentContext vfscontext = (VFSDeploymentContext) context;
+            ArrayList<VirtualFile> paths = new ArrayList<VirtualFile>();
+            if(vfscontext.getClassPath() != null)
+               paths.addAll(vfscontext.getClassPath());
+            LinkedHashSet<VirtualFile> cpSet = new LinkedHashSet<VirtualFile>();
+            // Add the manifest classpath, bug
+            VirtualFile war = vfscontext.getRoot();
+            // TODO: restore when JBMICROCONT-232 is fixed.
+            // VFSUtils.addManifestLocations(war, paths);
+            // Add the WEB-INF if requested
+            VirtualFile webInf = vfscontext.getFile("WEB-INF");
+            if(includeWebInfInClasspath && webInf != null)
+               cpSet.add(webInf);
+            // Process the war manifest
+            addManifestLocations(war, paths, log);
+            if(paths != null)
+               cpSet.addAll(paths);
+
+            VirtualFile[] warFiles = new VirtualFile[cpSet.size()];
+            cpSet.toArray(warFiles);
+            policy = new VFSClassLoaderPolicy(module.getName(), warFiles);
+            policy.setExportAll(module.getExportAll());
+            policy.setImportAll(module.isImportAll());
+            policy.setExcludedPackages(filteredPackages);
+         }
       }
       catch(Exception e)
       {
-         log.warn("", e);
+         log.warn("Failed to create war ClassLoaderPolicy", e);
       }
-      return loader;
+      return policy;
    }
 
    public void removeClassLoader(DeploymentContext context) throws Exception
    {
-      
    }
 
-   protected ClassLoader createClassLoader(JBossWebMetaData metaData, VFSDeploymentContext context) throws Exception
+   public static void addManifestLocations(VirtualFile file, List<VirtualFile> paths, Logger log)
+      throws Exception
    {
-      ClassLoader loader = null;
-      if (metaData != null)
+      Manifest manifest = VFSUtils.getManifest(file);
+      if (manifest != null)
       {
-         ClassLoader parent = context.getClassLoader();
-         if( parent == null )
-            parent = context.getTopLevel().getClassLoader();
-         if( parent == null )
-            parent = Thread.currentThread().getContextClassLoader();
-         Loader webLoader = getWebLoader(parent, metaData, context.getClassPath());
-         context.getDeploymentUnit().addAttachment(Loader.class, webLoader);
-         loader = webLoader.getClassLoader();
-      }
-      return loader;
-   }
+         VirtualFile parent = file.getParent();
+         URL parentURL = parent != null ? parent.toURL() : file.toURL();
 
-   /**
-    * Create the web app class loader.
-    * 
-    * @param loader
-    * @param metaData
-    * @param classpath
-    * @return the loader
-    * @throws Exception for any error
-    */
-   protected Loader getWebLoader(ClassLoader loader, JBossWebMetaData metaData,  List<VirtualFile> classpath) throws Exception
-   {
-      Loader webLoader = null;
-      TomcatInjectionContainer injectionContainer = null;
-      if (useJBossWebLoader)
-      {
-         WebCtxLoader jbossLoader = new WebCtxLoader(loader, injectionContainer);
-         ArrayList<URL> cp = new ArrayList<URL>();
-         for(VirtualFile vf : classpath)
+         Attributes mainAttributes = manifest.getMainAttributes();
+         String classPath = mainAttributes.getValue(Attributes.Name.CLASS_PATH);
+         if(classPath == null)
+            return;
+
+         StringTokenizer tokenizer = new StringTokenizer(classPath);
+         while (tokenizer.hasMoreTokens())
          {
+            String path = tokenizer.nextToken();
             try
             {
-               URL path = vf.toURL();
-               cp.add(path);
+               String parentPath = parentURL.toString();
+               if(parentPath.endsWith("/") == false)
+                  parentPath += "/";
+               VirtualFile pathvf = parent.getChild(path);
+               if(pathvf != null)
+               {
+                  paths.add(pathvf);
+                  // Recursively process the target
+                  addManifestLocations(pathvf, paths, log);
+               }
             }
-            catch(Exception e)
+            catch (Exception e)
             {
-               log.debug("Ignoring path element: "+vf, e);
+               log.debug("Manifest Class-Path entry " + path + " ignored for " + file.getPathName() + " reason=" + e);
             }
          }
-         jbossLoader.setClasspath(cp);
-         webLoader = jbossLoader;
-      }
-      else
-      {
-         WebAppLoader jbossLoader = new WebAppLoader(loader, filteredPackages, injectionContainer);
-         jbossLoader.setDelegate(java2ClassLoadingCompliance);
-         jbossLoader.start();
-         webLoader = jbossLoader;
-      }
-      return webLoader;
+      }      
    }
-
 }

Modified: trunk/tomcat/src/resources/war-deployers-beans.xml
===================================================================
--- trunk/tomcat/src/resources/war-deployers-beans.xml	2008-02-01 05:45:23 UTC (rev 69523)
+++ trunk/tomcat/src/resources/war-deployers-beans.xml	2008-02-01 07:54:28 UTC (rev 69524)
@@ -16,28 +16,31 @@
       <property name="relativeOrder">2001</property>
    </bean>
 
-   <!-- Allow for war local class loaders: in testing
-   <bean name="WarClassLoaderDeployer" class="org.jboss.web.tomcat.service.deployers.WarClassLoaderDeployer">
-      <!- - CLASSLOADER_DEPLOYER - 1 - ->
-      <property name="relativeOrder">3999</property>
-      <!- - A flag indicating if the JBoss Loader should be used. This loader
-         uses a unified class loader as the class loader rather than the tomcat
-         specific class loader.
-         The default is false to ensure that wars have isolated class loading
-         for duplicate jars and jsp files.
-      - ->
-      <property name="useJBossWebLoader">false</property>
-      <!- - The list of package prefixes that should not be loaded without
-         delegating to the parent class loader before trying the web app
-         class loader. The packages listed here are those tha are used by
-         the web container implementation and cannot be overriden. The format
-         is a comma separated list of the package names. There cannot be any
-         whitespace between the package prefixes.
-         This setting only applies when UseJBossWebLoader=false.
-         - ->
-      <property name="filteredPackages">javax.servlet,org.apache.commons.logging</property>
-   </bean>
-  --> 
+   <!-- Allow for war local class loaders: in testing -->
+   <bean name="WarClassLoaderDeployer" class="org.jboss.web.tomcat.service.deployers.WarClassLoaderDeployer">
+      <property name="relativeOrder">-1</property>
+      <property name="classLoading"><inject bean="ClassLoading"/></property>
+      <property name="system"><inject bean="ClassLoaderSystem"/></property>
+      <property name="mbeanServer"><inject bean="JMXKernel" property="mbeanServer"/></property>
+      
+      <property name="includeWebInfInClasspath">true</property>
+      
+      <!-- The list of package prefixes that should not be loaded without
+         delegating to the parent class loader before trying the web app
+         class loader. The packages listed here are those tha are used by
+         the web container implementation and cannot be overriden. The format
+         is a comma separated list of the package names. There cannot be any
+         whitespace between the package prefixes.
+         This setting only applies when UseJBossWebLoader=false.
+      -->
+      <property name="filteredPackages">
+         <set>
+            <value>javax.servlet</value>
+            <value>org.apache.commons.logging</value>
+         </set>
+      </property>
+      
+   </bean>
         
    <!-- 
         Injects default clustering metadata.        




More information about the jboss-cvs-commits mailing list