1 package org.apache.maven.cli;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.wagon.WagonConstants;
23 import org.apache.maven.wagon.events.TransferEvent;
24
25
26
27
28
29
30
31 public class ConsoleDownloadMonitor
32 extends AbstractConsoleDownloadMonitor
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
43 System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
44
45 complete = 0;
46 }
47
48 public void transferStarted( TransferEvent transferEvent )
49 {
50
51 }
52
53 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
54 {
55 long total = transferEvent.getResource().getContentLength();
56 complete += length;
57
58 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