1 package org.apache.maven.util;
2
3 import org.apache.commons.logging.Log;
4 import org.apache.commons.logging.LogFactory;
5 import org.apache.maven.wagon.events.TransferEvent;
6 import org.apache.maven.wagon.events.TransferListener;
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 /**
27 * Bootstrap download progress meter.
28 *
29 * @author <a href="mailto:brett@apache.org">Brett Porter</a>
30 * @version $Id: BootstrapDownloadMeter.java 517014 2007-03-11 21:15:50Z ltheussl $
31 */
32 public class BootstrapDownloadMeter
33 implements TransferListener
34 {
35 /** LOGGER for debug output */
36 private static final Log LOGGER = LogFactory.getLog( BootstrapDownloadMeter.class );
37
38 private int shownSoFar = 0;
39
40 private final int numHashes;
41
42 private final char hashChar;
43
44 private long complete = 0;
45
46 public BootstrapDownloadMeter()
47 {
48 this( 20, '.' );
49 }
50
51 public BootstrapDownloadMeter( int numHashes, char hashChar )
52 {
53 this.numHashes = numHashes;
54 this.hashChar = hashChar;
55 }
56
57 public void transferInitiated( TransferEvent transferEvent )
58 {
59
60 }
61
62 public void transferStarted( TransferEvent transferEvent )
63 {
64 shownSoFar = 0;
65 complete = 0;
66 }
67
68 public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
69 {
70 long total = transferEvent.getResource().getContentLength();
71
72 complete += length;
73
74 if ( total > 0 )
75 {
76 int numToShow = (int) ( ( complete * numHashes ) / total );
77 for ( int i = shownSoFar + 1; i <= numToShow; i++ )
78 {
79 System.out.print( hashChar );
80 }
81 shownSoFar = numToShow;
82 }
83 }
84
85 public void transferCompleted( TransferEvent transferEvent )
86 {
87 long total = transferEvent.getResource().getContentLength();
88 System.out.println( " (" + ( total / 1024 ) + "K)" );
89 }
90
91 public void transferError( TransferEvent transferEvent )
92 {
93 LOGGER.error( transferEvent.getException().getMessage() );
94 }
95
96 public void debug( String message )
97 {
98 LOGGER.debug( message );
99 }
100 }