Hi:

I was recently working on a project that required capturing exec-maven-plugin 
output to a file that would be packaged in the final maven artifact.  By 
default the current exec-maven-plugin sends the output to the console.

I added the file capturing functionality and am attaching the patch file for 
your review.  Please let me know if you would like to include this in your code 
base.

Thanks.

Index: src/main/java/org/codehaus/mojo/exec/ExecMojo.java
===================================================================
--- src/main/java/org/codehaus/mojo/exec/ExecMojo.java    (revision 4479)
+++ src/main/java/org/codehaus/mojo/exec/ExecMojo.java    (working copy)
@@ -28,6 +28,7 @@
 import org.codehaus.plexus.util.cli.StreamConsumer;
 
 import java.io.File;
+import java.io.FileNotFoundException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Iterator;
@@ -75,6 +76,11 @@
      * @required
      */
     private File basedir;
+
+    /**
+     * @parameter expression="${outputFile}"
+     */    
+    private File outputFile;
     
     /**
      * if exec.args expression is used when invokign the exec:exec goal,
@@ -191,14 +197,26 @@
         // FIXME what about redirecting the output to getLog() ??
         // what about consuming the input just to be on the safe side ?
         // what about allowing parametrization of the class name that acts as 
consumer?
-        StreamConsumer consumer = new StreamConsumer()
-        {
-            public void consumeLine( String line )
-            {
-                getLog().info( line );
-            }
-        };
-
+        StreamConsumer consumer = null;
+        if ( outputFile == null ) {
+        
+            consumer = new StreamConsumer()
+            {
+                public void consumeLine( String line )
+                {
+                    getLog().info( line );
+                }
+            };
+        }
+        else {
+            try {
+                consumer = new FileStreamConsumer(outputFile);
+            } catch (FileNotFoundException e) {
+                getLog().error("File not found " + outputFile, e);
+                throw new MojoExecutionException("File not found exception " + 
e.getMessage());
+            }
+        }
+        
         try
         {
             int result = executeCommandLine( commandLine, consumer, consumer );


       
---------------------------------
Yahoo! oneSearch: Finally,  mobile search that gives answers, not web links. 

Reply via email to