From 46584fbf1e6d26ee3a0496f2951f2bab4592bbc3 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Fri, 23 Oct 2009 12:11:47 +0000 Subject: [PATCH] o Fixed transfer listener to output to proper stream git-svn-id: https://svn.apache.org/repos/asf/maven/maven-3/trunk@829018 13f79535-47bb-0310-9956-ffa450edef68 --- .../maven/cli/AbstractMavenTransferListener.java | 12 ++++++++++-- .../maven/cli/BatchModeMavenTransferListener.java | 9 ++++++++- .../maven/cli/ConsoleMavenTransferListener.java | 13 ++++++++++--- .../main/java/org/apache/maven/cli/MavenCli.java | 9 +++++---- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java index fbf2d054e4..a43143d8cd 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/AbstractMavenTransferListener.java @@ -19,6 +19,7 @@ package org.apache.maven.cli; * under the License. */ +import java.io.PrintStream; import java.text.DecimalFormat; import java.text.DecimalFormatSymbols; import java.util.Locale; @@ -31,8 +32,15 @@ public abstract class AbstractMavenTransferListener implements ArtifactTransferListener { + protected PrintStream out; + private boolean showChecksumEvents; + protected AbstractMavenTransferListener( PrintStream out ) + { + this.out = ( out != null ) ? out : System.out; + } + protected boolean showEvent( ArtifactTransferEvent event ) { if ( event.getResource() == null ) @@ -70,7 +78,7 @@ public abstract class AbstractMavenTransferListener String message = transferEvent.getRequestType() == ArtifactTransferEvent.REQUEST_PUT ? "Uploading" : "Downloading"; - System.out.println( message + ": " + transferEvent.getResource().getUrl() ); + out.println( message + ": " + transferEvent.getResource().getUrl() ); } public void transferStarted( ArtifactTransferEvent transferEvent ) @@ -132,7 +140,7 @@ public abstract class AbstractMavenTransferListener throughput = " at " + format.format( kbPerSec ) + " KB/sec"; } - System.out.println( l + " " + type + throughput ); + out.println( l + " " + type + throughput ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/BatchModeMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/BatchModeMavenTransferListener.java index d746d1cada..837aa346cd 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/BatchModeMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/BatchModeMavenTransferListener.java @@ -19,8 +19,15 @@ package org.apache.maven.cli; * under the License. */ -public class BatchModeMavenTransferListener +import java.io.PrintStream; + +class BatchModeMavenTransferListener extends AbstractMavenTransferListener { + public BatchModeMavenTransferListener( PrintStream out ) + { + super( out ); + } + } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java index cab006f622..95dcb11dfa 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/ConsoleMavenTransferListener.java @@ -19,6 +19,8 @@ package org.apache.maven.cli; * under the License. */ +import java.io.PrintStream; + import org.apache.maven.repository.ArtifactTransferEvent; /** @@ -26,10 +28,15 @@ import org.apache.maven.repository.ArtifactTransferEvent; * * @author Brett Porter */ -public class ConsoleMavenTransferListener +class ConsoleMavenTransferListener extends AbstractMavenTransferListener { + public ConsoleMavenTransferListener( PrintStream out ) + { + super( out ); + } + @Override protected void doProgress( ArtifactTransferEvent transferEvent ) { @@ -39,11 +46,11 @@ public class ConsoleMavenTransferListener // TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()? if ( total >= 1024 ) { - System.out.print( ( complete / 1024 ) + "/" + ( total == -1 ? "?" : ( total / 1024 ) + " KB" ) + "\r" ); + out.print( ( complete / 1024 ) + "/" + ( total == -1 ? "?" : ( total / 1024 ) + " KB" ) + "\r" ); } else { - System.out.print( complete + "/" + ( total == -1 ? "?" : total + " B" ) + "\r" ); + out.print( complete + "/" + ( total == -1 ? "?" : total + " B" ) + "\r" ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java index ba619c1017..bff75775d5 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java @@ -343,7 +343,7 @@ public class MavenCli return 1; } - populateRequest( request, commandLine, workingDirectory, debug, quiet, showErrors ); + populateRequest( request, commandLine, workingDirectory, debug, quiet, showErrors, stdout ); request.setExecutionListener( new ExecutionEventLogger( logger ) ); @@ -602,7 +602,8 @@ public class MavenCli } private MavenExecutionRequest populateRequest( MavenExecutionRequest request, CommandLine commandLine, - String workingDirectory, boolean debug, boolean quiet, boolean showErrors ) + String workingDirectory, boolean debug, boolean quiet, + boolean showErrors, PrintStream stdout ) { // ---------------------------------------------------------------------- // Now that we have everything that we need we will fire up plexus and @@ -729,11 +730,11 @@ public class MavenCli if ( request.isInteractiveMode() ) { - transferListener = new ConsoleMavenTransferListener(); + transferListener = new ConsoleMavenTransferListener( stdout ); } else { - transferListener = new BatchModeMavenTransferListener(); + transferListener = new BatchModeMavenTransferListener( stdout ); } transferListener.setShowChecksumEvents( false );