[jboss-svn-commits] JBL Code SVN: r10409 - in labs/jbossbuild/maven-plugins/tags: jboss-deploy-maven-plugin-1.1 and 1 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Mar 21 16:07:52 EDT 2007


Author: pgier
Date: 2007-03-21 16:07:52 -0400 (Wed, 21 Mar 2007)
New Revision: 10409

Added:
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
Removed:
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/
   labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
Log:
[maven-scm] copy for tag jboss-deploy-maven-plugin-1.1

Copied: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1 (from rev 10080, labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin)

Deleted: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml	2007-03-08 19:54:43 UTC (rev 10080)
+++ labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml	2007-03-21 20:07:52 UTC (rev 10409)
@@ -1,65 +0,0 @@
-<?xml version="1.0"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
-  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>jboss</groupId>
-    <artifactId>jboss-parent</artifactId>
-    <version>1</version>
-  </parent>
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>jboss.maven-plugins</groupId>
-  <artifactId>jboss-deploy-maven-plugin</artifactId>
-  <packaging>maven-plugin</packaging>
-  <name>JBoss Deploy Maven Plugin</name>
-  <version>1.0-SNAPSHOT</version>
-  <description>Plugin for deploying artifacts to JBoss non-maven repository.</description>
-  <scm>
-    <connection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin</connection>
-  </scm>
-  <build>
-    <plugins>
-      <plugin>
-        <artifactId>maven-compiler-plugin</artifactId>
-        <version>2.0</version>
-        <configuration>
-          <optimize>true</optimize>
-          <source>1.5</source>
-          <target>1.5</target>
-        </configuration>
-      </plugin>
-    </plugins>
-  </build>
-  <repositories>
-    <repository>
-      <snapshots />
-      <id>jboss</id>
-      <name>JBoss Repository</name>
-      <url>http://repository.jboss.com/maven2/</url>
-    </repository>
-  </repositories>
-  <dependencies>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-plugin-api</artifactId>
-      <version>2.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-project</artifactId>
-      <version>2.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-artifact</artifactId>
-      <version>2.0</version>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.maven</groupId>
-      <artifactId>maven-model</artifactId>
-      <version>2.0</version>
-    </dependency>
-  </dependencies>
-  <properties>
-    <tagBase>https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/tags</tagBase>
-  </properties>
-</project>

Copied: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml (from rev 10408, labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml)
===================================================================
--- labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/pom.xml	2007-03-21 20:07:52 UTC (rev 10409)
@@ -0,0 +1,62 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>jboss</groupId>
+    <artifactId>jboss-parent</artifactId>
+    <version>1</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>jboss.maven-plugins</groupId>
+  <artifactId>jboss-deploy-maven-plugin</artifactId>
+  <packaging>maven-plugin</packaging>
+  <name>JBoss Deploy Maven Plugin</name>
+  <version>1.1</version>
+  <description>Plugin for deploying artifacts to JBoss non-maven repository.</description>
+  <scm>
+    <connection>scm:svn:https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1</connection>
+  </scm>
+  <build>
+    <plugins>
+      <plugin>
+        <artifactId>maven-release-plugin</artifactId>
+        <configuration>
+          <tagBase>https://svn.labs.jboss.org/labs/jbossbuild/maven-plugins/tags</tagBase>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+  <repositories>
+    <repository>
+      <snapshots />
+      <id>jboss</id>
+      <name>JBoss Repository</name>
+      <url>http://repository.jboss.com/maven2/</url>
+    </repository>
+  </repositories>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-plugin-api</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-model</artifactId>
+      <version>2.0</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>1.3.1</version>
+    </dependency>
+  </dependencies>
+</project>
\ No newline at end of file

Copied: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src (from rev 10079, labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src)

