[jboss-cvs] JBossAS SVN: r101663 - in projects/jboss-deployers/trunk: deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Mar 1 10:37:07 EST 2010


Author: alesj
Date: 2010-03-01 10:37:06 -0500 (Mon, 01 Mar 2010)
New Revision: 101663

Added:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyComponentRelativeOrderDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyRelativeOrderDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestAttachmentDeployer.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestSimpleDeployer4.java
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/test/DynamicRelativeOrderUnitTestCase.java
   projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentContextExt.java
   projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnitExt.java
Modified:
   projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
   projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeployer.java
   projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
   projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
   projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
Log:
[JBDEPLOY-243]; dynamic relative order - re-order on "dirty" order.

Modified: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java	2010-03-01 15:29:29 UTC (rev 101662)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/DeployersDeployerTestSuite.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -26,24 +26,7 @@
 import junit.textui.TestRunner;
 
 import org.jboss.test.deployers.deployer.helpers.test.ExactAttachmentDeployerWithVisitorTestCase;
-import org.jboss.test.deployers.deployer.test.ComponentUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DependenciesTopologicalOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerClassLoaderUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerContextClassLoaderUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerFlowUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerProtocolUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerRequiredInputsUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerRequiredStageUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployerWidthFirstUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DeployersImplUnitTestCase;
-import org.jboss.test.deployers.deployer.test.DominoOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.HeuristicAllOrNothingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.HeuristicRussionDollUnitTestCase;
-import org.jboss.test.deployers.deployer.test.InOutTopologicalOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.IndexingOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.KahnOrderingUnitTestCase;
-import org.jboss.test.deployers.deployer.test.MultipleComponentTypeUnitTestCase;
+import org.jboss.test.deployers.deployer.test.*;
 
 /**
  * Deployers Deployer Test Suite.
@@ -75,6 +58,7 @@
       suite.addTest(DeployerContextClassLoaderUnitTestCase.suite());
       suite.addTest(DeployerRequiredStageUnitTestCase.suite());
       suite.addTest(DeployerRequiredInputsUnitTestCase.suite());
+      suite.addTest(DynamicRelativeOrderUnitTestCase.suite());
 
       // sorting tests
       suite.addTest(DeployerFlowUnitTestCase.suite());

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyComponentRelativeOrderDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyComponentRelativeOrderDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyComponentRelativeOrderDeployer.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,53 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.Collection;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * ModifyRelativeOrder deployer.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ModifyComponentRelativeOrderDeployer extends AbstractRealDeployer
+{
+   public ModifyComponentRelativeOrderDeployer(DeploymentStage stage)
+   {
+      setStage(stage);
+      setComponentsOnly(true);
+   }
+
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      String value = unit.getAttachment(String.class);
+      changeRelativeOrder(unit, 5 - Integer.parseInt(value));
+   }
+
+   public void internalUndeploy(DeploymentUnit unit)
+   {
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyRelativeOrderDeployer.java (from rev 101619, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestSimpleDeployer3.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyRelativeOrderDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/ModifyRelativeOrderDeployer.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,54 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * ModifyRelativeOrder deployer.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ModifyRelativeOrderDeployer extends AbstractRealDeployer
+{
+   public ModifyRelativeOrderDeployer(DeploymentStage stage)
+   {
+      setStage(stage);
+   }
+
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      String name = unit.getSimpleName();
+      char end = name.charAt(name.length() - 1);
+      if (Character.isDigit(end))
+      {
+         changeRelativeOrder(unit, 3 - end + '0');
+      }
+   }
+
+   public void internalUndeploy(DeploymentUnit unit)
+   {
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestAttachmentDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestAttachmentDeployer.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestAttachmentDeployer.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,57 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.Collection;
+import java.util.Set;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * ModifyRelativeOrder deployer.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TestAttachmentDeployer extends AbstractRealDeployer
+{
+   public TestAttachmentDeployer(DeploymentStage stage)
+   {
+      setStage(stage);
+   }
+
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      Set<? extends String> strings = unit.getAllMetaData(String.class);
+      for (String s : strings)
+         unit.addComponent(s).addAttachment(String.class, s);
+   }
+
+   public void internalUndeploy(DeploymentUnit unit)
+   {
+      Set<? extends String> strings = unit.getAllMetaData(String.class);
+      for (String s : strings)
+         unit.removeComponent(s);
+   }
+}
\ No newline at end of file

Added: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestSimpleDeployer4.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestSimpleDeployer4.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/support/TestSimpleDeployer4.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,59 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.deployer.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * Test simple deployer deployer.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class TestSimpleDeployer4 extends AbstractRealDeployer
+{
+   public List<String> deployed = new ArrayList<String>();
+   public List<String> undeployed = new ArrayList<String>();
+
+   public TestSimpleDeployer4(DeploymentStage stage)
+   {
+      setStage(stage);
+      setComponentsOnly(true);
+   }
+
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      log.debug(this + " deploy  : " + unit.getName());
+      deployed.add(unit.getName());
+   }
+
+   public void internalUndeploy(DeploymentUnit unit)
+   {
+      log.debug(this + " undeploy: " + unit.getName());
+      undeployed.add(unit.getName());
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/test/DynamicRelativeOrderUnitTestCase.java (from rev 101619, projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/test/HeuristicDeploymentRelativeOrderUnitTestCase.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/test/DynamicRelativeOrderUnitTestCase.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-impl/src/test/java/org/jboss/test/deployers/deployer/test/DynamicRelativeOrderUnitTestCase.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,144 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.deployers.deployer.test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.spi.attachments.Attachments;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.*;
+import org.jboss.test.deployers.main.support.TestAttachment;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Dynamic relative order.
+ *
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
+ */
+public class DynamicRelativeOrderUnitTestCase extends AbstractDeployerTest
+{
+   private static final DeploymentFactory factory = new DeploymentFactory();
+
+   private TestSimpleDeployer3 deployer1 = new TestSimpleDeployer3(DeploymentStages.REAL);
+   private TestSimpleDeployer4 deployer2 = new TestSimpleDeployer4(DeploymentStages.PRE_REAL);
+
+   private static String P = "Parent";
+   private static String C1 = P + "/" + "C1";
+   private static String C2 = P + "/" + "C2";
+   private static List<String> NONE = Collections.emptyList();
+   private static List<String> PC2C1 = makeList(P, C2, C1);
+   private static List<String> C1C2P = makeList(C1, C2, P);
+   private static List<String> COMPS = makeList("4", "3", "2", "1");
+
+   private static <T> List<T> makeList(T... objects)
+   {
+      List<T> result = new ArrayList<T>();
+      result.addAll(Arrays.asList(objects));
+      return result;
+   }
+
+   public static Test suite()
+   {
+      return new TestSuite(DynamicRelativeOrderUnitTestCase.class);
+   }
+
+   public DynamicRelativeOrderUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void testSubDeployments() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment parent = createSimpleDeployment("Parent");
+      factory.addContext(parent, "C1");
+      factory.addContext(parent, "C2");
+      main.addDeployment(parent);
+
+      main.process();
+
+      assertEquals(PC2C1, deployer1.deployed);
+      assertEquals(NONE, deployer1.undeployed);
+
+      main.removeDeployment(parent);
+      main.process();
+
+      assertEquals(PC2C1, deployer1.deployed);
+      assertEquals(C1C2P, deployer1.undeployed);
+   }
+
+   public void testComponents() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment parent = createSimpleDeployment("Parent");
+
+      ContextInfo ci1 = factory.addContext(parent, "C1");
+      Attachments attachments1 = ci1.getPredeterminedManagedObjects();
+      MutableAttachments ma1 = (MutableAttachments) attachments1;
+      ma1.addAttachment("1.1", "1", String.class);
+      ma1.addAttachment("1.2", "2", String.class);
+
+      ContextInfo ci2 = factory.addContext(parent, "C2");
+      Attachments attachments2 = ci2.getPredeterminedManagedObjects();
+      MutableAttachments ma2 = (MutableAttachments) attachments2;
+      ma2.addAttachment("2.1", "3", String.class);
+      ma2.addAttachment("2.2", "4", String.class);
+
+      main.addDeployment(parent);
+      main.process();
+
+      assertEquals(PC2C1, deployer1.deployed);
+      assertEquals(NONE, deployer1.undeployed);
+      assertEquals(COMPS, deployer2.deployed);
+      assertEquals(NONE, deployer2.undeployed);
+
+      main.removeDeployment(parent);
+      main.process();
+
+      assertEquals(PC2C1, deployer1.deployed);
+      assertEquals(C1C2P, deployer1.undeployed);
+      assertEquals(COMPS, deployer2.deployed);
+      Collections.reverse(COMPS);
+      assertEquals(COMPS, deployer2.undeployed);
+   }
+
+   protected DeployerClient getMainDeployer()
+   {
+      TestAttachmentDeployer tad = new TestAttachmentDeployer(DeploymentStages.DESCRIBE);
+      ModifyRelativeOrderDeployer mrod = new ModifyRelativeOrderDeployer(DeploymentStages.CLASSLOADER);
+      ModifyComponentRelativeOrderDeployer mcrod = new ModifyComponentRelativeOrderDeployer(DeploymentStages.POST_CLASSLOADER);
+      return createMainDeployer(mrod, mcrod, tad, deployer1, deployer2);
+   }
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeployer.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeployer.java	2010-03-01 15:29:29 UTC (rev 101662)
+++ projects/jboss-deployers/trunk/deployers-spi/src/main/java/org/jboss/deployers/spi/deployer/helpers/AbstractDeployer.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -28,12 +28,14 @@
 import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnitExt;
 import org.jboss.logging.Logger;
 
 /**
  * AbstractDeployer.
  * 
  * @author <a href="adrian at jboss.org">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.org">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
 public abstract class AbstractDeployer implements Deployer
@@ -450,4 +452,19 @@
    {
       // Nothing
    }
+
+   /**
+    * Change relative order on unit.
+    *
+    * @param unit the deploymenty unit
+    * @param relativeOrder the relative order
+    */
+   protected static void changeRelativeOrder(DeploymentUnit unit, int relativeOrder)
+   {
+      if (unit instanceof DeploymentUnitExt)
+      {
+         DeploymentUnitExt ext = (DeploymentUnitExt) unit;
+         ext.changeRelativeOrder(relativeOrder);
+      }
+   }
 }

