File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\maven-plugin\src\main\java\hudson\maven\TransferListenerImpl.java.html

1 /*
2 * The MIT License
3 *
4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 * THE SOFTWARE.
23 */
24 package hudson.maven;
25
26 import hudson.model.TaskListener;
27 import org.apache.maven.wagon.events.TransferEvent;
28 import org.apache.maven.wagon.events.TransferListener;
29
30 import java.io.PrintStream;
31
32 /**
33 * {@link TransferListener} implementation.
34 *
35 * <p>
36 * This implementation puts the transfer progress indication in a distinctively formatted line,
37 * so that on HTML we can render the progress as a progress bar.
38 *
39 * @author Kohsuke Kawaguchi
40 */
41 final class TransferListenerImpl implements TransferListener {
42 /**
43 * Receives the formatter messages.
44 */
45 private final PrintStream out;
46
47 private long transferedSize;
48
49
50 public TransferListenerImpl(TaskListener listener) {
51 this.out = listener.getLogger();
52 }
53
54 public void transferInitiated( TransferEvent e )
55 {
56 String url = e.getWagon().getRepository().getUrl();
57
58 if(e.getRequestType()==TransferEvent.REQUEST_PUT) {
59 out.println("Uploading to "+url);
60 } else {
61 out.println("Downloading "+url);
62 }
63 }
64
65 public void transferStarted(TransferEvent e) {
66 transferedSize = 0;
67 long total = e.getResource().getContentLength();
68 out.println(HEADER+" start "+total);
69 }
70
71 public void transferProgress(TransferEvent e, byte[] buffer, int length) {
72 transferedSize += length;
73 out.println(HEADER + " progress " + transferedSize);
74 }
75
76 public void transferCompleted(TransferEvent e) {
77 out.println(HEADER + " completed");
78 }
79
80 public void transferError(TransferEvent e) {
81 out.println(HEADER + " error");
82 e.getException().printStackTrace(out);
83 }
84
85 public void debug(String message) {
86 }
87
88 /**
89 * Lines printed by this class will have this header.
90 */
91 public static final String HEADER = "[:TRANSFER:]";
92 }
93