The attached patches Cvs.java and also the documentation for that task.
 
Description:
Enable redirecting either the output or error or both from a cvs command to a file.
 
Example usage:
    <target name="diff">
        <cvs command="diff" output="patch.txt"/>
    </target>
Julian.
Index: docs/index.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
retrieving revision 1.118
diff -u -r1.118 index.html
--- docs/index.html     2000/09/27 15:58:34     1.118
+++ docs/index.html     2000/09/28 06:10:40
@@ -1372,6 +1372,16 @@
     <td valign="top">report only, don't change any files.</td>
     <td align="center" valign="top">No, default &quot;false&quot;</td>
   </tr>
+  <tr>
+    <td valign="top">output</td>
+    <td valign="top">the file to direct standard output from the command.</td>
+    <td align="center" valign="top">No, default output to ANT Log as 
MSG_INFO.</td>
+  </tr>
+  <tr>
+    <td valign="top">error</td>
+    <td valign="top">the file to direct standard error from the command.</td>
+    <td align="center" valign="top">No, default error to ANT Log as 
MSG_WARN.</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <pre>  &lt;cvs cvsRoot=&quot;:pserver:[EMAIL PROTECTED]:/home/cvspublic&quot;
Index: src/main/org/apache/tools/ant/taskdefs/Cvs.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Cvs.java,v
retrieving revision 1.10
diff -u -r1.10 Cvs.java
--- src/main/org/apache/tools/ant/taskdefs/Cvs.java     2000/09/11 10:33:49     
1.10
+++ src/main/org/apache/tools/ant/taskdefs/Cvs.java     2000/09/28 06:10:42
@@ -69,21 +69,55 @@
 public class Cvs extends Task {
 
     private Commandline cmd = new Commandline();
+    
+    /**
+     * the CVSROOT variable.
+     */
     private String cvsRoot;
+
+    /**
+     * the package/module to check out.
+     */
     private String pack;
+
+    /**
+     * the CVS command to execute.
+     */
     private String command = "checkout";
+
+    /**
+     * suppress information messages.
+     */
     private boolean quiet = false;
+
+    /**
+     * report only, don't change any files.
+     */
     private boolean noexec = false;
+
+    /**
+     * the directory where the checked out files should be placed.
+     */
     private File dest;
-    
+
+    /**
+     * the file to direct standard output from the command.
+     */
+    private File output;
+
+    /**
+     * the file to direct standard error from the command.
+     */
+    private File error; 
+
     public void execute() throws BuildException {
 
-       // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
-       // execution so that we don't rely on having native CVS stuff around 
(SM)
+    // XXX: we should use JCVS (www.ice.com/JCVS) instead of command line
+    // execution so that we don't rely on having native CVS stuff around (SM)
 
         // We can't do it ourselves as jCVS is GPLed, a third party task 
         // outside of jakarta repositories would be possible though (SB).
-       
+    
         Commandline toExecute = new Commandline();
 
         toExecute.setExecutable("cvs");
@@ -100,12 +134,42 @@
         toExecute.createArgument().setLine(command);
         toExecute.addArguments(cmd.getCommandline());
 
-       if (pack != null) {
+        if (pack != null) {
             toExecute.createArgument().setValue(pack);
-       }
+        }
+
+        ExecuteStreamHandler streamhandler = null;
+        OutputStream outputstream = null;
+        OutputStream errorstream = null; 
+        if (error == null && output == null) {
+            streamhandler = new LogStreamHandler(this, Project.MSG_INFO,
+                                                 Project.MSG_WARN);
+        }
+        else {
+            if (output != null) {
+                try {
+                    outputstream = new PrintStream(new 
BufferedOutputStream(new FileOutputStream(output)));
+                } catch (IOException e) {
+                    throw new BuildException(e, location);
+                }
+            }
+            else {
+                outputstream = new LogOutputStream(this, Project.MSG_INFO);
+            }
+            if (error != null) {
+                try {
+                    errorstream = new PrintStream(new BufferedOutputStream(new 
FileOutputStream(error)));
+                } catch (IOException e) {
+                    throw new BuildException(e, location);
+                }
+            }
+            else {
+                errorstream = new LogOutputStream(this, Project.MSG_WARN);
+            }
+            streamhandler = new PumpStreamHandler(outputstream, errorstream);
+        }
 
-        Execute exe = new Execute(new LogStreamHandler(this, Project.MSG_INFO,
-                                                       Project.MSG_WARN), 
+        Execute exe = new Execute(streamhandler, 
                                   null);
 
         exe.setAntRun(project);
@@ -115,6 +179,12 @@
         exe.setCommandline(toExecute.getCommandline());
         try {
             exe.execute();
+            if (outputstream != null) {
+                outputstream.close();
+            }
+            if (errorstream != null) {
+                errorstream.close();
+            }
         } catch (IOException e) {
             throw new BuildException(e, location);
         }
@@ -127,7 +197,7 @@
                 root = null; 
         } 
 
-       this.cvsRoot = root;
+    this.cvsRoot = root;
     }
 
     public void setDest(File dest) {
@@ -135,7 +205,7 @@
     }
 
     public void setPackage(String p) {
-       this.pack = p;
+        this.pack = p;
     }
 
     public void setTag(String p) { 
@@ -155,7 +225,7 @@
     }
 
     public void setCommand(String c) {
-       this.command = c;
+        this.command = c;
     }
     
     public void setQuiet(boolean q) {
@@ -164,6 +234,14 @@
     
     public void setNoexec(boolean ne) {
         noexec = ne;
+    }
+
+    public void setOutput(File output) {
+        this.output = output;
+    }
+    
+    public void setError(File error) {
+        this.error = error;
     }
 }
 

Reply via email to