ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r723422 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/taskdefs/optional/ssh/SSHExec.java
Date Thu, 04 Dec 2008 20:15:59 GMT
Author: bodewig
Date: Thu Dec  4 12:15:59 2008
New Revision: 723422

URL: http://svn.apache.org/viewvc?rev=723422&view=rev
Log:
store remote output in outputproperty even if it fails.  PR 46340.

Modified:
    ant/core/trunk/WHATSNEW
    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=723422&r1=723421&r2=723422&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Dec  4 12:15:59 2008
@@ -305,6 +305,10 @@
    of the file system).
    Bugzilla Report 43665.
 
+ * <sshexec> didn't store the ouput in outputproperty if the remote
+   command failed.
+   Bugzilla Report 46340.
+
 Other changes:
 --------------
 

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=723422&r1=723421&r2=723422&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 Thu Dec
 4 12:15:59 2008
@@ -185,31 +185,24 @@
         }
 
         Session session = null;
-
+        StringBuffer output = new StringBuffer();
         try {
             session = openSession();
             /* called once */
             if (command != null) {
                 log("cmd : " + command, Project.MSG_INFO);
-                ByteArrayOutputStream out = executeCommand(session, command);
-                if (outputProperty != null) {
-                    //#bugzilla 43437
-                    getProject().setNewProperty(outputProperty, command + " : " + out);
-                }
+                output.append(command).append(" : ");
+                executeCommand(session, command, output);
             } else { // read command resource and execute for each command
                 try {
                     BufferedReader br = new BufferedReader(
                             new InputStreamReader(commandResource.getInputStream()));
                     String cmd;
-                    String output = "";
                     while ((cmd = br.readLine()) != null) {
                         log("cmd : " + cmd, Project.MSG_INFO);
-                        ByteArrayOutputStream out = executeCommand(session, cmd);
-                        output += cmd + " : " + out + "\n";
-                    }
-                    if (outputProperty != null) {
-                        //#bugzilla 43437
-                        getProject().setNewProperty(outputProperty, output);
+                        output.append(cmd).append(" : ");
+                        executeCommand(session, cmd, output);
+                        output.append("\n");
                     }
                     FileUtils.close(br);
                 } catch (IOException e) {
@@ -219,13 +212,16 @@
         } catch (JSchException e) {
             throw new BuildException(e);
         } finally {
+            if (outputProperty != null) {
+                getProject().setNewProperty(outputProperty, output.toString());
+            }
             if (session != null && session.isConnected()) {
                 session.disconnect();
             }
         }
     }
 
-    private ByteArrayOutputStream executeCommand(Session session, String cmd)
+    private void executeCommand(Session session, String cmd, StringBuffer sb)
         throws BuildException {
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         TeeOutputStream tee = new TeeOutputStream(out, new KeepAliveOutputStream(System.out));
@@ -331,10 +327,9 @@
                 log("Caught exception: " + e.getMessage(), Project.MSG_ERR);
             }
         } finally {
+            sb.append(out.toString());
             FileUtils.close(istream);
         }
-
-        return out;
     }
 
     /**



Mime
View raw message