[Jboss-cvs] JBossAS SVN: r56804 - 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 main/org/jboss/deployers/spi/classloader main/org/jboss/deployers/spi/deployer main/org/jboss/deployers/spi/structure tests/org/jboss/test/deployers/deployer tests/org/jboss/test/deployers/deployer/support tests/org/jboss/test/deployers/deployer/test
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Sep 13 13:10:11 EDT 2006
Author: adrian at jboss.org
Date: 2006-09-13 13:09:56 -0400 (Wed, 13 Sep 2006)
New Revision: 56804
Added:
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTopLevelClassLoaderDeployer.java
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/
projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/ClassLoaderFactory.java
projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java
projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.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/DeployerTestSuite.java
Log:
[JBMICROCONT-5] - Additional support for classloading deployers.
They need to have access to the deployment context.
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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployer/AbstractDeploymentUnit.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -27,7 +27,9 @@
import java.util.Map;
import org.jboss.deployers.plugins.attachments.AbstractAttachments;
+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.deployer.DeploymentUnit;
import org.jboss.deployers.spi.structure.DeploymentContext;
import org.jboss.virtual.VirtualFile;
@@ -45,7 +47,7 @@
{
/** The deployment context */
private DeploymentContext deploymentContext;
-
+
/**
* Create a new AbstractDeploymentUnit.
*
@@ -71,6 +73,11 @@
return cl;
}
+ public boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException
+ {
+ return deploymentContext.createClassLoader(factory);
+ }
+
public VirtualFile getMetaDataFile(String name)
{
return deploymentContext.getMetaDataFile(name);
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java 2006-09-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractClassLoaderDeployer.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -0,0 +1,50 @@
+/*
+* 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 org.jboss.deployers.plugins.deployer.AbstractSimpleDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
+import org.jboss.deployers.spi.deployer.DeploymentUnit;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+
+/**
+ * AbstractClassLoaderDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractClassLoaderDeployer extends AbstractSimpleDeployer implements ClassLoaderFactory
+{
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ unit.createClassLoader(this);
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ }
+
+ public void removeClassLoader(DeploymentContext context) throws Exception
+ {
+ }
+}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTopLevelClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTopLevelClassLoaderDeployer.java 2006-09-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployers/helpers/AbstractTopLevelClassLoaderDeployer.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -0,0 +1,66 @@
+/*
+* 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 org.jboss.deployers.spi.structure.DeploymentContext;
+
+/**
+ * AbstractTopLevelClassLoaderDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractTopLevelClassLoaderDeployer extends AbstractClassLoaderDeployer
+{
+ public ClassLoader createClassLoader(DeploymentContext context) throws Exception
+ {
+ if (context.isTopLevel())
+ return createTopLevelClassLoader(context);
+
+ return context.getTopLevel().getClassLoader();
+ }
+
+ public void removeClassLoader(DeploymentContext context) throws Exception
+ {
+ if (context.isTopLevel())
+ removeTopLevelClassLoader(context);
+ }
+
+ /**
+ * Create a top level classloader
+ *
+ * @param context the context
+ * @return the classloader
+ * @throws Exception for any error
+ */
+ public abstract ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception;
+
+ /**
+ * Remove a top level classloader
+ *
+ * @param context the context
+ * @throws Exception for any error
+ */
+ public void removeTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ }
+}
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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/deployment/MainDeployerImpl.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -30,13 +30,15 @@
import static org.jboss.deployers.spi.structure.StructureDetermined.PREDETERMINED;
import static org.jboss.deployers.spi.structure.StructureDetermined.YES;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.SortedSet;
import java.util.TreeSet;
import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CopyOnWriteArraySet;
+import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicBoolean;
import org.jboss.deployers.plugins.deployer.AbstractDeploymentUnit;
@@ -79,10 +81,10 @@
private Map<String, DeploymentContext> allDeployments = new ConcurrentHashMap<String, DeploymentContext>();
/** The undeploy work */
- private Set<DeploymentContext> undeploy = new CopyOnWriteArraySet<DeploymentContext>();
+ private List<DeploymentContext> undeploy = new CopyOnWriteArrayList<DeploymentContext>();
/** The deploy work */
- private Set<DeploymentContext> deploy = new CopyOnWriteArraySet<DeploymentContext>();
+ private List<DeploymentContext> deploy = new CopyOnWriteArrayList<DeploymentContext>();
/**
* Get the structure deployers
@@ -91,7 +93,7 @@
*/
public synchronized Set<StructureDeployer> getStructureDeployers()
{
- return new HashSet<StructureDeployer>(structureDeployers);
+ return new TreeSet<StructureDeployer>(structureDeployers);
}
/**
@@ -154,7 +156,7 @@
*/
public synchronized Set<Deployer> getDeployers()
{
- return new HashSet<Deployer>(deployers);
+ return new TreeSet<Deployer>(deployers);
}
/**
@@ -288,8 +290,8 @@
if (shutdown.get())
throw new IllegalStateException("The main deployer is shutdown");
- Set<DeploymentContext> undeployContexts = null;
- Set<DeploymentContext> deployContexts = null;
+ List<DeploymentContext> undeployContexts = null;
+ List<DeploymentContext> deployContexts = null;
Deployer[] theDeployers;
synchronized (this)
{
@@ -297,12 +299,15 @@
throw new IllegalStateException("No deployers");
if (undeploy.isEmpty() == false)
{
- undeployContexts = new HashSet<DeploymentContext>(undeploy);
+ // Undeploy in reverse order (subdeployments first)
+ undeployContexts = new ArrayList<DeploymentContext>(undeploy.size());
+ for (int i = undeploy.size() -1; i >= 0; --i)
+ undeployContexts.add(undeploy.get(i));
undeploy.clear();
}
if (deploy.isEmpty() == false)
{
- deployContexts = new HashSet<DeploymentContext>(deploy);
+ deployContexts = new ArrayList<DeploymentContext>(deploy);
deploy.clear();
}
theDeployers = deployers.toArray(new Deployer[deployers.size()]);
@@ -318,6 +323,9 @@
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)
{
@@ -351,6 +359,7 @@
Deployer other = theDeployers[j];
other.prepareUndeploy(unit);
}
+ context.removeClassLoader();
}
}
deployContexts.removeAll(errors);
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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/plugins/structure/AbstractDeploymentContext.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -29,7 +29,9 @@
import java.util.concurrent.CopyOnWriteArraySet;
import org.jboss.deployers.plugins.attachments.AttachmentsImpl;
+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.deployer.DeploymentUnit;
import org.jboss.deployers.spi.structure.DeploymentContext;
import org.jboss.deployers.spi.structure.DeploymentState;
@@ -60,6 +62,7 @@
/** The deployment unit */
private DeploymentUnit unit;
+
/** The root */
private VirtualFile root;
@@ -72,6 +75,9 @@
/** The class loader */
private ClassLoader classLoader;
+ /** The class loader factory for this deployment */
+ private ClassLoaderFactory classLoaderFactory;
+
/** Whether this is a candidate deployment */
private boolean candidate = false;
@@ -302,9 +308,50 @@
{
this.classLoader = classLoader;
if (classLoader != null)
- log.trace("ClassLoader for " + root.getPathName() + " is " + classLoader);
+ log.trace("ClassLoader for " + name + " is " + classLoader);
}
+ public boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException
+ {
+ if (factory == null)
+ throw new IllegalArgumentException("Null factory");
+
+ ClassLoader cl = getClassLoader();
+ if (cl != null)
+ return false;
+
+ try
+ {
+ cl = factory.createClassLoader(this);
+ if (cl != null)
+ {
+ setClassLoader(cl);
+ this.classLoaderFactory = factory;
+ }
+ }
+ catch (Throwable t)
+ {
+ throw DeploymentException.rethrowAsDeploymentException("Error creating classloader for " + getName(), t);
+ }
+ return true;
+ }
+
+ public void removeClassLoader()
+ {
+ if (classLoaderFactory == null)
+ return;
+ try
+ {
+ classLoaderFactory.removeClassLoader(this);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Error removing classloader for " + getName(), t);
+ }
+ setClassLoader(null);
+ }
+
+
public List<VirtualFile> getClassPath()
{
return classPath;
@@ -322,6 +369,18 @@
return parent == null;
}
+ public DeploymentContext getTopLevel()
+ {
+ DeploymentContext result = this;
+ DeploymentContext parent = getParent();
+ while (parent != null)
+ {
+ result = parent;
+ parent = parent.getParent();
+ }
+ return result;
+ }
+
public DeploymentContext getParent()
{
return parent;
@@ -451,6 +510,7 @@
child.reset();
}
+ classLoader = null;
transientManagedObjects.clear();
transientAttachments.clear();
}
Added: projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/ClassLoaderFactory.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/ClassLoaderFactory.java 2006-09-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/classloader/ClassLoaderFactory.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -0,0 +1,50 @@
+/*
+* 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.classloader;
+
+import org.jboss.deployers.spi.structure.DeploymentContext;
+
+/**
+ * ClassLoaderFactory.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public interface ClassLoaderFactory
+{
+ /**
+ * Create a classloader for this deployment
+ *
+ * @param context the deployment context
+ * @return classloader or null if not created
+ * @throws Exception for any error
+ */
+ ClassLoader createClassLoader(DeploymentContext context) throws Exception;
+
+ /**
+ * Remove a classloader for this deployment
+ *
+ * @param context the deployment context
+ * @throws Exception for any error
+ */
+ void removeClassLoader(DeploymentContext context) throws Exception;
+}
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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/deployer/DeploymentUnit.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -23,7 +23,9 @@
import java.util.List;
+import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
import org.jboss.virtual.VirtualFile;
/**
@@ -71,6 +73,16 @@
ClassLoader getClassLoader();
/**
+ * Create the classloader
+ *
+ * @param factory the classloader factory
+ * @return false if the classloader already exists
+ * @throws IllegalArgumentException for a null factory
+ * @throws DeploymentException for any error
+ */
+ boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException;
+
+ /**
* Get the managed objects
*
* @return the managed objects
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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/main/org/jboss/deployers/spi/structure/DeploymentContext.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -24,7 +24,9 @@
import java.util.List;
import java.util.Set;
+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.deployer.DeploymentUnit;
import org.jboss.virtual.VirtualFile;
@@ -152,8 +154,22 @@
* @param classLoader the new classloader
*/
void setClassLoader(ClassLoader classLoader);
-
+
/**
+ * Create a classloader
+ *
+ * @param factory the factory
+ * @return false if there is already is a classloader
+ * @throws DeploymentException for any error
+ */
+ boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException;
+
+ /**
+ * Remove the classloader created by the factory
+ */
+ void removeClassLoader();
+
+ /**
* Get the class path
*
* @return the class path
@@ -175,6 +191,13 @@
boolean isTopLevel();
/**
+ * Get the top level deployment
+ *
+ * @return the top level deployment
+ */
+ DeploymentContext getTopLevel();
+
+ /**
* The parent
*
* @return the parent
Modified: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/DeployerTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/DeployerTestSuite.java 2006-09-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/DeployerTestSuite.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -27,6 +27,7 @@
import org.jboss.test.deployers.bean.test.BeanDeployerUnitTestCase;
import org.jboss.test.deployers.bean.test.KernelDeployerUnitTestCase;
+import org.jboss.test.deployers.deployer.test.DeployerClassLoaderUnitTestCase;
import org.jboss.test.deployers.deployer.test.DeployerOrderingUnitTestCase;
import org.jboss.test.deployers.deployer.test.DeployerProtocolUnitTestCase;
import org.jboss.test.deployers.deployer.test.DeployerWidthFirstUnitTestCase;
@@ -53,6 +54,7 @@
suite.addTest(DeployerProtocolUnitTestCase.suite());
suite.addTest(DeployerOrderingUnitTestCase.suite());
suite.addTest(DeployerWidthFirstUnitTestCase.suite());
+ suite.addTest(DeployerClassLoaderUnitTestCase.suite());
suite.addTest(MainDeployerDeployerUnitTestCase.suite());
suite.addTest(MetaDataUnitTestCase.suite());
suite.addTest(BeanDeployerUnitTestCase.suite());
Added: projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java 2006-09-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/support/TestClassLoaderDeployer.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -0,0 +1,52 @@
+/*
+* 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.deployer.support;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import org.jboss.deployers.plugins.deployers.helpers.AbstractTopLevelClassLoaderDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.classloader.ClassLoaderFactory;
+import org.jboss.deployers.spi.structure.DeploymentContext;
+
+/**
+ * TestDeployerOrdering.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestClassLoaderDeployer extends AbstractTopLevelClassLoaderDeployer implements ClassLoaderFactory
+{
+ public ClassLoader cl = new URLClassLoader(new URL[0]);
+
+ public ClassLoader createTopLevelClassLoader(DeploymentContext context) throws DeploymentException
+ {
+ log.debug("Created classloader: " + context.getName());
+ return cl;
+ }
+
+ public void removeTopLevelClassLoader(DeploymentContext context) throws Exception
+ {
+ log.debug("Removed classloader: " + context.getName());
+ }
+}
Added: 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-13 17:10:01 UTC (rev 56803)
+++ projects/microcontainer/trunk/deployers/src/tests/org/jboss/test/deployers/deployer/test/DeployerClassLoaderUnitTestCase.java 2006-09-13 17:09:56 UTC (rev 56804)
@@ -0,0 +1,92 @@
+/*
+* 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.deployer.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.plugins.deployment.MainDeployerImpl;
+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;
+
+/**
+ * DeployerClassLoaderUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeployerClassLoaderUnitTestCase extends BaseDeployersTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(DeployerClassLoaderUnitTestCase.class);
+ }
+
+ public DeployerClassLoaderUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testClassLoader() throws Exception
+ {
+ MainDeployerImpl main = new MainDeployerImpl();
+ TestClassLoaderDeployer deployer = new TestClassLoaderDeployer();
+ main.addDeployer(deployer);
+
+ DeploymentContext context = createSimpleDeployment("Single");
+ main.addDeploymentContext(context);
+ main.process();
+ assertEquals(DeploymentState.DEPLOYED, context.getState());
+ assertEquals(deployer.cl, context.getClassLoader());
+
+ main.removeDeploymentContext(context.getName());
+ main.process();
+ assertEquals(DeploymentState.UNDEPLOYED, context.getState());
+ assertNull(context.getClassLoader());
+ }
+
+ public void testSubdeploymentClassLoader() throws Exception
+ {
+ MainDeployerImpl main = new MainDeployerImpl();
+ TestClassLoaderDeployer deployer = new TestClassLoaderDeployer();
+ main.addDeployer(deployer);
+
+ DeploymentContext top = createSimpleDeployment("Top");
+ DeploymentContext sub = createSimpleDeployment("Sub");
+ top.addChild(sub);
+ main.addDeploymentContext(top);
+ main.process();
+ assertEquals(DeploymentState.DEPLOYED, top.getState());
+ assertEquals(deployer.cl, top.getClassLoader());
+ assertEquals(DeploymentState.DEPLOYED, sub.getState());
+ assertEquals(deployer.cl, sub.getClassLoader());
+
+ main.removeDeploymentContext(top.getName());
+ main.process();
+ assertEquals(DeploymentState.UNDEPLOYED, top.getState());
+ assertNull(top.getClassLoader());
+ assertEquals(DeploymentState.UNDEPLOYED, sub.getState());
+ assertNull(sub.getClassLoader());
+ }
+}
More information about the jboss-cvs-commits
mailing list