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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Aug 2 12:32:05 EDT 2007


Author: pgier
Date: 2007-08-02 12:32:05 -0400 (Thu, 02 Aug 2007)
New Revision: 13971

Added:
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarFileEntry.java
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarUtil.java
Modified:
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveMojo.java
   labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveTestsMojo.java
Log:
Moving jar operations into a separate package.  Changed some of the configuration parameters to making configuring the plugin a little simpler.

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveMojo.java	2007-08-02 15:49:45 UTC (rev 13970)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveMojo.java	2007-08-02 16:32:05 UTC (rev 13971)
@@ -1,16 +1,9 @@
 package org.jboss.maven.plugins.retro;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.jar.Attributes;
-import java.util.jar.JarEntry;
-import java.util.jar.JarOutputStream;
-import java.util.jar.Manifest;
-import java.util.zip.Deflater;
 
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.filefilter.NameFileFilter;
@@ -19,6 +12,7 @@
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
+import org.jboss.maven.plugins.retro.util.JarUtil;
 import org.jboss.weaver.WeaveRunner;
 import org.jboss.weaver.Weaver;
 
@@ -105,27 +99,27 @@
    protected String weaverClass = "org.jboss.weaver.Weaver";
 
    /**
-    * The jar file or directory where the weaved classes
-    * should be written.  The path is relative to the project
-    * output directory (target).
-    * Defaults to "target/classes-weaved"
-    * @parameter
+    * The directory where the weaved classes
+    * should be written.
+    * @parameter expression="${project.build.directory}/classes-weaved"
     */
-   protected String weaverOutputPath;
+   protected File outputDirectory;
    
    /**
     * Attach a jar of the weaved classes to the build lifecycle.  This will
-    * allow the weaved jar to be deployed with the other build components.
+    * allow the weaved jar to be deployed with the other build artifacts.
     * @parameter
     */
    protected boolean attachJar = true;
    
    /**
-    * Classifier to append to the weaved output file.
-    * Defaults to "weaved".
+    * Classifier to append to the weaved output file (artifact).
+    * Defaults to null.  If the classifier is null, then the jar
+    * of the weaved classes will replace the main artifact.
+    * 
     * @parameter
     */
-   protected String weaveClassifier = "weaved";
+   protected String classifier;
    
    /**
     * Suppress output information.
@@ -146,8 +140,15 @@
       {
          String jarFilePath = project.getBuild().getDirectory()
             + File.separator + project.getArtifactId() + "-" + this.getJarClassifier() + ".jar";
-         File jarFile = this.createJarFile(jarFilePath);
-         projectHelper.attachArtifact(project, jarFile, this.getJarClassifier());
+         try 
+         {
+            File jarFile = JarUtil.createJarFile(this.getOutputPath(), jarFilePath);
+            projectHelper.attachArtifact(project, jarFile, this.getJarClassifier());
+         }
+         catch (IOException ioe) 
+         {
+            getLog().warn("Unable to create Jar file: " + ioe);
+         }
       }
       
       long end = System.currentTimeMillis();
@@ -247,102 +248,10 @@
       
       return weaver;
    }
-
-   private ArrayList <JarFileEntry> createJarEntries(File directory)
-   {
-      ArrayList <JarFileEntry> fileEntries = new ArrayList <JarFileEntry> ();
-      try
-      {
-         this.getLog().info("DEBUG: " + directory.getAbsolutePath());
-         Collection files = FileUtils.listFiles(new File(this.getOutputPath()), null, true);
-         for (Object fileObj : files)
-         {
-            String relativePath = fileObj.toString().replace(directory.getAbsolutePath() + "/", "");
-            byte[] content = FileUtils.readFileToByteArray((File) fileObj);
-            fileEntries.add(new JarFileEntry(relativePath, content));
-         }
-      }
-      catch (IOException ioe)
-      {
-         this.getLog().error("error reading class file: " + ioe);
-      }
-      return fileEntries;
-   }
-
-   private File createJarFile(String jarFilePath)
-   {
-      File outputDir = new File(this.getOutputPath());
-      ArrayList <JarFileEntry> fileEntries = createJarEntries(outputDir);
-      try
-      {
-         Manifest manifest = new Manifest();
-         Attributes attributes = manifest.getMainAttributes();
-         attributes.putValue("Manifest-Version", "1.0");
-         attributes.putValue("Created-By", System.getProperty("java.vm.version") + " ("
-               + System.getProperty("java.vm.vendor") + ")");
-         JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFilePath), manifest);
-         stream.setLevel(Deflater.BEST_COMPRESSION);
-         for (JarFileEntry fileEntry : fileEntries)
-         {
-            JarEntry jarEntry = new JarEntry(fileEntry.getName());
-            stream.putNextEntry(jarEntry);
-            stream.write(fileEntry.getContent());
-         }
-         stream.close();
-      }
-      catch (IOException ioe)
-      {
-         this.getLog().error("Unable to write retro jar: " + ioe);
-      }
-      return new File(jarFilePath);
-   }
-
-   protected static class JarFileEntry
-   {
-
-      private byte[] content;
-
-      private String name;
-
-      public JarFileEntry(String name, byte[] content)
-      {
-         this.name = name;
-         this.content = content;
-      }
-
-      public byte[] getContent()
-      {
-         return content;
-      }
-
-      public String getName()
-      {
-         return name;
-      }
-
-      public void setName(String name)
-      {
-         this.name = name;
-      }
-   }
    
    protected String getOutputPath() 
    {
-      if (this.weaverOutputPath == null) {
-         String classesDirString = getClassesDirecotry().getAbsolutePath();
-         if(classesDirString.endsWith(this.fileSep)) {
-            classesDirString = classesDirString.substring(0, (classesDirString.length() - 2));
-         }
-         return (classesDirString + "-" + this.weaveClassifier);
-      }
-      else 
-      {
-         String buildDirectory = project.getBuild().getDirectory();
-         if (!buildDirectory.endsWith(fileSep)) {
-            buildDirectory += fileSep;
-         }
-         return buildDirectory + this.fileSep + this.weaverOutputPath;
-      }
+      return this.outputDirectory.getAbsolutePath();
    }
    
    public List getClasspathElements() {
@@ -354,7 +263,7 @@
    }
    
    protected String getJarClassifier() {
-      return this.weaveClassifier;
+      return this.classifier;
    }
    
 }

Modified: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveTestsMojo.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveTestsMojo.java	2007-08-02 15:49:45 UTC (rev 13970)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/WeaveTestsMojo.java	2007-08-02 16:32:05 UTC (rev 13971)
@@ -37,9 +37,9 @@
     * The jar file or directory where the weaved classes
     * should be written. Defaults to "target/test-classes-weaved"
     * 
-    * @parameter
+    * @parameter expression="${project.build.directory}/test-classes-weaved"
     */
