You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by pd...@apache.org on 2006/07/06 17:10:02 UTC

svn commit: r419576 - in /incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi: IsDeployedTask.java JbiProjectDeployerMojo.java

Author: pdodds
Date: Thu Jul  6 08:10:01 2006
New Revision: 419576

URL: http://svn.apache.org/viewvc?rev=419576&view=rev
Log:
Refactored the projectDeploy goal so that is can determine whether dependencies are already deployed and if so it will stop and undeploy them before redeploying

Added:
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/IsDeployedTask.java
Modified:
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java

Added: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/IsDeployedTask.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/IsDeployedTask.java?rev=419576&view=auto
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/IsDeployedTask.java (added)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/IsDeployedTask.java Thu Jul  6 08:10:01 2006
@@ -0,0 +1,60 @@
+package org.apache.servicemix.maven.plugin.jbi;
+
+import org.apache.servicemix.jbi.framework.AdminCommandsServiceMBean;
+import org.apache.servicemix.jbi.management.task.JbiTask;
+
+public class IsDeployedTask extends JbiTask {
+
+	private static final String JBI_SHARED_LIBRARY = "jbi-shared-library";
+
+	private static final String JBI_COMPONENT = "jbi-component";
+
+	private static final String JBI_SERVICE_ASSEMBLY = "jbi-service-assembly";
+
+	private boolean deployed = false;
+
+	private String type;
+
+	private String name;
+
+	public boolean isDeployed() {
+		return deployed;
+	}
+
+	public void setDeployed(boolean deployed) {
+		this.deployed = deployed;
+	}
+
+	protected void doExecute(AdminCommandsServiceMBean acs) throws Exception {		
+		if (JBI_SHARED_LIBRARY.equals(type)) {
+			String result = acs.listSharedLibraries(null, name);
+			setDeployed(isResultContaining(result, "shared-library", name));
+		} else if (JBI_SERVICE_ASSEMBLY.equals(type)) {
+			String result = acs.listServiceAssemblies(null, null, name);
+			setDeployed(isResultContaining(result, "service-assembly", name));
+		}
+		if (JBI_COMPONENT.equals(type)) {
+			String result = acs.listComponents(false, false, false, null, null,
+					null);
+			if (isResultContaining(result, "service-engine", name)
+					|| isResultContaining(result, "binding-component", name)) {
+				setDeployed(true);
+			}
+		}
+	}
+
+	private boolean isResultContaining(String result, String type, String name) {
+		String componentLine = "<component-info type='" + type + "' name='"
+				+ name + "'";		
+		return result.contains(componentLine);
+	}
+
+	public void setType(String type) {
+		this.type = type;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+}

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java?rev=419576&r1=419575&r2=419576&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/JbiProjectDeployerMojo.java Thu Jul  6 08:10:01 2006
@@ -36,8 +36,14 @@
 import org.apache.servicemix.jbi.management.task.DeployServiceAssemblyTask;
 import org.apache.servicemix.jbi.management.task.InstallComponentTask;
 import org.apache.servicemix.jbi.management.task.InstallSharedLibraryTask;
+import org.apache.servicemix.jbi.management.task.ShutDownComponentTask;
 import org.apache.servicemix.jbi.management.task.StartComponentTask;
 import org.apache.servicemix.jbi.management.task.StartServiceAssemblyTask;
+import org.apache.servicemix.jbi.management.task.StopComponentTask;
+import org.apache.servicemix.jbi.management.task.StopServiceAssemblyTask;
+import org.apache.servicemix.jbi.management.task.UndeployServiceAssemblyTask;
+import org.apache.servicemix.jbi.management.task.UninstallComponentTask;
+import org.apache.servicemix.jbi.management.task.UninstallSharedLibraryTask;
 
 /**
  * A Mojo that can take any project and determine its JBI dependencies and then
@@ -53,6 +59,12 @@
  */
 public class JbiProjectDeployerMojo extends AbstractDeployableMojo {
 
+	private static final String JBI_SHARED_LIBRARY = "jbi-shared-library";
+
+	private static final String JBI_COMPONENT = "jbi-component";
+
+	private static final String JBI_SERVICE_ASSEMBLY = "jbi-service-assembly";
+
 	private List deploymentTypes;
 
 	/**
@@ -80,6 +92,11 @@
 	 */
 	private List remoteRepos;
 
+	/**
+	 * @parameter default-value="true"
+	 */
+	private boolean deployDependencies;
+
 	public void execute() throws MojoExecutionException, MojoFailureException {
 		deployProject();
 	}
@@ -121,9 +138,39 @@
 			getLog()
 					.info(
 							"-----------------------------------------------------------");
-			while (!dependencies.empty()) {
-				deployDependency((JbiDeployableArtifact) dependencies.pop());
+
+			if (deployDependencies) {
+				// We need to stop all the dependencies first
+				for (Iterator iterator = dependencies.iterator(); iterator
+						.hasNext();) {
+					JbiDeployableArtifact jbiDeployable = (JbiDeployableArtifact) iterator
+							.next();
+
+					if (isDeployed(jbiDeployable)) {
+						stopDependency(jbiDeployable);
+						undeployDependency(jbiDeployable);
+					}
+				}
+
+				// Now we can walk the dependencies bottom up - re-deploying and
+				// starting them
+				while (!dependencies.empty()) {
+					JbiDeployableArtifact jbiDeployable = (JbiDeployableArtifact) dependencies
+							.pop();
+					deployDependency(jbiDeployable);
+					startDependency(jbiDeployable);
+				}
+			} else {
+				JbiDeployableArtifact jbiDeployable = (JbiDeployableArtifact) dependencies
+						.firstElement();
+				if (isDeployed(jbiDeployable)) {
+					stopDependency(jbiDeployable);
+					undeployDependency(jbiDeployable);
+				}
+				deployDependency(jbiDeployable);
+				startDependency(jbiDeployable);
 			}
+
 		} catch (Exception e) {
 			throw new MojoExecutionException("Unable to deploy project, "
 					+ e.getMessage(), e);
@@ -131,37 +178,99 @@
 
 	}
 
+	private void startDependency(JbiDeployableArtifact jbiDeployable) {
+		getLog().info("Starting " + jbiDeployable.getName());
+		if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
+			StartServiceAssemblyTask startTask = new StartServiceAssemblyTask();
+			initializeJbiTask(startTask);
+			startTask.setName(jbiDeployable.getName());
+			startTask.execute();
+		}
+		if (JBI_COMPONENT.equals(jbiDeployable.getType())) {
+			StartComponentTask startTask = new StartComponentTask();
+			initializeJbiTask(startTask);
+			startTask.setName(jbiDeployable.getName());
+			startTask.execute();
+		}
+	}
+
+	private void undeployDependency(JbiDeployableArtifact jbiDeployable) {
+		getLog().info("Undeploying " + jbiDeployable.getFile());
+		if (JBI_SHARED_LIBRARY.equals(jbiDeployable.getType())) {
+			UninstallSharedLibraryTask sharedLibraryTask = new UninstallSharedLibraryTask();
+			initializeJbiTask(sharedLibraryTask);
+			sharedLibraryTask.setName(jbiDeployable.getName());
+			sharedLibraryTask.execute();
+		} else if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
+			UndeployServiceAssemblyTask serviceAssemblyTask = new UndeployServiceAssemblyTask();
+			initializeJbiTask(serviceAssemblyTask);
+			serviceAssemblyTask.setName(jbiDeployable.getName());
+			serviceAssemblyTask.execute();
+		}
+		if (JBI_COMPONENT.equals(jbiDeployable.getType())) {
+			UninstallComponentTask componentTask = new UninstallComponentTask();
+			initializeJbiTask(componentTask);
+			componentTask.setName(jbiDeployable.getName());
+			componentTask.execute();
+		}
+	}
+
+	private boolean isDeployed(JbiDeployableArtifact jbiDeployable) {
+		IsDeployedTask isDeployedTask = new IsDeployedTask();
+		isDeployedTask.setType(jbiDeployable.getType());
+		isDeployedTask.setName(jbiDeployable.getName());
+		initializeJbiTask(isDeployedTask);
+		isDeployedTask.execute();
+		boolean deployed = isDeployedTask.isDeployed();
+		if (deployed)
+			getLog().info(jbiDeployable.getName() + " is deployed");
+		else
+			getLog().info(jbiDeployable.getName() + " is not deployed");
+		return deployed;
+	}
+
+	private void stopDependency(JbiDeployableArtifact jbiDeployable) {
+		getLog().info("Stopping " + jbiDeployable.getName());
+		if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
+			StopServiceAssemblyTask stopTask = new StopServiceAssemblyTask();
+			initializeJbiTask(stopTask);
+			stopTask.setName(jbiDeployable.getName());
+			stopTask.execute();
+		}
+		if (JBI_COMPONENT.equals(jbiDeployable.getType())) {
+			StopComponentTask stopTask = new StopComponentTask();
+			initializeJbiTask(stopTask);
+			stopTask.setName(jbiDeployable.getName());
+			stopTask.execute();
+
+			ShutDownComponentTask shutdownTask = new ShutDownComponentTask();
+			initializeJbiTask(shutdownTask);
+			shutdownTask.setName(jbiDeployable.getName());
+			shutdownTask.execute();
+		}
+	}
+
 	private void deployDependency(JbiDeployableArtifact jbiDeployable) {
 
 		getLog().info(
 				"Deploying " + jbiDeployable.getType() + " from "
 						+ jbiDeployable.getFile());
-		if ("jbi-shared-library".equals(jbiDeployable.getType())) {
+		if (JBI_SHARED_LIBRARY.equals(jbiDeployable.getType())) {
 			InstallSharedLibraryTask componentTask = new InstallSharedLibraryTask();
 			initializeJbiTask(componentTask);
 			componentTask.setFile(jbiDeployable.getFile());
 			componentTask.execute();
-		} else if ("jbi-service-assembly".equals(jbiDeployable.getType())) {
+		} else if (JBI_SERVICE_ASSEMBLY.equals(jbiDeployable.getType())) {
 			DeployServiceAssemblyTask componentTask = new DeployServiceAssemblyTask();
 			initializeJbiTask(componentTask);
 			componentTask.setFile(jbiDeployable.getFile());
 			componentTask.execute();
-
-			StartServiceAssemblyTask startTask = new StartServiceAssemblyTask();
-			initializeJbiTask(startTask);
-			startTask.setName(jbiDeployable.getName());
-			startTask.execute();
 		}
-		if ("jbi-component".equals(jbiDeployable.getType())) {
+		if (JBI_COMPONENT.equals(jbiDeployable.getType())) {
 			InstallComponentTask componentTask = new InstallComponentTask();
 			initializeJbiTask(componentTask);
 			componentTask.setFile(jbiDeployable.getFile());
 			componentTask.execute();
-
-			StartComponentTask startTask = new StartComponentTask();
-			initializeJbiTask(startTask);
-			startTask.setName(jbiDeployable.getName());
-			startTask.execute();
 		}
 
 	}
@@ -169,9 +278,9 @@
 	private List getDeployablePackagingTypes() {
 		if (deploymentTypes == null) {
 			deploymentTypes = new ArrayList();
-			deploymentTypes.add("jbi-shared-library");
-			deploymentTypes.add("jbi-service-assembly");
-			deploymentTypes.add("jbi-component");
+			deploymentTypes.add(JBI_SHARED_LIBRARY);
+			deploymentTypes.add(JBI_SERVICE_ASSEMBLY);
+			deploymentTypes.add(JBI_COMPONENT);
 		}
 		return deploymentTypes;
 	}
@@ -220,7 +329,7 @@
 	}
 
 	private String getExtension(MavenProject project2) {
-		if (project2.getPackaging().equals("jbi-service-assembly"))
+		if (project2.getPackaging().equals(JBI_SERVICE_ASSEMBLY))
 			return "";
 		else
 			return "installer";