Browse Source

add suppresssystemout attribute to optionally make sshexec silent PR 52070

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1447370 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 12 years ago
parent
commit
c4cc9c42b1
5 changed files with 38 additions and 4 deletions
  1. +2
    -0
      CONTRIBUTORS
  2. +3
    -0
      WHATSNEW
  3. +8
    -0
      contributors.xml
  4. +6
    -0
      manual/Tasks/sshexec.html
  5. +19
    -4
      src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java

+ 2
- 0
CONTRIBUTORS View File

@@ -143,6 +143,7 @@ Ignacio Coloma
Ingenonsya France Ingenonsya France
Ingmar Stein Ingmar Stein
Irene Rusman Irene Rusman
Isaac Shabtay
Ivan Ivanov Ivan Ivanov
J Bleijenbergh J Bleijenbergh
Jack J. Woehr Jack J. Woehr
@@ -335,6 +336,7 @@ Steve Loughran
Steve Morin Steve Morin
Steve Wadsworth Steve Wadsworth
Steven E. Newton Steven E. Newton
Sudheer Chigurupati
Takashi Okamoto Takashi Okamoto
TAMURA Kent TAMURA Kent
Taoufik Romdhane Taoufik Romdhane


+ 3
- 0
WHATSNEW View File

@@ -117,6 +117,9 @@ Other changes:
* Add the possibility to register a custom command line argument processor. * Add the possibility to register a custom command line argument processor.
See org.apache.tools.ant.ArgumentProcessor and manual/argumentprocessor.html See org.apache.tools.ant.ArgumentProcessor and manual/argumentprocessor.html


* add the possibility to suppress stdout in the sshexec task.
Bugzilla Report 50270.

Changes from Ant 1.8.3 TO Ant 1.8.4 Changes from Ant 1.8.3 TO Ant 1.8.4
=================================== ===================================




+ 8
- 0
contributors.xml View File

@@ -596,6 +596,10 @@
<first>Irene</first> <first>Irene</first>
<last>Rusman</last> <last>Rusman</last>
</name> </name>
<name>
<first>Isaac</first>
<last>Shabtay</last>
</name>
<name> <name>
<first>Ivan</first> <first>Ivan</first>
<last>Ivanov</last> <last>Ivanov</last>
@@ -1347,6 +1351,10 @@
<middle>E.</middle> <middle>E.</middle>
<last>Newton</last> <last>Newton</last>
</name> </name>
<name>
<first>Sudheer</first>
<last>Chigurupati</last>
</name>
<name> <name>
<first>Takashi</first> <first>Takashi</first>
<last>Okamoto</last> <last>Okamoto</last>


+ 6
- 0
manual/Tasks/sshexec.html View File

@@ -115,6 +115,12 @@ and won't work with versions of jsch earlier than
<td valign="top">Passphrase for your private key.</td> <td valign="top">Passphrase for your private key.</td>
<td valign="top" align="center">No, defaults to an empty string.</td> <td valign="top" align="center">No, defaults to an empty string.</td>
</tr> </tr>
<tr>
<td valign="top">suppresssystemout</td>
<td valign="top">Whether to suppress system out.
<em>since Ant 1.9.0</em></td>
<td align="center" valign="top">No, defaults to false</td>
</tr>
<tr> <tr>
<td valign="top">output</td> <td valign="top">output</td>
<td valign="top">Name of a file to which to write the output.</td> <td valign="top">Name of a file to which to write the output.</td>


+ 19
- 4
src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java View File

@@ -27,6 +27,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.StringReader; import java.io.StringReader;


import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
@@ -72,6 +73,11 @@ public class SSHExec extends SSHBase {
private static final String TIMEOUT_MESSAGE = private static final String TIMEOUT_MESSAGE =
"Timeout period exceeded, connection dropped."; "Timeout period exceeded, connection dropped.";


/**
* To supress writing logs to System.out
*/
private boolean suppressSystemOut = false;
/** /**
* Constructor for SSHExecTask. * Constructor for SSHExecTask.
*/ */
@@ -180,12 +186,22 @@ public class SSHExec extends SSHBase {
usePty = b; usePty = b;
} }


/**
* If suppressSystemOut is <code>true</code>, output will not be sent to System.out<br/>
* If suppressSystemOut is <code>false</code>, normal behavior
* @since Ant 1.9.0
*/
public void setSuppressSystemOut(boolean suppressSystemOut)
{
this.suppressSystemOut = suppressSystemOut;
}
/** /**
* Execute the command on the remote host. * Execute the command on the remote host.
* *
* @exception BuildException Most likely a network error or bad parameter. * @exception BuildException Most likely a network error or bad parameter.
*/ */
public void execute() throws BuildException { public void execute() throws BuildException {
if (getHost() == null) { if (getHost() == null) {
throw new BuildException("Host is required."); throw new BuildException("Host is required.");
} }
@@ -262,9 +278,7 @@ public class SSHExec extends SSHBase {
private void executeCommand(Session session, String cmd, StringBuffer sb) private void executeCommand(Session session, String cmd, StringBuffer sb)
throws BuildException { throws BuildException {
ByteArrayOutputStream out = new ByteArrayOutputStream(); ByteArrayOutputStream out = new ByteArrayOutputStream();
TeeOutputStream tee =
new TeeOutputStream(out,
KeepAliveOutputStream.wrapSystemOut());
OutputStream tee = suppressSystemOut ? out : new TeeOutputStream(out, KeepAliveOutputStream.wrapSystemOut());


InputStream istream = null ; InputStream istream = null ;
if (inputFile != null) { if (inputFile != null) {
@@ -407,4 +421,5 @@ public class SSHExec extends SSHBase {
} }
} }
} }
}

}

Loading…
Cancel
Save