Repository: maven-wagon
Updated Branches:
  refs/heads/master 87338f924 -> 246c6daf1


[WAGON-465] add options ignore stderr and/or none 0 exit code

* Introduce a new wagon-ssh execute interface the handle the options

* No new behavior changes for current interface

* dump stdout/sterr exec outputs  to session listen

* Fix a couple of NPE when session listener is enable

Project: http://git-wip-us.apache.org/repos/asf/maven-wagon/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-wagon/commit/246c6daf
Tree: http://git-wip-us.apache.org/repos/asf/maven-wagon/tree/246c6daf
Diff: http://git-wip-us.apache.org/repos/asf/maven-wagon/diff/246c6daf

Branch: refs/heads/master
Commit: 246c6daf1ca3fba385f71c89fdf798d2b519ced6
Parents: 87338f9
Author: Dan Tran <dant...@gmail.com>
Authored: Sun Oct 30 15:15:34 2016 -0700
Committer: Dan Tran <dant...@gmail.com>
Committed: Sun Oct 30 15:15:34 2016 -0700

----------------------------------------------------------------------
 .../org/apache/maven/wagon/AbstractWagon.java   |  7 +++--
 .../providers/ssh/jsch/AbstractJschWagon.java   | 31 +++++++++++++++++---
 2 files changed, 31 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/246c6daf/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
----------------------------------------------------------------------
diff --git 
a/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java 
b/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
index f80ff8f..9497260 100644
--- a/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
+++ b/wagon-provider-api/src/main/java/org/apache/maven/wagon/AbstractWagon.java
@@ -371,13 +371,14 @@ public abstract class AbstractWagon
         {
             transfer( resource, input, output, TransferEvent.REQUEST_GET, 
maxSize );
 
+            finishGetTransfer( resource, input, output );
+
             if ( closeInput )
             {
                 input.close();
                 input = null;
             }
 
-            finishGetTransfer( resource, input, output );
         }
         catch ( IOException e )
         {
@@ -471,13 +472,13 @@ public abstract class AbstractWagon
                           ? Long.MAX_VALUE
                           : resource.getContentLength() );
 
+            finishPutTransfer( resource, input, output );
+
             if ( closeOutput )
             {
                 output.close();
                 output = null;
             }
-
-            finishPutTransfer( resource, input, output );
         }
         catch ( IOException e )
         {

http://git-wip-us.apache.org/repos/asf/maven-wagon/blob/246c6daf/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
----------------------------------------------------------------------
diff --git 
a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
 
b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
index 9f51d90..8695235 100644
--- 
a/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
+++ 
b/wagon-providers/wagon-ssh/src/main/java/org/apache/maven/wagon/providers/ssh/jsch/AbstractJschWagon.java
@@ -305,16 +305,18 @@ public abstract class AbstractJschWagon
         }
     }
 
-    public Streams executeCommand( String command, boolean ignoreFailures )
+    public Streams executeCommand( String command, boolean ignoreStdErr, 
boolean ignoreNoneZeroExitCode )
         throws CommandExecutionException
     {
         ChannelExec channel = null;
         BufferedReader stdoutReader = null;
         BufferedReader stderrReader = null;
+        Streams streams = null;
         try
         {
             channel = (ChannelExec) session.openChannel( EXEC_CHANNEL );
 
+            fireSessionDebug( "Executing: " + command );
             channel.setCommand( command + "\n" );
 
             stdoutReader = new BufferedReader( new InputStreamReader( 
channel.getInputStream() ) );
@@ -322,7 +324,7 @@ public abstract class AbstractJschWagon
 
             channel.connect();
 
-            Streams streams = CommandExecutorStreamProcessor.processStreams( 
stderrReader, stdoutReader );
+            streams = CommandExecutorStreamProcessor.processStreams( 
stderrReader, stdoutReader );
 
             stdoutReader.close();
             stdoutReader = null;
@@ -330,9 +332,15 @@ public abstract class AbstractJschWagon
             stderrReader.close();
             stderrReader = null;
 
-            if ( streams.getErr().length() > 0 && !ignoreFailures )
+            int exitCode = channel.getExitStatus();
+
+            if ( streams.getErr().length() > 0 && !ignoreStdErr )
+            {
+                throw new CommandExecutionException( "Exit code: " + exitCode 
+ " - " + streams.getErr() );
+            }
+
+            if ( exitCode != 0 && !ignoreNoneZeroExitCode )
             {
-                int exitCode = channel.getExitStatus();
                 throw new CommandExecutionException( "Exit code: " + exitCode 
+ " - " + streams.getErr() );
             }
 
@@ -348,6 +356,12 @@ public abstract class AbstractJschWagon
         }
         finally
         {
+            if ( streams != null )
+            {
+                fireSessionDebug( "Stdout results:" + streams.getOut() );
+                fireSessionDebug( "Stderr results:" + streams.getErr() );
+            }
+
             IOUtil.close( stdoutReader );
             IOUtil.close( stderrReader );
             if ( channel != null )
@@ -400,6 +414,15 @@ public abstract class AbstractJschWagon
         executeCommand( command, false );
     }
 
+    public Streams executeCommand( String command, boolean ignoreFailures )
+            throws CommandExecutionException
+    {
+        fireTransferDebug( "Executing command: " + command );
+
+        //backward compatible with wagon 2.10
+        return executeCommand( command, ignoreFailures, ignoreFailures );
+    }
+
     public InteractiveUserInfo getInteractiveUserInfo()
     {
         return this.interactiveUserInfo;

Reply via email to