You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by mc...@apache.org on 2008/05/21 06:55:53 UTC

svn commit: r658553 [1/3] - in /geronimo/devtools/eclipse-plugin/trunk/plugins: org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/ org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/ org.apache.ge...

Author: mcconne
Date: Tue May 20 21:55:52 2008
New Revision: 658553

URL: http://svn.apache.org/viewvc?rev=658553&view=rev
Log:
GERONIMODEVTOOLS-347 DependencyHelper class and testcases ready

Added:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-application-example-1.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-ra-example-11.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-ra-example-2.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-3.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-4.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-5.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-6.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-7.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/geronimo-web-example-8.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/openejb-jar-example-10.xml   (with props)
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/resources/dependencyhelper/openejb-jar-example-9.xml   (with props)
Modified:
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/Artifact.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyManager.java
    geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyManagerTest.java

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/Artifact.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/Artifact.java?rev=658553&r1=658552&r2=658553&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/Artifact.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.jee.v21.jaxbmodel/src/main/java/org/apache/geronimo/jee/deployment/Artifact.java Tue May 20 21:55:52 2008
@@ -195,4 +195,64 @@
         this.type = value;
     }
 
+
+    /**
+     * 
+     * @return String representation of Artifact
+     */
+    public String toString() {
+        StringBuffer buffer = new StringBuffer();
+
+        if (groupId != null) {
+            buffer.append(groupId);
+        }
+        buffer.append("/");
+
+        if (artifactId != null) {
+            buffer.append(artifactId);
+        }
+        buffer.append("/");
+
+        if (version != null) {
+            buffer.append(version);
+        }
+        buffer.append("/");
+
+        if (type != null) {
+            buffer.append(type);
+        }
+        return buffer.toString();
+    }
+
+
+    /**
+     * 
+     */
+    public boolean equals(Object o) {
+
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        final Artifact that = (Artifact) o;
+
+        if (groupId != null ? !groupId.equals(that.groupId) : that.groupId != null) return false;
+        if (artifactId != null ? !artifactId.equals(that.artifactId) : that.artifactId != null) return false;
+        if (version != null ? !version.equals(that.version) : that.version != null) return false;
+        if (type != null ? !type.equals(that.type) : that.type != null) return false;
+
+        return true;
+    }
+    
+    /**
+     * 
+     */
+    public int hashCode() {
+        int result;
+        result = (groupId != null ? groupId.hashCode() : 0);
+        result = 29 * result + (artifactId != null? artifactId.hashCode() : 0);
+        result = 29 * result + (version != null ? version.hashCode() : 0);
+        result = 29 * result + (type != null ? type.hashCode() : 0);
+        return result;
+    }
+
 }

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java?rev=658553&r1=658552&r2=658553&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/GeronimoServerBehaviourDelegate.java Tue May 20 21:55:52 2008
@@ -36,6 +36,7 @@
 import org.apache.geronimo.st.core.commands.DeploymentCmdStatus;
 import org.apache.geronimo.st.core.commands.DeploymentCommandFactory;
 import org.apache.geronimo.st.core.commands.IDeploymentCommand;
+import org.apache.geronimo.st.core.internal.DependencyHelper;
 import org.apache.geronimo.st.core.internal.Messages;
 import org.apache.geronimo.st.core.internal.Trace;
 import org.apache.geronimo.st.core.operations.ISharedLibEntryCreationDataModelProperties;
@@ -131,7 +132,7 @@
 	 * @throws CoreException
 	 */
 	synchronized protected void setupLaunch(ILaunch launch, String launchMode, IProgressMonitor monitor) throws CoreException {
-		Trace.trace(Trace.INFO, "--> GeronimoServerBehaviorDelegate.setupLaunch()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.setupLaunch", launch, launchMode, monitor); 
 
 		if (!SocketUtil.isLocalhost(getServer().getHost()))
 			return;
@@ -162,7 +163,8 @@
 		};
 
 		getServer().addServerListener(listener);
