[jboss-svn-commits] JBL Code SVN: r10382 - in labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin: src/main/java/org/jboss/maven/plugins/deploy and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Mar 20 22:40:02 EDT 2007


Author: pgier
Date: 2007-03-20 22:40:01 -0400 (Tue, 20 Mar 2007)
New Revision: 10382

Modified:
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml
   labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java
Log:
JBBUILD-344; Made the copying of artifacts and generation of component-info.xml more dynamic.
Replaced IO code with calls to commons-io to make the code a little simpler.

Modified: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml	2007-03-21 00:58:25 UTC (rev 10381)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/pom.xml	2007-03-21 02:40:01 UTC (rev 10382)
@@ -1,66 +1,73 @@
-<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-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>
-      <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>
-  </dependencies>
-</project>
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<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-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>
+      <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>
+

Modified: labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/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-21 00:58:25 UTC (rev 10381)
+++ labs/jbossbuild/maven-plugins/trunk/jboss-deploy-maven-plugin/src/main/java/org/jboss/maven/plugins/deploy/JBossDeployMojo.java	2007-03-21 02:40:01 UTC (rev 10382)
@@ -1,19 +1,16 @@
 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.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;
@@ -43,6 +40,14 @@
    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
@@ -131,25 +136,11 @@
    {
       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 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);
 
-      // 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");
 
@@ -158,17 +149,12 @@
          this.getLog().error("Unable to load template file");
          return;
       }
-      StringBuffer compInfoTemplate = new StringBuffer(1000);
+
+      StringBuffer compInfoTemplate = new StringBuffer();
+
       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();
+         compInfoTemplate.append(IOUtils.toString(templateInputStream));
       }
       catch (IOException ioe)
       {
@@ -197,6 +183,7 @@
          project.setDescription(project.getId());
       }
       evaluateVariable(compInfoTemplate, "project.description", project.getDescription());
+
       if (scm == null || scm.getConnection() == null)
       {
          evaluateVariable(compInfoTemplate, "project.scm", "");
@@ -207,31 +194,52 @@
          evaluateVariable(compInfoTemplate, "project.scm", "scm=\"" + scmConnStr + "\"");
       }
 
-      // Create and set list of artifacts
+      // Get the list of artifacts, copy them to the lib directory, and add them to component-info
       StringBuffer artifacts = new StringBuffer();
-      artifacts.append("    <artifact id=\"" + artifactFileName + "\"/>\n");
-      if (new File(artifactTestsFilePath).exists())
+      Artifact projectArtifact = project.getArtifact();
+      if (projectArtifact != null && projectArtifact.getFile() != null)
       {
-         artifacts.append("    <artifact id=\"" + project.getArtifactId() + "-tests." + project.getPackaging()
-               + "\"/>\n");
+         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());
+         }
       }
-      if (new File(artifactSourcesFilePath).exists())
+
+      List list = project.getAttachedArtifacts();
+      this.getLog().debug("Number of artifacts: " + list.size());
+      for (Object obj : list)
       {
-         artifacts.append("    <artifact id=\"" + project.getArtifactId() + "-sources." + project.getPackaging()
+         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());
+         }
       }
-      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 exportsString = new StringBuffer();
-      exportsString.append("      <include input=\"" + artifactFileName + "\"/>\n");
-      if (exports!=null) {
-         for(Object export : exports) {
+      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");
          }
       }
@@ -257,16 +265,15 @@
          }
          evaluateVariable(compInfoTemplate, "imports", importsString.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");
+         File compInfoFile = new File(deployToDir + fileSep + "component-info.xml");
          FileWriter fw = new FileWriter(compInfoFile);
          fw.write(compInfoTemplate.toString());
          fw.close();
@@ -275,53 +282,9 @@
       {
          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




More information about the jboss-svn-commits mailing list