[jboss-cvs] JBossAS SVN: r64469 - in projects/microcontainer/trunk: deployers-impl/src/main/org/jboss/deployers/plugins/deployers and 13 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Aug 6 09:37:41 EDT 2007
Author: adrian at jboss.org
Date: 2007-08-06 09:37:41 -0400 (Mon, 06 Aug 2007)
New Revision: 64469
Added:
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDesribeDeployer.java
projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/DeployersClassLoadingTestSuite.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/
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/a/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/a/A.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/b/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/b/B.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java
projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/ModuleCapabilityImpl.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/PackageCapabilityImpl.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequireModuleImpl.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequirePackageImpl.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/VersionImpl.java
Modified:
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/deployers/DeployersImpl.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractClassLoaderDeployer.java
projects/microcontainer/trunk/deployers-structure-spi/.classpath
projects/microcontainer/trunk/deployers-structure-spi/pom.xml
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Capability.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/ClassLoaderMetaData.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/PackageCapability.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Requirement.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Version.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/VersionRange.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructureBuilder.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractOptionalVFSRealDeployer.java
Log:
[JBMICROCONT-182] - Make a start on classloader dependencies from metadata - very hack at the moment. Also fixed it so that the classloader deployer removes the classloader rather than waiting for full undeployment.
Added: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDesribeDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDesribeDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/AbstractClassLoaderDesribeDeployer.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,91 @@
+/*
+* 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.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;
+
+/**
+ * AbstractClassLoaderDesribeDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class AbstractClassLoaderDesribeDeployer extends AbstractOptionalRealDeployer<ClassLoaderMetaData>
+{
+ /** The classloading */
+ private ClassLoading classLoading;
+
+ /**
+ * Create a new AbstractClassLoaderDesribeDeployer.
+ */
+ public AbstractClassLoaderDesribeDeployer()
+ {
+ super(ClassLoaderMetaData.class);
+ setStage(DeploymentStages.DESCRIBE);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * Check the configuration
+ *
+ * @throws Exception for any error
+ */
+ public void create() throws Exception
+ {
+ if (classLoading == null)
+ throw new DeploymentException("Classloading has not been configured");
+ }
+
+ public void deploy(DeploymentUnit unit, ClassLoaderMetaData deployment) throws DeploymentException
+ {
+ classLoading.addDeploymentUnit(unit);
+ }
+
+ public void undeploy(DeploymentUnit unit, ClassLoaderMetaData deployment)
+ {
+ classLoading.removeDeploymentUnit(unit);
+ }
+
+}
Modified: 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 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/ClassLoading.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -28,6 +28,7 @@
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.
@@ -54,11 +55,12 @@
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);
- // TODO JBMICROCONT-182 default version
+ metadata.setVersion(Version.DEFAULT_VERSION);
deploymentUnit.addAttachment(ClassLoaderMetaData.class, metadata);
}
Modified: 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 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Domain.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,15 +21,20 @@
*/
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 $
*/
@@ -65,7 +70,7 @@
}
/**
- * Add a deployment context
+ * Add a deployment unit
*
* @param deploymentUnit the deployment unit
* @param metadata the classloader metadata
@@ -78,11 +83,54 @@
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;
+ }
/**
- * Remove a deployment context
+ * 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)
Modified: 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 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/Module.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,14 +21,21 @@
*/
package org.jboss.deployers.plugins.classloading;
+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;
/**
* Module.
@@ -47,8 +54,8 @@
/** The classloader metadata */
private ClassLoaderMetaData metadata;
- /** The delegates */
- private List<? extends DelegateLoader> delegates;
+ /** The requirements */
+ private List<RequirementDependencyItem> requirementDependencies;
/**
* Create a new Module.
@@ -72,6 +79,16 @@
}
/**
+ * Get the name of the module
+ *
+ * @return the string
+ */
+ public String getName()
+ {
+ return deploymentUnit.getName();
+ }
+
+ /**
* Get the deploymentUnit.
*
* @return the deploymentUnit.
@@ -167,23 +184,87 @@
*/
public List<? extends DelegateLoader> getDelegates()
{
- return delegates;
+ // 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()
{
- // TODO JBMICROCONT-186 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()
{
- delegates = null;
}
/**
Added: 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 (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/classloading/RequirementDependencyItem.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,107 @@
+/*
+* 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.getName(), 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 void unresolved()
+ {
+ setIDependOn(null);
+ setResolved(false);
+ }
+
+ 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();
+ }
+}
Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -379,7 +379,8 @@
{
controller.uninstall(deploymentControllerContext.getName());
setState(context, DeploymentState.UNDEPLOYED, null);
- // TODO JBMICROCONT-182 perform with the deployer that created the classloader?
+ // This is now in the abstract classloader deployer.undeploy,
+ // but left here in case somebody isn't using that.
removeClassLoader(context);
log.debug("Fully Undeployed " + context.getName());
}
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/AbstractDeployerTest.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -36,6 +36,7 @@
import org.jboss.deployers.spi.deployer.Deployers;
import org.jboss.deployers.spi.structure.ContextInfo;
import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.structure.spi.StructuralDeployers;
import org.jboss.deployers.structure.spi.StructureBuilder;
import org.jboss.deployers.structure.spi.helpers.AbstractStructuralDeployers;
@@ -137,6 +138,39 @@
return context;
}
+ protected DeploymentUnit getDeploymentUnit(DeployerClient main, String name)
+ {
+ MainDeployerImpl mainDeployerImpl = (MainDeployerImpl) main;
+ return mainDeployerImpl.getDeploymentUnit(name);
+ }
+
+ protected DeploymentUnit assertDeploymentUnit(DeployerClient main, String name)
+ {
+ DeploymentUnit unit = getDeploymentUnit(main, name);
+ assertNotNull(name + " not found", unit);
+ return unit;
+ }
+
+ protected DeploymentUnit deploy(DeployerClient main, Deployment deployment) throws Exception
+ {
+ main.deploy(deployment);
+ DeploymentUnit unit = assertDeploymentUnit(main, deployment.getName());
+ return unit;
+ }
+
+ protected DeploymentUnit assertDeploy(DeployerClient main, Deployment deployment) throws Exception
+ {
+ main.deploy(deployment);
+ DeploymentUnit unit = assertDeploymentUnit(main, deployment.getName());
+ main.checkComplete();
+ return unit;
+ }
+
+ protected void assertUndeploy(DeployerClient main, Deployment deployment) throws Exception
+ {
+ main.undeploy(deployment);
+ }
+
protected Deployment createSimpleDeployment(String name)
{
AbstractDeployment unit = new AbstractDeployment(name);
Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/DeployersImplTestSuite.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,6 +21,7 @@
*/
package org.jboss.test.deployers;
+import org.jboss.test.deployers.classloading.DeployersClassLoadingTestSuite;
import org.jboss.test.deployers.deployer.DeployersDeployerTestSuite;
import org.jboss.test.deployers.managed.DeployersManagedTestSuite;
@@ -47,6 +48,7 @@
suite.addTest(DeployersDeployerTestSuite.suite());
suite.addTest(DeployersManagedTestSuite.suite());
+ suite.addTest(DeployersClassLoadingTestSuite.suite());
return suite;
}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/DeployersClassLoadingTestSuite.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/DeployersClassLoadingTestSuite.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/DeployersClassLoadingTestSuite.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,51 @@
+/*
+* 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;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.jboss.test.deployers.classloading.test.MockClassLoaderDependenciesUnitTestCase;
+
+/**
+ * Deployers Deployer Test Suite.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 37459 $
+ */
+public class DeployersClassLoadingTestSuite extends TestSuite
+{
+ public static void main(String[] args)
+ {
+ TestRunner.run(suite());
+ }
+
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Deployers ClassLoading Tests");
+
+ suite.addTest(MockClassLoaderDependenciesUnitTestCase.suite());
+
+ return suite;
+ }
+}
Added: 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 (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/MockTopLevelClassLoaderSystemDeployer.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,71 @@
+/*
+ * 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.test.deployers.classloading.support;
+
+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;
+
+/**
+ * MockTopLevelClassLoaderSystemDeployer.
+ *
+ * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockTopLevelClassLoaderSystemDeployer extends AbstractTopLevelClassLoaderSystemDeployer
+{
+ 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());
+ super.deploy(unit);
+ }
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ undeployed.add(unit.getName());
+ super.undeploy(unit);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/a/A.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/a/A.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/a/A.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,32 @@
+/*
+* 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.a;
+
+/**
+ * A.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class A
+{
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/b/B.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/b/B.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/support/b/B.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,33 @@
+/*
+* 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.b;
+
+/**
+ * B.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class B
+{
+
+}
Added: 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 (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/classloading/test/MockClassLoaderDependenciesUnitTestCase.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,396 @@
+/*
+* 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.test;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.classloader.plugins.system.DefaultClassLoaderSystem;
+import org.jboss.classloader.spi.ClassLoaderSystem;
+import org.jboss.classloader.spi.ParentPolicy;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.plugins.classloading.AbstractClassLoaderDesribeDeployer;
+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.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.classloading.support.MockTopLevelClassLoaderSystemDeployer;
+import org.jboss.test.deployers.classloading.support.a.A;
+import org.jboss.test.deployers.classloading.support.b.B;
+
+/**
+ * HeuristicAllOrNothingUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class MockClassLoaderDependenciesUnitTestCase extends AbstractDeployerTest
+{
+ 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> A = makeList(NameA);
+ public static final List<String> B = makeList(NameB);
+ public static final List<String> AB = makeList(NameA, NameB);
+ public static final List<String> BA = makeList(NameB, NameA);
+ public static final List<String> BAA = makeList(NameB, NameA, NameA);
+ public static final List<String> BABA = makeList(NameB, NameA, NameB, NameA);
+
+ @SuppressWarnings("unchecked")
+ private static <T> List<T> makeList(T... objects)
+ {
+ List<T> result = new ArrayList<T>();
+ for (T object : objects)
+ result.add(object);
+ return result;
+ }
+
+ private AbstractClassLoaderDesribeDeployer deployer1;
+ private MockTopLevelClassLoaderSystemDeployer deployer2;
+
+ public static Test suite()
+ {
+ return new TestSuite(MockClassLoaderDependenciesUnitTestCase.class);
+ }
+
+ public MockClassLoaderDependenciesUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testSimpleClassLoader() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deployment = createSimpleDeployment(NameA);
+ addMetaData(deployment, null, A.class);
+
+ DeploymentUnit unit = assertDeploy(deployer, deployment);
+
+ assertEquals(A, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader cl = unit.getClassLoader();
+ assertLoadClass(cl, A.class);
+
+ assertUndeploy(deployer, deployment);
+
+ assertLoadClass(cl, A.class);
+
+ assertEquals(A, deployer2.deployed);
+ assertEquals(A, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBCorrectWay() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentB = createSimpleDeployment(NameB);
+ addMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(B, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentA = createSimpleDeployment(NameA);
+ ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = assertDeploy(deployer, deploymentA);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(A, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentB);
+ assertLoadClass(clB, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(AB, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBWrongWay() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createSimpleDeployment(NameA);
+ ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = deploy(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createSimpleDeployment(NameB);
+ addMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(A, deployer2.undeployed);
+
+ assertUndeploy(deployer, deploymentB);
+ assertLoadClass(clB, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(AB, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBRedeployA() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createSimpleDeployment(NameA);
+ ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = deploy(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createSimpleDeployment(NameB);
+ addMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ ClassLoader clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertUndeploy(deployer, deploymentA);
+ assertLoadClassIllegal(clA, B.class);
+
+ assertEquals(BA, deployer2.deployed);
+ assertEquals(A, deployer2.undeployed);
+
+ unitA = assertDeploy(deployer, deploymentA);
+ clA = unitA.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(BAA, deployer2.deployed);
+ assertEquals(A, deployer2.undeployed);
+ }
+
+ public void testADependsUponModuleBRedeployB() throws Exception
+ {
+ DeployerClient deployer = getMainDeployer();
+
+ Deployment deploymentA = createSimpleDeployment(NameA);
+ ClassLoaderMetaData classLoaderMetaData = addMetaData(deploymentA, null, A.class);
+ addRequireModule(classLoaderMetaData, "B", null);
+ DeploymentUnit unitA = deploy(deployer, deploymentA);
+
+ assertNoClassLoader(unitA);
+
+ assertEquals(NONE, deployer2.deployed);
+ assertEquals(NONE, deployer2.undeployed);
+
+ Deployment deploymentB = createSimpleDeployment(NameB);
+ addMetaData(deploymentB, null, B.class);
+ DeploymentUnit unitB = assertDeploy(deployer, deploymentB);
+
+ ClassLoader clB = unitB.getClassLoader();
+ assertLoadClass(clB, B.class);
+
+ assertEquals(BA, 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(BA, deployer2.deployed);
+ assertEquals(AB, deployer2.undeployed);
+
+ unitB = assertDeploy(deployer, deploymentB);
+ clA = unitA.getClassLoader();
+ clB = unitB.getClassLoader();
+ assertLoadClass(clA, B.class, clB);
+
+ assertEquals(BABA, deployer2.deployed);
+ assertEquals(AB, deployer2.undeployed);
+ }
+
+ 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 ClassLoaderMetaData addMetaData(Deployment deployment, Version version, Class... packages)
+ {
+ ClassLoaderMetaData classLoaderMetaData = createMetaData(deployment, version, packages);
+ addMetaData(deployment, classLoaderMetaData);
+ return classLoaderMetaData;
+ }
+
+ protected static ClassLoaderMetaData createMetaData(Deployment deployment, Version version, Class... packages)
+ {
+ ClassLoaderMetaData classLoaderMetaData = new ClassLoaderMetaData();
+ classLoaderMetaData.setName(deployment.getName());
+
+ List<Capability> capabilities = new ArrayList<Capability>();
+ Capability capability = new ModuleCapabilityImpl(deployment.getName(), version);
+ capabilities.add(capability);
+
+ if (packages != null)
+ {
+ for (Class pkg : packages)
+ {
+ capability = new PackageCapabilityImpl(pkg.getName());
+ capabilities.add(capability);
+ }
+ }
+
+ classLoaderMetaData.setCapabilities(capabilities);
+ return classLoaderMetaData;
+ }
+
+ protected static void addRequireModule(ClassLoaderMetaData classLoaderMetaData, String moduleName, VersionRange versionRange)
+ {
+ List<Requirement> requirements = classLoaderMetaData.getRequirements();
+ if (requirements == null)
+ {
+ requirements = new ArrayList<Requirement>();
+ classLoaderMetaData.setRequirements(requirements);
+ }
+
+ Requirement requirement = new RequireModuleImpl(moduleName, versionRange);
+ requirements.add(requirement);
+ }
+
+ protected static void addMetaData(PredeterminedManagedObjectAttachments attachments, ClassLoaderMetaData md)
+ {
+ MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+ mutable.addAttachment(ClassLoaderMetaData.class, md);
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ ClassLoading classLoading = new ClassLoading();
+ ClassLoaderSystem system = new DefaultClassLoaderSystem();
+ system.getDefaultDomain().setParentPolicy(ParentPolicy.BEFORE_BUT_JAVA_ONLY);
+
+ deployer1 = new AbstractClassLoaderDesribeDeployer();
+ deployer1.setClassLoading(classLoading);
+
+ deployer2 = new MockTopLevelClassLoaderSystemDeployer();
+ deployer2.setClassLoading(classLoading);
+ deployer2.setSystem(system);
+
+ return createMainDeployer(deployer1, deployer2);
+ }
+}
Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractClassLoaderDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractClassLoaderDeployer.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractClassLoaderDeployer.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -52,6 +52,14 @@
factory = this;
unit.createClassLoader(factory);
}
+
+ public void undeploy(DeploymentUnit unit)
+ {
+ ClassLoaderFactory factory = unit.getAttachment(ClassLoaderFactory.class);
+ if (factory == null)
+ factory = this;
+ unit.removeClassLoader(factory);
+ }
public void removeClassLoader(DeploymentContext context) throws Exception
{
Added: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java (rev 0)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractOptionalRealDeployer.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,87 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.deployers.spi.deployer.helpers;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+
+/**
+ * An abstract more complicated VFS real deployer where the input
+ * is optional instead of mandatory.
+ *
+ * @param <T> the deployment type
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author adrian at jboss.org
+ * @version $Revision: 63991 $
+ */
+public abstract class AbstractOptionalRealDeployer<T> extends AbstractRealDeployer
+{
+ /** The optional input */
+ private Class<T> optionalInput;
+
+ /**
+ * Create a new AbstractOptionalRealDeployer.
+ *
+ * @param optionalInput the optional input
+ * @throws IllegalArgumentException for null input
+ */
+ public AbstractOptionalRealDeployer(Class<T> optionalInput)
+ {
+ if (optionalInput == null)
+ throw new IllegalArgumentException("Null optional Input");
+ this.optionalInput = optionalInput;
+ setInputs(optionalInput);
+ }
+
+ public void deploy(DeploymentUnit unit) throws DeploymentException
+ {
+ deploy(unit, unit.getAttachment(optionalInput));
+ }
+
+ /**
+ * Deploy
+ *
+ * @param unit the deployment unit
+ * @param deployment the optional attachment
+ * @throws DeploymentException for any error
+ */
+ public abstract void deploy(DeploymentUnit unit, T deployment) throws DeploymentException;
+
+
+ @Override
+ public void undeploy(DeploymentUnit unit)
+ {
+ undeploy(unit, unit.getAttachment(optionalInput));
+ }
+
+ /**
+ * Undeploy
+ *
+ * @param unit the deployment unit
+ * @param deployment the optional attachment
+ */
+ public void undeploy(DeploymentUnit unit, T deployment)
+ {
+ // Nothing
+ }
+}
Modified: projects/microcontainer/trunk/deployers-structure-spi/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/.classpath 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/.classpath 2007-08-06 13:37:41 UTC (rev 64469)
@@ -34,6 +34,7 @@
<classpathentry kind="var" path="M2_REPO/wutka-dtdparser/dtdparser121/1.2.1/dtdparser121-1.2.1.jar"/>
<classpathentry kind="var" path="M2_REPO/apache-xerces/xml-apis/2.7.1/xml-apis-2.7.1.jar"/>
<classpathentry kind="var" path="M2_REPO/ant/ant/1.6.5/ant-1.6.5.jar" sourcepath="M2_REPO/ant/ant/1.6.5/ant-1.6.5-sources.jar"/>
+ <classpathentry kind="var" path="M2_REPO/org/osgi/osgi_R4_core/1.0/osgi_R4_core-1.0.jar"/>
<classpathentry kind="src" path="/jboss-deployers-core-spi"/>
<classpathentry kind="src" path="/jboss-dependency"/>
</classpath>
Modified: projects/microcontainer/trunk/deployers-structure-spi/pom.xml
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/pom.xml 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/pom.xml 2007-08-06 13:37:41 UTC (rev 64469)
@@ -41,6 +41,10 @@
<groupId>jboss</groupId>
<artifactId>jboss-logging-spi</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.osgi</groupId>
+ <artifactId>osgi_R4_core</artifactId>
+ </dependency>
<!-- Test dependencies -->
<dependency>
<groupId>jboss</groupId>
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -178,6 +178,13 @@
* Remove the classloader created by the factory
*/
void removeClassLoader();
+
+ /**
+ * Remove the classloader
+ *
+ * @param factory the original factory used to create the classloader
+ */
+ void removeClassLoader(ClassLoaderFactory factory);
/**
* Whether this is a top level deployment
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -101,6 +101,13 @@
boolean createClassLoader(ClassLoaderFactory factory) throws DeploymentException;
/**
+ * Remove the classloader
+ *
+ * @param factory the original factory used to create the classloader
+ */
+ void removeClassLoader(ClassLoaderFactory factory);
+
+ /**
* Get all the metadata for the expected type
*
* @param <T> the type to get
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Capability.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Capability.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Capability.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,23 +21,25 @@
*/
package org.jboss.deployers.structure.spi.classloading;
-import org.jboss.deployers.structure.spi.DeploymentContext;
+import java.io.Serializable;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
/**
* Capability.
*
* @author <a href="adrian at jboss.org">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public interface Capability
+public interface Capability extends Serializable
{
/**
* Whether this capability resolves the requirement
*
- * @param context the deployment context
+ * @param unit the deployment
* @param requirement the requirement
* @throws IllegalArgumentException for a null requirement
* @return true when it is resolves the requirement
*/
- boolean resolves(DeploymentContext context, Requirement requirement);
+ boolean resolves(DeploymentUnit unit, Requirement requirement);
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/ClassLoaderMetaData.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/ClassLoaderMetaData.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/ClassLoaderMetaData.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -22,7 +22,7 @@
package org.jboss.deployers.structure.spi.classloading;
import java.io.Serializable;
-import java.util.Set;
+import java.util.List;
/**
* ClassLoaderMetaData.
@@ -58,10 +58,10 @@
private boolean importAll;
/** The requirements */
- private Set<Requirement> requirements;
+ private List<Requirement> requirements;
/** The capabilities */
- private Set<Capability> capabilities;
+ private List<Capability> capabilities;
/**
* Get the name.
@@ -188,7 +188,7 @@
*
* @return the capabilities.
*/
- public Set<Capability> getCapabilities()
+ public List<Capability> getCapabilities()
{
return capabilities;
}
@@ -198,7 +198,7 @@
*
* @param capabilities the capabilities.
*/
- public void setCapabilities(Set<Capability> capabilities)
+ public void setCapabilities(List<Capability> capabilities)
{
this.capabilities = capabilities;
}
@@ -228,7 +228,7 @@
*
* @return the requirements.
*/
- public Set<Requirement> getRequirements()
+ public List<Requirement> getRequirements()
{
return requirements;
}
@@ -238,7 +238,7 @@
*
* @param requirements the requirements.
*/
- public void setRequirements(Set<Requirement> requirements)
+ public void setRequirements(List<Requirement> requirements)
{
this.requirements = requirements;
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/PackageCapability.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/PackageCapability.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/PackageCapability.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -34,7 +34,7 @@
*
* @return the package name
*/
- String getPackageName();
+ String getName();
/**
* Get the package version
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Requirement.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Requirement.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Requirement.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,12 +21,14 @@
*/
package org.jboss.deployers.structure.spi.classloading;
+import java.io.Serializable;
+
/**
* Requirement.
*
* @author <a href="adrian at jboss.org">Adrian Brock</a>
* @version $Revision: 1.1 $
*/
-public interface Requirement
+public interface Requirement extends Serializable
{
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Version.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Version.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/Version.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -21,6 +21,8 @@
*/
package org.jboss.deployers.structure.spi.classloading;
+import org.jboss.deployers.structure.spi.classloading.helpers.VersionImpl;
+
/**
* Version.
*
@@ -29,4 +31,6 @@
*/
public interface Version extends Comparable<Version>
{
+ /** The default version */
+ public static final Version DEFAULT_VERSION = new VersionImpl(null);
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/VersionRange.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/VersionRange.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/VersionRange.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -41,6 +41,9 @@
/** Whether high is inclusive */
private boolean highInclusive;
+ /** All versions */
+ public static final VersionRange ALL_VERSIONS = new VersionRange(Version.DEFAULT_VERSION);
+
/**
* Create a new VersionRange with just a low inclusive check
*
@@ -149,4 +152,85 @@
}
return true;
}
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof VersionRange == false)
+ return false;
+
+ VersionRange other = (VersionRange) obj;
+
+ Version thisLow = other.getLow();
+ Version otherLow = other.getLow();
+ if (thisLow == null)
+ {
+ if (otherLow != null)
+ return false;
+ }
+ else if (thisLow.equals(otherLow) == false)
+ return false;
+
+ if (thisLow != null && isLowInclusive() != other.isLowInclusive())
+ return false;
+
+ Version thisHigh = other.getHigh();
+ Version otherHigh = other.getHigh();
+ if (thisHigh == null)
+ {
+ if (otherHigh != null)
+ return false;
+ }
+ else if (thisHigh.equals(otherHigh) == false)
+ return false;
+
+ if (thisHigh != null && isHighInclusive() != other.isHighInclusive())
+ return false;
+
+ return true;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ if (low != null)
+ return low.hashCode();
+ if (high != null)
+ return high.hashCode();
+ return 0;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuilder builder = new StringBuilder();
+ if (low != null)
+ {
+ if (isLowInclusive())
+ builder.append("[");
+ else
+ builder.append("(");
+ builder.append(low);
+ }
+ else
+ {
+ builder.append("[").append(Version.DEFAULT_VERSION);
+ }
+ builder.append(",");
+ if (high != null)
+ {
+ builder.append(high);
+ if (isHighInclusive())
+ builder.append("]");
+ else
+ builder.append(")");
+ }
+ else
+ {
+ builder.append("inf)");
+ }
+ return builder.toString();
+ }
}
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/ModuleCapabilityImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/ModuleCapabilityImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/ModuleCapabilityImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,120 @@
+/*
+* 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.structure.spi.classloading.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.classloading.ModuleCapability;
+import org.jboss.deployers.structure.spi.classloading.RequireModule;
+import org.jboss.deployers.structure.spi.classloading.Requirement;
+import org.jboss.deployers.structure.spi.classloading.Version;
+
+/**
+ * ModuleCapabilityImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class ModuleCapabilityImpl implements ModuleCapability
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -5444212755644141118L;
+
+ /** The module name */
+ private String name;
+
+ /** The version */
+ private Version version;
+
+ /**
+ * Create a new ModuleCapabilityImpl with the default version
+ *
+ * @param name the name
+ * @throws IllegalArgumentException for a null name
+ */
+ public ModuleCapabilityImpl(String name)
+ {
+ this(name, null);
+ }
+
+ /**
+ * Create a new ModuleCapabilityImpl.
+ *
+ * @param name the name
+ * @param version the version - pass null for default version
+ * @throws IllegalArgumentException for a null name
+ */
+ public ModuleCapabilityImpl(String name, Version version)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (version == null)
+ version = Version.DEFAULT_VERSION;
+ this.name = name;
+ this.version = version;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Version getVersion()
+ {
+ return version;
+ }
+
+ public boolean resolves(DeploymentUnit unit, Requirement requirement)
+ {
+ if (requirement instanceof RequireModule == false)
+ return false;
+ RequireModule requireModule = (RequireModule) requirement;
+ if (getName().equals(requireModule.getName()) == false)
+ return false;
+ return requireModule.getVersionRange().isInRange(getVersion());
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof ModuleCapability == false)
+ return false;
+ ModuleCapability other = (ModuleCapability) obj;
+ if (getName().equals(other.getName()) == false)
+ return false;
+ return getVersion().equals(other.getVersion());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Module: " + getName() + ":" + getVersion();
+ }
+}
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/PackageCapabilityImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/PackageCapabilityImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/PackageCapabilityImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,120 @@
+/*
+* 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.structure.spi.classloading.helpers;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.classloading.PackageCapability;
+import org.jboss.deployers.structure.spi.classloading.RequirePackage;
+import org.jboss.deployers.structure.spi.classloading.Requirement;
+import org.jboss.deployers.structure.spi.classloading.Version;
+
+/**
+ * PackageCapabilityImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class PackageCapabilityImpl implements PackageCapability
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -1586959469453286396L;
+
+ /** The package name */
+ private String name;
+
+ /** The version */
+ private Version version;
+
+ /**
+ * Create a new PackageCapabilityImpl with the default version
+ *
+ * @param name the name
+ * @throws IllegalArgumentException for a null name
+ */
+ public PackageCapabilityImpl(String name)
+ {
+ this(name, null);
+ }
+
+ /**
+ * Create a new PackageCapabilityImpl.
+ *
+ * @param name the name
+ * @param version the version - pass null for default version
+ * @throws IllegalArgumentException for a null name
+ */
+ public PackageCapabilityImpl(String name, Version version)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (version == null)
+ version = Version.DEFAULT_VERSION;
+ this.name = name;
+ this.version = version;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Version getVersion()
+ {
+ return version;
+ }
+
+ public boolean resolves(DeploymentUnit unit, Requirement requirement)
+ {
+ if (requirement instanceof RequirePackage == false)
+ return false;
+ RequirePackage requirePackage = (RequirePackage) requirement;
+ if (getName().equals(requirePackage.getName()) == false)
+ return false;
+ return requirePackage.getVersionRange().isInRange(getVersion());
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof PackageCapability == false)
+ return false;
+ PackageCapability other = (PackageCapability) obj;
+ if (getName().equals(other.getName()) == false)
+ return false;
+ return getVersion().equals(other.getVersion());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "Package: " + getName() + ":" + getVersion();
+ }
+}
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequireModuleImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequireModuleImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequireModuleImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,107 @@
+/*
+* 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.structure.spi.classloading.helpers;
+
+import org.jboss.deployers.structure.spi.classloading.RequireModule;
+import org.jboss.deployers.structure.spi.classloading.VersionRange;
+
+/**
+ * RequireModuleImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequireModuleImpl implements RequireModule
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7108063877472769918L;
+
+ /** The module name required */
+ private String name;
+
+ /** The version range */
+ private VersionRange versionRange;
+
+ /**
+ * Create a new RequireModuleImpl with no version constraint
+ *
+ * @param name the name
+ * @throws IllegalArgumentException for a null name
+ */
+ public RequireModuleImpl(String name)
+ {
+ this(name, null);
+ }
+
+ /**
+ * Create a new RequireModuleImpl.
+ *
+ * @param name the name
+ * @param versionRange the version range - pass null for all versions
+ * @throws IllegalArgumentException for a null name
+ */
+ public RequireModuleImpl(String name, VersionRange versionRange)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (versionRange == null)
+ versionRange = VersionRange.ALL_VERSIONS;
+ this.name = name;
+ this.versionRange = versionRange;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return versionRange;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof RequireModule == false)
+ return false;
+ RequireModule other = (RequireModule) obj;
+ if (getName().equals(other.getName()) == false)
+ return false;
+ return getVersionRange().equals(other.getVersionRange());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "RequireModule: " + getName() + ":" + getVersionRange();
+ }
+}
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequirePackageImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequirePackageImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/RequirePackageImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,107 @@
+/*
+* 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.structure.spi.classloading.helpers;
+
+import org.jboss.deployers.structure.spi.classloading.RequirePackage;
+import org.jboss.deployers.structure.spi.classloading.VersionRange;
+
+/**
+ * RequirePackageImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RequirePackageImpl implements RequirePackage
+{
+ /** The serialVersionUID */
+ private static final long serialVersionUID = -7552921085464308835L;
+
+ /** The package name required */
+ private String name;
+
+ /** The version range */
+ private VersionRange versionRange;
+
+ /**
+ * Create a new RequirePackageImpl with no version constraint
+ *
+ * @param name the name
+ * @throws IllegalArgumentException for a null name
+ */
+ public RequirePackageImpl(String name)
+ {
+ this(name, null);
+ }
+
+ /**
+ * Create a new RequirePackageImpl.
+ *
+ * @param name the name
+ * @param versionRange the version range - pass null for all versions
+ * @throws IllegalArgumentException for a null name
+ */
+ public RequirePackageImpl(String name, VersionRange versionRange)
+ {
+ if (name == null)
+ throw new IllegalArgumentException("Null name");
+ if (versionRange == null)
+ versionRange = VersionRange.ALL_VERSIONS;
+ this.name = name;
+ this.versionRange = versionRange;
+ }
+
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public VersionRange getVersionRange()
+ {
+ return versionRange;
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof RequirePackage == false)
+ return false;
+ RequirePackage other = (RequirePackage) obj;
+ if (getName().equals(other.getName()) == false)
+ return false;
+ return getVersionRange().equals(other.getVersionRange());
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return getName().hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "RequirePackage: " + getName() + ":" + getVersionRange();
+ }
+}
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/VersionImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/VersionImpl.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/classloading/helpers/VersionImpl.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -0,0 +1,80 @@
+/*
+* 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.structure.spi.classloading.helpers;
+
+import org.jboss.deployers.structure.spi.classloading.Version;
+
+/**
+ * VersionImpl.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class VersionImpl implements Version
+{
+ /** The delegate */
+ private org.osgi.framework.Version delegate;
+
+ /**
+ * Create a new VersionImpl.
+ *
+ * @param version the version - pass null for the default version
+ * @throws IllegalArgumentException if the string does not conform to an OSGi version
+ */
+ public VersionImpl(String version)
+ {
+ delegate = org.osgi.framework.Version.parseVersion(version);
+ }
+
+ public int compareTo(Version o)
+ {
+ if (o == this)
+ return 0;
+ if (o == null || o instanceof VersionImpl == false)
+ throw new IllegalArgumentException("Not a version impl: " + o);
+ org.osgi.framework.Version other = (org.osgi.framework.Version) o;
+ return delegate.compareTo(other);
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (obj == this)
+ return true;
+ if (obj == null || obj instanceof VersionImpl == false)
+ return false;
+ org.osgi.framework.Version other = (org.osgi.framework.Version) obj;
+ return delegate.equals(other);
+ }
+
+ @Override
+ public int hashCode()
+ {
+ return delegate.hashCode();
+ }
+
+ @Override
+ public String toString()
+ {
+ return delegate.toString();
+ }
+}
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -284,6 +284,12 @@
setClassLoader(null);
}
+ public void removeClassLoader(ClassLoaderFactory factory)
+ {
+ if (classLoaderFactory == factory)
+ removeClassLoader();
+ }
+
public boolean isTopLevel()
{
return parent == null;
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -114,6 +114,11 @@
return deploymentContext.createClassLoader(factory);
}
+ public void removeClassLoader(ClassLoaderFactory factory)
+ {
+ deploymentContext.removeClassLoader(factory);
+ }
+
public DeploymentUnit getTopLevel()
{
DeploymentUnit top = getParent();
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructureBuilder.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructureBuilder.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructureBuilder.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -175,6 +175,8 @@
protected void applyComparator(DeploymentContext context, ContextInfo contextInfo) throws Exception
{
String className = contextInfo.getComparatorClassName();
+ if (className == null)
+ return;
Object o = null;
try
{
Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -184,6 +184,10 @@
{
}
+ public void removeClassLoader(ClassLoaderFactory factory)
+ {
+ }
+
public boolean isTopLevel()
{
return false;
Modified: projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractOptionalVFSRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractOptionalVFSRealDeployer.java 2007-08-06 13:28:59 UTC (rev 64468)
+++ projects/microcontainer/trunk/deployers-vfs-spi/src/main/org/jboss/deployers/vfs/spi/deployer/AbstractOptionalVFSRealDeployer.java 2007-08-06 13:37:41 UTC (rev 64469)
@@ -22,7 +22,7 @@
package org.jboss.deployers.vfs.spi.deployer;
import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.spi.deployer.helpers.AbstractOptionalRealDeployer;
import org.jboss.deployers.structure.spi.DeploymentUnit;
import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
@@ -30,25 +30,23 @@
* An abstract more complicated VFS real deployer where the input
* is optional instead of mandatory.
*
+ * @param <T> the deployment type
* @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @author adrian at jboss.org
* @version $Revision$
*/
-public abstract class AbstractOptionalVFSRealDeployer<T> extends AbstractRealDeployer
+public abstract class AbstractOptionalVFSRealDeployer<T> extends AbstractOptionalRealDeployer<T>
{
- private Class<T> optionalInput;
-
+ /**
+ * Create a new AbstractOptionalVFSRealDeployer.
+ *
+ * @param optionalInput the optional input
+ * @throws IllegalArgumentException for null input
+ */
public AbstractOptionalVFSRealDeployer(Class<T> optionalInput)
{
- if (optionalInput == null)
- throw new IllegalArgumentException("Null optionallInput");
- this.optionalInput = optionalInput;
- setInputs(optionalInput);
+ super(optionalInput);
}
-
- public void deploy(DeploymentUnit unit) throws DeploymentException
- {
- deploy(unit, unit.getAttachment(optionalInput));
- }
public void deploy(DeploymentUnit unit, T deployment) throws DeploymentException
{
@@ -69,11 +67,6 @@
public abstract void deploy(VFSDeploymentUnit unit, T deployment) throws DeploymentException;
@Override
- public void undeploy(DeploymentUnit unit)
- {
- undeploy(unit, unit.getAttachment(optionalInput));
- }
-
public void undeploy(DeploymentUnit unit, T deployment)
{
if (unit instanceof VFSDeploymentUnit == false)
More information about the jboss-cvs-commits
mailing list