1 package org.apache.maven.wagon.observers;
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.events.SessionEvent;
23 import org.apache.maven.wagon.events.SessionListener;
24 import org.apache.maven.wagon.events.TransferEvent;
25 import org.apache.maven.wagon.events.TransferListener;
26
27 import java.io.PrintStream;
28
29
30
31
32
33 public class Debug
34 implements SessionListener, TransferListener
35 {
36 private PrintStream out;
37
38 long timestamp;
39
40 long transfer;
41
42 public Debug()
43 {
44 this( System.out );
45 }
46
47 public Debug( PrintStream out )
48 {
49 this.out = out;
50 }
51
52
53
54
55 public void sessionOpening( final SessionEvent sessionEvent )
56 {
57
58 }
59
60
61
62
63 public void sessionOpened( final SessionEvent sessionEvent )
64 {
65 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Opened " );
66 }
67
68
69
70
71 public void sessionDisconnecting( final SessionEvent sessionEvent )
72 {
73 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Disconnecting " );
74
75 }
76
77
78
79
80 public void sessionDisconnected( final SessionEvent sessionEvent )
81 {
82 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Disconnected" );
83 }
84
85
86
87
88 public void sessionConnectionRefused( final SessionEvent sessionEvent )
89 {
90 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Connection refused" );
91
92 }
93
94
95
96
97 public void sessionLoggedIn( final SessionEvent sessionEvent )
98 {
99 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Logged in" );
100
101 }
102
103
104
105
106 public void sessionLoggedOff( final SessionEvent sessionEvent )
107 {
108 out.println( sessionEvent.getWagon().getRepository().getUrl() + " - Session: Logged off" );
109
110 }
111
112
113
114
115 public void debug( final String message )
116 {
117 out.println( message );
118
119 }
120
121 public void transferInitiated( TransferEvent transferEvent )
122 {
123
124 }
125
126
127
128
129 public void transferStarted( final TransferEvent transferEvent )
130 {
131 timestamp = transferEvent.getTimestamp();
132
133 transfer = 0;
134
135 if ( transferEvent.getRequestType() == TransferEvent.REQUEST_GET )
136 {
137 final String message = "Downloading: " + transferEvent.getResource().getName() + " from "
138 + transferEvent.getWagon().getRepository().getUrl();
139
140 out.println( message );
141 }
142 else
143 {
144 final String message = "Uploading: " + transferEvent.getResource().getName() + " to "
145 + transferEvent.getWagon().getRepository().getUrl();
146
147 out.println( message );
148
149 }
150 }
151
152
153
154
155 public void transferProgress( final TransferEvent transferEvent, byte[] buffer, int length )
156 {
157
158 out.print( "#" );
159
160
161 transfer += length;
162 }
163
164
165
166
167 public void transferCompleted( final TransferEvent transferEvent )
168 {
169 final double duration = (double) ( transferEvent.getTimestamp() - timestamp ) / 1000;
170
171 out.println();
172
173 final String message = "Transfer finished. " + transfer + " bytes copied in " + duration + " seconds";
174
175 out.println( message );
176
177 }
178
179
180
181
182 public void transferError( final TransferEvent transferEvent )
183 {
184 out.println( " Transfer error: " + transferEvent.getException() );
185
186 }
187
188
189
190
191 public void sessionError( final SessionEvent sessionEvent )
192 {
193 out.println( " Session error: " + sessionEvent.getException() );
194
195 }
196
197 public PrintStream getOut()
198 {
199 return out;
200 }
201
202 }