[Jboss-cvs] JBossAS SVN: r56838 - in projects/microcontainer/trunk/deployers/src: main/org/jboss/deployers/plugins/deployer main/org/jboss/deployers/plugins/deployers/helpers main/org/jboss/deployers/plugins/deployment main/org/jboss/deployers/plugins/structure main/org/jboss/deployers/spi/deployer main/org/jboss/deployers/spi/structure tests/org/jboss/test/deployers/deployer/test

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Sep 14 06:20:40 EDT 2006


Author: adrian at jboss.org
Date: 2006-09-14 06:20:27 -0400 (Thu, 14 Sep 2006)
New Revision: 56838

Added:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/ClassPathVisitor.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContextVisitor.java
Modified:
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
   projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
   projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java
Log:
[JBMICROCONT-5] - More changes for classloading including an awful hack
that exposes the DeploymentContext to the deployers for now.

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -130,4 +130,10 @@
    {
       return deploymentContext.getTransientManagedObjects();
    }
+
+   @Deprecated
+   public DeploymentContext getDeploymentContext()
+   {
+      return deploymentContext;
+   }
 }

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/ClassPathVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/ClassPathVisitor.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/ClassPathVisitor.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -0,0 +1,65 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.plugins.deployers.helpers;
+
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.spi.structure.DeploymentContextVisitor;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Collects all the classpath elements
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ClassPathVisitor implements DeploymentContextVisitor
+{
+   /** The full classpath */
+   private Set<VirtualFile> classPath = new LinkedHashSet<VirtualFile>();
+   
+   /**
+    * Get the full classpath after the visit
+    * 
+    * @return the full classpath
+    */
+   public Set<VirtualFile> getClassPath()
+   {
+      return classPath;
+   }
+   
+   public void visit(DeploymentContext context) throws DeploymentException
+   {
+      List<VirtualFile> paths = context.getClassPath();
+      if (paths != null)
+         classPath.addAll(paths);
+   }
+
+   public void error(DeploymentContext context)
+   {
+      // nothing
+   }
+}

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -323,12 +323,12 @@
                DeploymentUnit unit = context.getDeploymentUnit();
                deployer.prepareUndeploy(unit);
             }
-            // TODO perform with the deployer that created the classloader?
-            for (DeploymentContext context : undeployContexts)
-               context.removeClassLoader();
          }
          for (DeploymentContext context : undeployContexts)
          {
+            // TODO perform with the deployer that created the classloader?
+            context.removeClassLoader();
+
             context.setState(UNDEPLOYED);
             log.debug("Undeployed: " + context.getName());
          }

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -34,6 +34,7 @@
 import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
 import org.jboss.deployers.spi.deployer.DeploymentUnit;
 import org.jboss.deployers.spi.structure.DeploymentContext;
+import org.jboss.deployers.spi.structure.DeploymentContextVisitor;
 import org.jboss.deployers.spi.structure.DeploymentState;
 import org.jboss.deployers.spi.structure.StructureDetermined;
 import org.jboss.logging.Logger;
@@ -348,6 +349,7 @@
       {
          log.warn("Error removing classloader for " + getName(), t);
       }
+      classLoaderFactory = null;
       setClassLoader(null);
    }
 
@@ -411,7 +413,94 @@
          throw new IllegalArgumentException("Null child");
       return children.remove(child);
    }
+
+   public void visit(DeploymentContextVisitor visitor) throws DeploymentException
+   {
+      if (visitor == null)
+         throw new IllegalArgumentException("Null visitor");
+
+      visit(this, visitor);
+   }
    
