KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > maven > cli > BatchModeDownloadMonitor


1 package org.apache.maven.cli;
2
3 /*
4  * Copyright 2001-2005 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

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 /**
25  * Console download progress meter.
26  *
27  * @author <a HREF="mailto:brett@apache.org">Brett Porter</a>
28  * @version $Id: ConsoleDownloadMonitor.java 169548 2005-05-11 01:04:50Z brett $
29  */

30 public class BatchModeDownloadMonitor
31     extends AbstractLogEnabled
32     implements TransferListener
33 {
34     public void transferInitiated( TransferEvent transferEvent )
35     {
36         String JavaDoc message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading";
37
38         String JavaDoc url = transferEvent.getWagon().getRepository().getUrl();
39
40         // TODO: can't use getLogger() because this isn't currently instantiated as a component
41
System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() );
42     }
43
44     public void transferStarted( TransferEvent transferEvent )
45     {
46         // This space left intentionally blank
47
}
48
49     public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length )
50     {
51         // This space left intentionally blank
52
}
53
54     public void transferCompleted( TransferEvent transferEvent )
55     {
56         long contentLength = transferEvent.getResource().getContentLength();
57         if ( contentLength != WagonConstants.UNKNOWN_LENGTH )
58         {
59             String JavaDoc type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" );
60             String JavaDoc l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b";
61             System.out.println( l + " " + type );
62         }
63     }
64
65     public void transferError( TransferEvent transferEvent )
66     {
67         // TODO: can't use getLogger() because this isn't currently instantiated as a component
68
transferEvent.getException().printStackTrace();
69     }
70
71     public void debug( String JavaDoc message )
72     {
73         // TODO: can't use getLogger() because this isn't currently instantiated as a component
74
// getLogger().debug( message );
75
}
76 }
77
78
79
80
Popular Tags