-		Trace.trace(Trace.INFO, "<-- GeronimoServerBehaviorDelegate.setupLaunch()");
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.setupLaunch");
 	}
 
 	/*
@@ -171,7 +173,8 @@
 	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#stop(boolean)
 	 */
     synchronized public void stop(final boolean force) {
-        Trace.trace(Trace.INFO, "--> stop()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.stop", force);
+
         stopPingThread();
         if (getServer().getServerState() != IServer.STATE_STOPPED) {
             setServerState(IServer.STATE_STOPPING);
@@ -187,7 +190,8 @@
             return;
         if (state == IServer.STATE_STARTING || state == IServer.STATE_STOPPING)
             terminate();
-        Trace.trace(Trace.INFO, "<-- stop()");
+                                                   
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.stop");
     }
 
 	/* 
@@ -200,6 +204,20 @@
 	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishModules(int, java.util.List, java.util.List, org.eclipse.core.runtime.MultiStatus, org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	protected void publishModules(int kind, List modules, List deltaKind, MultiStatus multi, IProgressMonitor monitor) {
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.publishModules", deltaKindToString(kind), Arrays.asList(modules).toString(), Arrays.asList(deltaKind).toString(), multi, monitor);
+
+        // 
+        // WTP publishes modules in reverse alphabetical order which does not account for possible 
+        // dependencies between modules. If necessary reorder the publish order of the modules 
+        // based on any discovered dependencies. 
+        //
+        if (modules != null && modules.size() > 0) {
+            DependencyHelper dh = new DependencyHelper();
+            List list = dh.reorderModules(modules, deltaKind);
+            modules = (List) list.get(0);
+            deltaKind = (List) list.get(1);
+        }
+
 		IStatus status = Status.OK_STATUS;
 		if (modules != null && modules.size() > 0 && getGeronimoServer().isInPlaceSharedLib()) {
 			List rootModules = new ArrayList<IModule>();
@@ -244,6 +262,8 @@
 		} else {
 			multi.add(status);
 		}
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishModules");
 	}
 
 	/*
@@ -254,9 +274,8 @@
 	 *      org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	public void publishModule(int kind, int deltaKind, IModule[] module, IProgressMonitor monitor) throws CoreException {
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.publishModule", deltaKindToString(kind), deltaKindToString(deltaKind), Arrays.asList(module).toString(), monitor);
 
-		Trace.trace(Trace.INFO, ">> publishModule(), deltaKind = " + deltaKindToString(deltaKind), true);
-		Trace.trace(Trace.INFO, Arrays.asList(module).toString());
 		_monitor = monitor;
 
 		try {
@@ -270,7 +289,7 @@
 			setModulePublishState(module, IServer.PUBLISH_STATE_NONE);
 		}
 
-		Trace.trace(Trace.INFO, "<< publishModule()");
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishModule");
 	}
 
 	/*
@@ -279,6 +298,8 @@
 	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#publishFinish(org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	public void publishFinish(IProgressMonitor monitor) throws CoreException {
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.publishFinish", monitor);
+
 		IModule[] modules = this.getServer().getModules();
 		boolean allpublished = true;
 		for (int i = 0; i < modules.length; i++) {
@@ -289,6 +310,8 @@
 			setServerPublishState(IServer.PUBLISH_STATE_NONE);
 
 		GeronimoConnectionFactory.getInstance().destroy(getServer());
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.publishFinish");
 	}
 
 	/*
@@ -297,8 +320,11 @@
 	 * @see org.eclipse.wst.server.core.model.ServerBehaviourDelegate#initialize(org.eclipse.core.runtime.IProgressMonitor)
 	 */
 	protected void initialize(IProgressMonitor monitor) {
-		Trace.trace(Trace.INFO, "GeronimoServerBehavior.initialize()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.initialize", monitor);
+
 		startUpdateServerStateTask();
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.initialize");
 	}
 
 	/*
@@ -327,7 +353,8 @@
 	}
 
 	protected void terminate() {
-		Trace.trace(Trace.INFO,"terminate()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.terminate");
+
 		if (getServer().getServerState() == IServer.STATE_STOPPED)
 			return;
 
@@ -342,6 +369,8 @@
 		} catch (Exception e) {
 			Trace.trace(Trace.SEVERE, "Error killing the geronimo server process", e); //$NON-NLS-1$
 		}
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.terminate");
 	}
 
 	protected void stopImpl() {
@@ -354,6 +383,7 @@
 	}
 
 	protected void invokeCommand(int deltaKind, IModule module) throws CoreException {
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.invokeCommand", deltaKindToString(deltaKind), module.getName());
 		
 		ClassLoader old = Thread.currentThread().getContextClassLoader();
 		try {
@@ -387,6 +417,8 @@
 		} finally {
 			Thread.currentThread().setContextClassLoader(old);
 		}
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.invokeCommand");
 	}	
 
 	/**
@@ -395,7 +427,7 @@
 	 * @throws Exception
 	 */
 	protected void doAdded(IModule module, String configId) throws Exception {
-		Trace.trace(Trace.INFO, ">> doAdded() " + module.toString());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.doAdded", module.getName(), configId);
 		
 		configId = getLastKnowConfigurationId(module, configId);
 		if (configId == null) {
@@ -417,7 +449,7 @@
 			doChanged(module, configId);
 		}
 
-		Trace.trace(Trace.INFO, "<< doAdded() " + module.toString());
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.doAdded");
 	}
 
 	/**
@@ -426,7 +458,7 @@
 	 * @throws Exception
 	 */
 	protected void doChanged(IModule module, String configId) throws Exception {
-		Trace.trace(Trace.INFO, ">> doChanged() " + module.toString());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.doChanged", module.getName(), configId);
 		
 		configId = getLastKnowConfigurationId(module, configId);
 		if(configId != null) {
@@ -446,18 +478,21 @@
 			doAdded(module, configId);
 		}
 
-		Trace.trace(Trace.INFO, "<< doChanged() " + module.toString());
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.doChanged");
 	}
 
 	private String getLastKnowConfigurationId(IModule module, String configId) throws CoreException {
+        Trace.tracePoint("Entry ", "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", module.getName(), configId);
+
 		//use the correct configId, second from the .metadata, then from the plan
 		configId = configId != null ? configId : DeploymentUtils.getLastKnownConfigurationId(module, getServer());
-		Trace.trace(Trace.INFO, "Config ID to be processed: " + configId);
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.getLastKnowConfigurationId", configId);
 		return configId;
 	}
 
 	protected void doRemoved(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRemoved() " + module.toString());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.doRemoved", module.getName());
 
 		IStatus status = unDeploy(module);
 		if (!status.isOK()) {
@@ -466,11 +501,11 @@
 		
 		ModuleArtifactMapper.getInstance().removeEntry(getServer(), module.getProject());
 
-		Trace.trace(Trace.INFO, "<< doRemoved()" + module.toString());
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.doRemoved");
 	}
 	
 	protected void doNoChange(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doNoChange() " + module.toString());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.doNoChange", module.getName());
 		
 		if(DeploymentUtils.getLastKnownConfigurationId(module, getServer()) != null) {
 			start(module);
@@ -478,12 +513,12 @@
 			doAdded(module, null);
 		}
 		
-		Trace.trace(Trace.INFO, "<< doNoChange() " + module.toString());
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.doNoChange");
 	}
 
 	protected void doRestart(IModule module) throws Exception {
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
-
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.doRestart", module.getName());
+		
 		IStatus status = stop(module);
 		if (!status.isOK()) {
 			doFail(status, Messages.STOP_FAIL);
@@ -494,7 +529,7 @@
 			doFail(status, Messages.START_FAIL);
 		}
 
-		Trace.trace(Trace.INFO, ">> doRestart() " + module.toString());
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.doRestart");
 	}
 	
 	private TargetModuleID[] updateServerModuleConfigIDMap(IModule module, IStatus status) {
@@ -643,34 +678,48 @@
 	}
 
 	protected void startPingThread() {
-		Trace.trace(Trace.INFO, "startPingThread()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.startPingThread");
+
 		pingThread = new PingThread(this, getServer());
 		pingThread.start();
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.startPingThread");
 	}
 	
 	protected void stopPingThread() {
-		Trace.trace(Trace.INFO, "stopPingThread()");
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.stopPingThread");
+
 		if (pingThread != null) {
 			pingThread.interrupt();
 			pingThread = null;
 		}
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.stopPingThread");
 	}
 	
 	protected abstract void stopKernel();
 
 	protected void startUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "startUpdateServerStateTask() " + getServer().getName());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.startUpdateServerStateTask", getServer().getName());
