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