[jboss-cvs] JBossAS SVN: r69333 - in projects/microcontainer/trunk/deployers-vfs/src: main/org/jboss/deployers/vfs/plugins/structure and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 24 19:29:58 EST 2008


Author: adrian at jboss.org
Date: 2008-01-24 19:29:58 -0500 (Thu, 24 Jan 2008)
New Revision: 69333

Added:
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoader.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoaderDeployer.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerClassLoaderUnitTestCase.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoader.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoaderStructureDeployer.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/StructureDeployerContextClassLoaderTestCase.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/TerminateStructureTestCase.java
Removed:
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/TerminateStructureTestCase.java
Modified:
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/SecurityActions.java
   projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/Simple.java
   projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java
Log:
[JBMICROCONT-231] - Make the deployers run with the same context classloader as whoever registered them and use the deployment classloader for any pojos if they don't have a specific classloader configured in the xml

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/deployer/kernel/BeanMetaDataDeployer.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -21,7 +21,11 @@
 */
 package org.jboss.deployers.vfs.deployer.kernel;
 
+import org.jboss.beans.metadata.plugins.AbstractClassLoaderMetaData;
+import org.jboss.beans.metadata.plugins.AbstractValueMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.ClassLoaderMetaData;
+import org.jboss.beans.metadata.spi.ValueMetaData;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -63,6 +67,21 @@
    @Override
    public void deploy(DeploymentUnit unit, BeanMetaData deployment) throws DeploymentException
    {
+      // No explicit classloader, use the deployment's classloader
+      if (deployment.getClassLoader() == null)
+      {
+         try
+         {
+            // Check the unit has a classloader
+            unit.getClassLoader();
+            // TODO clone the metadata?
+            deployment.setClassLoader(new DeploymentClassLoaderMetaData(unit));
+         }
+         catch (Exception e)
+         {
+            log.debug("Unable to retrieve classloader for deployment: " + unit.getName() + " reason=" + e.toString());
+         }
+      }
       KernelControllerContext context = new AbstractKernelControllerContext(null, deployment, null);
       try
       {
@@ -78,5 +97,40 @@
    public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
    {
       controller.uninstall(deployment.getName());
+      
+      // Remove any classloader metadata we added (not necessary if we clone above)
+      ClassLoaderMetaData classLoader = deployment.getClassLoader();
+      if (classLoader instanceof DeploymentClassLoaderMetaData)
+         deployment.setClassLoader(null);
    }
+   
+   /**
+    * DeploymentClassLoaderMetaData.
+    */
+   private class DeploymentClassLoaderMetaData extends AbstractClassLoaderMetaData
+   {
+      /** The serialVersionUID */
+      private static final long serialVersionUID = 1L;
+      
+      /** The deployment unit */
+      private DeploymentUnit unit;
+
+      /**
+       * Create a new DeploymentClassLoaderMetaData.
+       * 
+       * @param unit the deployment unit
+       */
+      public DeploymentClassLoaderMetaData(DeploymentUnit unit)
+      {
+         if (unit == null)
+            throw new IllegalArgumentException("Null unit");
+         this.unit = unit;
+      }
+      
+      @Override
+      public ValueMetaData getClassLoader()
+      {
+         return new AbstractValueMetaData(unit.getClassLoader());
+      }
+   }
 }

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/SecurityActions.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/SecurityActions.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/SecurityActions.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -24,6 +24,7 @@
 import java.io.IOException;
 import java.lang.reflect.UndeclaredThrowableException;
 import java.security.AccessController;
+import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
 
@@ -87,4 +88,67 @@
       else
          return FileActions.NON_PRIVILEGED.isLeaf(f);
    }
