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