[jboss-cvs] JBossAS SVN: r70172 - in projects/microcontainer/trunk: deployers-client-spi/src/main/org/jboss/deployers/spi/deployer and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Feb 27 07:08:59 EST 2008


Author: adrian at jboss.org
Date: 2008-02-27 07:08:59 -0500 (Wed, 27 Feb 2008)
New Revision: 70172

Modified:
   projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java
   projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java
   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/main/MainDeployerImpl.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerChangeStageTestCase.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java
   projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java
Log:
Add the ability to get the DeploymentStage for a deployment

Modified: projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java
===================================================================
--- projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/client/spi/DeployerClient.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -111,6 +111,15 @@
    void change(String deploymentName, DeploymentStage stage) throws DeploymentException;
 
    /**
+    * Get the deployment stage for a deployment
+    * 
+    * @param deploymentName the deployment name
+    * @return the stage
+    * @throws DeploymentException for any error
+    */
+   DeploymentStage getDeploymentStage(String deploymentName) throws DeploymentException;
+
+   /**
     * Check all the deployments are complete
     * 
     * @throws DeploymentException when some deployment is not complete

Modified: projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java
===================================================================
--- projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-client-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -153,6 +153,24 @@
    }
    
    @Override
+   public boolean equals(Object obj)
+   {
+      if (obj == this)
+         return true;
+      if (obj == null || obj instanceof DeploymentStage == false)
+         return false;
+      
+      DeploymentStage other = (DeploymentStage) obj;
+      return getName().equals(other.getName());
+   }
+
+   @Override
+   public int hashCode()
+   {
+      return getName().hashCode();
+   }
+   
+   @Override
    public String toString()
    {
       return getName();

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	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -387,6 +387,17 @@
       }
    }
 
+   public DeploymentStage getDeploymentStage(DeploymentContext context) throws DeploymentException
+   {
+      DeploymentControllerContext deploymentControllerContext = context.getTransientAttachments().getAttachment(ControllerContext.class.getName(), DeploymentControllerContext.class);
+      if (deploymentControllerContext == null)
+         return null;
+      ControllerState state = deploymentControllerContext.getState();
+      if (ControllerState.ERROR.equals(state))
+         return DeploymentStages.NOT_INSTALLED;
+      return new DeploymentStage(state.getStateString());
+   }
+
    public void change(DeploymentContext context, DeploymentStage stage) throws DeploymentException
    {
       if (context == null)

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -39,6 +39,7 @@
 import org.jboss.deployers.spi.DeploymentState;
 import org.jboss.deployers.spi.deployer.Deployers;
 import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.spi.deployer.managed.ManagedDeploymentCreator;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
@@ -556,6 +557,37 @@
       }
    }
 
+   public DeploymentStage getDeploymentStage(String deploymentName) throws DeploymentException
+   {
+      if (deployers == null)
+         throw new IllegalStateException("No deployers");
+
+      lockRead();
+      try
+      {
+         DeploymentContext context = getTopLevelDeploymentContext(deploymentName);
+         if (context == null)
+            return DeploymentStages.NOT_INSTALLED;
+         DeploymentStage result = deployers.getDeploymentStage(context);
+         if (result != null)
+            return result;
+         else
+            return DeploymentStages.NOT_INSTALLED;
+      }
+      catch (Error e)
+      {
+         throw e;
+      }
+      catch (Throwable t)
+      {
+         throw DeploymentException.rethrowAsDeploymentException("Error getting stage for " + deploymentName, t);
+      }
+      finally
+      {
+         unlockRead();
+      }
+   }
+
    public void change(String deploymentName, DeploymentStage stage) throws DeploymentException
    {
       if (deployers == null)

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerChangeStageTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerChangeStageTestCase.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerChangeStageTestCase.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -61,7 +61,7 @@
       List<String> expected = new ArrayList<String>();
       expected.add(single.getName());
       assertEquals(expected, deployer.getDeployedUnits());
-
+      
       DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
       assertEquals(main, unit.getMainDeployer());
       
@@ -74,15 +74,19 @@
       DeployerClient main = getMainDeployer();
 
       Deployment single = createSimpleDeployment("single");
+      assertEquals(DeploymentStages.NOT_INSTALLED, main.getDeploymentStage(single.getName()));
       main.deploy(single);
       List<String> expected = new ArrayList<String>();
       expected.add(single.getName());
       assertEquals(expected, deployer.getDeployedUnits());
+      assertEquals(DeploymentStages.INSTALLED, main.getDeploymentStage(single.getName()));
 
       main.change(single.getName(), DeploymentStages.CLASSLOADER);
       assertEquals(expected, deployer.getUndeployedUnits());
+      assertEquals(DeploymentStages.CLASSLOADER, main.getDeploymentStage(single.getName()));
       
       main.undeploy(single);
+      assertEquals(DeploymentStages.NOT_INSTALLED, main.getDeploymentStage(single.getName()));
       assertEquals(expected, deployer.getDeployedUnits());
       assertEquals(expected, deployer.getUndeployedUnits());
       try
@@ -96,12 +100,16 @@
       }
       
       deployer.clear();
+      assertEquals(DeploymentStages.NOT_INSTALLED, main.getDeploymentStage(single.getName()));
       main.deploy(single);
       assertEquals(expected, deployer.getDeployedUnits());
+      assertEquals(DeploymentStages.INSTALLED, main.getDeploymentStage(single.getName()));
       main.change(single.getName(), DeploymentStages.CLASSLOADER);
+      assertEquals(DeploymentStages.CLASSLOADER, main.getDeploymentStage(single.getName()));
       deployer.clear();
       main.change(single.getName(), DeploymentStages.REAL);
       assertEquals(expected, deployer.getDeployedUnits());
+      assertEquals(DeploymentStages.REAL, main.getDeploymentStage(single.getName()));
    }
 
    public void testChangeStageFail() throws Throwable
@@ -109,12 +117,15 @@
       DeployerClient main = getMainDeployer();
 
       Deployment single = createSimpleDeployment("single");
+      assertEquals(DeploymentStages.NOT_INSTALLED, main.getDeploymentStage(single.getName()));
       main.deploy(single);
       List<String> expected = new ArrayList<String>();
       expected.add(single.getName());
       assertEquals(expected, deployer.getDeployedUnits());
+      assertEquals(DeploymentStages.INSTALLED, main.getDeploymentStage(single.getName()));
 
       main.change(single.getName(), DeploymentStages.CLASSLOADER);
+      assertEquals(DeploymentStages.CLASSLOADER, main.getDeploymentStage(single.getName()));
       DeploymentUnit unit = assertDeploymentUnit(main, single.getName());
       DeploymentContext context = assertDeploymentContext(main, single.getName());
       unit.addAttachment("fail", deployer);
@@ -132,5 +143,6 @@
       assertEquals(expected, deployer.getFailed());
       assertEquals(DeploymentState.ERROR, context.getState());
       checkThrowable(DeploymentException.class, context.getProblem());
+      assertEquals(DeploymentStages.NOT_INSTALLED, main.getDeploymentStage(single.getName()));
    }
 }

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/Deployers.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -65,6 +65,15 @@
    void change(DeploymentContext context, DeploymentStage stage) throws DeploymentException;
 
    /**
+    * Get the deployment stage for a deployment
+    * 
+    * @param context the context
+    * @return the stage or null if not deployed
+    * @throws DeploymentException for any error
+    */
+   DeploymentStage getDeploymentStage(DeploymentContext context) throws DeploymentException;
+
+   /**
     * Check all the deployments are complete
     *
     * @param errors the contexts in error

Modified: projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java
===================================================================
--- projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java	2008-02-27 11:17:39 UTC (rev 70171)
+++ projects/microcontainer/trunk/osgi-int/src/tests/org/jboss/test/bundle/support/TestMainDeployer.java	2008-02-27 12:08:59 UTC (rev 70172)
@@ -1,9 +1,24 @@
 /*
- * JBoss, the OpenSource J2EE webOS
- * 
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
+* JBoss, Home of Professional Open Source
+* Copyright 2008, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
 package org.jboss.test.bundle.support;
 
 import java.util.Collection;
@@ -19,12 +34,17 @@
 import org.jboss.managed.api.ManagedObject;
 import org.jboss.util.graph.Graph;
 
+/**
+ * TestMainDeployer.
+ * 
+ * @author johnbailey
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
 public class TestMainDeployer implements MainDeployer
 {
 
    /** Create a new TestMainDeployer.
-    * 
-    * @param bundleImplTestCase
     */
    public TestMainDeployer()
    {
@@ -47,6 +67,11 @@
       changesRequested.put(deploymentName, stage);
    }
 
+   public DeploymentStage getDeploymentStage(String deploymentName) throws DeploymentException
+   {
+      return changesRequested.get(deploymentName);
+   }
+
    public void checkComplete() throws DeploymentException
    {
 




More information about the jboss-cvs-commits mailing list