ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs ExecTask.java
Date Fri, 27 Jul 2001 09:55:46 GMT
bodewig     01/07/27 02:55:46

  Modified:    docs/manual/CoreTasks exec.html
               src/main/org/apache/tools/ant/taskdefs ExecTask.java
  Log:
  Add outputproperty attribute to <exec> to capture the output of the
  external command in a property.
  
  Submitted by:	Peter  Vogel <pvogel@arsin.com>
  
  Revision  Changes    Path
  1.6       +6 -0      jakarta-ant/docs/manual/CoreTasks/exec.html
  
  Index: exec.html
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/exec.html,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- exec.html	2001/07/06 15:11:28	1.5
  +++ exec.html	2001/07/27 09:55:46	1.6
  @@ -51,6 +51,12 @@
       <td align="center" valign="top">No</td>
     </tr>
     <tr>
  +    <td valign="top">outputproperty</td>
  +    <td valign="top">the name of a property in which the output of the 
  +      command should be stored.</td>
  +    <td align="center" valign="top">No</td>
  +  </tr>
  +  <tr>
       <td valign="top">timeout</td>
       <td valign="top">Stop the command if it doesn't finish within the
         specified time (given in milliseconds).</td>
  
  
  
  1.16      +31 -0     jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java
  
  Index: ExecTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/ExecTask.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- ExecTask.java	2001/07/06 15:18:40	1.15
  +++ ExecTask.java	2001/07/27 09:55:46	1.16
  @@ -70,6 +70,8 @@
    */
   public class ExecTask extends Task {
   
  +    private static String lSep = System.getProperty("line.separator");
  +
       private String os;
       private File out;
       private File dir;
  @@ -79,6 +81,8 @@
       private Environment env = new Environment();
       protected Commandline cmdl = new Commandline();
       private FileOutputStream fos = null;
  +    private ByteArrayOutputStream baos = null;
  +    private String outputprop;
   
       /** Controls whether the VM (1.3 and above) is used to execute the command */
       private boolean vmLauncher = true;
  @@ -129,6 +133,14 @@
       }
   
       /**
  +     * Property name whose value should be set to the output of
  +     * the process
  +     */
  +    public void setOutputproperty(String outputprop) {
  +	this.outputprop = outputprop;
  +    }
  +
  +    /**
        * Throw a BuildException if process returns non 0.
        */
       public void setFailonerror(boolean fail) {
  @@ -243,6 +255,19 @@
                   log("Result: " + err, Project.MSG_ERR);
               }
           }
  +        if (baos != null) {
  +            BufferedReader in = 
  +                new BufferedReader(new StringReader(baos.toString()));
  +            String line = null;
  +            StringBuffer val = new StringBuffer();
  +            while ((line = in.readLine()) != null) {
  +                if (val.length() != 0) {
  +                    val.append(lSep);
  +                }
  +                val.append(line);
  +            }
  +            project.setProperty(outputprop, val.toString());
  +        }
       }
       
       /**
  @@ -274,6 +299,11 @@
               } catch (IOException ioe) {
                   throw new BuildException("Cannot write to "+out, ioe, location);
               }
  +        } else if (outputprop != null) {
  +	    //	    try {
  +	    baos = new ByteArrayOutputStream();
  +	    log("Output redirected to ByteArray", Project.MSG_VERBOSE);
  +	    return new PumpStreamHandler(baos);
           } else {
               return new LogStreamHandler(this,
                                           Project.MSG_INFO, Project.MSG_WARN);
  @@ -294,6 +324,7 @@
       protected void logFlush() {
           try {
               if (fos != null) fos.close();
  +            if (baos != null) baos.close();
           } catch (IOException io) {}
       }
   
  
  
  

Mime
View raw message