[jboss-cvs] JBossAS SVN: r64369 - in projects/microcontainer/trunk: deployers-core-spi/src/main/org/jboss/deployers/spi/structure and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 31 09:07:19 EDT 2007
Author: adrian at jboss.org
Date: 2007-07-31 09:07:19 -0400 (Tue, 31 Jul 2007)
New Revision: 64369
Added:
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentContextComparator.java
projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/HeuristicDeploymentRelativeOrderUnitTestCase.java
projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/DefaultDeploymentContextComparator.java
Modified:
projects/microcontainer/trunk/deployers-core-spi/src/main/org/jboss/deployers/spi/structure/ContextInfo.java
projects/microcontainer/trunk/deployers-core/src/main/org/jboss/deployers/plugins/structure/ContextInfoImpl.java
projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.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/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
Log:
[JBMICROCONT-168] - Add support for ordering of child deployments.
There is a relativeOrder and a comparator.
The default comparator sorts by relative order then simple name.
Modified: projects/microcontainer/trunk/deployers-core/src/main/org/jboss/deployers/plugins/structure/ContextInfoImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-core/src/main/org/jboss/deployers/plugins/structure/ContextInfoImpl.java 2007-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-core/src/main/org/jboss/deployers/plugins/structure/ContextInfoImpl.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -54,10 +54,10 @@
/** The class path entries */
private List<ClassPathEntry> classPath = ClassPathEntryImpl.DEFAULT;
- public String getPath()
- {
- return path;
- }
+ private int relativeOrder = 0;
+
+ /** The comparator class name */
+ private String comparatorClassName;
/**
* Create a new ContextInfoImpl.
@@ -105,6 +105,11 @@
setMetaDataPath(metaDataPath);
setClassPath(classPath);
}
+
+ public String getPath()
+ {
+ return path;
+ }
/**
* Set the path.
@@ -166,6 +171,26 @@
classPath.add(entry);
}
+ public String getComparatorClassName()
+ {
+ return comparatorClassName;
+ }
+
+ public void setComparatorClassName(String className)
+ {
+ this.comparatorClassName = className;
+ }
+
+ public int getRelativeOrder()
+ {
+ return relativeOrder;
+ }
+
+ public void setRelativeOrder(int relativeOrder)
+ {
+ this.relativeOrder = relativeOrder;
+ }
+
@Override
public String toString()
{
@@ -187,6 +212,10 @@
builder.append("path=").append(getPath());
builder.append(" metaData=").append(getMetaDataPath());
builder.append(" classPath=").append(getClassPath());
+ if (relativeOrder != 0)
+ builder.append(" relativeOrder=").append(getRelativeOrder());
+ if (comparatorClassName != null)
+ builder.append(" comparator=").append(getComparatorClassName());
}
@Override
@@ -230,6 +259,10 @@
if (isNullMetaDataPath == false)
setMetaDataPath(in.readUTF());
setClassPath((List) in.readObject());
+ setRelativeOrder(in.readInt());
+ boolean isNullComparator = in.readBoolean();
+ if (isNullComparator == false)
+ setComparatorClassName(in.readUTF());
}
/**
@@ -249,5 +282,11 @@
if (isNullMetaDataPath == false)
out.writeUTF(metaDataPath);
out.writeObject(getClassPath());
+ out.writeInt(getRelativeOrder());
+ String comparator = getComparatorClassName();
+ boolean isNullComparator = (comparator == null);
+ out.writeBoolean(isNullComparator);
+ if (isNullComparator == false)
+ out.writeUTF(comparator);
}
}
Modified: projects/microcontainer/trunk/deployers-core-spi/src/main/org/jboss/deployers/spi/structure/ContextInfo.java
===================================================================
--- projects/microcontainer/trunk/deployers-core-spi/src/main/org/jboss/deployers/spi/structure/ContextInfo.java 2007-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-core-spi/src/main/org/jboss/deployers/spi/structure/ContextInfo.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -66,4 +66,40 @@
* @throws IllegalArgumentException for a null entry
*/
void addClassPathEntry(ClassPathEntry entry);
+
+ /**
+ * Get the relative order of this context
+ *
+ * @return the relative order
+ */
+ int getRelativeOrder();
+
+ /**
+ * Set the relative order of this context
+ *
+ * @param relativeOrder the relative order
+ */
+ void setRelativeOrder(int relativeOrder);
+
+ /**
+ * The comparator class name, the class must implement
+ * <pre>
+ * java.util.Comparator<DeploymentContext>
+ * </pre>
+ *
+ * If the class has a public static field called "INSTANCE"
+ * then that will be used rather than creating a new object.<p>
+ *
+ * If none is given then the deployments are ordered
+ * by their relative order and then path/simple name.
+ *
+ * @return the comparator class name
+ */
+ String getComparatorClassName();
+
+ /**
+ * The comparator class name, the class must implement
+ * @param className the comparator class name
+ */
+ void setComparatorClassName(String className);
}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentContextComparator.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentContextComparator.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/support/TestDeploymentContextComparator.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -0,0 +1,49 @@
+/*
+* 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.Comparator;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.helpers.DefaultDeploymentContextComparator;
+
+/**
+ * TestDeploymentContextComparator.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class TestDeploymentContextComparator implements Comparator<DeploymentContext>
+{
+ private static DefaultDeploymentContextComparator delegate = DefaultDeploymentContextComparator.INSTANCE;
+
+ public static final TestDeploymentContextComparator INSTANCE = new TestDeploymentContextComparator();
+
+ private TestDeploymentContextComparator()
+ {
+ }
+
+ public int compare(DeploymentContext o1, DeploymentContext o2)
+ {
+ return -delegate.compare(o1, o2);
+ }
+}
Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/HeuristicDeploymentRelativeOrderUnitTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/HeuristicDeploymentRelativeOrderUnitTestCase.java (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/deployer/test/HeuristicDeploymentRelativeOrderUnitTestCase.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -0,0 +1,153 @@
+/*
+* 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.Collections;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.jboss.deployers.client.plugins.deployment.AbstractDeployment;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.DeploymentFactory;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.structure.ContextInfo;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.deployer.support.TestDeploymentContextComparator;
+import org.jboss.test.deployers.deployer.support.TestSimpleDeployer3;
+
+/**
+ * DeployerDependencyUnitTestCase.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class HeuristicDeploymentRelativeOrderUnitTestCase extends AbstractDeployerTest
+{
+ private static final DeploymentFactory factory = new DeploymentFactory();
+
+ private TestSimpleDeployer3 deployer1 = new TestSimpleDeployer3(DeploymentStages.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> PC1C2 = makeList(P, C1, C2);
+ private static List<String> PC2C1 = makeList(P, C2, C1);
+ private static List<String> C2C1P = makeList(C2, C1, P);
+ private static List<String> C1C2P = makeList(C1, C2, P);
+
+ @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;
+ }
+
+ public static Test suite()
+ {
+ return new TestSuite(HeuristicDeploymentRelativeOrderUnitTestCase.class);
+ }
+
+ public HeuristicDeploymentRelativeOrderUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testNoRelativeOrderUsesSimpleName() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment parent = createSimpleDeployment("Parent");
+ factory.addContext(parent, "C1");
+ factory.addContext(parent, "C2");
+ main.addDeployment(parent);
+
+ main.process();
+
+ assertEquals(PC1C2, deployer1.deployed);
+ assertEquals(NONE, deployer1.undeployed);
+
+ main.removeDeployment(parent);
+ main.process();
+
+ assertEquals(PC1C2, deployer1.deployed);
+ assertEquals(C2C1P, deployer1.undeployed);
+ }
+
+ public void testRelativeOrder() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ Deployment parent = createSimpleDeployment("Parent");
+ ContextInfo c1 = factory.addContext(parent, "C1");
+ c1.setRelativeOrder(2);
+ ContextInfo c2 = factory.addContext(parent, "C2");
+ c2.setRelativeOrder(1);
+ 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 testComparator() throws Exception
+ {
+ DeployerClient main = getMainDeployer();
+
+ AbstractDeployment parent = new AbstractDeployment("Parent");
+ ContextInfo p = factory.addContext(parent, "");
+ // Reverse the default comparison
+ p.setComparatorClassName(TestDeploymentContextComparator.class.getName());
+ 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);
+ }
+
+ protected DeployerClient getMainDeployer()
+ {
+ return createMainDeployer(deployer1);
+ }
+}
Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java 2007-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/DeploymentStage.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -147,4 +147,10 @@
{
return before;
}
+
+ @Override
+ public String toString()
+ {
+ return getName();
+ }
}
Modified: projects/microcontainer/trunk/deployers-structure-spi/.classpath
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/.classpath 2007-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/.classpath 2007-07-31 13:07:19 UTC (rev 64369)
@@ -35,4 +35,5 @@
<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="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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/pom.xml 2007-07-31 13:07:19 UTC (rev 64369)
@@ -31,6 +31,10 @@
<!-- Global dependencies -->
<dependency>
<groupId>org.jboss.microcontainer</groupId>
+ <artifactId>jboss-dependency</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.microcontainer</groupId>
<artifactId>jboss-deployers-client-spi</artifactId>
</dependency>
<dependency>
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentContext.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -21,9 +21,11 @@
*/
package org.jboss.deployers.structure.spi;
+import java.util.Comparator;
import java.util.List;
import java.util.Set;
+import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.DeploymentState;
@@ -72,6 +74,34 @@
String getRelativePath();
/**
+ * Get the relative order
+ *
+ * @return the relative order
+ */
+ int getRelativeOrder();
+
+ /**
+ * Set the relative order
+ *
+ * @param relativeOrder the relativeOrder
+ */
+ void setRelativeOrder(int relativeOrder);
+
+ /**
+ * Get the comparator.
+ *
+ * @return the comparator.
+ */
+ Comparator<DeploymentContext> getComparator();
+
+ /**
+ * Set the comparator.
+ *
+ * @param comparator the comparator.
+ */
+ void setComparator(Comparator<DeploymentContext> comparator);
+
+ /**
* Get the deployment types associated with this deployment.
* @return set of deployment type names deployers have identified
* in this deployment.
@@ -241,6 +271,13 @@
* @return the resource classloader loader
*/
ClassLoader getResourceClassLoader();
+
+ /**
+ * Get the dependency info
+ *
+ * @return the dependency
+ */
+ DependencyInfo getDependencyInfo();
/**
* Visit the context and the children
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/DeploymentUnit.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -24,6 +24,8 @@
import java.util.List;
import java.util.Set;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.attachments.MutableAttachments;
@@ -174,4 +176,25 @@
* @return the resource classloader loader
*/
ClassLoader getResourceClassLoader();
+
+ /**
+ * Get the dependency info
+ *
+ * @return the dependency
+ */
+ DependencyInfo getDependencyInfo();
+
+ /**
+ * Add a dependency
+ *
+ * @param dependency the dependency to add
+ */
+ void addIDependOn(DependencyItem dependency);
+
+ /**
+ * Remove a dependency
+ *
+ * @param dependency the dependency to remove
+ */
+ void removeIDependOn(DependencyItem dependency);
}
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -24,12 +24,18 @@
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.List;
import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CopyOnWriteArraySet;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.DeploymentState;
@@ -96,11 +102,17 @@
private Set<String> deploymentTypes = new CopyOnWriteArraySet<String>();
/** The child contexts */
- private List<DeploymentContext> children = new CopyOnWriteArrayList<DeploymentContext>();
+ private SortedSet<DeploymentContext> children;
/** The component contexts */
private List<DeploymentContext> components = new CopyOnWriteArrayList<DeploymentContext>();
+ /** The relative order */
+ private int relativeOrder;
+
+ /** The context comparator */
+ private Comparator<DeploymentContext> comparator = DefaultDeploymentContextComparator.INSTANCE;
+
/**
* For serialization
*/
@@ -156,6 +168,28 @@
return relativePath;
}
+ public int getRelativeOrder()
+ {
+ return relativeOrder;
+ }
+
+ public void setRelativeOrder(int relativeOrder)
+ {
+ this.relativeOrder = relativeOrder;
+ }
+
+ public Comparator<DeploymentContext> getComparator()
+ {
+ return comparator;
+ }
+
+ public void setComparator(Comparator<DeploymentContext> comparator)
+ {
+ if (comparator == null)
+ comparator = DefaultDeploymentContextComparator.INSTANCE;
+ this.comparator = comparator;
+ }
+
public Set<String> getTypes()
{
return deploymentTypes;
@@ -281,13 +315,18 @@
public List<DeploymentContext> getChildren()
{
- return Collections.unmodifiableList(children);
+ if (children == null || children.isEmpty())
+ return Collections.emptyList();
+
+ return new ArrayList<DeploymentContext>(children);
}
public void addChild(DeploymentContext child)
{
if (child == null)
throw new IllegalArgumentException("Null child");
+ if (children == null)
+ children = new TreeSet<DeploymentContext>(comparator);
children.add(child);
}
@@ -295,6 +334,8 @@
{
if (child == null)
throw new IllegalArgumentException("Null child");
+ if (children == null)
+ return false;
return children.remove(child);
}
@@ -346,6 +387,20 @@
return EmptyResourceLoader.INSTANCE;
}
+ public DependencyInfo getDependencyInfo()
+ {
+ ControllerContext controllerContext = getTransientAttachments().getAttachment(ControllerContext.class);
+ if (controllerContext != null)
+ return controllerContext.getDependencyInfo();
+ else
+ {
+ DeploymentContext parent = getParent();
+ if (parent == null)
+ throw new IllegalStateException("Deployment ControllerContext has not been set");
+ return parent.getDependencyInfo();
+ }
+ }
+
public void visit(DeploymentContextVisitor visitor) throws DeploymentException
{
if (visitor == null)
@@ -487,7 +542,7 @@
deployed = in.readBoolean();
parent = (DeploymentContext) in.readObject();
deploymentTypes = (Set) in.readObject();
- children = (List) in.readObject();
+ children = (SortedSet) in.readObject();
components = (List) in.readObject();
}
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentUnit.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -32,6 +32,8 @@
import java.util.Map;
import java.util.Set;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.deployers.spi.attachments.helpers.AbstractMutableAttachments;
@@ -348,6 +350,21 @@
return deploymentContext.getResourceLoader();
}
+ public void addIDependOn(DependencyItem dependency)
+ {
+ getDependencyInfo().addIDependOn(dependency);
+ }
+
+ public DependencyInfo getDependencyInfo()
+ {
+ return deploymentContext.getDependencyInfo();
+ }
+
+ public void removeIDependOn(DependencyItem dependency)
+ {
+ getDependencyInfo().removeIDependOn(dependency);
+ }
+
/**
* Get the deployment context
*
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractStructureBuilder.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -21,14 +21,14 @@
*/
package org.jboss.deployers.structure.spi.helpers;
+import java.lang.reflect.Field;
+import java.util.Comparator;
import java.util.List;
-import java.util.Map.Entry;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.DeploymentState;
import org.jboss.deployers.spi.attachments.Attachments;
-import org.jboss.deployers.spi.attachments.MutableAttachments;
import org.jboss.deployers.spi.structure.ContextInfo;
import org.jboss.deployers.spi.structure.StructureMetaData;
import org.jboss.deployers.spi.structure.StructureMetaDataFactory;
@@ -148,7 +148,7 @@
/**
* Apply the context info. This transfers the PredeterminedManagedObjects
- * and TransientManagedObjects from the ContextInfo the DeploymentContext.
+ * and TransientManagedObjects and other information from the ContextInfo to the DeploymentContext.
*
* @param context the context
* @param contextInfo the contextInfo
@@ -159,9 +159,46 @@
Attachments attachments = contextInfo.getPredeterminedManagedObjects();
if (attachments != null)
context.setPredeterminedManagedObjects(attachments);
+
+ context.setRelativeOrder(contextInfo.getRelativeOrder());
+ applyComparator(context, contextInfo);
}
/**
+ * Try to apply the comparator
+ *
+ * @param context the context
+ * @param contextInfo the contextInfo
+ * @throws Exception for any error
+ */
+ @SuppressWarnings("unchecked")
+ protected void applyComparator(DeploymentContext context, ContextInfo contextInfo) throws Exception
+ {
+ String className = contextInfo.getComparatorClassName();
+ Object o = null;
+ try
+ {
+ Class clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
+ try
+ {
+ Field field = clazz.getField("INSTANCE");
+ o = field.get(null);
+ }
+ catch (NoSuchFieldException ignored)
+ {
+ }
+ if (o == null)
+ o = clazz.newInstance();
+ Comparator comparator = Comparator.class.cast(o);
+ context.setComparator(comparator);
+ }
+ catch (Throwable t)
+ {
+ log.warn("Unable to load/set comparator: " + className);
+ }
+ }
+
+ /**
* Create the root deployment context
*
* @param deployment the deployment
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-07-31 11:54:05 UTC (rev 64368)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -22,10 +22,12 @@
package org.jboss.deployers.structure.spi.helpers;
import java.util.Collections;
+import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.deployers.client.spi.Deployment;
import org.jboss.deployers.spi.DeploymentException;
import org.jboss.deployers.spi.DeploymentState;
@@ -71,7 +73,7 @@
/** The managed objects */
private transient MutableAttachments transientManagedObjects = AttachmentsFactory.createMutableAttachments();
-
+
/**
* For serialization
*/
@@ -111,6 +113,26 @@
return parent.getRelativePath();
}
+ public int getRelativeOrder()
+ {
+ return 0;
+ }
+
+ public void setRelativeOrder(int relativeOrder)
+ {
+ // No relative ordering of components?
+ }
+
+ public Comparator<DeploymentContext> getComparator()
+ {
+ return null;
+ }
+
+ public void setComparator(Comparator<DeploymentContext> comparator)
+ {
+ // No relative ordering of components?
+ }
+
public Set<String> getTypes()
{
return parent.getTypes();
@@ -241,6 +263,11 @@
return parent.getResourceLoader();
}
+ public DependencyInfo getDependencyInfo()
+ {
+ return parent.getDependencyInfo();
+ }
+
public void visit(DeploymentContextVisitor visitor) throws DeploymentException
{
if (visitor == null)
Added: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/DefaultDeploymentContextComparator.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/DefaultDeploymentContextComparator.java (rev 0)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/DefaultDeploymentContextComparator.java 2007-07-31 13:07:19 UTC (rev 64369)
@@ -0,0 +1,47 @@
+/*
+* 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.helpers;
+
+import java.util.Comparator;
+
+import org.jboss.deployers.structure.spi.DeploymentContext;
+
+/**
+ * DefaultDeploymentContextComparator.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultDeploymentContextComparator implements Comparator<DeploymentContext>
+{
+ /** The singleton */
+ public static final DefaultDeploymentContextComparator INSTANCE = new DefaultDeploymentContextComparator();
+
+ public int compare(DeploymentContext o1, DeploymentContext o2)
+ {
+ int relative = o1.getRelativeOrder() - o2.getRelativeOrder();
+ if (relative != 0)
+ return relative;
+ else
+ return o1.getSimpleName().compareTo(o2.getRelativePath());
+ }
+}
More information about the jboss-cvs-commits
mailing list