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