Added: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentContextExt.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentContextExt.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentContextExt.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,54 @@
+/*
+* 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;
+
+/**
+ * DeploymentContextExt -- extensions to context.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface DeploymentContextExt
+{
+   /**
+    * Change relative relative order.
+    *
+    * @param relativeOrder the relative order
+    */
+   void changeRelativeOrder(int relativeOrder);
+
+   /**
+    * Mark as dirty.
+    *
+    * @param type dirty flag type
+    */
+   void markDirty(DirtyType type);
+
+
+   /**
+    * The dirty type.
+    */
+   public enum DirtyType
+   {
+      SUB_DEPLOYMENT,
+      COMPONENT
+   }
+}
\ No newline at end of file

Copied: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnitExt.java (from rev 101619, projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnit.java)
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnitExt.java	                        (rev 0)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/DeploymentUnitExt.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -0,0 +1,37 @@
+/*
+* 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;
+
+/**
+ * DeploymentUnitExt -- extensions to unit.
+ *
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public interface DeploymentUnitExt
+{
+   /**
+    * Change relative relative order.
+    * 
+    * @param relativeOrder the relative order
+    */
+   void changeRelativeOrder(int relativeOrder);
+}
\ No newline at end of file

Modified: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2010-03-01 15:29:29 UTC (rev 101662)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -21,26 +21,18 @@
  */
 package org.jboss.deployers.structure.spi.helpers;
 
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.SortedSet;
-import java.util.TreeSet;
+import java.util.*;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.CopyOnWriteArraySet;
 