-   protected String outputPath;
+   protected File testOutputDirectory;
       
    /**
     * Suppress output information.
@@ -59,25 +59,16 @@
    
    protected String getOutputPath() 
    {
-      if (this.weaverOutputPath == null) {
-         String classesDirString = getClassesDirecotry().getAbsolutePath();
-         if(classesDirString.endsWith(this.fileSep)) {
-            classesDirString = classesDirString.substring(0, (classesDirString.length() - 2));
-         }
-         return (classesDirectory + "-" + this.weaveClassifier);
-      }
-      else 
-      {
-         String buildDirectory = project.getBuild().getDirectory();
-         if (!buildDirectory.endsWith(fileSep)) {
-            buildDirectory += fileSep;
-         }
-         return buildDirectory + this.fileSep + this.weaverOutputPath;
-      }
+      return this.testOutputDirectory.getAbsolutePath();
    }
    
    protected String getJarClassifier() {
-      return "tests-" + this.weaveClassifier;
+      if (this.classifier == null) {
+         return "tests";
+      }
+      else {
+         return "tests-" + this.classifier;
+      }
    }
    
 }

Added: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarFileEntry.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarFileEntry.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarFileEntry.java	2007-08-02 16:32:05 UTC (rev 13971)
@@ -0,0 +1,31 @@
+package org.jboss.maven.plugins.retro.util;
+
+public class JarFileEntry
+{
+
+   private byte[] content;
+
+   private String name;
+
+   public JarFileEntry(String name, byte[] content)
+   {
+      this.name = name;
+      this.content = content;
+   }
+
+   public byte[] getContent()
+   {
+      return content;
+   }
+
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+}

Added: labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarUtil.java
===================================================================
--- labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarUtil.java	                        (rev 0)
+++ labs/jbossbuild/maven-plugins/trunk/maven-jboss-retro-plugin/src/main/java/org/jboss/maven/plugins/retro/util/JarUtil.java	2007-08-02 16:32:05 UTC (rev 13971)
@@ -0,0 +1,54 @@
+package org.jboss.maven.plugins.retro.util;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.jar.Attributes;
+import java.util.jar.JarEntry;
+import java.util.jar.JarOutputStream;
+import java.util.jar.Manifest;
+import java.util.zip.Deflater;
+
+import org.apache.commons.io.FileUtils;
+
+public class JarUtil
+{
+   public static ArrayList <JarFileEntry> createJarEntries(File directory) throws IOException
+   {
+      ArrayList <JarFileEntry> fileEntries = new ArrayList <JarFileEntry> ();
+      //this.getLog().info("DEBUG: " + directory.getAbsolutePath());
+      Collection files = FileUtils.listFiles(directory, null, true);
+      for (Object fileObj : files)
+      {
+         String relativePath = fileObj.toString().replace(directory.getAbsolutePath() + "/", "");
+         byte[] content = FileUtils.readFileToByteArray((File) fileObj);
+         fileEntries.add(new JarFileEntry(relativePath, content));
+      }
+      return fileEntries;
+   }
+
+   public static File createJarFile(String inputPath, String jarFilePath) throws IOException
+   {
+      File outputDir = new File(inputPath);
+      ArrayList <JarFileEntry> fileEntries = createJarEntries(outputDir);
+      Manifest manifest = new Manifest();
+      Attributes attributes = manifest.getMainAttributes();
+      attributes.putValue("Manifest-Version", "1.0");
+      attributes.putValue("Created-By", System.getProperty("java.vm.version") + " ("
+            + System.getProperty("java.vm.vendor") + ")");
+      JarOutputStream stream = new JarOutputStream(new FileOutputStream(jarFilePath), manifest);
+      stream.setLevel(Deflater.BEST_COMPRESSION);
+      for (JarFileEntry fileEntry : fileEntries)
+      {
+         JarEntry jarEntry = new JarEntry(fileEntry.getName());
+         stream.putNextEntry(jarEntry);
+         stream.write(fileEntry.getContent());
+      }
+      stream.close();
+
+      return new File(jarFilePath);
+   }
+
+}




More information about the jboss-svn-commits mailing list