+
 		timer = new Timer(true);
 		timer.schedule(new UpdateServerStateTask(this, getServer()), TIMER_TASK_DELAY * 1000, TIMER_TASK_INTERVAL * 1000);
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.startUpdateServerStateTask");
 	}
 
 	public void stopUpdateServerStateTask() {
-		Trace.trace(Trace.INFO, "stopUpdateServerStateTask() " + getServer().getName());
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.stopUpdateServerStateTask", getServer().getName());
+
 		if (timer != null)
 			timer.cancel();
+
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.stopUpdateServerStateTask");
 	}
 
 	protected IPath getModulePath(IModule[] module, URL baseURL) {
+        Trace.tracePoint("Entry", "GeronimoServerBehaviourDelegate.getModulePath", Arrays.asList(module).toString(), baseURL);
+
 		IPath modulePath = new Path(baseURL.getFile());
 
 		if (module.length == 2) {
@@ -689,6 +738,7 @@
 			}
 		}
 
+        Trace.tracePoint("Exit ", "GeronimoServerBehaviourDelegate.getModulePath", modulePath);
 		return modulePath;
 	}
 

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java?rev=658553&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java Tue May 20 21:55:52 2008
@@ -0,0 +1,548 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.st.core.internal;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import javax.xml.bind.JAXBElement;
+
+import org.apache.geronimo.jee.application.Application;
+import org.apache.geronimo.jee.connector.Connector;
+import org.apache.geronimo.jee.deployment.Artifact;
+import org.apache.geronimo.jee.deployment.Dependencies;
+import org.apache.geronimo.jee.deployment.Dependency;
+import org.apache.geronimo.jee.deployment.Environment;
+import org.apache.geronimo.jee.deployment.ObjectFactory;
+import org.apache.geronimo.jee.openejb.OpenejbJar;
+import org.apache.geronimo.jee.web.WebApp;
+import org.apache.geronimo.st.core.GeronimoUtils;
+import org.apache.geronimo.st.core.jaxb.JAXBUtils;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.wst.common.componentcore.resources.IVirtualComponent;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.model.ServerBehaviourDelegate;
+
+/**
+ * <b>DependencyHelper</b> is a helper class with various methods to aid in the discovery of
+ * inter-dependencies between modules being deployed from the GEP to the Geronimo server. It
+ * performs the following capabilities:
+ * <ol>
+ *      <li>Discovery of dependencies between modules<p>
+ *      <li>Provides the proper publishing ordering of the modules based on the discovered
+ *          dependencies<p>
+ *      <li><b>TODO:</b> Query the server searching for missing dependencies
+ * </ol>
+ * 
+ * @version $Rev$ $Date$
+ */
+public class DependencyHelper {
+
+    private DependencyManager dm = new DependencyManager();
+    private ObjectFactory deploymentFactory = new ObjectFactory();
+    private List<JAXBElement> inputJAXBElements = new ArrayList();
+    private List<JAXBElement> reorderedJAXBElements = new ArrayList();
+
+
+    /**
+     * Reorder the publish order of the modules based on any discovered dependencies
+     * 
+     * @param modules   Modules to be published to the Geronimo server
+     * @param deltaKind Publish kind constant for each module
+     * 
+     * @return List of reordered modules and deltaKind (or input if no change)
+     */
+    public List reorderModules( List modules, List deltaKind ) {
+        Trace.tracePoint("Entry", "DependencyHelper.reorderModules", modules, deltaKind);
+
+        int size = modules.size();
+        if (size == 0) {
+            List reorderedLists = new ArrayList(2);
+            reorderedLists.add( modules );
+            reorderedLists.add( deltaKind );
+            Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedLists);
+            return reorderedLists;
+        }
+
+        // 
+        // Iterate through all the modules and register the dependencies
+        // 
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
+                Environment environment = getEnvironment(module[0]);
+                if (environment != null) {
+                    Artifact child = environment.getModuleId();
+                    Dependencies dependencies = environment.getDependencies();
+                    if (dependencies != null) {
+                        List<Dependency> depList = dependencies.getDependency();
+                        for ( Dependency dep : depList) {
+                            Artifact parent = deploymentFactory.createArtifact();
+                            parent.setGroupId( dep.getGroupId() );
+                            parent.setArtifactId( dep.getArtifactId() );
+                            parent.setVersion( dep.getVersion() );
+                            parent.setType( dep.getType() );
+                            dm.addDependency( child, parent );
+                        }
+                    }
+                }
+            }
+        }
+
+        // 
+        // Reorder modules and deltaKind as necessary
+        // 
+        List reorderedModules = new ArrayList(size);
+        List reorderedKinds  = new ArrayList(size);
+
+        // Move REMOVED modules first
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind == ServerBehaviourDelegate.REMOVED) {
+                reorderedModules.add( module );
+                reorderedKinds.add( moduleDeltaKind );
+            }
+        }
+
+        // Next move modules with no dependencies
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
+                Environment environment = getEnvironment(module[0]);
+                if (environment != null) {
+                    Artifact artifact = environment.getModuleId();
+                    if (dm.getChildren(artifact).size() == 0 && 
+                        dm.getParents(artifact).size() == 0) {
+                        reorderedModules.add( module );
+                        reorderedKinds.add( moduleDeltaKind );
+                    }
+                }
+            }
+        }
+
+        // Next move modules with children but no parents
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
+                Environment environment = getEnvironment(module[0]);
+                if (environment != null) {
+                    Artifact artifact = environment.getModuleId();
+                    if (dm.getChildren(artifact).size() > 0 &&
+                        dm.getParents(artifact).size() == 0) {
+                        reorderedModules.add( module );
+                        reorderedKinds.add( moduleDeltaKind );
+                    }
+                }
+            }
+        }
+
+        // Next move modules with parents but no children
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
+                Environment environment = getEnvironment(module[0]);
+                if (environment != null) {
+                    Artifact artifact = environment.getModuleId();
+                    if (dm.getChildren(artifact).size() == 0 &&
+                        dm.getParents(artifact).size() > 0) {
+                        reorderedModules.add( module );
+                        reorderedKinds.add( moduleDeltaKind );
+                    }
+                }
+            }
+        }
+
+        // Finally move modules with both parent(s) and children (TODO)
+        for (int ii=0; ii<size; ii++) {
+            IModule[] module = (IModule[]) modules.get(ii);
+            int moduleDeltaKind = ((Integer)deltaKind.get(ii)).intValue();
+            if (moduleDeltaKind != ServerBehaviourDelegate.REMOVED) {
+                Environment environment = getEnvironment(module[0]);
+                if (environment != null) {
+                    Artifact artifact = environment.getModuleId();
+                    if (dm.getChildren(artifact).size() > 0 &&
+                        dm.getParents(artifact).size() > 0) {
+                        reorderedModules.add( module );
+                        reorderedKinds.add( moduleDeltaKind );
+                    }
+                }
+            }
+        }
+
+        // 
+        // Ensure return lists are exactly the same size as the input lists 
+        // 
+        assert reorderedModules.size() == modules.size();
+        assert reorderedKinds.size() == deltaKind.size();
+
+        // 
+        // Return List of lists
+        // 
+        List reorderedLists = new ArrayList(2);
+        reorderedLists.add( reorderedModules );
+        reorderedLists.add( reorderedKinds );
+
+        Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedLists);
+        return reorderedLists;
+    }
+
+
+    /**
+     * Reorder the list of JAXBElements based on any discovered dependencies
+     * 
+     * @param jaxbElements
+     * 
+     * @return List of JAXBElements (or input if no change)
+     */
+    public List<JAXBElement> reorderJAXBElements( List<JAXBElement> jaxbElements ) {
+        Trace.tracePoint("Entry", "DependencyHelper.reorderModules", jaxbElements);
+
+        inputJAXBElements = jaxbElements;
+
+        int size = jaxbElements.size();
+        if (size == 0) {
+            Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", jaxbElements);
+            return jaxbElements;
+        }
+
+        // 
+        // Iterate through all the JAXBElements and register the dependencies
+        // 
+        for (JAXBElement jaxbElement : jaxbElements) {
+            Environment environment = getEnvironment(jaxbElement);
+            if (environment != null) {
+                Artifact child = environment.getModuleId();
+                if (child != null) {
+                    Dependencies dependencies = environment.getDependencies();
+                    if (dependencies != null) {
+                        List<Dependency> depList = dependencies.getDependency();
+                        if (depList != null) {
+                            for ( Dependency dep : depList) {
+                                Artifact parent = deploymentFactory.createArtifact();
+                                parent.setGroupId( dep.getGroupId() );
+                                parent.setArtifactId( dep.getArtifactId() );
+                                parent.setVersion( dep.getVersion() );
+                                parent.setType( dep.getType() );
+                                dm.addDependency( child, parent );
+                            }
+                        }
+                    }
+                }
+            }
+        }
+
+        // 
+        // Iterate through all the JAXBElements again and reorder as necessary
+        // 
+        for (JAXBElement jaxbElement : jaxbElements) {
+            // Already moved ??
+            if (!reorderedJAXBElements.contains(jaxbElement)) {
+                Environment environment = getEnvironment(jaxbElement);
+                if (environment != null) {
+                    Artifact artifact = environment.getModuleId();
+                    if (artifact == null) {
+                        // Move if null (nothing can be done)
+                        if (!reorderedJAXBElements.contains(jaxbElement)) {
+                            reorderedJAXBElements.add(jaxbElement);
+                        }
+                    }
+                    else if (dm.getParents(artifact).contains(artifact) ||  
+                             dm.getChildren(artifact).contains(artifact)) {
+                        // Move if a tight circular dependency (nothing can be done)
+                        if (!reorderedJAXBElements.contains(jaxbElement)) {
+                            reorderedJAXBElements.add(jaxbElement);
+                        }
+                    }
+                    else if (dm.getParents(artifact).size() == 0) {
+                        // Move if no parents (nothing to do)
+                        if (!reorderedJAXBElements.contains(jaxbElement)) {
+                            reorderedJAXBElements.add(jaxbElement);
+                        }
+                    }
+                    else if (dm.getParents(artifact).size() > 0) {
+                        // Move parents first
+                        processParents(dm.getParents(artifact), artifact);
+                        // Move self 
+                        if (!reorderedJAXBElements.contains(jaxbElement)) {
+                            reorderedJAXBElements.add(jaxbElement);
+                        }
+                    }
+                }
+            }
+        }
+
+        // 
+        // Ensure return list is exactly the same size as the input list 
+        // 
+        assert reorderedJAXBElements.size() == jaxbElements.size();
+
+        // 
+        // Return List of JAXBElements
+        // 
+        Trace.tracePoint("Exit ", "DependencyHelper.reorderModules", reorderedJAXBElements);
+        return reorderedJAXBElements;
+    }
+
+
+    /**
+     *
+     */
+    public void close() {
+        dm.close();
+    }
+
+
+    /*--------------------------------------------------------------------------------------------*\
+    |                                                                                              |
+    |  Private method(s)                                                                           | 
+    |                                                                                              |
+    \*--------------------------------------------------------------------------------------------*/
+
+    /**
+     * Returns the Environment for the given IModule
+     * 
+     * @param module IModule to be published
+     * 
+     * @return Environment
+     */
+    private Environment getEnvironment(IModule module) {
+        Trace.tracePoint("Enter", "DependencyHelper.getEnvironment", module);
+
+        Environment environment = null;
+        if (GeronimoUtils.isWebModule(module)) {
+            WebApp plan = getWebDeploymentPlan(module).getValue();
+            if (plan != null)
+                environment = plan.getEnvironment();
+        }
+        else if (GeronimoUtils.isEjbJarModule(module)) {
+            OpenejbJar plan = getOpenEjbDeploymentPlan(module).getValue();
+            if (plan != null)
+                environment = plan.getEnvironment();
+        }
+        else if (GeronimoUtils.isEarModule(module)) {
+            Application plan = getApplicationDeploymentPlan(module).getValue();
+            if (plan != null)
+                environment = plan.getEnvironment();
+        }
+        else if (GeronimoUtils.isRARModule(module)) {
+            Connector plan = getConnectorDeploymentPlan(module).getValue();
+            if (plan != null)
+                environment = plan.getEnvironment();
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getEnvironment", environment);
+        return environment;
+    }
+
+
+    /**
+     * Returns the Environment for the given JAXBElement plan
+     * 
+     * @param jaxbElement JAXBElement plan
+     * 
+     * @return Environment
+     */
+    private Environment getEnvironment(JAXBElement jaxbElement) {
+        Trace.tracePoint("Enter", "DependencyHelper.getEnvironment", jaxbElement);
+
+        Environment environment = null;
+        Object plan = jaxbElement.getValue();
+        if (WebApp.class.isInstance(plan)) {
+            if (plan != null)
+                environment = ((WebApp)plan).getEnvironment();
+        }
+        else if (OpenejbJar.class.isInstance(plan)) {
+            if (plan != null)
+                environment = ((OpenejbJar)plan).getEnvironment();
+        }
+        else if (Application.class.isInstance(plan)) {
+            if (plan != null)
+                environment = ((Application)plan).getEnvironment();
+        }
+        else if (Connector.class.isInstance(plan)) {
+            if (plan != null)
+                environment = ((Connector)plan).getEnvironment();
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getEnvironment", environment);
+        return environment;
+    }
+
+
+    /**
+     * Returns the WebApp for the given IModule
+     * 
+     * @param module IModule to be published
+     * 
+     * @return WebApp
+     */
+    private JAXBElement<WebApp> getWebDeploymentPlan(IModule module) {
+        Trace.tracePoint("Enter", "DependencyHelper.getWebDeploymentPlan", module);
+
+        IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
+        IFile file = GeronimoUtils.getWebDeploymentPlanFile(comp);
+        if (file.getName().equals(GeronimoUtils.WEB_PLAN_NAME) && file.exists()) {
+            Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", JAXBUtils.unmarshalDeploymentPlan(file));
+            return JAXBUtils.unmarshalDeploymentPlan(file);
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getWebDeploymentPlan", null);
+        return null;
+    }
+
+
+    /**
+     * Returns the OpenEjbJar for the given IModule
+     * 
+     * @param module IModule to be published
+     * 
+     * @return OpenEjbJar
+     */
+    private JAXBElement<OpenejbJar> getOpenEjbDeploymentPlan(IModule module) {
+        Trace.tracePoint("Enter", "DependencyHelper.getOpenEjbDeploymentPlan", module);
+
+        IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
+        IFile file = GeronimoUtils.getOpenEjbDeploymentPlanFile(comp);
+        if (file.getName().equals(GeronimoUtils.OPENEJB_PLAN_NAME) && file.exists()) {
+            Trace.tracePoint("Exit ", "DependencyHelper.getOpenEjbDeploymentPlan", JAXBUtils.unmarshalDeploymentPlan(file));
+            return JAXBUtils.unmarshalDeploymentPlan(file);
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getOpenEjbDeploymentPlan", null);
+        return null;
+    }
+
+
+    /**
+     * Returns the Application for the given IModule
+     * 
+     * @param module IModule to be published
+     * 
+     * @return Application
+     */
+    private JAXBElement<Application> getApplicationDeploymentPlan(IModule module) {
+        Trace.tracePoint("Enter", "DependencyHelper.getApplicationDeploymentPlan", module);
+
+        IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
+        IFile file = GeronimoUtils.getApplicationDeploymentPlanFile(comp);
+        if (file.getName().equals(GeronimoUtils.APP_PLAN_NAME) && file.exists()) {
+            Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", JAXBUtils.unmarshalDeploymentPlan(file));
+            return JAXBUtils.unmarshalDeploymentPlan(file);
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", null);
+        return null;
+    }
+
+
+    /**
+     * Returns the Connector for the given IModule
+     * 
+     * @param module IModule to be published
+     * 
+     * @return Application
+     */
+    private JAXBElement<Connector> getConnectorDeploymentPlan(IModule module) {
+        Trace.tracePoint("Enter", "DependencyHelper.getApplicationDeploymentPlan", module);
+
+        IVirtualComponent comp = GeronimoUtils.getVirtualComponent(module);
+        IFile file = GeronimoUtils.getConnectorDeploymentPlanFile(comp);
+        if (file.getName().equals(GeronimoUtils.CONNECTOR_PLAN_NAME) && file.exists()) {
+            Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", JAXBUtils.unmarshalDeploymentPlan(file));
+            return JAXBUtils.unmarshalDeploymentPlan(file);
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.getApplicationDeploymentPlan", null);
+        return null;
+    }
+
+
+    /**
+     * Process the parents for a given artifact. The terminatingArtifact parameter will be used as
+     * the terminating condition to ensure there will not be an infinite loop (i.e., if
+     * terminatingArtifact is encountered again there is a circular dependency).
+     * 
+     * @param parents
+     * @param terminatingArtifact
+     */
+    private void processParents(Set parents, Artifact terminatingArtifact) {
+        Trace.tracePoint("Enter", "DependencyHelper.processParents", parents, terminatingArtifact );
+
+        if (parents == null) {
+            return;
+        }
+        for (Iterator ii = parents.iterator(); ii.hasNext();) {
+            Artifact artifact = (Artifact)ii.next();
+            if (dm.getParents(artifact).size() > 0 && !artifact.equals(terminatingArtifact)) {
+                // Keep processing parents (as long as no circular dependencies)
+                processParents(dm.getParents(artifact), terminatingArtifact);
+                // Move self 
+                JAXBElement jaxbElement = getJaxbElement(artifact);
+                if (jaxbElement != null) {
+                    if (!reorderedJAXBElements.contains(jaxbElement)) {
+                        reorderedJAXBElements.add(jaxbElement);
+                    }
+                }
+            }
+            else {
+                // Move parent
+                JAXBElement jaxbElement = getJaxbElement(artifact);
+                if (jaxbElement != null) {
+                    if (!reorderedJAXBElements.contains(jaxbElement)) {
+                        reorderedJAXBElements.add(jaxbElement);
+                    }
+                }
+            }
+        }
+
+        Trace.tracePoint("Exit ", "DependencyHelper.processParents");
+    }
+
+
+    /**
+     * Return the JAXBElement for a given artifact
+     * 
+     * @param artifact
+     * 
+     * @return JAXBElement
+     */
+    private JAXBElement getJaxbElement(Artifact artifact) {
+        Trace.tracePoint("Enter", "DependencyHelper.getJaxbElement", artifact);
+
+        for (JAXBElement jaxbElement : inputJAXBElements) {
+            Environment environment = getEnvironment(jaxbElement);
+            if (environment != null) {
+                Artifact jaxbArtifact = environment.getModuleId();
+                if (artifact.equals(jaxbArtifact)) {
+                    return jaxbElement;
+                }
+            }
+        }
+
+        // TODO: Query the server searching for missing dependencies
+        Trace.tracePoint("Exit ", "DependencyHelper.getJaxbElement", null);
+        return null;
+    }
+}
\ No newline at end of file

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyHelper.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyManager.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyManager.java?rev=658553&r1=658552&r2=658553&view=diff
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyManager.java (original)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/main/java/org/apache/geronimo/st/core/internal/DependencyManager.java Tue May 20 21:55:52 2008
@@ -35,7 +35,7 @@
  * 
  * <p>Like the DependencyManager in the Geronimo server, it uses the nomenclature of parent-child
  * where a child is dependent on a parent. The names parent and child have no other meaning are just
- * a convience to make the code readable.
+ * a convenience to make the code readable.
  * 
  * <p>The initial usage of this DependencyManager in the GEP is somewhat limited but other usages 
  * are possible<p>
@@ -71,6 +71,7 @@
      * @param parent the component the child is depending on
      */
     public void addDependency(Artifact child, Artifact parent) {
+        Trace.tracePoint("Entry", "DependencyManager.addDependency", child, parent);
 
         Set parents = (Set) childToParentMap.get(child);
         if (parents == null) {
@@ -85,6 +86,9 @@
             parentToChildMap.put(parent, children);
         }
         children.add(child);
+
+        Trace.tracePoint("Exit ", "DependencyManager.addDependency", childToParentMap.size() );
+        Trace.tracePoint("Exit ", "DependencyManager.addDependency", parentToChildMap.size() );
     }
 
 
@@ -95,6 +99,7 @@
      * @param parent the component that the child wil no longer depend on
      */
     public void removeDependency(Artifact child, Artifact parent) {
+        Trace.tracePoint("Entry", "DependencyManager.removeDependency", child, parent);
 
         Set parents = (Set) childToParentMap.get(child);
         if (parents != null) {
@@ -105,6 +110,8 @@
         if (children != null) {
             children.remove(child);
         }
+
+        Trace.tracePoint("Exit ", "DependencyManager.addDependency");
     }
 
 
@@ -114,6 +121,7 @@
      * @param child the component that will no longer depend on anything
      */
     public void removeAllDependencies(Artifact child) {
+        Trace.tracePoint("Entry", "DependencyManager.removeAllDependencies", child);
 
         Set parents = (Set) childToParentMap.remove(child);
         if (parents == null) {
@@ -127,6 +135,8 @@
                 children.remove(child);
             }
         }
+
+        Trace.tracePoint("Exit ", "DependencyManager.removeAllDependencies");
     }
 
 
@@ -137,6 +147,7 @@
      * @param parents the set of components the child is depending on
      */
     public void addDependencies(Artifact child, Set parents) {
+        Trace.tracePoint("Entry", "DependencyManager.addDependencies", child, parents);
 
         Set existingParents = (Set) childToParentMap.get(child);
         if (existingParents == null) {
@@ -156,6 +167,8 @@
             }
             children.add(child);
         }
+
+        Trace.tracePoint("Exit ", "DependencyManager.addDependencies");
     }
 
 
@@ -166,12 +179,15 @@
      * @return a collection containing all of the components the child depends on; will never be null
      */
     public Set getParents(Artifact child) {
+        Trace.tracePoint("Entry", "DependencyManager.getParents", child);
 
         Set parents = (Set) childToParentMap.get(child);
         if (parents == null) {
+            Trace.tracePoint("Exit", "DependencyManager.getParents", 0);
             return Collections.EMPTY_SET;
         }
 
+        Trace.tracePoint("Exit", "DependencyManager.getParents", parents.size() );
         return new HashSet(parents);
     }
 
@@ -183,12 +199,15 @@
      * @return a collection containing all of the components that depend on the parent; will never be null
      */
     public Set getChildren(Artifact parent) {
+        Trace.tracePoint("Entry", "DependencyManager.getChildren", parent);
 
         Set children = (Set) parentToChildMap.get(parent);
         if (children == null) {
+            Trace.tracePoint("Exit ", "DependencyManager.getChildren", 0);
             return Collections.EMPTY_SET;
         }
 
+        Trace.tracePoint("Exit ", "DependencyManager.getChildren", children.size() );
         return new HashSet(children);
     }
 }

Added: geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java
URL: http://svn.apache.org/viewvc/geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java?rev=658553&view=auto
==============================================================================
--- geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java (added)
+++ geronimo/devtools/eclipse-plugin/trunk/plugins/org.apache.geronimo.st.core/src/test/java/org/apache/geronimo/st/core/internal/DependencyHelperTest.java Tue May 20 21:55:52 2008
@@ -0,0 +1,590 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.geronimo.st.core.internal;
+
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import junit.framework.TestCase;
+
+import org.apache.geronimo.st.core.jaxb.NamespacePrefixMapperImpl;
+import org.xml.sax.InputSource;
+
+/**
+ * <b>DependencyHelperTest</b> is used to test various inter-dependencies between various 
+ * Geronimo-specific deployment plans (represented by JAXBElements)<p> 
+ * 
+ * @version $Rev$ $Date$ 
+ */
+public class DependencyHelperTest extends TestCase {
+
+    private DependencyHelper dh = new DependencyHelper();
+    private Object jaxbElement1;
+    private Object jaxbElement2;
+    private Object jaxbElement3;
+    private Object jaxbElement4;
+    private Object jaxbElement5;
+    private Object jaxbElement6;
+    private Object jaxbElement7;
+    private Object jaxbElement8;
+    private Object jaxbElement9;
+    private Object jaxbElement10;
+    private Object jaxbElement11;
+    private List<JAXBElement> jaxbElements = new ArrayList<JAXBElement>();
+    private List<JAXBElement> jaxbReordered = new ArrayList<JAXBElement>();
+
+    // 
+    // JAXBContext instantiation is costly - should be done only once 
+    // 
+    private static final JAXBContext jaxbContext = newJAXBContext();
+    private static JAXBContext newJAXBContext() {
+        try {
+            return JAXBContext.newInstance(
+                                          "org.apache.geronimo.jee.connector:" +
+                                          "org.apache.geronimo.jee.openejb:" +
+                                          "org.apache.geronimo.jee.web:" +
+                                          "org.apache.geronimo.jee.application:" +
+                                          "org.apache.geronimo.jee.applicationclient:" +
+                                          "org.apache.geronimo.jee.deployment:" +
+                                          "org.apache.geronimo.jee.naming:" +
+                                          "org.apache.geronimo.jee.security", DependencyHelperTest.class.getClassLoader() );
+        }
+        catch (JAXBException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+    // 
+    // Set the JAXBElements to a known state 
+    // 
+    // TODO: Need to execute only once (i.e., TestSuite)
+    // 
+    public void setUp() throws Exception {
+
+
+        // 
+        // Create unmarshaller and marshaller
+        // 
+        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+        Marshaller marshaller = jaxbContext.createMarshaller();
+        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
+        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
+        marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl());
+
+        // 
+        // Read XML files 
+        // 
+        InputStream inputStream1 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-application-example-1.xml");
+        InputStream inputStream2 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-ra-example-2.xml");
+        InputStream inputStream3 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-3.xml");
+        InputStream inputStream4 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-4.xml");
+        InputStream inputStream5 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-5.xml");
+        InputStream inputStream6 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-6.xml");
+        InputStream inputStream7 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-7.xml");
+        InputStream inputStream8 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-web-example-8.xml");
+        InputStream inputStream9 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/openejb-jar-example-9.xml");
+        InputStream inputStream10 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/openejb-jar-example-10.xml");
+        InputStream inputStream11 = this.getClass().getClassLoader().getResourceAsStream("dependencyhelper/geronimo-ra-example-11.xml");
+        String file1 = readContent(inputStream1);
+        String file2 = readContent(inputStream2);
+        String file3 = readContent(inputStream3);
+        String file4 = readContent(inputStream4);
+        String file5 = readContent(inputStream5);
+        String file6 = readContent(inputStream6);
+        String file7 = readContent(inputStream7);
+        String file8 = readContent(inputStream8);
+        String file9 = readContent(inputStream9);
+        String file10 = readContent(inputStream10);
+        String file11 = readContent(inputStream11);
+
+        // 
+        // Unmarshall all files
+        // 
+        jaxbElement1 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file1.getBytes())));
+        jaxbElement2 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file2.getBytes())));
+        jaxbElement3 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file3.getBytes())));
+        jaxbElement4 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file4.getBytes())));
+        jaxbElement5 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file5.getBytes())));
+        jaxbElement6 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file6.getBytes())));
+        jaxbElement7 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file7.getBytes())));
+        jaxbElement8 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file8.getBytes())));
+        jaxbElement9 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file9.getBytes())));
+        jaxbElement10 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file10.getBytes())));
+        jaxbElement11 = unmarshaller.unmarshal(new InputSource(new ByteArrayInputStream(file11.getBytes())));
+
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+
+    /*--------------------------------------------------------------------------------------------*\
+    |                                                                                              |
+    |  Testcase(s)                                                                                 |
+    |                                                                                              |
+    \*--------------------------------------------------------------------------------------------*/ 
+
+    public void testSingleParent() {
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car | 
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement4
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(0) );       // jaxbElement3
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement6
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 1
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(0) );       // jaxbElement5
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleParents() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );       
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0  
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleChildrenAndParents1() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 6
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(4) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(6) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testMultipleChildrenAndParents2() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(1) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(3) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(5) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(0) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 7
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(6) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(7) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(4) );       // jaxbElement2
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+    public void testCircularDependency() throws Exception {
+
+        //---------+--------------------------------+-----------------------------------------------
+        // ELEMENT | ARTIFACT                       | PARENTS
+        //---------+--------------------------------+-----------------------------------------------
+        //    1    | default/geronimo-app-1/2.2/ear | org.apache.geronimo.configs/system-database//car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    2    | null                           | org.apache.derby/derby//jar
+        //---------+--------------------------------+-----------------------------------------------
+        //    3    | default/geronimo-web-1/1.0/car |
+        //---------+--------------------------------+-----------------------------------------------
+        //    4    | default/geronimo-web-2/1.0/car | default/geronimo-web-1/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    5    | default/geronimo-web-3/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    6    | default/geronimo-web-4/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-3/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    7    | default/geronimo-web-5/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    8    | default/geronimo-web-6/1.0/car | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-web-4/1.0/car
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //    9    | default/openejb-jar-1/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   10    | default/openejb-jar-2/2.0/ear  | org.apache.geronimo.testsuite/agent-ds/2.2-SNAPSHOT/car
+        //         |                                | org.apache.geronimo.configs/tomcat6/2.2-SNAPSHOT/car
+        //         |                                | default/geronimo-web-5/1.0/car
+        //         |                                | default/geronimo-ra-2/1.0/car 
+        //         |                                | default/geronimo-web-2/1.0/car
+        //---------+--------------------------------+-----------------------------------------------
+        //   11    | default/geronimo-ra-2/1.0/car  | org.apache.derby/ erby//jar 
+        //         |                                | default/openejb-jar-2/2.0/ear
+        //---------+--------------------------------+-----------------------------------------------
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(1) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(2) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(3) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(4) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(7) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(8) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement11
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(4) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(8) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(7) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(0) );       // jaxbElement11
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(1) );       // jaxbElement10
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(2) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(6) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(5) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(3) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(9) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement1
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+
+        jaxbElements.add( (JAXBElement)jaxbElement7 );                  // Element 0
+        jaxbElements.add( (JAXBElement)jaxbElement8 );                  // Element 1
+        jaxbElements.add( (JAXBElement)jaxbElement5 );                  // Element 2
+        jaxbElements.add( (JAXBElement)jaxbElement9 );                  // Element 3
+        jaxbElements.add( (JAXBElement)jaxbElement1 );                  // Element 4
+        jaxbElements.add( (JAXBElement)jaxbElement2 );                  // Element 5
+        jaxbElements.add( (JAXBElement)jaxbElement11 );                 // Element 6
+        jaxbElements.add( (JAXBElement)jaxbElement6 );                  // Element 7
+        jaxbElements.add( (JAXBElement)jaxbElement3 );                  // Element 8
+        jaxbElements.add( (JAXBElement)jaxbElement4 );                  // Element 9
+        jaxbElements.add( (JAXBElement)jaxbElement10 );                 // Element 10
+        jaxbReordered = dh.reorderJAXBElements( jaxbElements );
+        assertEquals( jaxbReordered.size(),jaxbElements.size() );
+        assertEquals( jaxbReordered.get(0),jaxbElements.get(0) );       // jaxbElement7
+        assertEquals( jaxbReordered.get(1),jaxbElements.get(2) );       // jaxbElement5
+        assertEquals( jaxbReordered.get(2),jaxbElements.get(7) );       // jaxbElement6
+        assertEquals( jaxbReordered.get(3),jaxbElements.get(8) );       // jaxbElement3
+        assertEquals( jaxbReordered.get(4),jaxbElements.get(9) );       // jaxbElement4
+        assertEquals( jaxbReordered.get(5),jaxbElements.get(1) );       // jaxbElement8
+        assertEquals( jaxbReordered.get(6),jaxbElements.get(3) );       // jaxbElement9
+        assertEquals( jaxbReordered.get(7),jaxbElements.get(4) );       // jaxbElement1
+        assertEquals( jaxbReordered.get(8),jaxbElements.get(5) );       // jaxbElement2
+        assertEquals( jaxbReordered.get(9),jaxbElements.get(6) );       // jaxbElement11
+        assertEquals( jaxbReordered.get(10),jaxbElements.get(10) );     // jaxbElement10
+        jaxbElements.clear();
+        jaxbReordered.clear();
+        dh.close();
+    }
+
+
+    /*--------------------------------------------------------------------------------------------*\
+    |                                                                                              |
+    |  Private method(s)                                                                           |
+    |                                                                                              |
+    \*--------------------------------------------------------------------------------------------*/ 
+
+    private static String readContent(InputStream in) throws IOException {
+        StringBuffer sb = new StringBuffer();
+        in = new BufferedInputStream(in);
+        int i = in.read();
+        while (i != -1) {
+            sb.append((char) i);
+            i = in.read();
+        }
+        String content = sb.toString();
+        return content;
+    }
+}