ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1555866 - in /ant/core/trunk: WHATSNEW manual/Tasks/sshexec.html src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
Date Mon, 06 Jan 2014 15:41:13 GMT
Author: bodewig
Date: Mon Jan  6 15:41:13 2014
New Revision: 1555866

URL: http://svn.apache.org/r1555866
Log:
various new attributes around System.err handling in sshexec.  Submitted by Gilbert Rebhan.
 PR 48478

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/manual/Tasks/sshexec.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1555866&r1=1555865&r2=1555866&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Jan  6 15:41:13 2014
@@ -81,6 +81,10 @@ Other changes:
  * <sshexec> can optionally pass System.in to the remote process
    Bugzilla Report 55393
 
+ * <sshexec> now supports capturing error output of the executed
+   process and setting a property from the return code.
+   Bugzilla Report 48478
+
 Changes from Ant 1.9.2 TO Ant 1.9.3
 ===================================
 

Modified: ant/core/trunk/manual/Tasks/sshexec.html
URL: http://svn.apache.org/viewvc/ant/core/trunk/manual/Tasks/sshexec.html?rev=1555866&r1=1555865&r2=1555866&view=diff
==============================================================================
--- ant/core/trunk/manual/Tasks/sshexec.html (original)
+++ ant/core/trunk/manual/Tasks/sshexec.html Mon Jan  6 15:41:13 2014
@@ -122,16 +122,35 @@ and won't work with versions of jsch ear
     <td align="center" valign="top">No, defaults to false</td>
   </tr>
   <tr>
+    <td valign="top">suppresssystemerr</td>
+    <td valign="top">Whether to suppress system err.
+      <em>since Ant 1.9.4</em></td>
+    <td align="center" valign="top">No, defaults to false</td>
+  </tr>
+  <tr>
     <td valign="top">output</td>
     <td valign="top">Name of a file to which to write the output.</td>
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">errorOutput</td>
+    <td valign="top">The file to which the standard error of the
+    command should be redirected.  <em>since Ant 1.9.4</em></td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
     <td valign="top">append</td>
     <td valign="top">Whether output file should be appended to or overwritten. Defaults
to false, meaning overwrite any existing file.</td>
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">errAppend</td>
+    <td valign="top">Whether errorOutput file should be appended to or
+    overwritten. Defaults to false, meaning overwrite any existing
+    file.  <em>since Ant 1.9.4</em></td>
+    <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.  If you use the commandResource
@@ -140,6 +159,19 @@ and won't work with versions of jsch ear
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">errorproperty</td>
+    <td valign="top">The name of a property in which the standard error of the
+      command should be stored.  <em>since Ant 1.9.4</em></td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
+    <td valign="top">resultproperty</td>
+    <td valign="top">the name of a property in which the return code
+      of the command should be stored. Only of interest if
+      failonerror=false.  <em>since Ant 1.9.4</em></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 <b>unlike telnet, which

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java?rev=1555866&r1=1555865&r2=1555866&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java Mon Jan
 6 15:41:13 2014
