1 package org.apache.maven.cli; 2 3 18 19 import org.apache.maven.wagon.WagonConstants; 20 import org.apache.maven.wagon.events.TransferEvent; 21 import org.apache.maven.wagon.events.TransferListener; 22 import org.codehaus.plexus.logging.AbstractLogEnabled; 23 24 30 public class ConsoleDownloadMonitor 31 extends AbstractLogEnabled 32 implements TransferListener 33 { 34 private long complete; 35 36 public void transferInitiated( TransferEvent transferEvent ) 37 { 38 String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading"; 39 40 String url = transferEvent.getWagon().getRepository().getUrl(); 41 42 System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() ); 44 45 complete = 0; 46 } 47 48 public void transferStarted( TransferEvent transferEvent ) 49 { 50 } 52 53 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length ) 54 { 55 long total = transferEvent.getResource().getContentLength(); 56 complete += length; 57 if ( total >= 1024 ) 59 { 60 System.out.print( 61 ( complete / 1024 ) + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : ( total / 1024 ) + "K" ) + 62 "\r" ); 63 } 64 else 65 { 66 System.out.print( complete + "/" + ( total == WagonConstants.UNKNOWN_LENGTH ? "?" : total + "b" ) + "\r" ); 67 } 68 } 69 70 public void transferCompleted( TransferEvent transferEvent ) 71 { 72 long contentLength = transferEvent.getResource().getContentLength(); 73 if ( contentLength != WagonConstants.UNKNOWN_LENGTH ) 74 { 75 String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" ); 76 String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b"; 77 System.out.println( l + " " + type ); 78 } 79 } 80 81 public void transferError( TransferEvent transferEvent ) 82 { 83 transferEvent.getException().printStackTrace(); 85 } 86 87 public void debug( String message ) 88 { 89 } 92 } 93 94 95 96 | Popular Tags |