1 | |
package org.apache.maven.wagon.events; |
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.Wagon; |
23 | |
import org.apache.maven.wagon.resource.Resource; |
24 | |
|
25 | |
import java.io.File; |
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
public class TransferEvent |
35 | |
extends WagonEvent |
36 | |
{ |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
public static final int TRANSFER_INITIATED = 0; |
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
public static final int TRANSFER_STARTED = 1; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
public static final int TRANSFER_COMPLETED = 2; |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public static final int TRANSFER_PROGRESS = 3; |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public static final int TRANSFER_ERROR = 4; |
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public static final int REQUEST_GET = 5; |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
public static final int REQUEST_PUT = 6; |
72 | |
|
73 | |
private Resource resource; |
74 | |
|
75 | |
private int eventType; |
76 | |
|
77 | |
private int requestType; |
78 | |
|
79 | |
private Exception exception; |
80 | |
|
81 | |
private File localFile; |
82 | |
|
83 | |
public TransferEvent( final Wagon wagon, final Resource resource, final int eventType, final int requestType ) |
84 | |
{ |
85 | 84 | super( wagon ); |
86 | |
|
87 | 84 | this.resource = resource; |
88 | |
|
89 | 84 | setEventType( eventType ); |
90 | |
|
91 | 84 | setRequestType( requestType ); |
92 | |
|
93 | 84 | } |
94 | |
|
95 | |
public TransferEvent( final Wagon wagon, final Resource resource, final Exception exception, final int requestType ) |
96 | |
{ |
97 | 17 | this( wagon, resource, TRANSFER_ERROR, requestType ); |
98 | |
|
99 | 17 | this.exception = exception; |
100 | 17 | } |
101 | |
|
102 | |
|
103 | |
|
104 | |
|
105 | |
public Resource getResource() |
106 | |
{ |
107 | 4 | return resource; |
108 | |
} |
109 | |
|
110 | |
|
111 | |
|
112 | |
|
113 | |
public Exception getException() |
114 | |
{ |
115 | 1 | return exception; |
116 | |
} |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
|
124 | |
public int getRequestType() |
125 | |
{ |
126 | 4 | return requestType; |
127 | |
} |
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
public void setRequestType( final int requestType ) |
138 | |
{ |
139 | 87 | switch ( requestType ) |
140 | |
{ |
141 | |
|
142 | |
case REQUEST_PUT: |
143 | |
case REQUEST_GET: |
144 | 86 | break; |
145 | |
|
146 | |
default : |
147 | 1 | throw new IllegalArgumentException( "Illegal request type: " + requestType ); |
148 | |
} |
149 | |
|
150 | 86 | this.requestType = requestType; |
151 | 86 | } |
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
public int getEventType() |
157 | |
{ |
158 | 6 | return eventType; |
159 | |
} |
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | |
public void setEventType( final int eventType ) |
165 | |
{ |
166 | 89 | switch ( eventType ) |
167 | |
{ |
168 | |
|
169 | |
case TRANSFER_INITIATED: |
170 | |
case TRANSFER_STARTED: |
171 | |
case TRANSFER_COMPLETED: |
172 | |
case TRANSFER_PROGRESS: |
173 | |
case TRANSFER_ERROR: |
174 | 88 | break; |
175 | |
default : |
176 | 1 | throw new IllegalArgumentException( "Illegal event type: " + eventType ); |
177 | |
} |
178 | |
|
179 | 88 | this.eventType = eventType; |
180 | 88 | } |
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
public void setResource( final Resource resource ) |
186 | |
{ |
187 | 2 | this.resource = resource; |
188 | 2 | } |
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
public File getLocalFile() |
194 | |
{ |
195 | 0 | return localFile; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public void setLocalFile( File localFile ) |
202 | |
{ |
203 | 46 | this.localFile = localFile; |
204 | 46 | } |
205 | |
|
206 | |
public String toString() |
207 | |
{ |
208 | 0 | StringBuffer sb = new StringBuffer(); |
209 | |
|
210 | 0 | sb.append( "TransferEvent[" ); |
211 | |
|
212 | 0 | switch ( this.getRequestType() ) |
213 | |
{ |
214 | |
case REQUEST_GET: |
215 | 0 | sb.append( "GET" ); |
216 | 0 | break; |
217 | |
case REQUEST_PUT: |
218 | 0 | sb.append( "PUT" ); |
219 | 0 | break; |
220 | |
default: |
221 | 0 | sb.append( this.getRequestType() ); |
222 | |
break; |
223 | |
} |
224 | |
|
225 | 0 | sb.append( "|" ); |
226 | 0 | switch ( this.getEventType() ) |
227 | |
{ |
228 | |
case TRANSFER_COMPLETED: |
229 | 0 | sb.append( "COMPLETED" ); |
230 | 0 | break; |
231 | |
case TRANSFER_ERROR: |
232 | 0 | sb.append( "ERROR" ); |
233 | 0 | break; |
234 | |
case TRANSFER_INITIATED: |
235 | 0 | sb.append( "INITIATED" ); |
236 | 0 | break; |
237 | |
case TRANSFER_PROGRESS: |
238 | 0 | sb.append( "PROGRESS" ); |
239 | 0 | break; |
240 | |
case TRANSFER_STARTED: |
241 | 0 | sb.append( "STARTED" ); |
242 | 0 | break; |
243 | |
default: |
244 | 0 | sb.append( this.getEventType() ); |
245 | |
break; |
246 | |
} |
247 | |
|
248 | 0 | sb.append( "|" ); |
249 | |
|
250 | 0 | sb.append( this.getWagon().getRepository() ).append( "|" ); |
251 | 0 | sb.append( this.getLocalFile() ).append( "|" ); |
252 | 0 | sb.append( this.getResource().inspect() ); |
253 | 0 | sb.append( "]" ); |
254 | |
|
255 | 0 | return sb.toString(); |
256 | |
} |
257 | |
|
258 | |
public int hashCode() |
259 | |
{ |
260 | 0 | final int prime = 31; |
261 | 0 | int result = 1; |
262 | 0 | result = prime * result + eventType; |
263 | 0 | result = prime * result + ( ( exception == null ) ? 0 : exception.hashCode() ); |
264 | 0 | result = prime * result + ( ( localFile == null ) ? 0 : localFile.hashCode() ); |
265 | 0 | result = prime * result + requestType; |
266 | 0 | result = prime * result + ( ( resource == null ) ? 0 : resource.hashCode() ); |
267 | 0 | return result; |
268 | |
} |
269 | |
|
270 | |
public boolean equals( Object obj ) |
271 | |
{ |
272 | 15 | if ( this == obj ) |
273 | |
{ |
274 | 8 | return true; |
275 | |
} |
276 | 7 | if ( ( obj == null ) || ( getClass() != obj.getClass() ) ) |
277 | |
{ |
278 | 0 | return false; |
279 | |
} |
280 | 7 | final TransferEvent other = (TransferEvent) obj; |
281 | 7 | if ( eventType != other.eventType ) |
282 | |
{ |
283 | 0 | return false; |
284 | |
} |
285 | 7 | if ( exception == null ) |
286 | |
{ |
287 | 1 | if ( other.exception != null ) |
288 | |
{ |
289 | 0 | return false; |
290 | |
} |
291 | |
} |
292 | 6 | else if ( !exception.getClass().equals( other.exception.getClass() ) ) |
293 | |
{ |
294 | 0 | return false; |
295 | |
} |
296 | 7 | if ( requestType != other.requestType ) |
297 | |
{ |
298 | 0 | return false; |
299 | |
} |
300 | 7 | if ( resource == null ) |
301 | |
{ |
302 | 0 | if ( other.resource != null ) |
303 | |
{ |
304 | 0 | return false; |
305 | |
} |
306 | |
} |
307 | 7 | else if ( !resource.equals( other.resource ) ) |
308 | |
{ |
309 | 0 | return false; |
310 | |
} |
311 | 7 | else if ( !source.equals( other.source ) ) |
312 | |
{ |
313 | 0 | return false; |
314 | |
} |
315 | 7 | return true; |
316 | |
} |
317 | |
|
318 | |
} |