+
+   static ClassLoader getContextClassLoader()
+   {
+      if (System.getSecurityManager() == null)
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+      else
+      {
+         return AccessController.doPrivileged(GetContextClassLoader.INSTANCE);
+      }
+   }
+
+   static class GetContextClassLoader implements PrivilegedAction<ClassLoader>
+   {
+      static GetContextClassLoader INSTANCE = new GetContextClassLoader();
+      
+      public ClassLoader run()
+      {
+         return Thread.currentThread().getContextClassLoader();
+      }
+   }
+   
+   static ClassLoader setContextClassLoader(final ClassLoader classLoader)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         ClassLoader previous = Thread.currentThread().getContextClassLoader();
+         Thread.currentThread().setContextClassLoader(classLoader);
+         return previous;
+      }
+      else
+      {
+         return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+         {
+            public ClassLoader run()
+            {
+               ClassLoader previous = Thread.currentThread().getContextClassLoader();
+               Thread.currentThread().setContextClassLoader(classLoader);
+               return previous;
+            }
+         });
+      }
+   }
+
+   static void resetContextClassLoader(final ClassLoader classLoader)
+   {
+      if (System.getSecurityManager() == null)
+      {
+         Thread.currentThread().setContextClassLoader(classLoader);
+      }
+      else
+      {
+         AccessController.doPrivileged(new PrivilegedAction<Object>()
+         {
+            public Object run()
+            {
+               Thread.currentThread().setContextClassLoader(classLoader);
+               return null;
+            }
+         });
+      }
+   }
 }

Modified: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/structure/StructureDeployerWrapper.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -21,8 +21,8 @@
 */
 package org.jboss.deployers.vfs.plugins.structure;
 
+import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
 import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
 import org.jboss.logging.Logger;
@@ -43,7 +43,10 @@
    
    /** The structure deployer */
    private StructureDeployer deployer;   
-
+   
+   /** The context classloader of the person registering the deployer */
+   private ClassLoader classLoader;
+   
    /**
     * Create a new StructureDeployerWrapper.
     * 
@@ -55,6 +58,7 @@
          throw new IllegalArgumentException("Null deployer");
       this.deployer = deployer;
       log = Logger.getLogger(deployer.getClass());
+      this.classLoader = SecurityActions.getContextClassLoader();
    }
    
    public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
@@ -62,15 +66,23 @@
       if (file == null)
          throw new IllegalArgumentException("Null file");
 
-      boolean result = deployer.determineStructure(root, parent, file, metaData, deployers);
-      if (log.isTraceEnabled())
+      ClassLoader previous = SecurityActions.setContextClassLoader(classLoader);
+      try
       {
-         if (result == false)
-            log.trace("Not recognised: " + file.getName());
-         else
-            log.trace("Recognised: " + file.getName());
+         boolean result = deployer.determineStructure(root, parent, file, metaData, deployers);
+         if (log.isTraceEnabled())
+         {
+            if (result == false)
+               log.trace("Not recognised: " + file.getName());
+            else
+               log.trace("Recognised: " + file.getName());
+         }
+         return result;
       }
-      return result;
+      finally
+      {
+         SecurityActions.resetContextClassLoader(previous);
+      }
    }
    
    public int getRelativeOrder()

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/BeanDeployerTestSuite.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -21,6 +21,7 @@
 */
 package org.jboss.test.deployers.vfs.deployer.bean;
 
+import org.jboss.test.deployers.vfs.deployer.bean.test.BeanDeployerClassLoaderUnitTestCase;
 import org.jboss.test.deployers.vfs.deployer.bean.test.BeanDeployerUnitTestCase;
 import org.jboss.test.deployers.vfs.deployer.bean.test.KernelDeployerUnitTestCase;
 import org.jboss.test.deployers.vfs.deployer.bean.test.AliasDeployerUnitTestCase;
@@ -49,6 +50,7 @@
       suite.addTest(BeanDeployerUnitTestCase.suite());
       suite.addTest(KernelDeployerUnitTestCase.suite());
       suite.addTest(AliasDeployerUnitTestCase.suite());
+      suite.addTest(BeanDeployerClassLoaderUnitTestCase.suite());
 
       return suite;
    }

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/Simple.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/Simple.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/Simple.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -21,6 +21,8 @@
 */
 package org.jboss.test.deployers.vfs.deployer.bean.support;
 
