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