-import javax.management.MBeanRegistration;
-import javax.management.MBeanServer;
-import javax.management.MalformedObjectNameException;
-import javax.management.ObjectName;
-
 import org.jboss.classloading.spi.RealClassLoader;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.dependency.spi.DependencyInfo;
@@ -52,12 +44,7 @@
 import org.jboss.deployers.spi.attachments.helpers.ManagedObjectsWithTransientAttachmentsImpl;
 import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.deployer.DeploymentStages;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
-import org.jboss.deployers.structure.spi.DeploymentMBean;
-import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.*;
 import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
 import org.jboss.deployers.structure.spi.scope.helpers.DefaultScopeBuilder;
 import org.jboss.logging.Logger;
@@ -77,7 +64,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
-public class AbstractDeploymentContext extends ManagedObjectsWithTransientAttachmentsImpl implements DeploymentContext, AbstractDeploymentContextMBean, MBeanRegistration
+public class AbstractDeploymentContext extends ManagedObjectsWithTransientAttachmentsImpl implements DeploymentContext, DeploymentContextExt, AbstractDeploymentContextMBean, MBeanRegistration
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 7368360479461613969L;
@@ -159,7 +146,10 @@
    
    /** The required stage */
    private DeploymentStage requiredStage = DeploymentStages.INSTALLED;