+import org.jboss.test.AbstractTestCaseWithSetup;
+
 /**
  * Simple.
  * 
@@ -29,4 +31,25 @@
  */
 public class Simple
 {
+   private static ClassLoader classLoader;
+ 
+   public static ClassLoader getAndResetClassLoader()
+   {
+      ClassLoader result = classLoader;
+      classLoader = null;
+      return result;
+   }
+   
+   public Simple()
+   {
+      SecurityManager sm = AbstractTestCaseWithSetup.suspendSecurity();
+      try
+      {
+         classLoader = Thread.currentThread().getContextClassLoader();
+      }
+      finally
+      {
+         AbstractTestCaseWithSetup.resumeSecurity(sm);
+      }
+   }
 }

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoader.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoader.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoader.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.test.deployers.vfs.deployer.bean.support;
+
+/**
+ * TestClassLoader.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestClassLoader extends ClassLoader
+{
+   public TestClassLoader()
+   {
+      super(TestClassLoader.class.getClassLoader());
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoaderDeployer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/support/TestClassLoaderDeployer.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.test.deployers.vfs.deployer.bean.support;
+
+import org.jboss.deployers.spi.deployer.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+
+/**
+ * TestClassLoaderDeployer.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestClassLoaderDeployer extends AbstractTopLevelClassLoaderDeployer
+{
+   protected ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception
+   {
+      return new TestClassLoader();
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerClassLoaderUnitTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/deployer/bean/test/BeanDeployerClassLoaderUnitTestCase.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,81 @@
+/*
+* 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.test.deployers.vfs.deployer.bean.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.deployer.kernel.BeanDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer;
+import org.jboss.deployers.vfs.deployer.kernel.KernelDeploymentDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.kernel.Kernel;
+import org.jboss.test.deployers.vfs.deployer.bean.support.Simple;
+import org.jboss.test.deployers.vfs.deployer.bean.support.TestClassLoaderDeployer;
+
+/**
+ * BeanDeployerUnitTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanDeployerClassLoaderUnitTestCase extends AbstractDeployerUnitTestCase
+{
+   public static Test suite()
+   {
+      return new TestSuite(BeanDeployerClassLoaderUnitTestCase.class);
+   }
+
+   public BeanDeployerClassLoaderUnitTestCase(String name) throws Throwable
+   {
+      super(name);
+   }
+
+   protected void addDeployers(Kernel kernel)
+   {
+      BeanDeployer beanDeployer = new BeanDeployer();
+      TestClassLoaderDeployer classLoaderDeployer = new TestClassLoaderDeployer();
+      KernelDeploymentDeployer kernelDeploymentDeployer = new KernelDeploymentDeployer();
+      BeanMetaDataDeployer beanMetaDataDeployer = new BeanMetaDataDeployer(kernel);
+      addDeployer(main, beanDeployer);
+      addDeployer(main, classLoaderDeployer);
+      addDeployer(main, kernelDeploymentDeployer);
+      addDeployer(main, beanMetaDataDeployer);
+   }
+
+   public void testClassLoader() throws Exception
+   {
+      VFSDeployment context = createDeployment("/bean", "toplevel/my-beans.xml");
+      assertDeploy(context);
+      try
+      {
+         assertNotNull(controller.getInstalledContext("Test"));
+         DeploymentUnit unit = assertDeploymentUnit(main, context.getName());
+         assertEquals(unit.getClassLoader(), Simple.getAndResetClassLoader());
+      }
+      finally
+      {
+         assertUndeploy(context);
+      }
+   }
+}

Deleted: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/TerminateStructureTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/TerminateStructureTestCase.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/TerminateStructureTestCase.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -1,148 +0,0 @@
-/*
-* 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.test.deployers.vfs.structure;
-
-import junit.framework.Test;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.structure.StructureMetaData;
-import org.jboss.deployers.vfs.spi.client.VFSDeployment;
-import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
-import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
-import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * Terminate test case.
- *
- * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
- */
-public class TerminateStructureTestCase extends AbstractStructureTest
-{
-   public TerminateStructureTestCase(String name)
-   {
-      super(name);
-   }
-
-   public static Test suite()
-   {
-      return suite(TerminateStructureTestCase.class);
-   }
-
-   protected StructureDeployer[] getStructureDeployers(int failNumber, int size, boolean checkCause)
-   {
-      StructureDeployer[] deployers = new StructureDeployer[size];
-      for(int i = 0; i < size; i++)
-      {
-         if (i == failNumber)
-         {
-            if (checkCause)
-               deployers[i] = new REStructureDeployer(i);
-            else
-               deployers[i] = new FailStructureDeployer(i);
-         }
-         else
-            deployers[i] = new PassStructureDeployer(i);
-      }
-      return deployers;
-   }
-
-   protected void checkFailedNumber(VFSDeployment deployment, int failNumber, int size, boolean checkCause)
-         throws Exception
-   {
-      try
-      {
-         determineStructureWithStructureDeployers(deployment, getStructureDeployers(failNumber, size, checkCause));
-         fail("Should not be here.");
-      }
-      catch (Throwable t)
-      {
-         if (checkCause)
-            t = t.getCause();
-         String msg = t.getMessage();
-         int number = Integer.parseInt(msg);
-         assertEquals(failNumber, number);
-      }
-   }
-
-   public void testTerminate() throws Exception
-   {
-      // some deployment
-      VFSDeployment deployment = createDeployment("/structure/file", "simple");
-      checkFailedNumber(deployment, 0, 3, false);
-      checkFailedNumber(deployment, 1, 3, false);
-      checkFailedNumber(deployment, 2, 3, false);
-   }
-
-   public void testRuntimeTerminate() throws Exception
-   {
-      // some deployment
-      VFSDeployment deployment = createDeployment("/structure/file", "simple");
-      checkFailedNumber(deployment, 0, 3, true);
-      checkFailedNumber(deployment, 1, 3, true);
-      checkFailedNumber(deployment, 2, 3, true);
-   }
-
-   protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
-   {
-      throw new UnsupportedOperationException("No use case.");
-   }
-
-   private class PassStructureDeployer extends AbstractStructureDeployer
-   {
-      public PassStructureDeployer(int order)
-      {
-         setRelativeOrder(order);
-      }
-
-      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
-      {
-         return false;
-      }
-   }
-
-   private class FailStructureDeployer extends AbstractStructureDeployer
-   {
-      public FailStructureDeployer(int order)
-      {
-         setRelativeOrder(order);
-      }
-
-      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
-      {
-         throw new DeploymentException(String.valueOf(getRelativeOrder()));
-      }
-   }
-
-   private class REStructureDeployer extends AbstractStructureDeployer
-   {
-      public REStructureDeployer(int order)
-      {
-         setRelativeOrder(order);
-      }
-
-      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
-      {
-         throw new RuntimeException(String.valueOf(getRelativeOrder()));
-      }
-   }
-}

Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java	2008-01-25 00:28:59 UTC (rev 69332)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/VFSStructureTestSuite.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -34,6 +34,8 @@
 import org.jboss.test.deployers.vfs.structure.jar.test.CombinedJARStructureUnitTestCase;
 import org.jboss.test.deployers.vfs.structure.jar.test.ConfiguredSuffixJARStructureUnitTestCase;
 import org.jboss.test.deployers.vfs.structure.jar.test.JARStructureUnitTestCase;
