I had some problem with SVN and the diff did not capture the new stream 
consumer.  I apologize for that.  Here is the updated patch file:

Index: src/main/java/org/codehaus/mojo/exec/FileStreamConsumer.java
===================================================================
--- src/main/java/org/codehaus/mojo/exec/FileStreamConsumer.java    (revision 0)
+++ src/main/java/org/codehaus/mojo/exec/FileStreamConsumer.java    (revision 0)
@@ -0,0 +1,38 @@
+package org.codehaus.mojo.exec;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+
+import org.codehaus.plexus.util.cli.StreamConsumer;
+
+/**
+ * File stream consumer
+ * @author msingh
+ */
+public class FileStreamConsumer implements StreamConsumer {
+
+    /**
+     * The output writer
+     */
+    private PrintWriter outputWriter;
+    
+    /**
+     * Constructor
+     * @param file which is used to consume the output stream
+     * @throws FileNotFoundException
+     */
+    public FileStreamConsumer(File file) throws FileNotFoundException {
+        outputWriter = new PrintWriter(file);
+    }
+    
+    /**
+     * Consume the line
+     * @param line to be consumed
+     * @see StreamConsumer
+     */
+    public void consumeLine(String line) {
+        outputWriter.println(line);
+        outputWriter.flush();
+    }
+}
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 );


M Singh <[EMAIL PROTECTED]> wrote: 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.   

       
---------------------------------
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. 

Reply via email to