-   
+
+   /** The dirty flag types */
+   private Set<DirtyType> dirty = Collections.emptySet();
+
    /**
     * Get the scope builder for a deployment context
     * 
@@ -372,6 +362,24 @@
       this.relativePath = relativePath;
    }
 
+   public void changeRelativeOrder(int relativeOrder)
+   {
+      if (parent != null && parent instanceof DeploymentContextExt)
+      {
+         DeploymentContextExt ext = (DeploymentContextExt) parent;
+         ext.markDirty(DirtyType.SUB_DEPLOYMENT);
+      }
+      setRelativeOrder(relativeOrder);
+   }
+
+   public synchronized void markDirty(DirtyType type)
+   {
+      if (dirty instanceof CopyOnWriteArraySet == false)
+         dirty = new CopyOnWriteArraySet<DirtyType>();
+
+      dirty.add(type);
+   }
+
    public String getName()
    {
       return name;
@@ -655,8 +663,19 @@
    {
       if (children == null || children.isEmpty())
          return Collections.emptyList();
-      
-      return new ArrayList<DeploymentContext>(children);
+
+      synchronized (this)
+      {
+         List<DeploymentContext> contexts = new ArrayList<DeploymentContext>(children);
+         if (dirty.remove(DirtyType.SUB_DEPLOYMENT))
+         {
+            Collections.sort(contexts, comparator);
+            SortedSet<DeploymentContext> copy = new TreeSet<DeploymentContext>(comparator);
+            copy.addAll(contexts);
+            children = copy; // fixed/re-ordered copy
+         }
+         return contexts;
+      }
    }
 
    public List<ObjectName> getChildNames()
@@ -700,7 +719,23 @@
    
    public List<DeploymentContext> getComponents()
    {
-      return Collections.unmodifiableList(components);
+      if (components == null || components.isEmpty())
+         return Collections.emptyList();
+
+      synchronized (this)
+      {
+         if (dirty.remove(DirtyType.COMPONENT))
+         {
+            List<DeploymentContext> copy = new ArrayList<DeploymentContext>(components);
+            Collections.sort(copy, RelativeDeploymentContextComparator.getInstance());
+            components = copy;
+            return copy;
+         }
+         else
+         {
+            return Collections.unmodifiableList(components);
+         }
+      }
    }
 
    public List<ObjectName> getComponentNames()

Modified: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java	2010-03-01 15:29:29 UTC (rev 101662)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -39,11 +39,7 @@
 import org.jboss.deployers.spi.deployer.DeploymentStage;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
 import org.jboss.deployers.spi.attachments.helpers.AbstractMutableAttachments;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
+import org.jboss.deployers.structure.spi.*;
 import org.jboss.metadata.spi.MetaData;
 import org.jboss.metadata.spi.MutableMetaData;
 import org.jboss.metadata.spi.scope.ScopeKey;
@@ -59,7 +55,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 1.1 $
  */
-public class AbstractDeploymentUnit extends AbstractMutableAttachments implements DeploymentUnit
+public class AbstractDeploymentUnit extends AbstractMutableAttachments implements DeploymentUnit, DeploymentUnitExt
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = 1513962148798298768L;
@@ -86,7 +82,16 @@
          throw new IllegalArgumentException("Null deployment context");
       this.deploymentContext = deploymentContext;
    }