+import org.jboss.test.deployers.vfs.structure.test.StructureDeployerContextClassLoaderTestCase;
+import org.jboss.test.deployers.vfs.structure.test.TerminateStructureTestCase;
 import org.jboss.test.deployers.vfs.structure.war.test.CombinedWARStructureUnitTestCase;
 import org.jboss.test.deployers.vfs.structure.war.test.WARStructureUnitTestCase;
 
@@ -66,6 +68,7 @@
       suite.addTest(CombinedWARStructureUnitTestCase.suite());
       suite.addTest(CombinedFileStructureUnitTestCase.suite());
       suite.addTest(TerminateStructureTestCase.suite());
+      suite.addTest(StructureDeployerContextClassLoaderTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoader.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoader.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoader.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2007, 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.test.deployers.vfs.structure.support;
+
+/**
+ * TestDummyClassLoader.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDummyClassLoader extends ClassLoader
+{
+   public TestDummyClassLoader()
+   {
+      super(TestDummyClassLoader.class.getClassLoader());
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoaderStructureDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoaderStructureDeployer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/support/TestDummyClassLoaderStructureDeployer.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,63 @@
+/*
+* 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.test.deployers.vfs.structure.support;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
+import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * TestDummyClassLoaderStructureDeployer.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDummyClassLoaderStructureDeployer extends AbstractStructureDeployer
+{
+   private static ClassLoader classLoader;
+
+   public static ClassLoader getAndResetClassLoader()
+   {
+      ClassLoader result = classLoader;
+      classLoader = null;
+      return result;
+   }
+
+   protected static void checkClassLoader()
+   {
+      classLoader = Thread.currentThread().getContextClassLoader();
+   }
+
+   public TestDummyClassLoaderStructureDeployer()
+   {
+      setRelativeOrder(-1);
+   }
+   
+   public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file,
+         StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+   {
+      checkClassLoader();
+      return false;
+   }
+}

Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/StructureDeployerContextClassLoaderTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/StructureDeployerContextClassLoaderTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/StructureDeployerContextClassLoaderTestCase.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,84 @@
+/*
+* 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.test.deployers.vfs.structure.test;
+
+import junit.framework.Test;
+
+import org.jboss.deployers.vfs.plugins.structure.VFSStructuralDeployersImpl;
+import org.jboss.deployers.vfs.plugins.structure.VFSStructureBuilder;
+import org.jboss.deployers.vfs.plugins.structure.file.FileStructure;
+import org.jboss.deployers.vfs.plugins.structure.jar.JARStructure;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.test.deployers.vfs.structure.AbstractStructureTest;
+import org.jboss.test.deployers.vfs.structure.support.TestDummyClassLoader;
+import org.jboss.test.deployers.vfs.structure.support.TestDummyClassLoaderStructureDeployer;
+
+/**
+ * StructureDeployerContextClassLoaderTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class StructureDeployerContextClassLoaderTestCase extends AbstractStructureTest
+{
+   public StructureDeployerContextClassLoaderTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(StructureDeployerContextClassLoaderTestCase.class);
+   }
+
+   public void testContextClassLoader() throws Exception
+   {
+      TestDummyClassLoader dummy = new TestDummyClassLoader();
+      VFSStructuralDeployersImpl structuralDeployers = new VFSStructuralDeployersImpl();
+      VFSStructureBuilder builder = new VFSStructureBuilder();
+      structuralDeployers.setStructureBuilder(builder);
+      structuralDeployers.addDeployer(new JARStructure());
+      structuralDeployers.addDeployer(new FileStructure());
+
+      ClassLoader previous = Thread.currentThread().getContextClassLoader();
+      Thread.currentThread().setContextClassLoader(dummy);
+      try
+      {
+         TestDummyClassLoaderStructureDeployer deployer = new TestDummyClassLoaderStructureDeployer();
+         structuralDeployers.addDeployer(deployer);
+      }
+      finally
+      {
+         Thread.currentThread().setContextClassLoader(previous);
+      }
+
+      VFSDeployment deployment = createDeployment("/structure/file", "simple");
+      structuralDeployers.determineStructure(deployment);
+      assertEquals(dummy, TestDummyClassLoaderStructureDeployer.getAndResetClassLoader());
+   }
+
+   protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
+   {
+      throw new UnsupportedOperationException("not used");
+   }
+}

Copied: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/TerminateStructureTestCase.java (from rev 69204, projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/TerminateStructureTestCase.java)
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/TerminateStructureTestCase.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/structure/test/TerminateStructureTestCase.java	2008-01-25 00:29:58 UTC (rev 69333)
@@ -0,0 +1,149 @@
+/*
+* 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.test.deployers.vfs.structure.test;
+
+import junit.framework.Test;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.structure.StructureMetaData;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.structure.StructureDeployer;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.deployers.vfs.spi.structure.VFSStructuralDeployers;
+import org.jboss.deployers.vfs.spi.structure.helpers.AbstractStructureDeployer;
+import org.jboss.test.deployers.vfs.structure.AbstractStructureTest;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * Terminate test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TerminateStructureTestCase extends AbstractStructureTest
+{
+   public TerminateStructureTestCase(String name)
+   {
+      super(name);
+   }
+
+   public static Test suite()
+   {
+      return suite(TerminateStructureTestCase.class);
+   }
+
+   protected StructureDeployer[] getStructureDeployers(int failNumber, int size, boolean checkCause)
+   {
+      StructureDeployer[] deployers = new StructureDeployer[size];
+      for(int i = 0; i < size; i++)
+      {
+         if (i == failNumber)
+         {
+            if (checkCause)
+               deployers[i] = new REStructureDeployer(i);
+            else
+               deployers[i] = new FailStructureDeployer(i);
+         }
+         else
+            deployers[i] = new PassStructureDeployer(i);
+      }
+      return deployers;
+   }
+
+   protected void checkFailedNumber(VFSDeployment deployment, int failNumber, int size, boolean checkCause)
+         throws Exception
+   {
+      try
+      {
+         determineStructureWithStructureDeployers(deployment, getStructureDeployers(failNumber, size, checkCause));
+         fail("Should not be here.");
+      }
+      catch (Throwable t)
+      {
+         if (checkCause)
+            t = t.getCause();
+         String msg = t.getMessage();
+         int number = Integer.parseInt(msg);
+         assertEquals(failNumber, number);
+      }
+   }
+
+   public void testTerminate() throws Exception
+   {
+      // some deployment
+      VFSDeployment deployment = createDeployment("/structure/file", "simple");
+      checkFailedNumber(deployment, 0, 3, false);
+      checkFailedNumber(deployment, 1, 3, false);
+      checkFailedNumber(deployment, 2, 3, false);
+   }
+
+   public void testRuntimeTerminate() throws Exception
+   {
+      // some deployment
+      VFSDeployment deployment = createDeployment("/structure/file", "simple");
+      checkFailedNumber(deployment, 0, 3, true);
+      checkFailedNumber(deployment, 1, 3, true);
+      checkFailedNumber(deployment, 2, 3, true);
+   }
+
+   protected VFSDeploymentContext determineStructure(VFSDeployment deployment) throws Exception
+   {
+      throw new UnsupportedOperationException("No use case.");
+   }
+
+   private class PassStructureDeployer extends AbstractStructureDeployer
+   {
+      public PassStructureDeployer(int order)
+      {
+         setRelativeOrder(order);
+      }
+
+      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+      {
+         return false;
+      }
+   }
+
+   private class FailStructureDeployer extends AbstractStructureDeployer
+   {
+      public FailStructureDeployer(int order)
+      {
+         setRelativeOrder(order);
+      }
+
+      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+      {
+         throw new DeploymentException(String.valueOf(getRelativeOrder()));
+      }
+   }
+
+   private class REStructureDeployer extends AbstractStructureDeployer
+   {
+      public REStructureDeployer(int order)
+      {
+         setRelativeOrder(order);
+      }
+
+      public boolean determineStructure(VirtualFile root, VirtualFile parent, VirtualFile file, StructureMetaData metaData, VFSStructuralDeployers deployers) throws DeploymentException
+      {
+         throw new RuntimeException(String.valueOf(getRelativeOrder()));
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list