From b1002575177abd1108fe50f457cceb9c7c3cf7d8 Mon Sep 17 00:00:00 2001 From: Michael Osipov Date: Fri, 15 Jul 2016 23:26:56 +0200 Subject: [PATCH] [MNG-5457] Show repository id when downloading or uploading from/to a remote repository --- .../AbstractMavenTransferListener.java | 31 +++++++++++++------ .../transfer/Slf4jMavenTransferListener.java | 31 +++++++++++++------ 2 files changed, 42 insertions(+), 20 deletions(-) diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java index 21822bedf7..2b13879330 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/AbstractMavenTransferListener.java @@ -217,9 +217,15 @@ public abstract class AbstractMavenTransferListener public void transferInitiated( TransferEvent event ) { String action = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading"; + String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; TransferResource resource = event.getResource(); - out.println( action + ": " + resource.getRepositoryUrl() + resource.getResourceName() ); + StringBuilder message = new StringBuilder(); + message.append( action ).append( ' ' ).append( direction ).append( ' ' ).append( resource.getRepositoryId() ); + message.append( ": " ); + message.append( resource.getRepositoryUrl() ).append( resource.getResourceName() ); + + out.println( message.toString() ); } @Override @@ -228,30 +234,35 @@ public abstract class AbstractMavenTransferListener { TransferResource resource = event.getResource(); // TODO This needs to be colorized - out.println( "[WARNING] " + event.getException().getMessage() + " for " + resource.getRepositoryUrl() - + resource.getResourceName() ); + out.println( "[WARNING] " + event.getException().getMessage() + " from " + resource.getRepositoryId() + " for " + + resource.getRepositoryUrl() + resource.getResourceName() ); } @Override public void transferSucceeded( TransferEvent event ) { + String action = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); + String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; + TransferResource resource = event.getResource(); long contentLength = event.getTransferredBytes(); - FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - String result = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); - String len = format.format( contentLength ); - String throughput = ""; + StringBuilder message = new StringBuilder(); + message.append( action ).append( ' ' ).append( direction ).append( ' ' ).append( resource.getRepositoryId() ); + message.append( ": " ); + message.append( resource.getRepositoryUrl() ).append( resource.getResourceName() ); + message.append( " (" ).append( format.format( contentLength ) ); + long duration = System.currentTimeMillis() - resource.getTransferStartTime(); if ( duration > 0L ) { double bytesPerSecond = contentLength / ( duration / 1000.0 ); - throughput = " at " + format.format( (long) bytesPerSecond ) + "/s"; + message.append( " at " ).append( format.format( (long) bytesPerSecond ) ).append( "/s" ); } - out.println( result + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len - + throughput + ")" ); + message.append( ')' ); + out.println( message.toString() ); } } diff --git a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java index ac5333ec35..5c97acb51a 100644 --- a/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java +++ b/maven-embedder/src/main/java/org/apache/maven/cli/transfer/Slf4jMavenTransferListener.java @@ -50,9 +50,15 @@ public class Slf4jMavenTransferListener public void transferInitiated( TransferEvent event ) { String action = event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploading" : "Downloading"; + String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; TransferResource resource = event.getResource(); - out.info( action + ": " + resource.getRepositoryUrl() + resource.getResourceName() ); + StringBuilder message = new StringBuilder(); + message.append( action ).append( ' ' ).append( direction ).append( ' ' ).append( resource.getRepositoryId() ); + message.append( ": " ); + message.append( resource.getRepositoryUrl() ).append( resource.getResourceName() ); + + out.info( message.toString() ); } @Override @@ -60,30 +66,35 @@ public class Slf4jMavenTransferListener throws TransferCancelledException { TransferResource resource = event.getResource(); - out.warn( event.getException().getMessage() + " for " + resource.getRepositoryUrl() - + resource.getResourceName() ); + out.warn( event.getException().getMessage() + " from " + resource.getRepositoryId() + " for " + + resource.getRepositoryUrl() + resource.getResourceName() ); } @Override public void transferSucceeded( TransferEvent event ) { + String action = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); + String direction = event.getRequestType() == TransferEvent.RequestType.PUT ? "to" : "from"; + TransferResource resource = event.getResource(); long contentLength = event.getTransferredBytes(); - FileSizeFormat format = new FileSizeFormat( Locale.ENGLISH ); - String result = ( event.getRequestType() == TransferEvent.RequestType.PUT ? "Uploaded" : "Downloaded" ); - String len = format.format( contentLength ); - String throughput = ""; + StringBuilder message = new StringBuilder(); + message.append( action ).append( ' ' ).append( direction ).append( ' ' ).append( resource.getRepositoryId() ); + message.append( ": " ); + message.append( resource.getRepositoryUrl() ).append( resource.getResourceName() ); + message.append( " (" ).append( format.format( contentLength ) ); + long duration = System.currentTimeMillis() - resource.getTransferStartTime(); if ( duration > 0L ) { double bytesPerSecond = contentLength / ( duration / 1000.0 ); - throughput = " at " + format.format( (long) bytesPerSecond ) + "/s"; + message.append( " at " ).append( format.format( (long) bytesPerSecond ) ).append( "/s" ); } - out.info( result + ": " + resource.getRepositoryUrl() + resource.getResourceName() + " (" + len - + throughput + ")" ); + message.append( ')' ); + out.info( message.toString() ); } }