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/08/02 15:42:47 UTC

svn commit: r427980 - in /incubator/servicemix/trunk: samples/loan-broker/loan-broker-lw-su/pom.xml servicemix-components/pom.xml tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java

Author: pdodds
Date: Wed Aug  2 06:42:46 2006
New Revision: 427980

URL: http://svn.apache.org/viewvc?rev=427980&view=rev
Log:
Added the functionality to bundle the require libs into the service unit,  however this also required a change to the servicemix components to make servicemix core a provided library and also the loan-broker-lw-su/pom.xml to add servicemix-core as a provided library to stop the whole of the servicemix being packaged under the SU.

Modified:
    incubator/servicemix/trunk/samples/loan-broker/loan-broker-lw-su/pom.xml
    incubator/servicemix/trunk/servicemix-components/pom.xml
    incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java

Modified: incubator/servicemix/trunk/samples/loan-broker/loan-broker-lw-su/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/samples/loan-broker/loan-broker-lw-su/pom.xml?rev=427980&r1=427979&r2=427980&view=diff
==============================================================================
--- incubator/servicemix/trunk/samples/loan-broker/loan-broker-lw-su/pom.xml (original)
+++ incubator/servicemix/trunk/samples/loan-broker/loan-broker-lw-su/pom.xml Wed Aug  2 06:42:46 2006
@@ -47,6 +47,12 @@
             <version>${project.version}</version>            
         </dependency>
         <dependency>
+            <groupId>org.apache.servicemix</groupId>
+            <artifactId>servicemix-core</artifactId>
+            <version>${project.version}</version>            
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
             <groupId>org.apache.geronimo.specs</groupId>
             <artifactId>geronimo-jms_1.1_spec</artifactId>
             <version>1.0.1</version>

Modified: incubator/servicemix/trunk/servicemix-components/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-components/pom.xml?rev=427980&r1=427979&r2=427980&view=diff
==============================================================================
--- incubator/servicemix/trunk/servicemix-components/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-components/pom.xml Wed Aug  2 06:42:46 2006
@@ -37,6 +37,7 @@
     <dependency>
       <groupId>${pom.groupId}</groupId>
       <artifactId>servicemix-core</artifactId>
+      <scope>provided</scope>      
     </dependency>
     <dependency>
       <groupId>commons-httpclient</groupId>

Modified: incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java?rev=427980&r1=427979&r2=427980&view=diff
==============================================================================
--- incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java (original)
+++ incubator/servicemix/trunk/tooling/jbi-maven-plugin/src/main/java/org/apache/servicemix/maven/plugin/jbi/GenerateServiceUnitMojo.java Wed Aug  2 06:42:46 2006
@@ -17,9 +17,24 @@
 package org.apache.servicemix.maven.plugin.jbi;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
 
+import org.apache.maven.archiver.MavenArchiveConfiguration;
+import org.apache.maven.archiver.MavenArchiver;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DependencyResolutionRequiredException;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuildingException;
+import org.codehaus.plexus.archiver.ArchiverException;
+import org.codehaus.plexus.archiver.jar.JarArchiver;
+import org.codehaus.plexus.archiver.jar.ManifestException;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
  * A Mojo used to build the jbi service unit zip file
@@ -37,7 +52,7 @@
 	/**
 	 * The name of the generated war.
 	 * 
-	 * @parameter expression="${project.artifactId}-${project.version}.jar"
+	 * @parameter expression="${project.artifactId}-${project.version}.zip"
 	 * @required
 	 */
 	private String serviceUnitName;
@@ -50,8 +65,137 @@
 	 */
 	private File outputDirectory;
 
