[jboss-cvs] JBossAS SVN: r79112 - projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Oct 4 05:07:01 EDT 2008


Author: alesj
Date: 2008-10-04 05:07:01 -0400 (Sat, 04 Oct 2008)
New Revision: 79112

Modified:
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/ModuleRequirementIntegrationDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/PackageRequirementIntegrationDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/RequirementIntegrationDeployer.java
   projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/UrlIntegrationDeployer.java
Log:
[JBDEPLOY-97, JBDEPLOY-98]; refactor integration deployers.

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/ModuleRequirementIntegrationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/ModuleRequirementIntegrationDeployer.java	2008-10-04 05:29:37 UTC (rev 79111)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/ModuleRequirementIntegrationDeployer.java	2008-10-04 09:07:01 UTC (rev 79112)
@@ -45,6 +45,9 @@
 
    protected AbstractRequirement hasIntegrationModuleRequirement(RequirementsMetaData metadata)
    {
+      if (metadata == null)
+         return null;
+
       List<Requirement> requirements = metadata.getRequirements();
       if (requirements != null && requirements.isEmpty() == false)
       {

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/PackageRequirementIntegrationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/PackageRequirementIntegrationDeployer.java	2008-10-04 05:29:37 UTC (rev 79111)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/PackageRequirementIntegrationDeployer.java	2008-10-04 09:07:01 UTC (rev 79112)
@@ -46,6 +46,9 @@
 
    protected AbstractRequirement hasIntegrationModuleRequirement(RequirementsMetaData metadata)
    {
+      if (metadata == null)
+         return null;
+
       List<Requirement> requirements = metadata.getRequirements();
       if (requirements != null && requirements.isEmpty() == false && packages != null && packages.isEmpty() == false)
       {

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/RequirementIntegrationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/RequirementIntegrationDeployer.java	2008-10-04 05:29:37 UTC (rev 79111)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/RequirementIntegrationDeployer.java	2008-10-04 09:07:01 UTC (rev 79112)
@@ -21,6 +21,11 @@
 */
 package org.jboss.deployers.vfs.plugins.classloader;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
+
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.classloading.spi.metadata.ClassLoadingMetaDataFactory;
 import org.jboss.classloading.spi.metadata.Requirement;
@@ -41,17 +46,15 @@
  */
 public abstract class RequirementIntegrationDeployer<T> extends AbstractOptionalVFSRealDeployer<T>
 {
-   /** The jboss integration module name */
-   private String integrationModuleName;
+   /** The jboss integration module names */
+   private Set<String> integrationModuleNames;
 
    public RequirementIntegrationDeployer(Class<T> input)
    {
       super(input);
-
       // We have to run before the classloading is setup
       setStage(DeploymentStages.DESCRIBE);
-
-      // We modify the classloading "imports"/requirements
+      // We modify the classloading imports/requirements
       addInput(ClassLoadingMetaData.class);
       setOutput(ClassLoadingMetaData.class);
    }
@@ -63,7 +66,10 @@
     */
    public String getIntegrationModuleName()
    {
-      return integrationModuleName;
+      if (integrationModuleNames == null || integrationModuleNames.isEmpty())
+         return null;
+      else
+         return integrationModuleNames.iterator().next();
    }
 
    /**
@@ -73,24 +79,105 @@
     */
    public void setIntegrationModuleName(String integrationModuleName)
    {
-      this.integrationModuleName = integrationModuleName;
+      if (integrationModuleName == null)
+         this.integrationModuleNames = Collections.singleton(integrationModuleName);
+      else
+         this.integrationModuleNames.add(integrationModuleName);
    }
 
+   /**
+    * Get integration module names.
+    *
+    * @return the integration module names
+    */
+   public Set<String> getIntegrationModuleNames()
+   {
+      return integrationModuleNames;
+   }
+
+   /**
+    * Set integration module names
+    *
+    * @param integrationModuleNames the integration modeul names
+    */
+   public void setIntegrationModuleNames(Set<String> integrationModuleNames)
+   {
+      this.integrationModuleNames = integrationModuleNames;
+   }
+
+   /**
+    * Check if integration urls exist.
+    */
+   public void start()
+   {
+      if (integrationModuleNames == null || integrationModuleNames.isEmpty())
+         throw new IllegalArgumentException("No integration module names.");
+   }
+
    @Override
    public void deploy(VFSDeploymentUnit unit, T metaData) throws DeploymentException
    {
       ClassLoadingMetaData clmd = unit.getAttachment(ClassLoadingMetaData.class);
+      if (clmd == null)
+      {
+         log.warn("Missing ClassLoadingMetaData: " + unit);
+         return;
+      }
+
       RequirementsMetaData requirements = clmd.getRequirements();
       AbstractRequirement integrationModule = hasIntegrationModuleRequirement(requirements);
-      // If we are importing integration core then import the jboss integration at the same version
+      // If we are importing integration core then import the integration at the same version
       if (integrationModule != null)
       {
          ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
-         Requirement integrationRequirement = factory.createRequireModule(integrationModuleName, integrationModule.getVersionRange());
-         requirements.addRequirement(integrationRequirement);
+         List<Requirement> added = new ArrayList<Requirement>();
+         try
+         {
+            for (String integrationModuleName : integrationModuleNames)
+            {
+               Requirement integrationRequirement = factory.createRequireModule(integrationModuleName, integrationModule.getVersionRange());
+               requirements.addRequirement(integrationRequirement);
+               added.add(integrationModule);
+            }
+         }
+         catch (Throwable t)
+         {
+            for (int i = added.size() - 1; i >=0; i--)
+            {
+               requirements.removeRequirement(added.get(i));
+            }
+            throw DeploymentException.rethrowAsDeploymentException("Error adding integration requirement.", t);
+         }
       }
    }
 
+   @Override
+   public void undeploy(VFSDeploymentUnit unit, T deployment)
+   {
+      ClassLoadingMetaData clmd = unit.getAttachment(ClassLoadingMetaData.class);
+      if (clmd != null)
+      {
+         RequirementsMetaData requirements = clmd.getRequirements();
+         AbstractRequirement integrationModule = hasIntegrationModuleRequirement(requirements);
+         if (integrationModule != null)
+         {
+            ClassLoadingMetaDataFactory factory = ClassLoadingMetaDataFactory.getInstance();
+            for (String integrationModuleName : integrationModuleNames)
+            {
+               try
+               {
+                  Requirement integrationRequirement = factory.createRequireModule(integrationModuleName, integrationModule.getVersionRange());
+                  requirements.removeRequirement(integrationRequirement);
+               }
+               catch (Throwable t)
+               {
+                  log.warn("Error during requirement removal: " + integrationModuleName, t);
+               }
+            }
+         }
+      }
+   }
+
    /**
     * Do we have integration module requirements.
     *

Modified: projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/UrlIntegrationDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/UrlIntegrationDeployer.java	2008-10-04 05:29:37 UTC (rev 79111)
+++ projects/jboss-deployers/trunk/deployers-vfs/src/main/java/org/jboss/deployers/vfs/plugins/classloader/UrlIntegrationDeployer.java	2008-10-04 09:07:01 UTC (rev 79112)
@@ -21,9 +21,13 @@
 */
 package org.jboss.deployers.vfs.plugins.classloader;
 
-import java.io.IOException;
 import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Set;
 
+import org.jboss.classloading.spi.metadata.ClassLoadingMetaData;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.vfs.spi.deployer.AbstractOptionalVFSRealDeployer;
@@ -42,13 +46,15 @@
 public abstract class UrlIntegrationDeployer<T> extends AbstractOptionalVFSRealDeployer<T>
 {
    /** Location of integration jar */
-   private URL integrationURL;
+   private Set<URL> integrationURLs;
 
    public UrlIntegrationDeployer(Class<T> input)
    {
       super(input);
       // We have to run before the classloading is setup
-      setStage(DeploymentStages.POST_PARSE);
+      setStage(DeploymentStages.DESCRIBE);
+      // Keep things simple having one attachment to control the classloader processing order
+      setOutput(ClassLoadingMetaData.class);
    }
 
    /**
@@ -58,7 +64,10 @@
     */
    public URL getIntegrationURL()
    {
-      return integrationURL;
+      if (integrationURLs == null || integrationURLs.isEmpty())
+         return null;
+      else
+         return integrationURLs.iterator().next();
    }
 
    /**
@@ -68,26 +77,89 @@
     */
    public void setIntegrationURL(URL url)
    {
-      this.integrationURL = url;
+      if (integrationURLs == null)
+         integrationURLs = Collections.singleton(url);
+      else
+         integrationURLs.add(url);
    }
 
+   /**
+    * Get integration urls.
+    *
+    * @return the integration urls
+    */
+   public Set<URL> getIntegrationURLs()
+   {
+      return integrationURLs;
+   }
+
+   /**
+    * Set integration urls.
+    *
+    * @param integrationURLs the integration urls
+    */
+   public void setIntegrationURLs(Set<URL> integrationURLs)
+   {
+      this.integrationURLs = integrationURLs;
+   }
+
+   /**
+    * Check if integration urls exist.
+    */
+   public void start()
+   {
+      if (integrationURLs == null || integrationURLs.isEmpty())
+         throw new IllegalArgumentException("No integration urls.");
+   }
+
    @Override
    public void deploy(VFSDeploymentUnit unit, T metaData) throws DeploymentException
    {
       if (isIntegrationDeployment(unit))
       {
+         List<VirtualFile> added = new ArrayList<VirtualFile>();
          try
          {
-            VirtualFile integration = VFS.getRoot(integrationURL);
-            unit.addClassPath(integration);
+            for (URL integrationURL : integrationURLs)
+            {
+               VirtualFile integration = VFS.getRoot(integrationURL);
+               unit.addClassPath(integration);
+               added.add(integration);
+            }
          }
-         catch (IOException e)
+         catch (Throwable t)
          {
-            throw DeploymentException.rethrowAsDeploymentException("Error adding integration path.", e);
+            List<VirtualFile> classPath = unit.getClassPath();
+            for (int i = added.size() - 1; i >=0; i--)
+            {
+               classPath.remove(added.get(i));
+            }
+            throw DeploymentException.rethrowAsDeploymentException("Error adding integration path.", t);
          }
       }
    }
 
+   @Override
+   public void undeploy(VFSDeploymentUnit unit, T deployment)
+   {
+      if (isIntegrationDeployment(unit))
+      {
+         List<VirtualFile> classPath = unit.getClassPath();
+         for (URL integrationURL : integrationURLs)
+         {
+            try
+            {
+               VirtualFile integration = VFS.getRoot(integrationURL);
+               classPath.remove(integration);
+            }
+            catch (Throwable t)
+            {
+               log.warn("Error removing integration from classpath: " + integrationURL, t);
+            }
+         }
+      }
+   }
+
    /**
     * Is unit integration deployment unit?
     *




More information about the jboss-cvs-commits mailing list