Deleted: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-03-08 19:47:37 UTC (rev 10079)
+++ labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-03-21 20:07:52 UTC (rev 10409)
@@ -1,339 +0,0 @@
-package org.jboss.maven.plugins.deploy;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.nio.channels.FileChannel;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.model.License;
-import org.apache.maven.plugin.AbstractMojo;
-import org.apache.maven.plugin.MojoExecutionException;
-import org.apache.maven.project.MavenProject;
-
-/**
- * Maven plugin for deploying to jboss repository.  By default
- * it will bind to the deploy phase.
- * 
- * @phase deploy
- * @goal jboss-deploy
- * 
- */
-public class JBossDeployMojo extends AbstractMojo
-{
-
-   private static String fileSep = System.getProperty("file.separator");
-
-   /**
-    * The Maven Project Object
-    *
-    * @parameter expression="${project}"
-    * @required
-    * @readonly
-    */
-   protected MavenProject project;
-
-   /**
-    * Source control information.
-    * @parameter expression="${project.scm}"
-    * @readonly
-    */
-   private org.apache.maven.model.Scm scm;
-
-   /**
-    * License information.
-    * @parameter expression="${project.licenses}"
-    * @required
-    * @readonly
-    */
-   private List licenses;
-
-   //private org.apache.maven.model.License license;
-
-   /**
-    * The Maven Plugin Object
-    *
-    * @parameter expression="${plugin.components}"
-    * @required
-    * @readonly
-    */
-   protected List pluginComponents;
-
-   /**
-    * Maven project properties.
-    *
-    * @parameter expression="${project.properties}"
-    * @required
-    * @readonly
-    */
-   protected Properties projectProperties;
-
-   /**
-    * The plugin dependencies.
-    *
-    * @parameter expression="${plugin.artifacts}"
-    * @required
-    * @readonly
-    */
-   private List pluginArtifacts;
-
-   /**
-    * The directory for compiled classes.
-    *
-    * @parameter expression="${project.build.directory}"
-    * @required
-    * @readonly
-    */
-   private File targetDirectory;
-
-   /**
-    * Project artifacts.
-    *
-    * @parameter expression="${project.artifact}"
-    * @required
-    * @readonly
-    * @todo this is an export variable, really
-    */
-   private Artifact projectArtifact;
-
-   /**
-    * This is the location that the jboss repository (non-maven) files will be copied to.
-    * @parameter
-    * @required
-    */
-   private String jbossDeployRoot;
-
-   /**
-    * This is the list of components that this project depends on.
-    * @parameter
-    */
-   private Map importsParam;
-
-   /**
-    * This is the list of artifacts to be added to the classpath.
-    * @parameter
-    */
-   private List exportsParam;
-
-   /**
-    * Main execution path of the plugin.  Generates component-info.xml, and copies jar files to repository location.
-    */
-   public void execute() throws MojoExecutionException
-   {
-      this.getLog().debug("Executing JBoss deploy plugin");
-
-      // Check that the project is using jar packaging because we don't handle other types yet.
-      if (!project.getPackaging().equals("jar"))
-      {
-         getLog().info("Ignoring project with packaging type: " + project.getPackaging());
-         return;
-      }
-
-      // Initialize local variables
-      String artifactFileName = project.getArtifactId() + "." + project.getPackaging();
-      String artifactFilePath = targetDirectory.toString() + fileSep + artifactFileName;
-      String artifactSourcesFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-sources"
-            + "." + project.getPackaging();
-      String artifactJavadocFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-javadoc"
-            + "." + project.getPackaging();
-      String artifactTestsFilePath = targetDirectory.toString() + fileSep + project.getArtifactId() + "-tests" + "."
-            + project.getPackaging();
-      String deployToPath = jbossDeployRoot + fileSep + project.getGroupId() + fileSep + project.getArtifactId()
-            + fileSep + project.getVersion() + fileSep;
-
-      // Load template file
-      InputStream templateInputStream = this.getClass().getResourceAsStream("component-info-template.txt");
-
-      if (templateInputStream == null)
-      {
-         this.getLog().error("Unable to load template file");
-         return;
-      }
-      StringBuffer compInfoTemplate = new StringBuffer(1000);
-      try
-      {
-         BufferedReader reader = new BufferedReader(new InputStreamReader(templateInputStream));
-         char[] buf = new char[1000];
-         int numRead = 0;
-         while ((numRead = reader.read(buf)) != -1)
-         {
-            compInfoTemplate.append(String.valueOf(buf, 0, numRead));
-         }
-         reader.close();
-      }
-      catch (IOException ioe)
-      {
-         this.getLog().error("Unable to load component info template.");
-         this.getLog().error(ioe.toString());
-         throw new MojoExecutionException(ioe.getMessage());
-      }
-
-      // Evaluate the place holders in the template
-      String componentId = project.getGroupId() + "/" + project.getArtifactId();
-      evaluateVariable(compInfoTemplate, "project.name", componentId + "-component-info");
-      evaluateVariable(compInfoTemplate, "component.id", componentId);
-      evaluateVariable(compInfoTemplate, "project.version", project.getVersion());
-      if (licenses.size() == 0)
-      {
-         getLog().warn("No license specified in pom.xml.  Default lgpl license will be used.");
-         evaluateVariable(compInfoTemplate, "project.license", "lgpl");
-      }
-      else
-      {
-         License firstLicense = (License) licenses.get(0);
-         evaluateVariable(compInfoTemplate, "project.license", firstLicense.getName());
-      }
-      if (project.getDescription() == null || project.getDescription().equals(""))
-      {
-         project.setDescription(project.getId());
-      }
-      evaluateVariable(compInfoTemplate, "project.description", project.getDescription());
-      if (scm == null || scm.getConnection() == null)
-      {
-         evaluateVariable(compInfoTemplate, "project.scm", "");
-      }
-      else
-      {
-         String scmConnStr = scm.getConnection().replaceFirst("scm:", "");
-         evaluateVariable(compInfoTemplate, "project.scm", "scm=\"" + scmConnStr + "\"");
-      }
-
-      // Create and set list of artifacts
-      StringBuffer artifacts = new StringBuffer();
-      artifacts.append("    <artifact id=\"" + artifactFileName + "\"/>\n");
-      if (new File(artifactTestsFilePath).exists())
-      {
-         artifacts.append("    <artifact id=\"" + project.getArtifactId() + "-tests." + project.getPackaging()
-               + "\"/>\n");
-      }
-      if (new File(artifactSourcesFilePath).exists())
-      {
-         artifacts.append("    <artifact id=\"" + project.getArtifactId() + "-sources." + project.getPackaging()
-               + "\"/>\n");
-      }
-      if (new File(artifactJavadocFilePath).exists())
-      {
-         artifacts.append("    <artifact id=\"" + project.getArtifactId() + "-javadoc." + project.getPackaging()
-               + "\"/>\n");
-      }
-      evaluateVariable(compInfoTemplate, "artifacts", artifacts.toString());
-
-      // Create and set list of includes
-      StringBuffer includes = new StringBuffer();
-      includes.append("      <include input=\"" + artifactFileName + "\"/>");
-      evaluateVariable(compInfoTemplate, "includes", includes.toString());
-
-      // Get list of imports
-      //TODO: Maybe this can be determined based on the dependencies, but for now we just have to set it 
-      //      in the plugin configuration 
-      //      List dependencies = project.getDependencies();
-      if (importsParam == null)
-      {
-         evaluateVariable(compInfoTemplate, "imports", "");
-      }
-      else
-      {
-         StringBuffer imports = new StringBuffer();
-         Set componentNames = importsParam.keySet();
-         for (Object component : componentNames)
-         {
-            imports.append("    <import componentref=\"" + component + "\">\n");
-            imports.append("      <compatible version=\"" + importsParam.get(component) + "\"/>\n");
-            imports.append("    </import>\n");
-         }
-         evaluateVariable(compInfoTemplate, "imports", imports.toString());
-      }
-
-      // Write the component info file
-      try
-      {
-         File deployToDir = new File(deployToPath);
-         if (!deployToDir.exists())
-         {
-            deployToDir.mkdirs();
-         }
-         File compInfoFile = new File(deployToPath + "component-info.xml");
-         FileWriter fw = new FileWriter(compInfoFile);
-         fw.write(compInfoTemplate.toString());
-         fw.close();
-      }
-      catch (IOException ioe)
-      {
-         ioe.printStackTrace();
-      }
-
-      // Deploy lib directory.
-      getLog().debug("Copying from: " + artifactFilePath);
-      getLog().info("Deploying to: " + deployToPath);
-      String deployToPathLib = deployToPath + "lib" + fileSep;
-      try
-      {
-         copyFileToDir(artifactFilePath, deployToPathLib);
-         copyFileToDir(artifactTestsFilePath, deployToPathLib);
-         copyFileToDir(artifactSourcesFilePath, deployToPathLib);
-         copyFileToDir(artifactJavadocFilePath, deployToPathLib);
-      }
-      catch (IOException ioe)
-      {
-         throw new MojoExecutionException("Problem copying artifacts: " + ioe.getMessage());
-      }
-   }
-
-   /**
-    * Copy a file from the source path to the destination.
-    * 
-    * @param src The file to copy.  If the source file does not exist, the method does nothing.
-    * @param dest The directory to copy the file.  If the dest path does not exist,
-    *     any necessary folders will be created.
-    */
-   public void copyFileToDir(String src, String dest) throws IOException
-   {
-      File srcFile = new File(src);
-      if (!srcFile.exists())
-      {
-         return;
-      }
-      File destDir = new File(dest);
-      if (!destDir.exists())
-      {
-         destDir.mkdirs();
-      }
-      File destFile = new File(destDir.getCanonicalPath() + fileSep + srcFile.getName());
-      FileChannel srcChannel = new FileInputStream(srcFile).getChannel();
-      FileChannel dstChannel = new FileOutputStream(destFile).getChannel();
-      dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
-      srcChannel.close();
-      dstChannel.close();
-      this.getLog().debug("Copied to file: " + destFile.getCanonicalPath());
-   }
-
-   /**
-    * Replace all instances of var with value in the given buffer.
-    * For example if var is "project.name", this method will search
-    * the buffer for "${project.name}" and replace it with the value
-    * provided.
-    * 
-    * @param buffer The buffer to be modified
-    * @param var The name of the variable to be evaluated.
-    * @param value The replacement string.
-    */
-   public void evaluateVariable(StringBuffer buffer, String var, String value)
-   {
-      int start = 0;
-      while ((start = buffer.indexOf("${" + var + "}")) != -1)
-      {
-         int end = start + ("${" + var + "}").length();
-         buffer.replace(start, end, value);
-      }
-   }
-
-}