+	/**
+	 * The Zip archiver.
+	 * 
+	 * @parameter expression="${component.org.codehaus.plexus.archiver.Archiver#jar}"
+	 * @required
+	 */
+	private JarArchiver jarArchiver;
+
+	/**
+	 * The maven archive configuration to use.
+	 * 
+	 * @parameter
+	 */
+	private MavenArchiveConfiguration archive = new MavenArchiveConfiguration();
+
+	/**
+	 * Directory where the application.xml file will be auto-generated.
+	 * 
+	 * @parameter expression="${project.build.directory}/classes"
+	 */
+	private File serviceUnitLocation;
+
 	public void execute() throws MojoExecutionException, MojoFailureException {
-		projectHelper.attachArtifact(project, "zip", "", new File(
-				outputDirectory, serviceUnitName));
+		try {
+
+			createUnpackedInstaller();
+
+			File serviceUnitFile = new File(outputDirectory, serviceUnitName);
+			createArchive(serviceUnitFile);
+
+			projectHelper.attachArtifact(project, "zip", "", new File(
+					outputDirectory, serviceUnitName));
+
+		} catch (JbiPluginException e) {
+			throw new MojoExecutionException("Failed to create service unit", e);
+		}
+
+	}
+
+	private void createArchive(File installerFile) throws JbiPluginException {
+		try {
+
+			// generate war file
+			getLog().info(
+					"Generating service unit "
+							+ installerFile.getAbsolutePath());
+			MavenArchiver archiver = new MavenArchiver();
+			archiver.setArchiver(jarArchiver);
+			archiver.setOutputFile(installerFile);
+			jarArchiver.addDirectory(workDirectory);
+
+			// create archive
+			archiver.createArchive(getProject(), archive);
+
+		} catch (ArchiverException e) {
+			throw new JbiPluginException("Error creating service unit: "
+					+ e.getMessage(), e);
+		} catch (ManifestException e) {
+			throw new JbiPluginException("Error creating service unit: "
+					+ e.getMessage(), e);
+		} catch (IOException e) {
+			throw new JbiPluginException("Error creating service unit: "
+					+ e.getMessage(), e);
+		} catch (DependencyResolutionRequiredException e) {
+			throw new JbiPluginException("Error creating service unit: "
+					+ e.getMessage(), e);
+		}
+
+	}
+
+	private void createUnpackedInstaller() throws JbiPluginException {
+
+		if (!workDirectory.isDirectory()) {
+			if (!workDirectory.mkdirs()) {
+				throw new JbiPluginException(
+						"Unable to create work directory: " + workDirectory);
+			}
+		}
+
+		try {
+			FileUtils.copyDirectory(serviceUnitLocation, workDirectory);
+		} catch (IOException e) {
+			throw new JbiPluginException("Unable to copy directory "
+					+ serviceUnitLocation, e);
+		}
+
+		ScopeArtifactFilter filter = new ScopeArtifactFilter(
+				Artifact.SCOPE_RUNTIME);
+
+		JbiResolutionListener listener = resolveProject();
+		// print(listener.getRootNode(), "");
+		
+		Set includes = new HashSet();
+		for (Iterator iter = project.getArtifacts().iterator(); iter.hasNext();) {
+			Artifact artifact = (Artifact) iter.next();
+			if (!artifact.isOptional() && filter.include(artifact)) {
+				MavenProject project = null;
+				getLog().info("Resolving "+artifact);
+				try {
+					project = projectBuilder.buildFromRepository(artifact,
+							remoteRepos, localRepo);
+				} catch (ProjectBuildingException e) {
+					getLog().warn(
+							"Unable to determine packaging for dependency : "
+									+ artifact.getArtifactId()
+									+ " assuming jar");
+				}
+				String type = project != null ? project.getPackaging()
+						: artifact.getType();
+				if ("jbi-component".equals(type)) {
+					removeBranch(listener, artifact);
+				} else if ("jbi-shared-library".equals(type)) {
+					removeBranch(listener, artifact);
+				}  else if ("jar".equals(type)) {
+					includes.add(artifact);
+				}
+			}
+		}
+		// print(listener.getRootNode(), "");
+
+		for (Iterator iter = retainArtifacts(includes, listener).iterator(); iter
+				.hasNext();) {
+			Artifact artifact = (Artifact) iter.next();
+			try {
+				getLog().info("Including: " + artifact);
+				FileUtils.copyFileToDirectory(artifact.getFile(), new File(
+						workDirectory, LIB_DIRECTORY));
+			} catch (IOException e) {
+				throw new JbiPluginException("Unable to copy file "
+						+ artifact.getFile(), e);
+			}
+		}
 	}
 }