1 package org.apache.maven.plugin.war;
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.artifact.Artifact;
23
24 import java.util.ArrayList;
25 import java.util.Arrays;
26 import java.util.List;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41 public class Overlay
42 {
43
44
45
46
47 public static final String[] DEFAULT_INCLUDES = new String[] { "**/**" };
48
49
50
51
52 public static final String[] DEFAULT_EXCLUDES = new String[] { "META-INF/MANIFEST.MF" };
53
54 private String id;
55
56 private String groupId;
57
58 private String artifactId;
59
60 private String classifier = null;
61
62 private String[] includes = DEFAULT_INCLUDES;
63
64 private String[] excludes = DEFAULT_EXCLUDES;
65
66 private boolean filtered = false;
67
68 private boolean skip = false;
69
70 private Artifact artifact;
71
72 private String targetPath;
73
74
75 private String type = "war";
76
77
78
79
80 public Overlay()
81 {
82 super();
83 }
84
85
86
87
88
89 public Overlay( String groupId, String artifactId )
90 {
91 this();
92 this.groupId = groupId;
93 this.artifactId = artifactId;
94 }
95
96
97
98
99
100
101 public boolean isCurrentProject()
102 {
103 return ( groupId == null && artifactId == null );
104 }
105
106
107
108
109 public static Overlay createInstance()
110 {
111 Overlay overlay = new Overlay();
112 overlay.setId( "currentBuild" );
113 return overlay;
114 }
115
116
117
118
119
120
121 public String getId()
122 {
123 if ( id == null )
124 {
125 final StringBuilder sb = new StringBuilder();
126 sb.append( getGroupId() ).append( ":" ).append( getArtifactId() );
127 if ( getClassifier() != null )
128 {
129 sb.append( ":" ).append( getClassifier() );
130 }
131 id = sb.toString();
132 }
133 return id;
134 }
135
136
137
138
139 public void setId( String id )
140 {
141 this.id = id;
142 }
143
144
145
146
147 public String getGroupId()
148 {
149 return groupId;
150 }
151
152
153
154
155 public void setGroupId( String groupId )
156 {
157 this.groupId = groupId;
158 }
159
160
161
162
163 public String getArtifactId()
164 {
165 return artifactId;
166 }
167
168
169
170
171 public void setArtifactId( String artifactId )
172 {
173 this.artifactId = artifactId;
174 }
175
176
177
178
179 public String getClassifier()
180 {
181 return classifier;
182 }
183
184
185
186
187 public void setClassifier( String classifier )
188 {
189 this.classifier = classifier;
190 }
191
192
193
194
195 public String[] getIncludes()
196 {
197 return includes;
198 }
199
200
201
202
203 public void setIncludes( String includes )
204 {
205 this.includes = parse( includes );
206 }
207
208
209
210
211 public void setIncludes( String[] includes )
212 {
213 this.includes = includes;
214 }
215
216
217
218
219 public String[] getExcludes()
220 {
221 return excludes;
222 }
223
224
225
226
227 public void setExcludes( String excludes )
228 {
229 this.excludes = parse( excludes );
230 }
231
232
233
234
235 public void setExcludes( String[] excludes )
236 {
237 this.excludes = excludes;
238 }
239
240
241
242
243 public boolean isFiltered()
244 {
245 return filtered;
246 }
247
248
249
250
251 public void setFiltered( boolean filtered )
252 {
253 this.filtered = filtered;
254 }
255
256
257
258
259 public boolean shouldSkip()
260 {
261 return skip;
262 }
263
264
265
266
267 public void setSkip( boolean skip )
268 {
269 this.skip = skip;
270 }
271
272
273
274
275 public Artifact getArtifact()
276 {
277 return artifact;
278 }
279
280
281
282
283 public void setArtifact( Artifact artifact )
284 {
285 this.artifact = artifact;
286 }
287
288
289
290
291 public String getTargetPath()
292 {
293 return targetPath;
294 }
295
296
297
298
299 public void setTargetPath( String targetPath )
300 {
301 this.targetPath = targetPath;
302 }
303
304
305
306
307 public String getType()
308 {
309 return type;
310 }
311
312
313
314
315 public void setType( String type )
316 {
317 this.type = type;
318 }
319
320
321
322
323 public String toString()
324 {
325 return " id " + getId();
326 }
327
328
329
330
331 public boolean equals( Object o )
332 {
333 if ( this == o )
334 {
335 return true;
336 }
337 if ( o == null || getClass() != o.getClass() )
338 {
339 return false;
340 }
341
342 Overlay overlay = (Overlay) o;
343
344 if ( excludes != null ? !Arrays.equals( excludes, overlay.excludes ) : overlay.excludes != null )
345 {
346 return false;
347 }
348 if ( getId() != null ? !getId().equals( overlay.getId() ) : overlay.getId() != null )
349 {
350 return false;
351 }
352 if ( includes != null ? !Arrays.equals( includes, overlay.includes ) : overlay.includes != null )
353 {
354 return false;
355 }
356
357 return true;
358 }
359
360
361
362
363 public int hashCode()
364 {
365 int result;
366 result = ( getId() != null ? getId().hashCode() : 0 );
367 result = 31 * result + ( includes != null ? includes.hashCode() : 0 );
368 result = 31 * result + ( excludes != null ? excludes.hashCode() : 0 );
369 return result;
370 }
371
372 private String[] parse( String s )
373 {
374 final List<String> result = new ArrayList<String>();
375 if ( s == null )
376 {
377 return result.toArray( new String[result.size()] );
378 }
379 else
380 {
381 String[] tokens = s.split( "," );
382 for ( String token : tokens )
383 {
384 result.add( token.trim() );
385 }
386 return result.toArray( new String[result.size()] );
387 }
388 }
389
390 }