Copied: labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java (from rev 10382, labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java)
===================================================================
--- labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/tags/jboss-deploy-maven-plugin-1.1/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-03-21 20:07:52 UTC (rev 10409)
@@ -0,0 +1,307 @@
+package org.jboss.maven.plugins.deploy;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.IOUtils;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.License;
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Maven plugin for deploying to jboss repository.  By default
+ * it will bind to the deploy phase.
+ * 
+ * @phase deploy
+ * @goal jboss-deploy
+ * 
+ */
+public class JBossDeployMojo extends AbstractMojo
+{
+
+   private static String fileSep = System.getProperty("file.separator");
+
+   /**
+    * The Maven Project Object
+    *
+    * @parameter expression="${project}"
+    * @required
+    * @readonly
+    */
+   protected MavenProject project;
+
+   /**
+    * The Maven Project Helper Object
+    *
+    * @component
+    * @required
+    */
+   protected org.apache.maven.project.MavenProjectHelper projectHelper;
+
+   /**
+    * Source control information.
+    * @parameter expression="${project.scm}"
+    * @readonly
+    */
+   private org.apache.maven.model.Scm scm;
+
+   /**
+    * License information.
+    * @parameter expression="${project.licenses}"
+    * @required
+    * @readonly
+    */
+   private List licenses;
+
+   //private org.apache.maven.model.License license;
+
+   /**
+    * The Maven Plugin Object
+    *
+    * @parameter expression="${plugin.components}"
+    * @required
+    * @readonly
+    */
+   protected List pluginComponents;
+
+   /**
+    * Maven project properties.
+    *
+    * @parameter expression="${project.properties}"
+    * @required
+    * @readonly
+    */
+   protected Properties projectProperties;
+
+   /**
+    * The plugin dependencies.
+    *
+    * @parameter expression="${plugin.artifacts}"
+    * @required
+    * @readonly
+    */
+   private List pluginArtifacts;
+
+   /**
+    * The directory for compiled classes.
+    *
+    * @parameter expression="${project.build.directory}"
+    * @required
+    * @readonly
+    */
+   private File targetDirectory;
+
+   /**
+    * Project artifacts.
+    *
+    * @parameter expression="${project.artifact}"
+    * @required
+    * @readonly
+    * @todo this is an export variable, really
+    */
+   private Artifact projectArtifact;
+
+   /**
+    * This is the location that the jboss repository (non-maven) files will be copied to.
+    * @parameter
+    * @required
+    */
+   private String jbossDeployRoot;
+
+   /**
+    * This is the map of components that this project depends on.
+    * @parameter
+    */
+   private Map imports;
+
+   /**
+    * This is the list of artifacts to be added to the classpath.
+    * @parameter
+    */
+   private List exports;
+
+   /**
+    * Main execution path of the plugin.  Generates component-info.xml, and copies jar files to repository location.
+    */
+   public void execute() throws MojoExecutionException
+   {
+      this.getLog().debug("Executing JBoss deploy plugin");
+
+      // Initialize some local variables
+      File deployToDir = new File(jbossDeployRoot + fileSep + project.getGroupId() + fileSep + project.getArtifactId()
+            + fileSep + project.getVersion() + fileSep);
+      File deployToLibDir = new File(deployToDir.getAbsolutePath() + fileSep + "lib" + fileSep);
+
+      // Load template file
+      InputStream templateInputStream = this.getClass().getResourceAsStream("component-info-template.txt");
+
+      if (templateInputStream == null)
+      {
+         this.getLog().error("Unable to load template file");
+         return;
+      }
+
+      StringBuffer compInfoTemplate = new StringBuffer();
+
+      try
+      {
+         compInfoTemplate.append(IOUtils.toString(templateInputStream));
+      }
+      catch (IOException ioe)
+      {
+         this.getLog().error("Unable to load component info template.");
+         this.getLog().error(ioe.toString());
+         throw new MojoExecutionException(ioe.getMessage());
+      }
+
+      // Evaluate the place holders in the template
+      String componentId = project.getGroupId() + "/" + project.getArtifactId();
+      evaluateVariable(compInfoTemplate, "project.name", componentId + "-component-info");
+      evaluateVariable(compInfoTemplate, "component.id", componentId);
+      evaluateVariable(compInfoTemplate, "project.version", project.getVersion());
+      if (licenses.size() == 0)
+      {
+         getLog().warn("No license specified in pom.xml.  Default lgpl license will be used.");
+         evaluateVariable(compInfoTemplate, "project.license", "lgpl");
+      }
+      else
+      {
+         License firstLicense = (License) licenses.get(0);
+         evaluateVariable(compInfoTemplate, "project.license", firstLicense.getName());
+      }
+      if (project.getDescription() == null || project.getDescription().equals(""))
+      {
+         project.setDescription(project.getId());
+      }
+      evaluateVariable(compInfoTemplate, "project.description", project.getDescription());
+
+      if (scm == null || scm.getConnection() == null)
+      {
+         evaluateVariable(compInfoTemplate, "project.scm", "");
+      }
+      else
+      {
+         String scmConnStr = scm.getConnection().replaceFirst("scm:", "");
+         evaluateVariable(compInfoTemplate, "project.scm", "scm=\"" + scmConnStr + "\"");
+      }
+
+      // Get the list of artifacts, copy them to the lib directory, and add them to component-info
+      StringBuffer artifacts = new StringBuffer();
+      Artifact projectArtifact = project.getArtifact();
+      if (projectArtifact != null && projectArtifact.getFile() != null)
+      {
+         artifacts.append("    <artifact id=\"" + projectArtifact.getFile().getName() + "\"/>\n");
+         try
+         {
+            FileUtils.copyFileToDirectory(projectArtifact.getFile(), deployToLibDir);
+         }
+         catch (IOException ioe)
+         {
+            throw new MojoExecutionException("Problem copying artifact: " + ioe.getMessage());
+         }
+      }
+
+      List list = project.getAttachedArtifacts();
+      this.getLog().debug("Number of artifacts: " + list.size());
+      for (Object obj : list)
+      {
+         Artifact artifact = (Artifact) obj;
+         this.getLog().debug(artifact.getArtifactId());
+         artifacts.append("    <artifact id=\"" + artifact.getArtifactId() + "-" + artifact.getClassifier() + ".jar"
+               + "\"/>\n");
+         try
+         {
+            FileUtils.copyFileToDirectory(artifact.getFile(), deployToLibDir);
+         }
+         catch (IOException ioe)
+         {
+            throw new MojoExecutionException("Problem copying artifact: " + ioe.getMessage());
+         }
+      }
+
+      evaluateVariable(compInfoTemplate, "artifacts", artifacts.toString());
+
+      // Create and set list of includes
+      StringBuffer exportsString = new StringBuffer();
+      if (project.getArtifact().getFile() != null)
+      {
+         exportsString.append("      <include input=\"" + project.getArtifact().getFile().getName() + "\"/>\n");
+      }
+      if (exports != null)
+      {
+         for (Object export : exports)
+         {
+            exportsString.append("      <include input=\"" + export + "\"/>\n");
+         }
+      }
+      evaluateVariable(compInfoTemplate, "includes", exportsString.toString());
+
+      // Get list of imports
+      //TODO: Maybe this can be determined based on the dependencies, but for now we just have to set it 
+      //      in the plugin configuration 
+      //      List dependencies = project.getDependencies();
+      if (imports == null)
+      {
+         evaluateVariable(compInfoTemplate, "imports", "");
+      }
+      else
+      {
+         StringBuffer importsString = new StringBuffer();
+         Set componentNames = imports.keySet();
+         for (Object component : componentNames)
+         {
+            importsString.append("    <import componentref=\"" + component + "\">\n");
+            importsString.append("      <compatible version=\"" + imports.get(component) + "\"/>\n");
+            importsString.append("    </import>\n");
+         }
+         evaluateVariable(compInfoTemplate, "imports", importsString.toString());
+      }
+
+      // Write the component info file
+      try
+      {
+         if (!deployToDir.exists())
+         {
+            deployToDir.mkdirs();
+         }
+         File compInfoFile = new File(deployToDir + fileSep + "component-info.xml");
+         FileWriter fw = new FileWriter(compInfoFile);
+         fw.write(compInfoTemplate.toString());
+         fw.close();
+      }
+      catch (IOException ioe)
+      {
+         ioe.printStackTrace();
+      }
+   }
+
+   /**
+    * Replace all instances of var with value in the given buffer.
+    * For example if var is "project.name", this method will search
+    * the buffer for "${project.name}" and replace it with the value
+    * provided.
+    * 
+    * @param buffer The buffer to be modified
+    * @param var The name of the variable to be evaluated.
+    * @param value The replacement string.
+    */
+   public void evaluateVariable(StringBuffer buffer, String var, String value)
+   {
+      int start = 0;
+      while ((start = buffer.indexOf("${" + var + "}")) != -1)
+      {
+         int end = start + ("${" + var + "}").length();
+         buffer.replace(start, end, value);
+      }
+   }
+
+}




More information about the jboss-svn-commits mailing list