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 a43143d8cd..455031b384 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 @@ -129,7 +129,7 @@ public abstract class AbstractMavenTransferListener { String type = ( transferEvent.getRequestType() == ArtifactTransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" ); - String l = contentLength >= 1024 ? ( ( contentLength + 1023 ) / 1024 ) + " KB" : contentLength + " B"; + String l = contentLength >= 1024 ? toKB( contentLength ) + " KB" : contentLength + " B"; String throughput = ""; long duration = System.currentTimeMillis() - artifact.getTransferStartTime(); @@ -144,6 +144,11 @@ public abstract class AbstractMavenTransferListener } } + protected long toKB( long bytes ) + { + return ( bytes + 1023 ) / 1024; + } + public boolean isShowChecksumEvents() { return showChecksumEvents; 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 95dcb11dfa..61c9a7a7b7 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 @@ -46,11 +46,19 @@ class ConsoleMavenTransferListener // TODO [BP]: Sys.out may no longer be appropriate, but will \r work with getLogger()? if ( total >= 1024 ) { - out.print( ( complete / 1024 ) + "/" + ( total == -1 ? "?" : ( total / 1024 ) + " KB" ) + "\r" ); + out.print( toKB( complete ) + "/" + toKB( total ) + " KB" + "\r" ); + } + else if ( total >= 0 ) + { + out.print( complete + "/" + total + " B" + "\r" ); + } + else if ( complete >= 1024 ) + { + out.print( toKB( complete ) + " KB" + "\r" ); } else { - out.print( complete + "/" + ( total == -1 ? "?" : total + " B" ) + "\r" ); + out.print( complete + " B" + "\r" ); } }