[jboss-cvs] JBossAS SVN: r69935 - in projects/microcontainer/trunk: deployers-impl/src/main/org/jboss/deployers/plugins/classloading and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 19 10:54:00 EST 2008
Author: adrian at jboss.org
Date: 2008-02-19 10:54:00 -0500 (Tue, 19 Feb 2008)
New Revision: 69935
Added:
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractDeploymentClassLoaderPolicyModule.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockClassLoaderDescribeDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockDeploymentClassLoaderPolicyModule.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderDescribeDeployer.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/TestTopLevelClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/a/
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/a/A.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/b/
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/b/B.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesTest.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesUnitTestCase.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSUndeployOrderClassLoaderUnitTestCase.java
Removed:
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/
projects/microcontainer/trunk/deployers-structure-spi/src/tests/org/jboss/test/deployers/structure/version/
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/PackageVisitor.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderPolicy.java
projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSTopLevelClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ExportAllUnitTestCase.java
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/FilteredExportUnitTestCase.java
Modified:
projects/microcontainer/trunk/deployers-impl/.classpath
projects/microcontainer/trunk/deployers-impl/pom.xml
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDescribeDeployer.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockTopLevelClassLoaderSystemDeployer.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/ClassLoaderDependenciesTest.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/UndeployOrderClassLoaderUnitTestCase.java
projects/microcontainer/trunk/deployers-structure-spi/src/tests/org/jboss/test/deployers/DeployersStructureTestSuite.java
projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/ClassPathVisitor.java
projects/microcontainer/trunk/deployers-vfs/.classpath
projects/microcontainer/trunk/deployers-vfs/pom.xml
projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java
Log:
[JBMICROCONT-241] - Integrate new classloading spi into the deployers
Modified: projects/microcontainer/trunk/deployers-impl/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers-impl/.classpath 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/.classpath 2008-02-19 15:54:00 UTC (rev 69935)
@@ -21,6 +21,7 @@
<classpathentry kind="var" path="M2_REPO/qdox/qdox/1.6/qdox-1.6.jar" sourcepath="M2_REPO/qdox/qdox/1.6/qdox-1.6-sources.jar"/>
<classpathentry kind="var" path="M2_REPO/trove/trove/2.1.1/trove-2.1.1.jar"/>
<classpathentry kind="src" path="/jboss-classloader"/>
+ <classpathentry kind="src" path="/jboss-classloading"/>
<classpathentry kind="src" path="/jboss-container"/>
<classpathentry kind="var" path="M2_REPO/apache-xerces/xercesImpl/2.7.1/xercesImpl-2.7.1.jar"/>
<classpathentry kind="var" path="M2_REPO/javax/xml/bind/jaxb-api/2.0/jaxb-api-2.0.jar"/>
@@ -36,5 +37,5 @@
<classpathentry kind="src" path="/jboss-deployers-core"/>
<classpathentry kind="src" path="/jboss-deployers-spi"/>
<classpathentry kind="src" path="/jboss-deployers-structure-spi"/>
- <classpathentry kind="src" path="/jboss-kernel"/>
+ <classpathentry kind="src" path="/jboss-kernel"/>
</classpath>
\ No newline at end of file
Modified: projects/microcontainer/trunk/deployers-impl/pom.xml
===================================================================
--- projects/microcontainer/trunk/deployers-impl/pom.xml 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/pom.xml 2008-02-19 15:54:00 UTC (rev 69935)
@@ -50,6 +50,10 @@
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-container</artifactId>
</dependency>
<dependency>
Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDescribeDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDescribeDeployer.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDescribeDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -21,11 +21,14 @@
*/
package org.jboss.deployers.plugins.classloading;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.deployer.DeploymentStages;
import org.jboss.deployers.spi.deployer.helpers.AbstractOptionalRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
/**
* AbstractClassLoaderDescribeDeployer.
@@ -33,7 +36,7 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class AbstractClassLoaderDescribeDeployer extends AbstractOptionalRealDeployer<ClassLoaderMetaData>
+public abstract class AbstractClassLoaderDescribeDeployer extends AbstractOptionalRealDeployer<ClassLoadingMetaData>
{
/** The classloading */
private ClassLoading classLoading;
@@ -43,7 +46,7 @@
*/
public AbstractClassLoaderDescribeDeployer()
{
- super(ClassLoaderMetaData.class);
+ super(ClassLoadingMetaData.class);
setStage(DeploymentStages.DESCRIBE);
}
@@ -78,13 +81,28 @@
throw new DeploymentException("Classloading has not been configured");
}
- public void deploy(DeploymentUnit unit, ClassLoaderMetaData deployment) throws DeploymentException
+ public void deploy(DeploymentUnit unit, ClassLoadingMetaData deployment) throws DeploymentException
{
- classLoading.addDeploymentUnit(unit);
+ if (unit.isTopLevel() == false)
+ return;
+ ClassLoaderPolicyModule module = createModule(unit, deployment);
+ if (module != null)
+ {
+ classLoading.addModule(module);
+ unit.addAttachment(Module.class, module);
+ }
}
- public void undeploy(DeploymentUnit unit, ClassLoaderMetaData deployment)
+ public void undeploy(DeploymentUnit unit, ClassLoadingMetaData deployment)
{
- classLoading.removeDeploymentUnit(unit);
+ if (unit.isTopLevel() == false)
+ return;
+
+ Module module = unit.removeAttachment(Module.class);
+ if (module == null)
+ return;
+ classLoading.removeModule(module);
}
+
+ protected abstract ClassLoaderPolicyModule createModule(DeploymentUnit unit, ClassLoadingMetaData metaData) throws DeploymentException;
}
Deleted: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderSystemDeployer.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderSystemDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,248 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.classloading;
-
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-
-import org.jboss.classloader.spi.ClassLoaderDomain;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.ParentPolicy;
-import org.jboss.classloading.spi.RealClassLoader;
-import org.jboss.deployers.spi.deployer.helpers.AbstractClassLoaderDeployer;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-
-/**
- * A system class loader deployer.
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public abstract class AbstractClassLoaderSystemDeployer extends AbstractClassLoaderDeployer
-{
- /** The classloading */
- private ClassLoading classLoading;
-
- /** The classloader system */
- private ClassLoaderSystem system;
-
- /** The MBeanServer */
- private MBeanServer mbeanServer;
-
- /**
- * Get the classLoading.
- *
- * @return the classLoading.
- */
- public ClassLoading getClassLoading()
- {
- return classLoading;
- }
-
- /**
- * Set the classLoading.
- *
- * @param classLoading the classLoading.
- */
- public void setClassLoading(ClassLoading classLoading)
- {
- this.classLoading = classLoading;
- }
-
- /**
- * Get the system.
- *
- * @return the system.
- */
- public ClassLoaderSystem getSystem()
- {
- return system;
- }
-
- /**
- * Set the system.
- *
- * @param system the system.
- */
- public void setSystem(ClassLoaderSystem system)
- {
- this.system = system;
- }
-
- /**
- * Get the mbeanServer.
- *
- * @return the mbeanServer.
- */
- public MBeanServer getMbeanServer()
- {
- return mbeanServer;
- }
-
- /**
- * Set the mbeanServer.
- *
- * @param mbeanServer the mbeanServer.
- */
- public void setMbeanServer(MBeanServer mbeanServer)
- {
- this.mbeanServer = mbeanServer;
- }
-
- public ClassLoader createClassLoader(DeploymentContext context) throws Exception
- {
- if (classLoading == null)
- throw new IllegalStateException("The classLoading has not been set");
- if (system == null)
- throw new IllegalStateException("The system has not been set");
-
- Module module = context.getTransientAttachments().getAttachment(Module.class);
- if (module == null)
- throw new IllegalStateException("Deployment Context has no module: " + context);
-
- ClassLoaderPolicy policy = createClassLoaderPolicy(context, module);
-
- ClassLoaderDomain domain;
- synchronized (this)
- {
- String domainName = module.getDomainName();
- domain = system.getDomain(domainName);
- if (domain == null)
- {
- ClassLoaderDomain parent = null;
- String parentDomain = module.getParentDomain();
- if (parentDomain != null)
- parent = system.getDomain(parentDomain);
-
- ParentPolicy parentPolicy = module.getParentPolicy();
-
- domain = system.createAndRegisterDomain(domainName, parentPolicy, parent);
- }
- }
- ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
- try
- {
- registerClassLoaderWithMBeanServer(classLoader);
- }
- catch (Throwable t)
- {
- log.warn("Unable to register classloader with mbeanserver: " + classLoader, t);
- }
- return classLoader;
- }
- @Override
- public void removeClassLoader(DeploymentContext context) throws Exception
- {
- ClassLoader classLoader = context.getClassLoader();
- try
- {
- unregisterClassLoaderFromMBeanServer(classLoader);
- }
- catch (Throwable t)
- {
- log.warn("Unable to unregister classloader from mbeanserver: " + classLoader, t);
- }
-
- try
- {
- // Remove the classloader
- system.unregisterClassLoader(classLoader);
- }
- finally
- {
- // Reset the module to avoid possible memory leaks
- Module module = context.getTransientAttachments().getAttachment(Module.class);
-
- if (module == null)
- throw new IllegalStateException("Deployment Context has no module: " + context);
- cleanup(context, module);
- module.reset();
- }
- }
-
- /**
- * Create a deployment classloader policy
- *
- * @param context the deployment context
- * @param module the module
- * @return the classloader
- * @throws Exception for any error
- */
- protected abstract ClassLoaderPolicy createClassLoaderPolicy(DeploymentContext context, Module module) throws Exception;
-
- /**
- * Hook to perform cleanup on destruction of classloaader
- *
- * @param context the deployment context
- * @param module the module
- * @throws Exception for any error
- */
- protected void cleanup(DeploymentContext context, Module module) throws Exception
- {
- }
-
- /**
- * Register the classloader with the mbeanserver
- *
- * @param classLoader the classloader
- * @throws Exception for any error
- */
- protected void registerClassLoaderWithMBeanServer(ClassLoader classLoader) throws Exception
- {
- if (mbeanServer == null)
- return;
-
- if (classLoader instanceof RealClassLoader == false)
- return;
-
- RealClassLoader jmxClassLoader = (RealClassLoader) classLoader;
- ObjectName name = jmxClassLoader.getObjectName();
- if (mbeanServer.isRegistered(name))
- return;
-
- mbeanServer.registerMBean(classLoader, name);
- }
-
- /**
- * Unregister the classloader from the mbeanserver
- *
- * @param classLoader the classloader
- * @throws Exception for any error
- */
- protected void unregisterClassLoaderFromMBeanServer(ClassLoader classLoader) throws Exception
- {
- if (mbeanServer == null)
- return;
-
- if (classLoader instanceof RealClassLoader == false)
- return;
-
- RealClassLoader jmxClassLoader = (RealClassLoader) classLoader;
- ObjectName name = jmxClassLoader.getObjectName();
- if (mbeanServer.isRegistered(name) == false)
- return;
- mbeanServer.unregisterMBean(name);
- }
-
-}
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractDeploymentClassLoaderPolicyModule.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractDeploymentClassLoaderPolicyModule.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractDeploymentClassLoaderPolicyModule.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,106 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloading;
+
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * AbstractDeploymentClassLoaderPolicyModule.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public abstract class AbstractDeploymentClassLoaderPolicyModule extends ClassLoaderPolicyModule
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The classloader state for deployments */
+ private static ControllerState CLASSLOADER_STATE = new ControllerState(DeploymentStages.CLASSLOADER.getName());
+
+ /** The deployment unit */
+ private DeploymentUnit unit;
+
+ /**
+ * Determine the classloading metadata for the deployment unit
+ *
+ * @param unit the deployment unit
+ * @return the classloading metadata
+ */
+ private static ClassLoadingMetaData determineClassLoadingMetaData(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+ return unit.getAttachment(ClassLoadingMetaData.class);
+ }
+
+ /**
+ * Determine the classloading metadata for the deployment unit
+ *
+ * @param unit the deployment unit
+ * @return the classloading metadata
+ */
+ private static String determineContextName(DeploymentUnit unit)
+ {
+ if (unit == null)
+ throw new IllegalArgumentException("Null unit");
+ ControllerContext context = unit.getAttachment(ControllerContext.class);
+ if (context == null)
+ throw new IllegalStateException("Deployment has no controller context");
+ return (String) context.getName();
+ }
+
+ /**
+ * Create a new AbstractDeploymentClassLoaderPolicyModule.
+ *
+ * @param unit the deployment unit
+ * @throws IllegalArgumentException for a null unit
+ */
+ public AbstractDeploymentClassLoaderPolicyModule(DeploymentUnit unit)
+ {
+ super(determineClassLoadingMetaData(unit), determineContextName(unit));
+ this.unit = unit;
+ ControllerContext context = unit.getAttachment(ControllerContext.class);
+ setControllerContext(context);
+ }
+
+ /**
+ * Get the unit.
+ *
+ * @return the unit.
+ */
+ public DeploymentUnit getDeploymentUnit()
+ {
+ return unit;
+ }
+
+ @Override
+ public ControllerState getClassLoaderState()
+ {
+ return CLASSLOADER_STATE;
+ }
+}
Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -24,11 +24,11 @@
import javax.management.MBeanServer;
import javax.management.ObjectName;
-import org.jboss.classloader.spi.ClassLoaderDomain;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.ParentPolicy;
import org.jboss.classloading.spi.RealClassLoader;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.Module;
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
import org.jboss.deployers.spi.deployer.helpers.AbstractTopLevelClassLoaderDeployer;
import org.jboss.deployers.structure.spi.DeploymentContext;
@@ -108,7 +108,7 @@
{
this.mbeanServer = mbeanServer;
}
-
+
@Override
protected ClassLoader createTopLevelClassLoader(DeploymentContext context) throws Exception
{
@@ -117,30 +117,16 @@
if (system == null)
throw new IllegalStateException("The system has not been set");
+ // No module means no classloader for the deployment, use the deployer's classloader
Module module = context.getTransientAttachments().getAttachment(Module.class);
if (module == null)
- throw new IllegalStateException("Deployment Context has no module: " + context);
+ return null;
- ClassLoaderPolicy policy = createTopLevelClassLoaderPolicy(context, module);
+ if (module instanceof ClassLoaderPolicyModule == false)
+ throw new IllegalStateException("Module is not an instance of " + ClassLoaderPolicyModule.class.getName() + " actual=" + module.getClass().getName());
+ ClassLoaderPolicyModule classLoaderPolicyModule = (ClassLoaderPolicyModule) module;
- ClassLoaderDomain domain;
- synchronized (this)
- {
- String domainName = module.getDomainName();
- domain = system.getDomain(domainName);
- if (domain == null)
- {
- ClassLoaderDomain parent = null;
- String parentDomain = module.getParentDomain();
- if (parentDomain != null)
- parent = system.getDomain(parentDomain);
-
- ParentPolicy parentPolicy = module.getParentPolicy();
-
- domain = system.createAndRegisterDomain(domainName, parentPolicy, parent);
- }
- }
- ClassLoader classLoader = system.registerClassLoaderPolicy(domain, policy);
+ ClassLoader classLoader = classLoaderPolicyModule.registerClassLoaderPolicy(system);
try
{
registerClassLoaderWithMBeanServer(classLoader);
@@ -155,6 +141,11 @@
@Override
protected void removeTopLevelClassLoader(DeploymentContext context) throws Exception
{
+ // No module means no for the deployment classloader
+ Module module = context.getTransientAttachments().getAttachment(Module.class);
+ if (module == null)
+ return;
+
ClassLoader classLoader = context.getClassLoader();
try
{
@@ -172,11 +163,6 @@
}
finally
{
- // Reset the module to avoid possible memory leaks
- Module module = context.getTransientAttachments().getAttachment(Module.class);
-
- if (module == null)
- throw new IllegalStateException("Deployment Context has no module: " + context);
cleanup(context, module);
module.reset();
}
@@ -226,16 +212,6 @@
}
/**
- * Create a top level classloader policy
- *
- * @param context the deployment context
- * @param module the module
- * @return the classloader
- * @throws Exception for any error
- */
- protected abstract ClassLoaderPolicy createTopLevelClassLoaderPolicy(DeploymentContext context, Module module) throws Exception;
-
- /**
* Hook to perform cleanup on destruction of classloaader
*
* @param context the deployment context
Deleted: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,104 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.classloading;
-
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.deployers.structure.spi.classloading.Version;
-
-/**
- * ClassLoading.
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ClassLoading
-{
- /** The classloading domains by name */
- private Map<String, Domain> domains = new ConcurrentHashMap<String, Domain>();
-
- /**
- * Add a deployment unit
- *
- * @param deploymentUnit the deployment unit
- * @throws IllegalArgumentException for a null deployment unit
- */
- public void addDeploymentUnit(DeploymentUnit deploymentUnit)
- {
- if (deploymentUnit == null)
- throw new IllegalArgumentException("Null deployment unit");
-
- ClassLoaderMetaData metadata = deploymentUnit.getAttachment(ClassLoaderMetaData.class);
- if (metadata == null)
- {
- // REVIEW: There should probably be a warning here?
- metadata = new ClassLoaderMetaData();
- metadata.setName(deploymentUnit.getName());
- metadata.setExportAll(ExportAll.NON_EMPTY);
- metadata.setImportAll(true);
- metadata.setVersion(Version.DEFAULT_VERSION);
- deploymentUnit.addAttachment(ClassLoaderMetaData.class, metadata);
- }
-
- String domainName = metadata.getDomain();
- if (domainName == null)
- {
- domainName = ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
- metadata.setDomain(domainName);
- }
-
- Domain domain;
- synchronized (domains)
- {
- domain = domains.get(domainName);
- if (domain == null)
- {
- domain = new Domain(domainName);
- domains.put(domainName, domain);
- }
- }
-
- domain.addDeploymentUnit(deploymentUnit, metadata);
- }
-
- /**
- * Remove a deployment unit
- *
- * @param deploymentUnit the deployment unit
- * @throws IllegalArgumentException for a null deployment context
- */
- public void removeDeploymentUnit(DeploymentUnit deploymentUnit)
- {
- if (deploymentUnit == null)
- throw new IllegalArgumentException("Null deployment context");
-
- Module module = deploymentUnit.getAttachment(Module.class);
- if (module == null)
- throw new IllegalStateException("Deployment Unit has no module: " + deploymentUnit);
- module.release();
- }
-}
Deleted: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,143 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.classloading;
-
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import org.jboss.dependency.spi.Controller;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.Capability;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
-import org.jboss.deployers.structure.spi.classloading.Requirement;
-
-/**
- * Domain.
- *
- * TODO JBMICROCONT-182 - need to include some parent delegation as well
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class Domain
-{
- /** The domain name */
- private String name;
-
- /** The registered deployment units */
- private Map<DeploymentUnit, Module> units = new ConcurrentHashMap<DeploymentUnit, Module>();
-
- /**
- * Create a new Domain.
- *
- * @param name the name
- * @throws IllegalArgumentException for a null domain
- */
- public Domain(String name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
- this.name = name;
- }
-
- /**
- * Get the name.
- *
- * @return the name.
- */
- public String getName()
- {
- return name;
- }
-
- /**
- * Add a deployment unit
- *
- * @param deploymentUnit the deployment unit
- * @param metadata the classloader metadata
- * @throws IllegalArgumentException for a null parameter
- */
- public void addDeploymentUnit(DeploymentUnit deploymentUnit, ClassLoaderMetaData metadata)
- {
- Module module = new Module(this, deploymentUnit, metadata);
- deploymentUnit.addAttachment(Module.class, module);
- units.put(deploymentUnit, module);
- module.createDependencies();
- }
-
- /**
- * Get a module for a name
- *
- * @param name the name
- * @return the module
- */
- protected Module getModule(String name)
- {
- for (Module module : units.values())
- {
- if (name.equals(module.getName()))
- return module;
- }
- return null;
- }
-
- /**
- * Resolve the requirement
- *
- * @param controller the controller
- * @param module the module
- * @param requirement the requirement
- * @return the resolved name or null if not resolved
- */
- protected Object resolve(Controller controller, Module module, Requirement requirement)
- {
- // TODO JBMICROCONT-182 - do this properly
- for (Module other : units.values())
- {
- ClassLoaderMetaData metadata = other.getMetadata();
- List<Capability> capabilities = metadata.getCapabilities();
- if (capabilities != null)
- {
- for (Capability capability : capabilities)
- {
- if (capability.resolves(module.getDeploymentUnit(), requirement))
- return other.getName();
- }
- }
- }
- return null;
- }
-
- /**
- * Remove a deployment
- *
- * @param module the module
- * @throws IllegalArgumentException for a null parameter
- */
- protected void removeModule(Module module)
- {
- if (module == null)
- throw new IllegalArgumentException("Null module");
- DeploymentUnit unit = module.getDeploymentUnit();
- units.remove(unit);
- }
-}
Deleted: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,299 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.classloading;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.DelegateLoader;
-import org.jboss.classloader.spi.ParentPolicy;
-import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
-import org.jboss.dependency.spi.Controller;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.Capability;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.deployers.structure.spi.classloading.PackageCapability;
-import org.jboss.deployers.structure.spi.classloading.Requirement;
-import org.jboss.util.id.GUID;
-
-/**
- * Module.
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class Module
-{
- /** The domain */
- private Domain domain;
-
- /** The deployment unit */
- private DeploymentUnit deploymentUnit;
-
- /** The classloader metadata */
- private ClassLoaderMetaData metadata;
-
- /** The requirements */
- private List<RequirementDependencyItem> requirementDependencies;
-
- /** The URL for the dynamic classes */
- private URL dynamicClassRoot;
-
- /**
- * Create a new Module.
- *
- * @param domain the domain
- * @param deploymentUnit the deployment unit
- * @param metadata the metadata
- * @throws IllegalArgumentException for a null parameter
- */
- public Module(Domain domain, DeploymentUnit deploymentUnit, ClassLoaderMetaData metadata)
- {
- if (domain == null)
- throw new IllegalArgumentException("Null domain");
- if (deploymentUnit == null)
- throw new IllegalArgumentException("Null unit");
- if (metadata == null)
- throw new IllegalArgumentException("Null metadata");
- this.domain = domain;
- this.deploymentUnit = deploymentUnit;
- this.metadata = metadata;
- }
-
- /**
- * Get the name of the module
- *
- * @return the string
- */
- public String getName()
- {
- return deploymentUnit.getName();
- }
-
- /**
- * Get the deploymentUnit.
- *
- * @return the deploymentUnit.
- */
- public DeploymentUnit getDeploymentUnit()
- {
- return deploymentUnit;
- }
-
- /**
- * Get the domain.
- *
- * @return the domain.
- */
- public Domain getDomain()
- {
- return domain;
- }
-
- /**
- * Get the metadata.
- *
- * @return the metadata.
- */
- public ClassLoaderMetaData getMetadata()
- {
- return metadata;
- }
-
- /**
- * Get the domain name.
- *
- * @return the domain name.
- */
- public String getDomainName()
- {
- return getDomain().getName();
- }
-
- /**
- * Get the parentDomain.
- *
- * @return the parentDomain.
- */
- public String getParentDomain()
- {
- String parentDomain = getMetadata().getParentDomain();
- if (parentDomain == null)
- {
- if (ClassLoaderSystem.DEFAULT_DOMAIN_NAME.equals(getDomainName()) == false)
- return ClassLoaderSystem.DEFAULT_DOMAIN_NAME;
- }
- return parentDomain;
- }
-
- /**
- * Get the export all for the module
- *
- * @return the export all
- */
- public ExportAll getExportAll()
- {
- return getMetadata().getExportAll();
- }
-
- /**
- * Get the import all for the module
- *
- * @return the import all
- */
- public boolean isImportAll()
- {
- return getMetadata().isImportAll();
- }
-
- /**
- * Get delegate policy
- *
- * @return the delegation policy
- */
- public ParentPolicy getParentPolicy()
- {
- if (getMetadata().isJ2seClassLoadingCompliance())
- return ParentPolicy.BEFORE;
- else
- return ParentPolicy.AFTER;
- }
-
- /**
- * Get the delegate loaders for this module
- *
- * @return the delegates
- */
- public List<? extends DelegateLoader> getDelegates()
- {
- // TODO JBMICROCONT-182 - this should be already determined
- if (requirementDependencies == null || requirementDependencies.isEmpty())
- return null;
-
- List<DelegateLoader> result = new ArrayList<DelegateLoader>();
- for (RequirementDependencyItem item : requirementDependencies)
- {
- String name = (String) item.getIDependOn();
- Module module = domain.getModule(name);
- if (module == null)
- throw new IllegalStateException("Module not found with name: " + name);
- result.add(module.getDelegateLoader());
- }
- return result;
- }
-
- /**
- * Get the delegate loader
- *
- * @return the delegate loader
- */
- public DelegateLoader getDelegateLoader()
- {
- // TODO JBMICROCONT-182 - this should be already determined
- ClassLoaderPolicy policy = deploymentUnit.getAttachment(ClassLoaderPolicy.class);
- if (policy == null)
- throw new IllegalStateException("No policy for " + deploymentUnit.getName());
- return new FilteredDelegateLoader(policy);
- }
-
- public String[] getPackageNames()
- {
- // TODO JBMICROCONT-182 - this should be first class to include "uses" processing
- List<Capability> capabilities = metadata.getCapabilities();
- if (capabilities == null)
- return new String[0];
-
- List<String> packageNames = new ArrayList<String>();
- for (Capability capability : capabilities)
- {
- if (capability instanceof PackageCapability)
- packageNames.add(((PackageCapability) capability).getName());
- }
- return packageNames.toArray(new String[packageNames.size()]);
- }
-
- /**
- * Create the dependencies for the module
- */
- public void createDependencies()
- {
- List<Requirement> requirements = metadata.getRequirements();
- if (requirements != null)
- {
- requirementDependencies = new ArrayList<RequirementDependencyItem>();
- for (Requirement requirement : requirements)
- {
- RequirementDependencyItem item = new RequirementDependencyItem(this, requirement);
- requirementDependencies.add(item);
- deploymentUnit.addIDependOn(item);
- }
- }
- }
-
- /**
- * Resolve the requirement
- *
- * @param controller the controller
- * @param requirement the requirement
- * @return the resolved name or null if not resolved
- */
- protected Object resolve(Controller controller, Requirement requirement)
- {
- return domain.resolve(controller, this, requirement);
- }
-
- /**
- * Reset the module
- */
- public void reset()
- {
- }
-
- /**
- * Release the module
- */
- public void release()
- {
- domain.removeModule(this);
- }
-
- public URL getDynamicClassRoot()
- {
- if (dynamicClassRoot == null)
- {
- try
- {
- dynamicClassRoot = new URL("vfsmemory://" + new GUID());
- }
- catch (MalformedURLException e)
- {
- throw new RuntimeException(e);
- }
- }
- return dynamicClassRoot;
- }
-}
Deleted: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,108 +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.deployers.plugins.classloading;
-
-import org.jboss.dependency.plugins.AbstractDependencyItem;
-import org.jboss.dependency.spi.Controller;
-import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
-import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.structure.spi.classloading.Requirement;
-import org.jboss.util.JBossStringBuilder;
-
-/**
- * RequirementDependencyItem.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class RequirementDependencyItem extends AbstractDependencyItem
-{
- private static final ControllerState CLASSLOADER = new ControllerState(DeploymentStages.CLASSLOADER.getName());
-
- /** The module */
- private Module module;
-
- /** The requirement */
- private Requirement requirement;
-
- /**
- * Create a new RequirementDependencyItem.
- *
- * @param module the module
- * @param requirement the requirement
- * @throws IllegalArgumentException for a null parameter
- */
- public RequirementDependencyItem(Module module, Requirement requirement)
- {
- super(module != null ? module.getName() : null, null, CLASSLOADER, CLASSLOADER);
- if (module == null)
- throw new IllegalArgumentException("Null module");
- if (requirement == null)
- throw new IllegalArgumentException("Null requirement");
- this.module = module;
- this.requirement = requirement;
- }
-
- public boolean resolve(Controller controller)
- {
- Object iDependOn = module.resolve(controller, requirement);
- if (iDependOn != null)
- {
- ControllerContext context = controller.getContext(iDependOn, CLASSLOADER);
- if (context != null)
- {
- setIDependOn(context.getName());
- addDependsOnMe(controller, context);
- setResolved(true);
- }
- else
- {
- setResolved(false);
- }
- }
- return isResolved();
- }
-
- public boolean unresolved(Controller controller)
- {
- setIDependOn(null);
- setResolved(false);
- return true;
- }
-
- public void toString(JBossStringBuilder buffer)
- {
- super.toString(buffer);
- buffer.append(" requirement=").append(requirement);
- }
-
- public void toShortString(JBossStringBuilder buffer)
- {
- buffer.append(getName()).append(" ").append(requirement);
- }
-
- public String toHumanReadableString()
- {
- return requirement.toString();
- }
-}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockClassLoaderDescribeDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockClassLoaderDescribeDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockClassLoaderDescribeDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,42 @@
+/*
+* 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.classloading.support;
+
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDescribeDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * MockClassLoaderDescribeDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockClassLoaderDescribeDeployer extends AbstractClassLoaderDescribeDeployer
+{
+ protected ClassLoaderPolicyModule createModule(DeploymentUnit unit, ClassLoadingMetaData metaData) throws DeploymentException
+ {
+ return new MockDeploymentClassLoaderPolicyModule(unit);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockDeploymentClassLoaderPolicyModule.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockDeploymentClassLoaderPolicyModule.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockDeploymentClassLoaderPolicyModule.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,118 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloading.support;
+
+import java.util.List;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.test.support.MockClassLoaderHelper;
+import org.jboss.classloader.test.support.MockClassLoaderPolicy;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * MockDeploymentClassLoaderPolicyModule.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockDeploymentClassLoaderPolicyModule extends AbstractDeploymentClassLoaderPolicyModule
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Create a new MockDeploymentClassLoaderPolicyModule.
+ *
+ * @param unit the deployment unit
+ * @throws IllegalArgumentException for a null deployment unit
+ */
+ public MockDeploymentClassLoaderPolicyModule(DeploymentUnit unit)
+ {
+ super(unit);
+
+ ClassLoadingMetaData metaData = unit.getAttachment(ClassLoadingMetaData.class);
+ if (metaData == null || (metaData instanceof MockClassLoadingMetaData == false))
+ throw new IllegalArgumentException("MetaData is not mocked: " + metaData);
+ }
+
+ @Override
+ protected List<Capability> determineCapabilities()
+ {
+ List<Capability> capabilities = super.determineCapabilities();
+ if (capabilities != null)
+ return capabilities;
+
+ // We need to work it out
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+ capabilities = new CopyOnWriteArrayList<Capability>();
+
+ // We have a module capability
+ Object version = getVersion();
+ Capability capability = factory.createModule(getName(), version);
+ capabilities.add(capability);
+
+ MockClassLoadingMetaData metadata = getClassLoadingMetaData();
+ String[] exported = metadata.getExportedPackages();
+ // Do we determine package capabilities?
+ if (exported != null)
+ {
+ for (String packageName : exported)
+ {
+ capability = factory.createPackage(packageName, version);
+ capabilities.add(capability);
+ }
+ }
+ return capabilities;
+ }
+
+ @Override
+ protected MockClassLoadingMetaData getClassLoadingMetaData()
+ {
+ return (MockClassLoadingMetaData) super.getClassLoadingMetaData();
+ }
+
+ @Override
+ public MockClassLoaderPolicy getPolicy()
+ {
+ return (MockClassLoaderPolicy) super.getPolicy();
+ }
+
+ @Override
+ protected MockClassLoaderPolicy determinePolicy()
+ {
+ MockClassLoadingMetaData metaData = getClassLoadingMetaData();
+ MockClassLoaderPolicy policy = MockClassLoaderHelper.createMockClassLoaderPolicy(getContextName());
+ policy.setPrefix(metaData.getPrefix());
+ policy.setPackageNames(getPackageNames());
+ policy.setPaths(metaData.getPaths());
+ policy.setIncluded(metaData.getIncludedClasses());
+ policy.setExcluded(metaData.getExcludedClasses());
+ policy.setImportAll(isImportAll());
+ policy.setDelegates(getDelegates());
+ return policy;
+ }
+}
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockTopLevelClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -24,12 +24,8 @@
import java.util.ArrayList;
import java.util.List;
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.test.support.MockClassLoaderPolicy;
import org.jboss.deployers.plugins.classloading.AbstractTopLevelClassLoaderSystemDeployer;
-import org.jboss.deployers.plugins.classloading.Module;
import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.structure.spi.DeploymentContext;
import org.jboss.deployers.structure.spi.DeploymentUnit;
/**
@@ -43,20 +39,6 @@
public List<String> deployed = new ArrayList<String>();
public List<String> undeployed = new ArrayList<String>();
- @Override
- protected MockClassLoaderPolicy createTopLevelClassLoaderPolicy(DeploymentContext context, Module module) throws Exception
- {
- MockClassLoaderPolicy policy = new MockClassLoaderPolicy(context.getName());
- policy.setImportAll(module.isImportAll());
- policy.setDelegates(module.getDelegates());
- policy.setPathsAndPackageNames(module.getPackageNames());
-
- // TODO JBMICROCONT-182 - remove this hack
- context.getTransientAttachments().addAttachment(ClassLoaderPolicy.class, policy);
-
- return policy;
- }
-
public void deploy(DeploymentUnit unit) throws DeploymentException
{
deployed.add(unit.getName());
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/ClassLoaderDependenciesTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/ClassLoaderDependenciesTest.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/ClassLoaderDependenciesTest.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -28,23 +28,24 @@
import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
import org.jboss.classloader.spi.ClassLoaderSystem;
import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.dependency.policy.mock.MockClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
import org.jboss.deployers.client.spi.DeployerClient;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDescribeDeployer;
-import org.jboss.deployers.plugins.classloading.ClassLoading;
import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.Capability;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
-import org.jboss.deployers.structure.spi.classloading.Requirement;
-import org.jboss.deployers.structure.spi.classloading.Version;
-import org.jboss.deployers.structure.spi.classloading.VersionRange;
-import org.jboss.deployers.structure.spi.classloading.helpers.ModuleCapabilityImpl;
-import org.jboss.deployers.structure.spi.classloading.helpers.PackageCapabilityImpl;
-import org.jboss.deployers.structure.spi.classloading.helpers.RequireModuleImpl;
-import org.jboss.deployers.structure.spi.classloading.helpers.RequirePackageImpl;
import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.classloading.support.MockClassLoaderDescribeDeployer;
import org.jboss.test.deployers.classloading.support.MockTopLevelClassLoaderSystemDeployer;
/**
@@ -54,6 +55,8 @@
*/
public abstract class ClassLoaderDependenciesTest extends AbstractDeployerTest
{
+ private static ClassLoadingMetaDataFactory classLoadingMetaDataFactory = ClassLoadingMetaDataFactory.getInstance();
+
public static final String NameA = "A";
public static final String NameB = "B";
@@ -134,78 +137,70 @@
}
}
- protected static ClassLoaderMetaData addClassLoaderMetaData(Deployment deployment, Version version, Class<?>... packages)
+ protected static ClassLoadingMetaData addClassLoadingMetaData(Deployment deployment, Version version, Class<?>... packages)
{
- return addClassLoaderMetaData(deployment, version, false, packages);
+ return addClassLoadingMetaData(deployment, version, false, packages);
}
- protected static ClassLoaderMetaData addClassLoaderMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ protected static ClassLoadingMetaData addClassLoadingMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
{
- ClassLoaderMetaData classLoaderMetaData = createMetaData(deployment, version, useVersionOnPackages, packages);
- addMetaData(deployment, classLoaderMetaData);
- return classLoaderMetaData;
+ ClassLoadingMetaData classLoadingMetaData = createMetaData(deployment, version, useVersionOnPackages, packages);
+ addMetaData(deployment, classLoadingMetaData);
+ return classLoadingMetaData;
}
- protected static ClassLoaderMetaData createMetaData(Deployment deployment, Version version, Class<?>... packages)
+ protected static ClassLoadingMetaData createMetaData(Deployment deployment, Version version, Class<?>... packages)
{
return createMetaData(deployment, version, false, packages);
}
- protected static ClassLoaderMetaData createMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ protected static ClassLoadingMetaData createMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
{
- ClassLoaderMetaData classLoaderMetaData = new ClassLoaderMetaData();
- classLoaderMetaData.setName(deployment.getName());
+ String name = deployment.getName();
+ MockClassLoadingMetaData classLoadingMetaData = new MockClassLoadingMetaData(name, version);
- List<Capability> capabilities = new ArrayList<Capability>();
- Capability capability = new ModuleCapabilityImpl(deployment.getName(), version);
- capabilities.add(capability);
+ classLoadingMetaData.setPaths(packages);
+
+ CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
+ Capability capability = classLoadingMetaDataFactory.createModule(name, version);
+ capabilities.addCapability(capability);
if (packages != null)
{
for (Class<?> pkg : packages)
{
if (useVersionOnPackages)
- capability = new PackageCapabilityImpl(pkg.getName(), version);
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName(), version);
else
- capability = new PackageCapabilityImpl(pkg.getName());
- capabilities.add(capability);
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName());
+ capabilities.addCapability(capability);
}
}
- classLoaderMetaData.setCapabilities(capabilities);
- return classLoaderMetaData;
+ classLoadingMetaData.setCapabilities(capabilities);
+ return classLoadingMetaData;
}
- protected static void addRequireModule(ClassLoaderMetaData classLoaderMetaData, String moduleName, VersionRange versionRange)
+ protected static void addRequireModule(ClassLoadingMetaData classLoadingMetaData, String moduleName, VersionRange versionRange)
{
- List<Requirement> requirements = classLoaderMetaData.getRequirements();
- if (requirements == null)
- {
- requirements = new ArrayList<Requirement>();
- classLoaderMetaData.setRequirements(requirements);
- }
+ RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
- Requirement requirement = new RequireModuleImpl(moduleName, versionRange);
- requirements.add(requirement);
+ Requirement requirement = classLoadingMetaDataFactory.createRequireModule(moduleName, versionRange);
+ requirements.addRequirement(requirement);
}
- protected static void addRequirePackage(ClassLoaderMetaData classLoaderMetaData, Class<?> pck, VersionRange versionRange)
+ protected static void addRequirePackage(ClassLoadingMetaData classLoadingMetaData, Class<?> pck, VersionRange versionRange)
{
- List<Requirement> requirements = classLoaderMetaData.getRequirements();
- if (requirements == null)
- {
- requirements = new ArrayList<Requirement>();
- classLoaderMetaData.setRequirements(requirements);
- }
+ RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
- Requirement requirement = new RequirePackageImpl(pck.getName(), versionRange);
- requirements.add(requirement);
+ Requirement requirement = classLoadingMetaDataFactory.createRequirePackage(pck.getPackage().getName(), versionRange);
+ requirements.addRequirement(requirement);
}
- protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, ClassLoaderMetaData md)
+ protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, ClassLoadingMetaData md)
{
MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
- mutable.addAttachment(ClassLoaderMetaData.class, md);
+ mutable.addAttachment(ClassLoadingMetaData.class, md);
}
protected DeployerClient getMainDeployer()
@@ -214,7 +209,7 @@
ClassLoaderSystem system = new DefaultClassLoaderSystem();
system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
- deployer1 = new AbstractClassLoaderDescribeDeployer();
+ deployer1 = new MockClassLoaderDescribeDeployer();
deployer1.setClassLoading(classLoading);
deployer2 = new MockTopLevelClassLoaderSystemDeployer();
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -23,10 +23,11 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
import org.jboss.deployers.client.spi.DeployerClient;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
import org.jboss.test.deployers.classloading.support.a.A;
import org.jboss.test.deployers.classloading.support.b.B;
@@ -53,7 +54,7 @@
DeployerClient deployer = getMainDeployer();
Deployment deployment = createSimpleDeployment(NameA);
- addClassLoaderMetaData(deployment, null, A.class);
+ addClassLoadingMetaData(deployment, null, A.class);
DeploymentUnit unit = assertDeploy(deployer, deployment);
@@ -76,7 +77,7 @@
DeployerClient deployer = getMainDeployer();
Deployment deploymentB = createSimpleDeployment(NameB);
- addClassLoaderMetaData(deploymentB, null, B.class);
+ addClassLoadingMetaData(deploymentB, null, B.class);
DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
ClassLoader clB = unitB.getClassLoader();
@@ -86,8 +87,8 @@
assertEquals(NONE, deployer2.undeployed);
Deployment deploymentA = createSimpleDeployment(NameA);
- ClassLoaderMetaData classLoaderMetaData = addClassLoaderMetaData(deploymentA, null, A.class);
- addRequireModule(classLoaderMetaData, "B", null);
+ ClassLoadingMetaData classLoadingMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoadingMetaData, "B", null);
DeploymentUnit unitA = assertDeploy(deployer, deploymentA);
ClassLoader clA = unitA.getClassLoader();
@@ -114,7 +115,7 @@
DeployerClient deployer = getMainDeployer();
Deployment deploymentA = createSimpleDeployment(NameA);
- ClassLoaderMetaData classLoaderMetaData = addClassLoaderMetaData(deploymentA, null, A.class);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
addRequireModule(classLoaderMetaData, "B", null);
DeploymentUnit unitA = addDeployment(deployer, deploymentA);
@@ -124,7 +125,7 @@
assertEquals(NONE, deployer2.undeployed);
Deployment deploymentB = createSimpleDeployment(NameB);
- addClassLoaderMetaData(deploymentB, null, B.class);
+ addClassLoadingMetaData(deploymentB, null, B.class);
DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
ClassLoader clB = unitB.getClassLoader();
@@ -154,7 +155,7 @@
DeployerClient deployer = getMainDeployer();
Deployment deploymentA = createSimpleDeployment(NameA);
- ClassLoaderMetaData classLoaderMetaData = addClassLoaderMetaData(deploymentA, null, A.class);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
addRequireModule(classLoaderMetaData, "B", null);
DeploymentUnit unitA = addDeployment(deployer, deploymentA);
@@ -164,7 +165,7 @@
assertEquals(NONE, deployer2.undeployed);
Deployment deploymentB = createSimpleDeployment(NameB);
- addClassLoaderMetaData(deploymentB, null, B.class);
+ addClassLoadingMetaData(deploymentB, null, B.class);
DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
ClassLoader clB = unitB.getClassLoader();
@@ -195,7 +196,7 @@
DeployerClient deployer = getMainDeployer();
Deployment deploymentA = createSimpleDeployment(NameA);
- ClassLoaderMetaData classLoaderMetaData = addClassLoaderMetaData(deploymentA, null, A.class);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
addRequireModule(classLoaderMetaData, "B", null);
DeploymentUnit unitA = addDeployment(deployer, deploymentA);
@@ -205,7 +206,7 @@
assertEquals(NONE, deployer2.undeployed);
Deployment deploymentB = createSimpleDeployment(NameB);
- addClassLoaderMetaData(deploymentB, null, B.class);
+ addClassLoadingMetaData(deploymentB, null, B.class);
DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
ClassLoader clB = unitB.getClassLoader();
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/UndeployOrderClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/UndeployOrderClassLoaderUnitTestCase.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/UndeployOrderClassLoaderUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -22,12 +22,14 @@
package org.jboss.test.deployers.classloading.test;
import junit.framework.Test;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
import org.jboss.deployers.client.spi.DeployerClient;
import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.structure.spi.classloading.ClassLoaderMetaData;
-import org.jboss.deployers.structure.spi.classloading.VersionRange;
-import org.jboss.deployers.structure.spi.classloading.helpers.VersionImpl;
import org.jboss.test.deployers.classloading.support.a.A;
import org.jboss.test.deployers.classloading.support.b.B;
@@ -51,20 +53,20 @@
public void testUndeployOrder() throws Exception
{
DeployerClient mainDeployer = getMainDeployer();
- VersionImpl v1 = VersionImpl.parseVersion("1");
- VersionImpl v2 = VersionImpl.parseVersion("2");
+ Version v1 = Version.parseVersion("1");
+ Version v2 = Version.parseVersion("2");
Deployment ad = createSimpleDeployment("A");
- addClassLoaderMetaData(ad, v1, true, A.class);
+ addClassLoadingMetaData(ad, v1, true, A.class);
assertDeploy(mainDeployer, ad);
Deployment bd = createSimpleDeployment("B");
- addClassLoaderMetaData(bd, v2, true, B.class);
+ addClassLoadingMetaData(bd, v2, true, B.class);
assertDeploy(mainDeployer, bd);
mainDeployer.checkComplete(bd);
Deployment cd = createSimpleDeployment("C");
- ClassLoaderMetaData clmd = addClassLoaderMetaData(cd, null);
+ ClassLoadingMetaData clmd = addClassLoadingMetaData(cd, null);
addRequirePackage(clmd, A.class, new VersionRange(v1, true, v2, true));
addRequirePackage(clmd, B.class, new VersionRange(v1, true, v2, true));
assertDeploy(mainDeployer, cd);
@@ -75,10 +77,23 @@
try
{
mainDeployer.checkComplete();
+ fail("Should not be here!");
}
catch (DeploymentException e)
{
- e.printStackTrace();
+ checkThrowable(IncompleteDeploymentException.class, e);
}
+ mainDeployer.undeploy(ad);
+ try
+ {
+ mainDeployer.checkComplete();
+ fail("Should not be here!");
+ }
+ catch (DeploymentException e)
+ {
+ checkThrowable(IncompleteDeploymentException.class, e);
+ }
+ mainDeployer.undeploy(cd);
+ mainDeployer.checkComplete();
}
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/tests/org/jboss/test/deployers/DeployersStructureTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/tests/org/jboss/test/deployers/DeployersStructureTestSuite.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/tests/org/jboss/test/deployers/DeployersStructureTestSuite.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -24,9 +24,9 @@
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
+
import org.jboss.test.deployers.structure.attachments.StructureAttachmentsTestSuite;
import org.jboss.test.deployers.structure.structurebuilder.StructureBuilderTestSuite;
-import org.jboss.test.deployers.structure.version.test.VersionTestSuite;
/**
* Deployers Structure Test Suite.
@@ -47,7 +47,6 @@
suite.addTest(StructureAttachmentsTestSuite.suite());
suite.addTest(StructureBuilderTestSuite.suite());
- suite.addTest(VersionTestSuite.suite());
return suite;
}
Modified: projects/microcontainer/trunk/deployers-vfs/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/.classpath 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/.classpath 2008-02-19 15:54:00 UTC (rev 69935)
@@ -30,6 +30,8 @@
<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
<classpathentry kind="var" path="M2_REPO/sun-jaxb/jaxb-api/2.0.5/jaxb-api-2.0.5.jar"/>
<classpathentry kind="src" path="/jboss-classloader"/>
+ <classpathentry kind="src" path="/jboss-classloading"/>
+ <classpathentry kind="src" path="/jboss-classloading-vfs"/>
<classpathentry kind="var" path="M2_REPO/org/jboss/jboss-classloading-spi/5.0.0.Beta3/jboss-classloading-spi-5.0.0.Beta3.jar" sourcepath="M2_REPO/org/jboss/jboss-classloading-spi/5.0.0.Beta3/jboss-classloading-spi-5.0.0.Beta3-sources.jar"/>
<classpathentry kind="src" path="/jboss-dependency"/>
<classpathentry kind="src" path="/jboss-deployers-client"/>
Modified: projects/microcontainer/trunk/deployers-vfs/pom.xml
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/pom.xml 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/pom.xml 2008-02-19 15:54:00 UTC (rev 69935)
@@ -75,6 +75,14 @@
</dependency>
<dependency>
<groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-classloading</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-classloading-vfs</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-core</artifactId>
</dependency>
<dependency>
Deleted: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/PackageVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/PackageVisitor.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/PackageVisitor.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,182 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.vfs.plugins.classloader;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.VirtualFileVisitor;
-import org.jboss.virtual.VisitorAttributes;
-
-/**
- * Visits a virtual file system recursively
- * to determine package names based on the exportAll policy
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-class PackageVisitor implements VirtualFileVisitor
-{
- /** The packages */
- private Set<String> packages = new HashSet<String>();
-
- /** The root */
- private String rootPath;
-
- /** The root with slash*/
- private String rootPathWithSlash;
-
- /** The exportAll policy */
- private ExportAll exportAll;
-
- /** The excluded packages */
- private Set<String> excludedPackages;
-
- /**
- * Create a new PackageVisitor.
- *
- * @param exportAll the export all policy
- * @throws IllegalArgumentException for a null exportAll policy
- */
- public PackageVisitor(ExportAll exportAll)
- {
- this(exportAll, null);
- }
-
- /**
- * Create a new PackageVisitor.
- *
- * @param exportAll the export all policy
- * @param excludedPackages the excluded packages
- * @throws IllegalArgumentException for a null exportAll policy
- */
- public PackageVisitor(ExportAll exportAll, Set<String> excludedPackages)
- {
- if (exportAll == null)
- throw new IllegalArgumentException("Null exportAll policy");
- this.exportAll = exportAll;
- this.excludedPackages = excludedPackages;
- }
-
- /**
- * Set the root
- *
- * @param root the root
- * @throws IllegalArgumentException for a null root
- */
- public void setRoot(VirtualFile root)
- {
- if (root == null)
- throw new IllegalArgumentException("Null root");
- rootPath = root.getPathName();
- rootPathWithSlash = rootPath + "/";
- }
-
- /**
- * Get the packages.
- *
- * @return the packages.
- */
- public Set<String> getPackages()
- {
- return packages;
- }
-
- public VisitorAttributes getAttributes()
- {
- VisitorAttributes attributes = new VisitorAttributes();
- attributes.setIncludeRoot(true);
- attributes.setRecurseFilter(VisitorAttributes.RECURSE_ALL);
- return attributes;
- }
-
- public void visit(VirtualFile file)
- {
- try
- {
- // We only want only directories
- if (file.isLeaf() == false)
- {
- boolean empty = true;
- // Include empty directories?
- if (exportAll == ExportAll.ALL)
- empty = false;
- else
- {
- // Determine whether there is anything there
- List<VirtualFile> children = file.getChildren();
- if (children != null && children.isEmpty() == false)
- {
- for (VirtualFile child : children)
- {
- // We must have a leaf to be non-empty
- if (child.isLeaf())
- {
- empty = false;
- break;
- }
- }
- }
- }
- // This looks interesting
- if (empty == false)
- {
- String path = file.getPathName();
- if (path.equals(rootPath))
- path = "";
- else if (path.startsWith(rootPathWithSlash))
- path = path.substring(rootPathWithSlash.length());
- String pkg = path.replace('/', '.');
- // Check for excluded package prefixes
- if(excludedPackages != null)
- {
- // Look at each package up to the root
- String prefix = pkg;
- while(prefix.length() >= 0)
- {
- if(excludedPackages.contains(prefix))
- {
- pkg = null;
- break;
- }
- int dot = prefix.lastIndexOf('.');
- if(dot > 0)
- prefix = prefix.substring(0, dot);
- else
- break;
- }
- }
- if(pkg != null)
- packages.add(pkg);
- }
- }
- }
- catch (IOException e)
- {
- throw new Error("Error visiting " + file, e);
- }
- }
-}
\ No newline at end of file
Added: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderDescribeDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderDescribeDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderDescribeDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,45 @@
+/*
+* 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.vfs.plugins.classloader;
+
+import org.jboss.classloading.spi.dependency.policy.ClassLoaderPolicyModule;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDescribeDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+
+/**
+ * VFSClassLoaderDescribeDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSClassLoaderDescribeDeployer extends AbstractClassLoaderDescribeDeployer
+{
+ protected ClassLoaderPolicyModule createModule(DeploymentUnit unit, ClassLoadingMetaData metaData) throws DeploymentException
+ {
+ if (unit instanceof VFSDeploymentUnit == false)
+ return null;
+ return new VFSDeploymentClassLoaderPolicyModule((VFSDeploymentUnit) unit);
+ }
+}
Deleted: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderPolicy.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderPolicy.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSClassLoaderPolicy.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,447 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.vfs.plugins.classloader;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.URL;
-import java.security.CodeSource;
-import java.security.PermissionCollection;
-import java.security.Policy;
-import java.security.ProtectionDomain;
-import java.security.cert.Certificate;
-import java.util.Arrays;
-import java.util.Map;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.jar.Manifest;
-
-import org.jboss.classloader.spi.ClassLoaderPolicy;
-import org.jboss.classloader.spi.DelegateLoader;
-import org.jboss.classloader.spi.PackageInformation;
-import org.jboss.classloader.spi.filter.ClassFilter;
-import org.jboss.classloader.spi.filter.FilteredDelegateLoader;
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.logging.Logger;
-import org.jboss.virtual.VFSUtils;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * VFSClassLoaderPolicy.
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class VFSClassLoaderPolicy extends ClassLoaderPolicy
-{
- /** The log */
- private static Logger log = Logger.getLogger(VFSClassLoaderPolicy.class);
-
- /** Tag for no manifest */
- private static final Manifest NO_MANIFEST = new Manifest();
-
- /** A name for the policy */
- private String name;
-
- /** The roots */
- private VirtualFile[] roots;
-
- /** Whether to export all */
- private ExportAll exportAll;
-
- /** The exported packages */
- private String[] exportedPackages;
-
- /** Package */
- private Set<String> excludedPackages;
-
- /** The import all */
- private boolean importAll;
-
- /** Manifest cache */
- private Map<URL, Manifest> manifestCache = new ConcurrentHashMap<URL, Manifest>();
-
- /**
- * Determine a name from the roots
- *
- * @param roots the roots
- * @return the name
- */
- private static String determineName(VirtualFile[] roots)
- {
- if (roots == null)
- return "";
-
- try
- {
- for (VirtualFile root : roots)
- return root.toURL().toString();
- }
- catch (Exception ignored)
- {
- }
- return "";
- }
-
- /**
- * Create a new VFSClassLoaderPolicy.
- *
- * @param roots the roots
- * @return the classloader policy
- * @throws IllegalArgumentException for null roots
- */
- public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(VirtualFile... roots)
- {
- return new VFSClassLoaderPolicy(roots);
- }
-
- /**
- * Create a new VFSClassLoaderPolicy.
- *
- * @param name a name of the policy
- * @param roots the roots
- * @return the classloader policy
- * @throws IllegalArgumentException for null roots
- */
- public static VFSClassLoaderPolicy createVFSClassLoaderPolicy(String name, VirtualFile... roots)
- {
- return new VFSClassLoaderPolicy(name, roots);
- }
-
- /**
- * Create a new VFSClassLoaderPolicy.
- *
- * @param roots the roots
- * @throws IllegalArgumentException for null roots
- */
- public VFSClassLoaderPolicy(VirtualFile[] roots)
- {
- this(determineName(roots), roots);
- }
-
- /**
- * Create a new VFSClassLoaderPolicy.
- *
- * @param name the name
- * @param roots the roots
- * @throws IllegalArgumentException for null roots
- */
- public VFSClassLoaderPolicy(String name, VirtualFile[] roots)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
- if (roots == null)
- throw new IllegalArgumentException("Null roots");
- for (VirtualFile root : roots)
- {
- if (root == null)
- throw new IllegalArgumentException("Null root in " + Arrays.asList(roots));
- }
-
- this.name = name;
- this.roots = roots;
- }
-
- @Override
- public String getName()
- {
- return name;
- }
-
- /**
- * Get the exportAll.
- *
- * @return the exportAll.
- */
- public ExportAll getExportAll()
- {
- return exportAll;
- }
-
- /**
- * Set the exportAll.
- *
- * @param exportAll the exportAll.
- */
- public void setExportAll(ExportAll exportAll)
- {
- this.exportAll = exportAll;
- if (exportAll != null)
- exportedPackages = determineAllPackages().toArray(new String[0]);
- else
- exportedPackages = null;
- }
-
-
-
- public Set<String> getExcludedPackages()
- {
- return excludedPackages;
- }
-
- public void setExcludedPackages(Set<String> excludedPackages)
- {
- this.excludedPackages = excludedPackages;
- }
-
- public String[] getExportedPackages()
- {
- return exportedPackages;
- }
-
- @Override
- public boolean isImportAll()
- {
- return importAll;
- }
-
- /**
- * Set the importAll.
- *
- * @param importAll the importAll.
- */
- public void setImportAll(boolean importAll)
- {
- this.importAll = importAll;
- }
-
- @Override
- public String[] getPackageNames()
- {
- return exportedPackages;
- }
-
- /**
- * Set the exportedPackages.
- *
- * @param exportedPackages the exportedPackages.
- */
- public void setExportedPackages(String[] exportedPackages)
- {
- this.exportedPackages = exportedPackages;
- }
-
- @Override
- public DelegateLoader getExported()
- {
- if (getExportAll() != null)
- return new FilteredDelegateLoader(this, ClassFilter.EVERYTHING);
- return super.getExported();
- }
-
- @Override
- public URL getResource(String path)
- {
- VirtualFile child = findChild(path);
- if (child != null)
- {
- try
- {
- return child.toURL();
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Error determining URL for " + child, ignored);
- return null;
- }
- }
- return null;
- }
-
- @Override
- public InputStream getResourceAsStream(String path)
- {
- VirtualFile child = findChild(path);
- if (child != null)
- {
- try
- {
- return child.openStream();
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Error opening stream for " + child, ignored);
- return null;
- }
- }
- return null;
- }
-
- @Override
- public void getResources(String name, Set<URL> urls) throws IOException
- {
- for (VirtualFile root : roots)
- {
- try
- {
- VirtualFile child = root.getChild(name);
- if (child != null)
- urls.add(child.toURL());
- }
- catch (Exception e)
- {
- if (log.isTraceEnabled())
- log.trace("Error getting resources for " + root, e);
- }
- }
- }
-
- /**
- * Find a child from a path
- *
- * @param path the path
- * @return the child if found in the roots
- */
- protected VirtualFile findChild(String path)
- {
- for (VirtualFile root : roots)
- {
- try
- {
- VirtualFile child = root.getChild(path);
- if (child != null)
- return child;
- }
- catch (Exception ignored)
- {
- // not found
- }
- }
- return null;
- }
-
- /**
- * Find a root from a path
- *
- * @param path the path
- * @return the root if found in the roots
- */
- protected VirtualFile findRoot(String path)
- {
- for (VirtualFile root : roots)
- {
- try
- {
- if (root.getChild(path) != null)
- return root;
- }
- catch (Exception ignored)
- {
- // not found
- }
- }
- return null;
- }
-
- @Override
- public PackageInformation getPackageInformation(String packageName)
- {
- String path = packageName.replace('.', '/');
- VirtualFile root = findRoot(path);
- Manifest manifest = null;
- URL rootURL = null;
- if (root != null)
- {
- try
- {
- rootURL = root.toURL();
- manifest = manifestCache.get(rootURL);
- if (manifest == null)
- {
- manifest = VFSUtils.getManifest(root);
- if (manifest == null)
- manifestCache.put(rootURL, NO_MANIFEST);
- else
- manifestCache.put(rootURL, manifest);
- }
-
- if (manifest == NO_MANIFEST)
- manifest = null;
- }
- catch (Exception ignored)
- {
- if (log.isTraceEnabled())
- log.trace("Unable to retrieve manifest for " + path + " url=" + rootURL + " error=" + ignored.getMessage());
- }
- }
- return new PackageInformation(packageName, manifest);
- }
-
- @Override
- protected void toLongString(StringBuilder builder)
- {
- builder.append(" roots=").append(Arrays.asList(roots)).append(" ");
- super.toLongString(builder);
- if (exportAll != null)
- builder.append(exportAll);
- }
-
- @Override
- protected ProtectionDomain getProtectionDomain(String className, String path)
- {
- VirtualFile clazz = findChild(path);
- if (clazz == null)
- {
- log.trace("Unable to determine class file for " + className);
- return null;
- }
- try
- {
- VirtualFile root = clazz.getVFS().getRoot();
- URL codeSourceURL = root.toURL();
- Certificate[] certs = null; // TODO JBMICROCONT-182 determine certificates
- CodeSource cs = new CodeSource(codeSourceURL, certs);
- PermissionCollection permissions = Policy.getPolicy().getPermissions(cs);
- return new ProtectionDomain(cs, permissions);
- }
- catch (Exception e)
- {
- throw new Error("Error determining protection domain for " + clazz, e);
- }
- }
-
- /**
- * Determine all the packages
- *
- * @return the packages
- * @throws IllegalArgumentException if there is no exportAll policy
- */
- protected Set<String> determineAllPackages()
- {
- PackageVisitor visitor = new PackageVisitor(exportAll, excludedPackages);
- for (VirtualFile root : roots)
- {
- try
- {
- visitor.setRoot(root);
- root.visit(visitor);
- }
- catch (Exception e)
- {
- throw new Error("Error visiting " + root, e);
- }
- }
- return visitor.getPackages();
- }
-}
Added: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSDeploymentClassLoaderPolicyModule.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,163 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.vfs.plugins.classloader;
+
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.CopyOnWriteArrayList;
+
+import org.jboss.classloader.spi.filter.ClassFilter;
+import org.jboss.classloading.plugins.vfs.PackageVisitor;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.ExportAll;
+import org.jboss.classloading.spi.vfs.policy.VFSClassLoaderPolicy;
+import org.jboss.deployers.plugins.classloading.AbstractDeploymentClassLoaderPolicyModule;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
+import org.jboss.deployers.vfs.spi.structure.helpers.ClassPathVisitor;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * VFSDeploymentClassLoaderPolicyModule.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSDeploymentClassLoaderPolicyModule extends AbstractDeploymentClassLoaderPolicyModule
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = 1L;
+
+ /** The cached roots */
+ private VirtualFile[] vfsRoots;
+
+ /**
+ * Create a new VFSDeploymentClassLoaderPolicyModule.
+ *
+ * @param unit the deployment unit
+ * @throws IllegalArgumentException for a null deployment unit
+ */
+ public VFSDeploymentClassLoaderPolicyModule(VFSDeploymentUnit unit)
+ {
+ super(unit);
+ }
+
+ @Override
+ public VFSDeploymentUnit getDeploymentUnit()
+ {
+ return (VFSDeploymentUnit) super.getDeploymentUnit();
+ }
+
+ @Override
+ protected List<Capability> determineCapabilities()
+ {
+ // While we are here, check the roots
+ VirtualFile[] roots = determineVFSRoots();
+
+ List<Capability> capabilities = super.determineCapabilities();
+ if (capabilities != null)
+ return capabilities;
+
+ // We need to work it out
+ ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+ capabilities = new CopyOnWriteArrayList<Capability>();
+
+ // We have a module capability
+ Object version = getVersion();
+ Capability capability = factory.createModule(getName(), version);
+ capabilities.add(capability);
+
+ // Do we determine package capabilities
+ ClassFilter included = getIncluded();
+ ClassFilter excluded = getExcluded();
+ ClassFilter excludedExport = getExcludedExport();
+ ExportAll exportAll = getExportAll();
+ if (exportAll != null)
+ {
+ Set<String> exportedPackages = PackageVisitor.determineAllPackages(roots, exportAll, included, excluded, excludedExport);
+ for (String packageName : exportedPackages)
+ {
+ capability = factory.createPackage(packageName, version);
+ capabilities.add(capability);
+ }
+ }
+
+ return capabilities;
+ }
+
+ /**
+ * Get the virtual file roots
+ *
+ * @return the roots
+ */
+ protected VirtualFile[] determineVFSRoots()
+ {
+ if (vfsRoots != null)
+ return vfsRoots;
+
+ ClassPathVisitor visitor = new ClassPathVisitor();
+ try
+ {
+ getDeploymentUnit().visit(visitor);
+ }
+ catch (DeploymentException e)
+ {
+ throw new RuntimeException("Error visiting deployment: " + e);
+ }
+ Set<VirtualFile> classPath = visitor.getClassPath();
+
+ vfsRoots = classPath.toArray(new VirtualFile[classPath.size()]);
+ return vfsRoots;
+ }
+
+ @Override
+ public VFSClassLoaderPolicy getPolicy()
+ {
+ return (VFSClassLoaderPolicy) super.getPolicy();
+ }
+
+ @Override
+ protected VFSClassLoaderPolicy determinePolicy()
+ {
+ VirtualFile[] roots = determineVFSRoots();
+ VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(getContextName(), roots);
+ String[] packageNames = getPackageNames();
+ policy.setExportedPackages(packageNames);
+ policy.setIncluded(getIncluded());
+ policy.setExcluded(getExcluded());
+ policy.setExcludedExport(getExcludedExport());
+ policy.setExportAll(getExportAll());
+ policy.setImportAll(isImportAll());
+ policy.setCacheable(isCacheable());
+ policy.setBlackListable(isBlackListable());
+ policy.setDelegates(getDelegates());
+ return policy;
+ }
+
+ @Override
+ public void reset()
+ {
+ super.reset();
+ vfsRoots = null;
+ }
+}
Deleted: projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSTopLevelClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/main/org/jboss/deployers/vfs/plugins/classloader/VFSTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,74 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2007, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file 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.vfs.plugins.classloader;
-
-import java.net.URL;
-import java.util.Set;
-
-import org.jboss.deployers.plugins.classloading.AbstractTopLevelClassLoaderSystemDeployer;
-import org.jboss.deployers.plugins.classloading.Module;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.vfs.spi.structure.helpers.ClassPathVisitor;
-import org.jboss.virtual.VirtualFile;
-import org.jboss.virtual.plugins.context.memory.MemoryContextFactory;
-
-/**
- * VFSTopLevelClassLoaderSystemDeployer.
- *
- * @author <a href="adrian at jboss.org">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class VFSTopLevelClassLoaderSystemDeployer extends AbstractTopLevelClassLoaderSystemDeployer
-{
- @Override
- protected VFSClassLoaderPolicy createTopLevelClassLoaderPolicy(DeploymentContext context, Module module) throws Exception
- {
- ClassPathVisitor visitor = new ClassPathVisitor();
- context.visit(visitor);
- Set<VirtualFile> classPath = visitor.getClassPath();
-
- VirtualFile[] roots = new VirtualFile[classPath.size() + 1];
- int i = 0;
- for (VirtualFile path : classPath)
- roots[i++] = path;
-
- MemoryContextFactory factory = MemoryContextFactory.getInstance();
- factory.createRoot(module.getDynamicClassRoot());
-
- URL url = new URL(module.getDynamicClassRoot() + "/classes");
- roots[i++] = factory.createDirectory(url).getVirtualFile();
-
- VFSClassLoaderPolicy policy = new VFSClassLoaderPolicy(module.getName(), roots);
- policy.setExportAll(module.getExportAll());
- policy.setImportAll(module.isImportAll());
- // TODO JBMICROCONT-182 more policy from "module"
- return policy;
- }
-
- @Override
- protected void cleanup(DeploymentContext context, Module module) throws Exception
- {
- MemoryContextFactory factory = MemoryContextFactory.getInstance();
- factory.deleteRoot(module.getDynamicClassRoot());
- }
-
-}
Modified: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/ClassLoaderTestSuite.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -21,12 +21,13 @@
*/
package org.jboss.test.deployers.vfs.classloader;
+import org.jboss.test.deployers.vfs.classloader.test.VFSClassLoaderDependenciesUnitTestCase;
+import org.jboss.test.deployers.vfs.classloader.test.VFSUndeployOrderClassLoaderUnitTestCase;
+
import junit.framework.Test;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
-import org.jboss.test.deployers.vfs.classloader.test.ExportAllUnitTestCase;
-
/**
* BeanDeployerTestSuite.
*
@@ -44,7 +45,8 @@
{
TestSuite suite = new TestSuite("VFS ClassLoader Tests");
- suite.addTest(ExportAllUnitTestCase.suite());
+ suite.addTest(VFSClassLoaderDependenciesUnitTestCase.suite());
+ suite.addTest(VFSUndeployOrderClassLoaderUnitTestCase.suite());
return suite;
}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/TestTopLevelClassLoaderSystemDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/TestTopLevelClassLoaderSystemDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/TestTopLevelClassLoaderSystemDeployer.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.classloader.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.plugins.classloading.AbstractTopLevelClassLoaderSystemDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestTopLevelClassLoaderSystemDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestTopLevelClassLoaderSystemDeployer extends AbstractTopLevelClassLoaderSystemDeployer
+{
+ public List<String> deployed = new ArrayList<String>();
+ public List<String> undeployed = new ArrayList<String>();
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ deployed.add(unit.getName());
+ super.deploy(unit);
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ undeployed.add(unit.getName());
+ super.undeploy(unit);
+ }
+}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/a/A.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/a/A.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/a/A.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,33 @@
+/*
+* 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.classloader.support.a;
+
+/**
+ * A.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+
+}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/b/B.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/b/B.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/support/b/B.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,33 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloader.support.b;
+
+/**
+ * B.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}
Deleted: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ExportAllUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ExportAllUnitTestCase.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/ExportAllUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,301 +0,0 @@
-/*
-* 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.classloader.test;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderPolicy;
-import org.jboss.test.BaseTestCase;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * ExportAllUnitTestCase.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @version $Revision: 1.1 $
- */
-public class ExportAllUnitTestCase extends BaseTestCase
-{
- protected void testExportAll(ExportAll exportAll, Map<String, String> expected, String... urls) throws Exception
- {
- Set<String> empty = Collections.emptySet();
- testExportAll(exportAll, expected, empty, urls);
- }
-
- protected void testExportAll(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
- {
- testExportAllAbsolute(exportAll, expected, empty, urls);
- testExportAllFromBase(exportAll, expected, empty, urls);
- }
-
- protected void testExportAllCommon(ExportAll exportAll, Map<String, String> expected, Set<String> empty, VirtualFile[] files) throws Exception
- {
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(files);
- policy.setExportAll(exportAll);
-
- String[] packageNames = policy.getPackageNames();
- Set<String> actual = makeSet(packageNames);
- assertEquals(expected.keySet(), actual);
-
- ClassLoaderSystem system = new DefaultClassLoaderSystem();
- ClassLoader classLoader = system.registerClassLoaderPolicy(policy);
-
- for (Map.Entry<String, String> entry : expected.entrySet())
- {
- String packageName = entry.getKey();
- String resource = packageName.replace('.', '/') + "/notempty";
- InputStream is = classLoader.getResourceAsStream(resource);
- if (empty.contains(packageName))
- assertNull("Did not expect resource: " + resource, is);
- else
- {
- assertNotNull("Did not find resource: " + resource, is);
- String contents = getContents(is);
- assertEquals(entry.getValue(), contents);
- }
- }
- }
-
- protected void testExportAllFromBase(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
- {
- URL baseURL = getResource("/classloader");
- assertNotNull(baseURL);
- VirtualFile base = VFS.getRoot(baseURL);
- VirtualFile[] files = new VirtualFile[urls.length];
- for (int i = 0; i < urls.length; ++i)
- files[i] = base.findChild(urls[i]);
-
- testExportAllCommon(exportAll, expected, empty, files);
- }
-
- protected void testExportAllAbsolute(ExportAll exportAll, Map<String, String> expected, Set<String> empty, String... urls) throws Exception
- {
- VirtualFile[] files = new VirtualFile[urls.length];
- for (int i = 0; i < urls.length; ++i)
- {
- String urlString = "/classloader/" + urls[i];
- URL url = getResource(urlString);
- assertNotNull("Expected to find resource: " + urlString, url);
- files[i]= VFS.getRoot(url);
- }
-
- testExportAllCommon(exportAll, expected, empty, files);
- }
-
- public void testExportAllJar1() throws Exception
- {
- Map<String,String> expected = makeSimpleMap("testjar1",
- "",
- "package1",
- "package2",
- "package2.subpackage1",
- "package2.subpackage2",
- "package2.subpackage3"
- );
-
- testExportAll(ExportAll.ALL, expected, "testjar1");
- }
- public void testJar1Resources()
- throws Exception
- {
- URL testjar1URL = getResource("/classloader/testjar1");
- VirtualFile testjar1 = VFS.getRoot(testjar1URL);
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(testjar1);
- policy.setExportAll(ExportAll.ALL);
-
- ClassLoaderSystem system = new DefaultClassLoaderSystem();
- ClassLoader classLoader = system.registerClassLoaderPolicy(policy);
- URL notempty = classLoader.getResource("notempty");
- assertNotNull(notempty);
- }
- public void testWar1Resources()
- throws Exception
- {
- URL testwar1URL = getResource("/classloader/testwar1.war");
- VirtualFile testwar1 = VFS.getRoot(testwar1URL);
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(testwar1);
- policy.setExportAll(ExportAll.NON_EMPTY);
- policy.setImportAll(true);
-
- ClassLoaderSystem system = new DefaultClassLoaderSystem();
- ClassLoader classLoader = system.registerClassLoaderPolicy(policy);
- URL resURL = classLoader.getResource("test-resource.txt");
- assertNull(resURL);
- resURL = classLoader.getResource("WEB-INF/test-resource.txt");
- assertNotNull(resURL);
- }
-
- public void testExportAllJar1NonEmpty() throws Exception
- {
- Map<String, String> expected = makeSimpleMap("testjar1",
- "",
- "package1",
- "package2",
- "package2.subpackage1",
- "package2.subpackage2",
- "package2.subpackage3"
- );
-
- testExportAll(ExportAll.NON_EMPTY, expected, "testjar1");
- }
-
- public void testExportAllJar2() throws Exception
- {
- Map<String,String> expected = makeSimpleMap("testjar2",
- "",
- "package1"
- );
-
- Set<String> empty = makeSet("");
-
- testExportAll(ExportAll.ALL, expected, empty, "testjar2");
- }
-
- public void testExportAllJar2NonEmpty() throws Exception
- {
- Map<String, String> expected = makeSimpleMap("testjar2",
- "package1"
- );
-
- testExportAll(ExportAll.NON_EMPTY, expected, "testjar2");
- }
-
- public void testExportAllJar1And2() throws Exception
- {
- Map<String,String> expected = makeSimpleMap("testjar1",
- "",
- "package1",
- "package2",
- "package2.subpackage1",
- "package2.subpackage2",
- "package2.subpackage3"
- );
-
- testExportAll(ExportAll.ALL, expected, "testjar1", "testjar2");
- }
-
- public void testExportAllJar1And2NonEmpty() throws Exception
- {
- Map<String, String> expected = makeSimpleMap("testjar1",
- "",
- "package1",
- "package2",
- "package2.subpackage1",
- "package2.subpackage2",
- "package2.subpackage3"
- );
-
- testExportAll(ExportAll.NON_EMPTY, expected, "testjar1", "testjar2");
- }
-
- public void testExportAllJar2And1() throws Exception
- {
- Map<String,String> expected = makeComplexMap(
- "", "testjar1",
- "package1", "testjar2",
- "package2", "testjar1",
- "package2.subpackage1", "testjar1",
- "package2.subpackage2", "testjar1",
- "package2.subpackage3", "testjar1"
- );
-
- testExportAll(ExportAll.ALL, expected, "testjar2", "testjar1");
- }
-
- public void testExportAllJar2And1NonEmpty() throws Exception
- {
- Map<String, String> expected = makeComplexMap(
- "", "testjar1",
- "package1", "testjar2",
- "package2", "testjar1",
- "package2.subpackage1", "testjar1",
- "package2.subpackage2", "testjar1",
- "package2.subpackage3", "testjar1"
- );
-
- testExportAll(ExportAll.NON_EMPTY, expected, "testjar2", "testjar1");
- }
-
- protected String getContents(InputStream is) throws Exception
- {
- StringBuilder builder = new StringBuilder();
- InputStreamReader reader = new InputStreamReader(is);
- int character = reader.read();
- while (character != -1)
- {
- builder.append((char) character);
- character = reader.read();
- }
- return builder.toString();
- }
-
- protected Set<String> makeSet(String... elements)
- {
- assertNotNull(elements);
- Set<String> result = new HashSet<String>();
- for (String string : elements)
- result.add(string);
- return result;
- }
-
- protected Map<String,String> makeSimpleMap(String prefix, String... elements)
- {
- assertNotNull(prefix);
- assertNotNull(elements);
- Map<String, String> result = new HashMap<String, String>();
- for (String string : elements)
- result.put(string, prefix + "." + string);
- return result;
- }
-
- protected Map<String,String> makeComplexMap(String... elements)
- {
- assertNotNull(elements);
- Map<String, String> result = new HashMap<String, String>();
- for (int i = 0; i < elements.length; i += 2)
- result.put(elements[i], elements[i+1] + '.' + elements[i]);
- return result;
- }
-
- public static Test suite()
- {
- return new TestSuite(ExportAllUnitTestCase.class);
- }
-
- public ExportAllUnitTestCase(String name) throws Throwable
- {
- super(name);
- }
-}
Deleted: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/FilteredExportUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/FilteredExportUnitTestCase.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/FilteredExportUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -1,295 +0,0 @@
-/*
-* 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.classloader.test;
-
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
-import org.jboss.classloader.spi.ClassLoaderDomain;
-import org.jboss.classloader.spi.ClassLoaderSystem;
-import org.jboss.classloader.spi.ParentPolicy;
-import org.jboss.deployers.structure.spi.classloading.ExportAll;
-import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderPolicy;
-import org.jboss.test.BaseTestCase;
-import org.jboss.virtual.VFS;
-import org.jboss.virtual.VirtualFile;
-
-/**
- * FilteredExportUnitTestCase tests of multiple bundle behavior.
- *
- * @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author Scott.Stark at jboss.org
- * @version $Revision$
- */
-public class FilteredExportUnitTestCase extends BaseTestCase
-{
- ClassLoaderSystem system;
-
- public FilteredExportUnitTestCase(String name)
- {
- super(name);
- }
-
- protected void setUp()
- throws Exception
- {
- super.setUp();
- system = new DefaultClassLoaderSystem();
- ClassLoaderDomain domain = system.getDefaultDomain();
- domain.setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
- }
- protected void tearDown()
- throws Exception
- {
- system.shutdown();
- super.tearDown();
- }
- protected ClassLoader buildClassLoader(ExportAll exportAll, Map<String, String> expected, VirtualFile[] files, String[] exportPkgs)
- throws Exception
- {
- return buildClassLoader(exportAll, expected, files, exportPkgs, null);
- }
- protected ClassLoader buildClassLoader(ExportAll exportAll, Map<String, String> expected, VirtualFile[] files,
- String[] exportPkgs, Set<String> excludedPkgs)
- throws Exception
- {
- VFSClassLoaderPolicy policy = VFSClassLoaderPolicy.createVFSClassLoaderPolicy(files);
- if(excludedPkgs != null)
- policy.setExcludedPackages(excludedPkgs);
- if(exportPkgs != null)
- policy.setExportedPackages(exportPkgs);
- else
- policy.setExportAll(exportAll);
- policy.setImportAll(true);
- String[] packageNames = policy.getPackageNames();
- Set<String> actual = makeSet(packageNames);
- log.info(policy+" : packages: "+actual);
- if(expected != null)
- assertEquals(expected.keySet(), actual);
-
- ClassLoader classLoader = system.registerClassLoaderPolicy(policy);
- return classLoader;
- }
-
- protected String getContents(InputStream is) throws Exception
- {
- StringBuilder builder = new StringBuilder();
- InputStreamReader reader = new InputStreamReader(is);
- int character = reader.read();
- while (character != -1)
- {
- builder.append((char) character);
- character = reader.read();
- }
- return builder.toString();
- }
-
- protected Set<String> makeSet(String... elements)
- {
- assertNotNull(elements);
- Set<String> result = new HashSet<String>();
- for (String string : elements)
- result.add(string);
- return result;
- }
-
- protected Map<String,String> makeSimpleMap(String prefix, String... elements)
- {
- assertNotNull(prefix);
- assertNotNull(elements);
- Map<String, String> result = new HashMap<String, String>();
- for (String string : elements)
- result.put(string, prefix + "." + string);
- return result;
- }
-
- protected Map<String,String> makeComplexMap(String... elements)
- {
- assertNotNull(elements);
- Map<String, String> result = new HashMap<String, String>();
- for (int i = 0; i < elements.length; i += 2)
- result.put(elements[i], elements[i+1] + '.' + elements[i]);
- return result;
- }
-
- public static Test suite()
- {
- return new TestSuite(FilteredExportUnitTestCase.class);
- }
-
- /**
- *
- * @throws Exception
- */
- public void testEar1() throws Exception
- {
- Map<String,String> expectedEar = makeSimpleMap("testear1.ear",
- "",
- "util"
- );
- // Need to get the testear1.ear URL from a class resource
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- URL libClassURL = loader.getResource("ClassInTestear1Lib.class");
- assertNotNull(libClassURL);
- URL ear1URL = new URL(libClassURL, "../../");
-
- VirtualFile earRoot = VFS.getRoot(ear1URL);
- VirtualFile[] ear1Files = {earRoot.getChild("lib/jar1.jar")};
- buildClassLoader(ExportAll.NON_EMPTY, expectedEar, ear1Files, null);
- // ejb1.jar
- Map<String,String> expectedEjb1 = makeSimpleMap("testear1.ear",
- "",
- "pkg1.ejbs",
- "pkg1.ifaces"
- );
- /*
- URL usersURL = ear1Loader.getResource("META-INF/users.properties");
- log.info("users.properties: "+usersURL);
- assertNotNull(usersURL);
- assertTrue(usersURL.toString().contains("testear1.ear/META-INF"));
-*/
- VirtualFile ejb1Root = earRoot.getChild("ejb1.jar");
- VirtualFile[] ejb1Files = {ejb1Root};
- ClassLoader ejb1Loader = buildClassLoader(ExportAll.NON_EMPTY, expectedEjb1, ejb1Files, null);
-
- URL usersURL = ejb1Loader.getResource("users.properties");
- log.info("users.properties: "+usersURL);
- assertNotNull(usersURL);
- assertTrue(usersURL.toString().contains("ejb1"));
-
- Enumeration<URL> userURLs = ejb1Loader.getResources("users.properties");
- assertNotNull(userURLs);
- int count = 0;
- boolean sawEarUsersProperties = false;
- boolean sawEjbUsersProperties = false;
- while(userURLs.hasMoreElements())
- {
- URL url = userURLs.nextElement();
- if(url.toString().contains("lib/jar1.jar"))
- sawEarUsersProperties = true;
- if(url.toString().contains("ejb1.jar"))
- sawEjbUsersProperties = true;
- log.info(url);
- count ++;
- }
- assertEquals("Saw 2 users.properties", 2, count);
- assertTrue("sawEarUsersProperties", sawEarUsersProperties);
- assertTrue("sawEjbUsersProperties", sawEjbUsersProperties);
-
- // war1.war
- Map<String,String> expectedWeb1 = makeSimpleMap("testear1.ear",
- "",
- "web"
- );
- super.enableTrace("org.jboss.deployers.vfs.plugins.classloader");
- VirtualFile war1Root = earRoot.getChild("war1.war");
- VirtualFile war1Classes = war1Root.getChild("WEB-INF/classes");
- VirtualFile war1WebInf = war1Root.getChild("WEB-INF");
- VirtualFile[] war1Files = {war1Root, war1Classes, war1WebInf};
- String[] webPkgs = {"", "web"};
- ClassLoader war1Loader = buildClassLoader(ExportAll.NON_EMPTY, expectedWeb1, war1Files, webPkgs);
- Set<String> excludedPkgs = makeSet("WEB-INF", "META-INF", "java", "classes");
- ClassLoader war1LoaderAll = buildClassLoader(ExportAll.NON_EMPTY, expectedWeb1, war1Files, null, excludedPkgs);
- URL jdkClassURL = war1Loader.getResource("java/lang/JdkClass.class");
- assertNull(jdkClassURL);
- // Test that the java.* package was excluded
- try
- {
- Class<?> jdkClass = war1LoaderAll.loadClass("java.lang.JdkClass");
- fail("Was able to load java.lang.JdkClass: "+jdkClass.getProtectionDomain());
- }
- catch(ClassNotFoundException e)
- {
- log.debug("CNFE for java.lang.JdkClass");
- }
- jdkClassURL = war1LoaderAll.getResource("java/lang/JdkClass.class");
- assertNull(jdkClassURL);
- system.unregisterClassLoader(war1LoaderAll);
- // Should be able to load java/lang/JdkClass.class as resource if java is not excluded
- war1LoaderAll = buildClassLoader(ExportAll.NON_EMPTY, null, war1Files, null);
- jdkClassURL = war1LoaderAll.getResource("java/lang/JdkClass.class");
- assertNull(jdkClassURL);
-
- }
-
- /**
- * Compressed ear version of testEar1
- * @throws Exception
- */
- public void testEar1x() throws Exception
- {
- Map<String,String> expectedEar = makeSimpleMap("testear1x.ear",
- "",
- "util"
- );
- URL ear1URL = getResource("/classloader/testear1x.ear");
- log.info(ear1URL);
- assertNotNull(ear1URL);
- VirtualFile earRoot = VFS.getRoot(ear1URL);
- log.info(earRoot);
- VirtualFile[] ear1Files = {earRoot.getChild("lib/jar1.jar")};
- buildClassLoader(ExportAll.NON_EMPTY, expectedEar, ear1Files, null);
- // ejb1.jar
- Map<String,String> expectedEjb1 = makeSimpleMap("testear1x.ear",
- "",
- "pkg1.ejbs",
- "pkg1.ifaces"
- );
- VirtualFile ejb1Root = earRoot.getChild("ejb1.jar");
- log.info(ejb1Root);
- VirtualFile[] ejb1Files = {ejb1Root};
- ClassLoader ejb1Loader = buildClassLoader(ExportAll.NON_EMPTY, expectedEjb1, ejb1Files, null);
-
- URL usersURL = ejb1Loader.getResource("users.properties");
- log.info("users.properties: "+usersURL);
- assertNotNull(usersURL);
- assertTrue(usersURL.toString().contains("ejb1"));
-
- Enumeration<URL> userURLs = ejb1Loader.getResources("users.properties");
- assertNotNull(userURLs);
- int count = 0;
- boolean sawEarUsersProperties = false;
- boolean sawEjbUsersProperties = false;
- while(userURLs.hasMoreElements())
- {
- URL url = userURLs.nextElement();
- if(url.toString().contains("lib/jar1.jar"))
- sawEarUsersProperties = true;
- if(url.toString().contains("ejb1.jar"))
- sawEjbUsersProperties = true;
- log.info(url);
- count ++;
- }
- assertEquals("Saw 2 users.properties", 2, count);
- assertTrue("sawEarUsersProperties", sawEarUsersProperties);
- assertTrue("sawEjbUsersProperties", sawEjbUsersProperties);
- }
-}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesTest.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesTest.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,260 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloader.test;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.classloader.plugins.jdk.AbstractJDKChecker;
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.classloading.spi.dependency.ClassLoading;
+import org.jboss.classloading.spi.metadata.CapabilitiesMetaData;
+import org.jboss.classloading.spi.metadata.Capability;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
+import org.jboss.classloading.spi.metadata.Requirement;
+import org.jboss.classloading.spi.metadata.RequirementsMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDescribeDeployer;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.vfs.plugins.classloader.VFSClassLoaderDescribeDeployer;
+import org.jboss.deployers.vfs.spi.client.VFSDeployment;
+import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
+import org.jboss.test.deployers.BaseDeployersVFSTest;
+import org.jboss.test.deployers.vfs.classloader.support.TestTopLevelClassLoaderSystemDeployer;
+import org.jboss.virtual.VFS;
+import org.jboss.virtual.VirtualFile;
+
+/**
+ * ClassLoadersDependencies test.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class VFSClassLoaderDependenciesTest extends BaseDeployersVFSTest
+{
+ private static ClassLoadingMetaDataFactory classLoadingMetaDataFactory = ClassLoadingMetaDataFactory.getInstance();
+
+ public static final String NameA = "A";
+ public static final String NameB = "B";
+
+ public static final List<String> NONE = Collections.emptyList();
+ public static final List<String> XA = makeList(NameA);
+ public static final List<String> XB = makeList(NameB);
+ public static final List<String> XAB = makeList(NameA, NameB);
+ public static final List<String> XBA = makeList(NameB, NameA);
+ public static final List<String> XBAA = makeList(NameB, NameA, NameA);
+ public static final List<String> XBABA = makeList(NameB, NameA, NameB, NameA);
+
+ @SuppressWarnings("unchecked")
+ protected static <T> List<T> makeList(T... objects)
+ {
+ List<T> result = new ArrayList<T>();
+ for (T object : objects)
+ result.add(object);
+ return result;
+ }
+
+ protected AbstractClassLoaderDescribeDeployer deployer1;
+ protected TestTopLevelClassLoaderSystemDeployer deployer2;
+
+ protected VFSClassLoaderDependenciesTest(String name)
+ {
+ super(name);
+ }
+
+ /**
+ * Create a deployment
+ *
+ * @param name the name
+ * @return the deployment
+ * @throws Exception for any error
+ */
+ protected VFSDeployment createDeployment(String name) throws Exception
+ {
+ URL url = getClass().getProtectionDomain().getCodeSource().getLocation();
+ VirtualFile file = VFS.getRoot(url);
+ VFSDeployment deployment = VFSDeploymentFactory.getInstance().createVFSDeployment(file);
+ DeploymentFactory factory = new DeploymentFactory();
+ factory.addContext(deployment, "");
+ ((AbstractDeployment) deployment).setName(name);
+ return deployment;
+ }
+
+ protected Class<?> assertLoadClass(ClassLoader start, Class<?> reference) throws Exception
+ {
+ return assertLoadClass(start, reference, start);
+ }
+
+ protected Class<?> assertLoadClass(ClassLoader start, Class<?> reference, ClassLoader expected) throws Exception
+ {
+ Class<?> clazz = start.loadClass(reference.getName());
+ if (expected != null)
+ assertEquals(expected, clazz.getClassLoader());
+ return clazz;
+ }
+
+ protected void assertLoadClassFail(ClassLoader start, Class<?> reference) throws Exception
+ {
+ try
+ {
+ start.loadClass(reference.getName());
+ fail("Should not be here!");
+ }
+ catch (Exception e)
+ {
+ checkThrowable(ClassNotFoundException.class, e);
+ }
+ }
+
+ protected void assertLoadClassIllegal(ClassLoader start, Class<?> reference) throws Exception
+ {
+ try
+ {
+ start.loadClass(reference.getName());
+ fail("Should not be here!");
+ }
+ catch (Exception e)
+ {
+ checkThrowable(IllegalStateException.class, e);
+ }
+ }
+
+ protected void assertNoClassLoader(DeploymentUnit unit) throws Exception
+ {
+ try
+ {
+ unit.getClassLoader();
+ fail("Should not be here!");
+ }
+ catch (Exception e)
+ {
+ checkThrowable(IllegalStateException.class, e);
+ }
+ }
+
+ protected static ClassLoadingMetaData addClassLoadingMetaData(Deployment deployment, Version version, Class<?>... packages)
+ {
+ return addClassLoadingMetaData(deployment, version, false, packages);
+ }
+
+ protected static ClassLoadingMetaData addClassLoadingMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ {
+ ClassLoadingMetaData classLoadingMetaData = createMetaData(deployment, version, useVersionOnPackages, packages);
+ addMetaData(deployment, classLoadingMetaData);
+ return classLoadingMetaData;
+ }
+
+ protected static ClassLoadingMetaData createMetaData(Deployment deployment, Version version, Class<?>... packages)
+ {
+ return createMetaData(deployment, version, false, packages);
+ }
+
+ protected static ClassLoadingMetaData createMetaData(Deployment deployment, Version version, boolean useVersionOnPackages, Class<?>... packages)
+ {
+ String name = deployment.getName();
+ ClassLoadingMetaData classLoadingMetaData = new ClassLoadingMetaData();
+ classLoadingMetaData.setName(name);
+ classLoadingMetaData.setVersion(version);
+
+ StringBuffer included = new StringBuffer();
+ boolean first = true;
+ for (Class<?> pkg : packages)
+ {
+ if (first)
+ first = false;
+ else
+ included.append(",");
+ included.append(pkg.getPackage().getName());
+ }
+ classLoadingMetaData.setIncludedPackages(included.toString());
+
+ CapabilitiesMetaData capabilities = classLoadingMetaData.getCapabilities();
+ Capability capability = classLoadingMetaDataFactory.createModule(name, version);
+ capabilities.addCapability(capability);
+
+ if (packages != null)
+ {
+ for (Class<?> pkg : packages)
+ {
+ if (useVersionOnPackages)
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName(), version);
+ else
+ capability = classLoadingMetaDataFactory.createPackage(pkg.getPackage().getName());
+ capabilities.addCapability(capability);
+ }
+ }
+
+ classLoadingMetaData.setCapabilities(capabilities);
+ return classLoadingMetaData;
+ }
+
+ protected static void addRequireModule(ClassLoadingMetaData classLoadingMetaData, String moduleName, VersionRange versionRange)
+ {
+ RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
+
+ Requirement requirement = classLoadingMetaDataFactory.createRequireModule(moduleName, versionRange);
+ requirements.addRequirement(requirement);
+ }
+
+ protected static void addRequirePackage(ClassLoadingMetaData classLoadingMetaData, Class<?> pck, VersionRange versionRange)
+ {
+ RequirementsMetaData requirements = classLoadingMetaData.getRequirements();
+
+ Requirement requirement = classLoadingMetaDataFactory.createRequirePackage(pck.getPackage().getName(), versionRange);
+ requirements.addRequirement(requirement);
+ }
+
+ protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, ClassLoadingMetaData md)
+ {
+ MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+ mutable.addAttachment(ClassLoadingMetaData.class, md);
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ AbstractJDKChecker.getExcluded().add(VFSClassLoaderDependenciesTest.class);
+
+ ClassLoading classLoading = new ClassLoading();
+ ClassLoaderSystem system = new DefaultClassLoaderSystem();
+ system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+
+ deployer1 = new VFSClassLoaderDescribeDeployer();
+ deployer1.setClassLoading(classLoading);
+
+ deployer2 = new TestTopLevelClassLoaderSystemDeployer();
+ deployer2.setClassLoading(classLoading);
+ deployer2.setSystem(system);
+
+ return createMainDeployer(deployer1, deployer2);
+ }
+}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSClassLoaderDependenciesUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,238 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, 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.classloader.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.test.deployers.vfs.classloader.support.a.A;
+import org.jboss.test.deployers.vfs.classloader.support.b.B;
+
+/**
+ * VFSClassLoaderDependenciesUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VFSClassLoaderDependenciesUnitTestCase extends VFSClassLoaderDependenciesTest
+{
+ public static Test suite()
+ {
+ return new TestSuite(VFSClassLoaderDependenciesUnitTestCase.class);
+ }
+
+ public VFSClassLoaderDependenciesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleClassLoader() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deployment = createDeployment(NameA);
+ addClassLoadingMetaData(deployment, null, A.class);
+
+ DeploymentUnit unit = assertDeploy(deployer, deployment);
+
+ assertEquals(XA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader cl = unit.getClassLoader();
+ enableTrace("org.jboss.classloader");
+ assertLoadClass(cl, A.class);
+
+ assertUndeploy(deployer, deployment);
+
+ assertLoadClass(cl, A.class);
+
+ assertEquals(XA, deployer2.deployed);
+ assertEquals(XA, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBCorrectWay() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentB = createDeployment(NameB);
+ addClassLoadingMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XB, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentA = createDeployment(NameA);
+ ClassLoadingMetaData classLoadingMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoadingMetaData, "B", null);
+ DeploymentUnit unitA = assertDeploy(deployer, deploymentA);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XA, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentB);
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XAB, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBWrongWay() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createDeployment(NameA);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = addDeployment(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createDeployment(NameB);
+ addClassLoadingMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XA, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentB);
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XAB, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBRedeployA() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createDeployment(NameA);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = addDeployment(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createDeployment(NameB);
+ addClassLoadingMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XA, deployer2.undeployed);
+
+ unitA = assertDeploy(deployer, deploymentA);
+ clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(XBAA, deployer2.deployed);
+ assertEquals(XA, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBRedeployB() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createDeployment(NameA);
+ ClassLoadingMetaData classLoaderMetaData = addClassLoadingMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = addDeployment(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createDeployment(NameB);
+ addClassLoadingMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ enableTrace("org.jboss.deployers");
+ enableTrace("org.jboss.dependency");
+ assertUndeploy(deployer, deploymentB);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(XBA, deployer2.deployed);
+ assertEquals(XAB, deployer2.undeployed);
+
+ unitB = assertDeploy(deployer, deploymentB);
+ clA = unitA.getClassLoader();
+ clB = unitB.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(XBABA, deployer2.deployed);
+ assertEquals(XAB, deployer2.undeployed);
+ }
+}
Added: projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSUndeployOrderClassLoaderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSUndeployOrderClassLoaderUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-vfs/src/tests/org/jboss/test/deployers/vfs/classloader/test/VFSUndeployOrderClassLoaderUnitTestCase.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -0,0 +1,99 @@
+/*
+* 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.classloader.test;
+
+import junit.framework.Test;
+
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
+import org.jboss.classloading.spi.version.Version;
+import org.jboss.classloading.spi.version.VersionRange;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.test.deployers.vfs.classloader.support.a.A;
+import org.jboss.test.deployers.vfs.classloader.support.b.B;
+
+/**
+ * Undeploy order test case.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class VFSUndeployOrderClassLoaderUnitTestCase extends VFSClassLoaderDependenciesTest
+{
+ public VFSUndeployOrderClassLoaderUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(VFSUndeployOrderClassLoaderUnitTestCase.class);
+ }
+
+ public void testUndeployOrder() throws Exception
+ {
+ DeployerClient mainDeployer = getMainDeployer();
+ Version v1 = Version.parseVersion("1");
+ Version v2 = Version.parseVersion("2");
+
+ Deployment ad = createDeployment("A");
+ addClassLoadingMetaData(ad, v1, true, A.class);
+ assertDeploy(mainDeployer, ad);
+
+ Deployment bd = createDeployment("B");
+ addClassLoadingMetaData(bd, v2, true, B.class);
+ assertDeploy(mainDeployer, bd);
+ mainDeployer.checkComplete(bd);
+
+ Deployment cd = createDeployment("C");
+ ClassLoadingMetaData clmd = addClassLoadingMetaData(cd, null);
+ addRequirePackage(clmd, A.class, new VersionRange(v1, true, v2, true));
+ addRequirePackage(clmd, B.class, new VersionRange(v1, true, v2, true));
+ assertDeploy(mainDeployer, cd);
+
+ mainDeployer.checkComplete();
+
+ mainDeployer.undeploy(bd);
+ try
+ {
+ mainDeployer.checkComplete();
+ fail("Should not be here!");
+ }
+ catch (DeploymentException e)
+ {
+ checkThrowable(IncompleteDeploymentException.class, e);
+ }
+ mainDeployer.undeploy(ad);
+ try
+ {
+ mainDeployer.checkComplete();
+ fail("Should not be here!");
+ }
+ catch (DeploymentException e)
+ {
+ checkThrowable(IncompleteDeploymentException.class, e);
+ }
+ mainDeployer.undeploy(cd);
+ mainDeployer.checkComplete();
+ }
+}
Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/ClassPathVisitor.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/ClassPathVisitor.java 2008-02-19 15:50:53 UTC (rev 69934)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/structure/helpers/ClassPathVisitor.java 2008-02-19 15:54:00 UTC (rev 69935)
@@ -26,9 +26,9 @@
import java.util.Set;
import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
-import org.jboss.deployers.vfs.spi.structure.VFSDeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
+import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
import org.jboss.virtual.VirtualFile;
/**
@@ -37,7 +37,7 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public class ClassPathVisitor implements DeploymentContextVisitor
+public class ClassPathVisitor implements DeploymentUnitVisitor
{
/** The full classpath */
private Set<VirtualFile> classPath = new LinkedHashSet<VirtualFile>();
@@ -52,15 +52,17 @@
return classPath;
}
- public void visit(DeploymentContext context) throws DeploymentException
+ public void visit(DeploymentUnit unit) throws DeploymentException
{
- VFSDeploymentContext vfsContext = (VFSDeploymentContext) context;
- List<VirtualFile> paths = vfsContext.getClassPath();
+ if (unit instanceof VFSDeploymentUnit == false)
+ return;
+ VFSDeploymentUnit vfsUnit = (VFSDeploymentUnit) unit;
+ List<VirtualFile> paths = vfsUnit.getClassPath();
if (paths != null)
classPath.addAll(paths);
}
- public void error(DeploymentContext context)
+ public void error(DeploymentUnit context)
{
// nothing
}
More information about the jboss-cvs-commits
mailing list