Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AbstractConsoleDownloadMonitor |
|
| 1.1666666666666667;1.167 |
1 | package org.apache.maven.cli; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import org.apache.maven.wagon.WagonConstants; | |
23 | import org.apache.maven.wagon.events.TransferEvent; | |
24 | import org.apache.maven.wagon.events.TransferListener; | |
25 | import org.codehaus.plexus.logging.AbstractLogEnabled; | |
26 | ||
27 | /** | |
28 | * Abstract console download progress meter. | |
29 | * | |
30 | * @author <a href="mailto:carlos@apache.org">Carlos Sanchez</a> | |
31 | * @version $Id: AbstractConsoleDownloadMonitor.java 708758 2008-10-29 03:11:58Z brett $ | |
32 | * @since 2.0.5 | |
33 | */ | |
34 | 0 | public abstract class AbstractConsoleDownloadMonitor |
35 | extends AbstractLogEnabled | |
36 | implements TransferListener | |
37 | { | |
38 | ||
39 | public void transferInitiated( TransferEvent transferEvent ) | |
40 | { | |
41 | 0 | String message = transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "Uploading" : "Downloading"; |
42 | ||
43 | 0 | String url = transferEvent.getWagon().getRepository().getUrl(); |
44 | ||
45 | // TODO: can't use getLogger() because this isn't currently instantiated as a component | |
46 | 0 | System.out.println( message + ": " + url + "/" + transferEvent.getResource().getName() ); |
47 | 0 | } |
48 | ||
49 | /** | |
50 | * Do nothing | |
51 | */ | |
52 | public void transferStarted( TransferEvent transferEvent ) | |
53 | { | |
54 | // This space left intentionally blank | |
55 | 0 | } |
56 | ||
57 | /** | |
58 | * Do nothing | |
59 | */ | |
60 | public void transferProgress( TransferEvent transferEvent, byte[] buffer, int length ) | |
61 | { | |
62 | // This space left intentionally blank | |
63 | 0 | } |
64 | ||
65 | public void transferCompleted( TransferEvent transferEvent ) | |
66 | { | |
67 | 0 | long contentLength = transferEvent.getResource().getContentLength(); |
68 | 0 | if ( contentLength != WagonConstants.UNKNOWN_LENGTH ) |
69 | { | |
70 | 0 | String type = ( transferEvent.getRequestType() == TransferEvent.REQUEST_PUT ? "uploaded" : "downloaded" ); |
71 | 0 | String l = contentLength >= 1024 ? ( contentLength / 1024 ) + "K" : contentLength + "b"; |
72 | 0 | System.out.println( l + " " + type ); |
73 | } | |
74 | 0 | } |
75 | ||
76 | public void transferError( TransferEvent transferEvent ) | |
77 | { | |
78 | // these errors should already be handled elsewhere by Maven since they all result in an exception from Wagon | |
79 | 0 | } |
80 | ||
81 | /** | |
82 | * Do nothing | |
83 | */ | |
84 | public void debug( String message ) | |
85 | { | |
86 | // TODO: can't use getLogger() because this isn't currently instantiated as a component | |
87 | // getLogger().debug( message ); | |
88 | 0 | } |
89 | ||
90 | } |