+   /**
+    * Visit a context
+    * 
+    * @param context the context
+    * @param visitor the visitor
+    * @throws DeploymentException for any error
+    */
+   private void visit(DeploymentContext context, DeploymentContextVisitor visitor) throws DeploymentException
+   {
+      visitor.visit(context);
+      try
+      {
+         Set<DeploymentContext> children = context.getChildren();
+         if (children.isEmpty())
+            return;
+         
+         DeploymentContext[] childContexts = children.toArray(new DeploymentContext[children.size()]);
+         for (int i = 0; i < childContexts.length; ++i)
+         {
+            if (childContexts[i] == null)
+               throw new IllegalStateException("Null child context for " + context.getName() + " children=" + children);
+            try
+            {
+               visit(childContexts[i], visitor);
+            }
+            catch (Throwable t)
+            {
+               for (int j = i-1; j >= 0; --j)
+                  visitError(childContexts[j], visitor, true);
+               throw DeploymentException.rethrowAsDeploymentException("Error visiting: " + childContexts[i].getName(), t);
+            }
+         }
+      }
+      catch (Throwable t)
+      {
+         visitError(context, visitor, false);
+         throw DeploymentException.rethrowAsDeploymentException("Error visiting: " + context.getName(), t);
+      }
+   }
+
+   /**
+    * Unwind the visit invoking the previously visited context's error handler
+    * 
+    * @param context the context
+    * @param visitor the visitor
+    * @param visitChildren whether to visit the children
+    * @throws DeploymentException for any error
+    */
+   private void visitError(DeploymentContext context, DeploymentContextVisitor visitor, boolean visitChildren) throws DeploymentException
+   {
+      if (visitChildren)
+      {
+         Set<DeploymentContext> children = context.getChildren();
+         if (children.isEmpty())
+            return;
+         
+         for (DeploymentContext child : children)
+         {
+            try
+            {
+               visitError(child, visitor, true);
+            }
+            catch (Throwable t)
+            {
+               log.warn("Error during visit error: " + child.getName(), t);
+            }
+         }
+         
+      }
+      try
+      {
+         visitor.error(context);
+      }
+      catch (Throwable t)
+      {
+         log.warn("Error during visit error: " + context.getName(), t);
+      }
+   }
+
    public Attachments getPredeterminedManagedObjects()
    {
       return predeterminedManagedObjects;

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -26,6 +26,7 @@
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.attachments.Attachments;
 import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
+import org.jboss.deployers.spi.structure.DeploymentContext;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -88,4 +89,12 @@
     * @return the managed objects
     */
    Attachments getTransientManagedObjects();
+   
+   /**
+    * Get the deployment contxt
+    * 
+    * @return the deployment context
+    */
+   @Deprecated // If you are using this, then think about it.
+   DeploymentContext getDeploymentContext();
 }

Modified: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -234,6 +234,15 @@
    boolean removeChild(DeploymentContext child);
 
    /**
+    * Visit the context and the children
+    * 
+    * @param visitor the visitor
+    * @throws DeploymentException for any error in the visitor
+    * @throws IllegalArgumentException for a null visitor
+    */
+   void visit(DeploymentContextVisitor visitor) throws DeploymentException;
+   
+   /**
     * Get the predetermined managed objects
     * 
     * @return the predetermined managed objects

Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContextVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContextVisitor.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContextVisitor.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.spi.structure;
+
+import org.jboss.deployers.spi.DeploymentException;
+
+/**
+ * DeploymentContextVisitor.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface DeploymentContextVisitor
+{
+   /**
+    * Visit a context
+    * 
+    * @param context the context
+    * @throws DeploymentException for any error
+    */
+   void visit(DeploymentContext context) throws DeploymentException;
+   
+   /**
+    * Invoked when there is a subsequent error in the visit
+    * 
+    * @param context the context
+    */
+   void error(DeploymentContext context);
+}

Modified: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java	2006-09-14 09:16:52 UTC (rev 56837)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java	2006-09-14 10:20:27 UTC (rev 56838)
@@ -21,14 +21,19 @@
 */
 package org.jboss.test.deployers.deployer.test;
 
+import java.util.HashSet;
+
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
+import org.jboss.deployers.plugins.deployers.helpers.ClassPathVisitor;
 import org.jboss.deployers.plugins.deployment.MainDeployerImpl;
+import org.jboss.deployers.plugins.structure.vfs.jar.JARStructure;
 import org.jboss.deployers.spi.structure.DeploymentContext;
 import org.jboss.deployers.spi.structure.DeploymentState;
 import org.jboss.test.deployers.BaseDeployersTest;
 import org.jboss.test.deployers.deployer.support.TestClassLoaderDeployer;
+import org.jboss.virtual.VirtualFile;
 
 /**
  * DeployerClassLoaderUnitTestCase.
@@ -89,4 +94,19 @@
       assertEquals(DeploymentState.UNDEPLOYED, sub.getState());
       assertNull(sub.getClassLoader());
    }
+
+   public void testClassPathVisitor() throws Exception
+   {
+      MainDeployerImpl main = new MainDeployerImpl();
+      main.addStructureDeployer(new JARStructure());
+      DeploymentContext context = createDeploymentContext("/structure/jar", "indirectory");
+      main.addDeploymentContext(context);
+      ClassPathVisitor visitor = new ClassPathVisitor();
+      context.visit(visitor);
+      HashSet<VirtualFile> expected = new HashSet<VirtualFile>();
+      expected.add(context.getRoot());
+      expected.add(context.getRoot().findChild("archive.zip"));
+      expected.add(context.getRoot().findChild("archive.jar"));
+      assertEquals(expected, visitor.getClassPath());
+   }
 }




More information about the jboss-cvs-commits mailing list