@@ -62,11 +62,15 @@ public class SSHExec extends SSHBase {
     private Thread thread = null;
 
     private String outputProperty = null;   // like <exec>
+    private String errorProperty = null;
+    private String resultProperty = null;
     private File outputFile = null;   // like <exec>
+    private File errorFile = null;
     private String inputProperty = null;
     private String inputString = null;   // like <exec>
     private File inputFile = null;   // like <exec>
     private boolean append = false;   // like <exec>
+    private boolean appenderr = false;
     private boolean usePty = false;
     private boolean useSystemIn = false;
 
@@ -76,9 +80,14 @@ public class SSHExec extends SSHBase {
         "Timeout period exceeded, connection dropped.";
 
     /**
-     * To supress writing logs to System.out
+     * To suppress writing logs to System.out
      */
     private boolean suppressSystemOut = false;
+
+    /**
+     * To suppress writing logs to System.err
+     */
+    private boolean suppressSystemErr = false;
     
     /**
      * Constructor for SSHExecTask.
@@ -126,6 +135,16 @@ public class SSHExec extends SSHBase {
     }
 
     /**
+     * If used, stores the erroutput of the command to the given file.
+     *
+     * @param output  The file to write to.
+     * @since Apache Ant 1.9.4
+     */
+    public void setErrorOutput(File output) {
+      errorFile = output;
+    }
+
+    /**
      * If used, the content of the file is piped to the remote command
      *
      * @param input  The file which provides the input data for the remote command
@@ -169,6 +188,18 @@ public class SSHExec extends SSHBase {
     public void setAppend(boolean append) {
         this.append = append;
     }
+    
+    /**
+     * Determines if the output is appended to the file given in
+     * <code>setErrorOutput</code>. Default is false, that is, overwrite
+     * the file.
+     *
+     * @param append  True to append to an existing file, false to overwrite.
+     * @since Apache Ant 1.9.4
+     */    
+    public void setErrAppend(boolean appenderr) {
+      this.appenderr = appenderr;
+    }
 
     /**
      * If set, the output of the command will be stored in the given property.
@@ -179,6 +210,28 @@ public class SSHExec extends SSHBase {
     public void setOutputproperty(String property) {
         outputProperty = property;
     }
+    
+    /**
+     * If set, the erroroutput of the command will be stored in the given property.
+     *
+     * @param property  The name of the property in which the command erroroutput
+     *      will be stored.
+     * @since Apache Ant 1.9.4
+     */    
+    public void setErrorproperty (String property) {
+      errorProperty = property;
+    }
+    
+    /**
+     * If set, the exitcode of the command will be stored in the given property.
+     *
+     * @param property  The name of the property in which the exitcode
+     *      will be stored.
+     * @since Apache Ant 1.9.4
+     */    
+    public void setResultproperty(String property) {
+      resultProperty = property;
+    }
 
     /**
      * Whether a pseudo-tty should be allocated.
@@ -207,6 +260,17 @@ public class SSHExec extends SSHBase {
     {
         this.suppressSystemOut = suppressSystemOut;
     }
+    
+    /**
+     * If suppressSystemErr is <code>true</code>, output will not be sent to
System.err<br/>
+     * If suppressSystemErr is <code>false</code>, normal behavior
+     * @since Ant 1.9.4
+     */
+    public void setSuppressSystemErr(boolean suppressSystemErr)
+    {
+        this.suppressSystemErr = suppressSystemErr;
+    }
+    
     /**
      * Execute the command on the remote host.
      *
@@ -290,6 +354,8 @@ public class SSHExec extends SSHBase {
     private void executeCommand(Session session, String cmd, StringBuffer sb)
         throws BuildException {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
+        ByteArrayOutputStream errout = new ByteArrayOutputStream();
+        OutputStream teeErr = suppressSystemErr ? errout : new TeeOutputStream(out, KeepAliveOutputStream.wrapSystemErr());
         OutputStream tee = suppressSystemOut ? out : new TeeOutputStream(out, KeepAliveOutputStream.wrapSystemOut());
 
         InputStream istream = null ;
@@ -326,6 +392,7 @@ public class SSHExec extends SSHBase {
             channel.setCommand(cmd);
             channel.setOutputStream(tee);
             channel.setExtOutputStream(tee);
+            channel.setErrStream(teeErr);
             if (istream != null) {
                 channel.setInputStream(istream);
             }
@@ -360,14 +427,25 @@ public class SSHExec extends SSHBase {
                     log(TIMEOUT_MESSAGE, Project.MSG_ERR);
                 }
             } else {
-                //success
+                // stdout to outputFile
                 if (outputFile != null) {
                     writeToFile(out.toString(), append, outputFile);
                 }
-
+                // set errorProperty
+                if (errorProperty != null) {
+                    getProject().setNewProperty(errorProperty, errout.toString());    
+                }
+                // stderr to errorFile
+                if (errorFile != null) {
+                    writeToFile(errout.toString(), appenderr, errorFile);
+                }
                 // this is the wrong test if the remote OS is OpenVMS,
                 // but there doesn't seem to be a way to detect it.
                 int ec = channel.getExitStatus();
+                // set resultproperty
+                if (resultProperty != null) {
+                    getProject().setNewProperty(resultProperty, Integer.toString(ec));
+                }
                 if (ec != 0) {
                     String msg = "Remote command failed with exit status " + ec;
                     if (getFailonerror()) {



Mime
View raw message