[MNG-5457] Show repository id when downloading or uploading from/to a remote repository

This commit is contained in:
Michael Osipov 2016-07-15 23:26:56 +02:00
parent e520324c8d
commit b100257517
2 changed files with 42 additions and 20 deletions

View File

@ -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() );
}
}

View File

@ -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() );
}
}