-   
+
+   public void changeRelativeOrder(int relativeOrder)
+   {
+      if (deploymentContext instanceof DeploymentContextExt)
+      {
+         DeploymentContextExt ext = (DeploymentContextExt) deploymentContext;
+         ext.changeRelativeOrder(relativeOrder);
+      }
+   }
+
    public String getName()
    {
       return deploymentContext.getName();

Modified: projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
===================================================================
--- projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2010-03-01 15:29:29 UTC (rev 101662)
+++ projects/jboss-deployers/trunk/deployers-structure-spi/src/main/java/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2010-03-01 15:37:06 UTC (rev 101663)
@@ -29,6 +29,7 @@
 import java.util.Set;
 import java.util.HashSet;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.CopyOnWriteArraySet;
 
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
@@ -44,12 +45,7 @@
 import org.jboss.deployers.spi.attachments.Attachments;
 import org.jboss.deployers.spi.attachments.AttachmentsFactory;
 import org.jboss.deployers.spi.attachments.MutableAttachments;
-import org.jboss.deployers.structure.spi.ClassLoaderFactory;
-import org.jboss.deployers.structure.spi.DeploymentContext;
-import org.jboss.deployers.structure.spi.DeploymentContextVisitor;
-import org.jboss.deployers.structure.spi.DeploymentMBean;
-import org.jboss.deployers.structure.spi.DeploymentResourceLoader;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.*;
 import org.jboss.deployers.structure.spi.scope.ScopeBuilder;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.spi.MetaData;
@@ -64,7 +60,7 @@
  * @author <a href="ales.justin at jboss.com">Ales Justin</a>
  * @version $Revision: 59630 $
  */
-public class ComponentDeploymentContext implements DeploymentContext, ComponentDeploymentContextMBean, MBeanRegistration
+public class ComponentDeploymentContext implements DeploymentContext, DeploymentContextExt, ComponentDeploymentContextMBean, MBeanRegistration
 {
    /** The serialVersionUID */
    private static final long serialVersionUID = -5105972679660633071L;
@@ -104,7 +100,13 @@
    
    /** The mutable scope */
    private ScopeKey mutableScope;
-   
+
+   /** The relative order */
+   private int relativeOrder;
+
+   /** The dirty flag type */
+   private Set<DirtyType> dirty = Collections.emptySet();
+
    /**
     * For serialization
     */
@@ -129,6 +131,24 @@
       this.parent = parent;
    }
 
+   public void changeRelativeOrder(int relativeOrder)
+   {
+      if (parent != null && parent instanceof DeploymentContextExt)
+      {
+         DeploymentContextExt ext = (DeploymentContextExt) parent;
+         ext.markDirty(DirtyType.COMPONENT);
+      }
+      setRelativeOrder(relativeOrder);
+   }
+
+   public synchronized void markDirty(DirtyType type)
+   {
+      if (dirty instanceof CopyOnWriteArraySet == false)
+         dirty = new CopyOnWriteArraySet<DirtyType>();
+
+      dirty.add(type);
+   }
+
    public String getName()
    {
       return name;
@@ -189,12 +209,12 @@
 
    public int getRelativeOrder()
    {
-      return 0;
+      return relativeOrder;
    }
 
    public void setRelativeOrder(int relativeOrder)
    {
-      // No relative ordering of components?
+      this.relativeOrder = relativeOrder;
    }
 
    public Comparator<DeploymentContext> getComparator()
@@ -379,7 +399,23 @@
 
    public List<DeploymentContext> getComponents()
    {
-      return Collections.unmodifiableList(components);
+      if (components == null || components.isEmpty())
+         return Collections.emptyList();
+
+      synchronized (this)
+      {
+         if (dirty.remove(DirtyType.COMPONENT))
+         {
+            List<DeploymentContext> copy = new ArrayList<DeploymentContext>(components);
+            Collections.sort(copy, RelativeDeploymentContextComparator.getInstance());
+            components = copy;
+            return copy;
+         }
+         else
+         {
+            return Collections.unmodifiableList(components);
+         }
+      }
    }
 
    public List<ObjectName> getComponentNames()




More information about the jboss-cvs-commits mailing list