1 | |
package org.apache.maven.plugin.ant; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.ByteArrayInputStream; |
23 | |
import java.io.File; |
24 | |
import java.io.IOException; |
25 | |
import java.text.DateFormat; |
26 | |
import java.util.ArrayList; |
27 | |
import java.util.Date; |
28 | |
import java.util.HashMap; |
29 | |
import java.util.Iterator; |
30 | |
import java.util.List; |
31 | |
import java.util.Locale; |
32 | |
import java.util.Map; |
33 | |
|
34 | |
import javax.xml.parsers.DocumentBuilderFactory; |
35 | |
|
36 | |
import org.apache.maven.artifact.Artifact; |
37 | |
import org.apache.maven.model.Plugin; |
38 | |
import org.apache.maven.model.ReportPlugin; |
39 | |
import org.apache.maven.project.MavenProject; |
40 | |
import org.apache.xpath.XPathAPI; |
41 | |
import org.codehaus.plexus.util.PathTool; |
42 | |
import org.codehaus.plexus.util.StringUtils; |
43 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
44 | |
import org.codehaus.plexus.util.xml.XmlWriterUtil; |
45 | |
import org.w3c.dom.Document; |
46 | |
import org.w3c.dom.Node; |
47 | |
import org.w3c.dom.NodeList; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class AntBuildWriterUtil |
56 | |
{ |
57 | |
|
58 | |
|
59 | |
|
60 | |
|
61 | |
public static List removeEmptyCompileSourceRoots( List compileSourceRoots ) |
62 | |
{ |
63 | 12 | List newCompileSourceRootsList = new ArrayList(); |
64 | 12 | if ( compileSourceRoots != null ) |
65 | |
{ |
66 | |
|
67 | 12 | for ( Iterator i = compileSourceRoots.iterator(); i.hasNext(); ) |
68 | |
{ |
69 | 12 | String srcDir = (String) i.next(); |
70 | 12 | if ( new File( srcDir ).exists() ) |
71 | |
{ |
72 | 0 | newCompileSourceRootsList.add( srcDir ); |
73 | |
} |
74 | |
} |
75 | |
} |
76 | |
|
77 | 12 | return newCompileSourceRootsList; |
78 | |
} |
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
|
86 | |
|
87 | |
public static void writeIncludesExcludes( XMLWriter writer, List includes, List excludes ) |
88 | |
{ |
89 | 10 | if ( includes != null ) |
90 | |
{ |
91 | 10 | for ( Iterator i = includes.iterator(); i.hasNext(); ) |
92 | |
{ |
93 | 0 | String include = (String) i.next(); |
94 | 0 | writer.startElement( "include" ); |
95 | 0 | writer.addAttribute( "name", include ); |
96 | 0 | writer.endElement(); |
97 | |
} |
98 | |
} |
99 | 10 | if ( excludes != null ) |
100 | |
{ |
101 | 10 | for ( Iterator i = excludes.iterator(); i.hasNext(); ) |
102 | |
{ |
103 | 0 | String exclude = (String) i.next(); |
104 | 0 | writer.startElement( "exclude" ); |
105 | 0 | writer.addAttribute( "name", exclude ); |
106 | 0 | writer.endElement(); |
107 | |
} |
108 | |
} |
109 | 10 | } |
110 | |
|
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | |
public static void writeHeader( XMLWriter writer ) |
117 | |
{ |
118 | 6 | writeAntVersionHeader( writer ); |
119 | |
|
120 | 6 | XmlWriterUtil.writeCommentLineBreak( writer ); |
121 | 6 | XmlWriterUtil.writeComment( writer, StringUtils.repeat( "=", 21 ) + " - DO NOT EDIT THIS FILE! - " |
122 | |
+ StringUtils.repeat( "=", 21 ) ); |
123 | 6 | XmlWriterUtil.writeCommentLineBreak( writer ); |
124 | 6 | XmlWriterUtil.writeComment( writer, " " ); |
125 | 6 | XmlWriterUtil.writeComment( writer, "Any modifications will be overwritten." ); |
126 | 6 | XmlWriterUtil.writeComment( writer, " " ); |
127 | 6 | DateFormat dateFormat = DateFormat.getDateTimeInstance( DateFormat.SHORT, DateFormat.SHORT, Locale.US ); |
128 | 6 | XmlWriterUtil.writeComment( writer, "Generated by Maven Ant Plugin on " |
129 | |
+ dateFormat.format( new Date( System.currentTimeMillis() ) ) ); |
130 | 6 | XmlWriterUtil.writeComment( writer, "See: http://maven.apache.org/plugins/maven-ant-plugin/" ); |
131 | 6 | XmlWriterUtil.writeComment( writer, " " ); |
132 | 6 | XmlWriterUtil.writeCommentLineBreak( writer ); |
133 | |
|
134 | 6 | XmlWriterUtil.writeLineBreak( writer ); |
135 | 6 | } |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | |
public static void writeAntVersionHeader( XMLWriter writer ) |
143 | |
{ |
144 | 6 | XmlWriterUtil.writeCommentText( writer, "Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above.", 0 ); |
145 | 6 | } |
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
public static void writeAntTask( XMLWriter writer, MavenProject project, String moduleSubPath, String tasks ) |
156 | |
{ |
157 | 0 | writer.startElement( "ant" ); |
158 | 0 | writer.addAttribute( "antfile", "build.xml" ); |
159 | 0 | writer.addAttribute( "dir", toRelative( project.getBasedir(), moduleSubPath ) ); |
160 | 0 | writer.addAttribute( "target", tasks ); |
161 | 0 | writer.endElement(); |
162 | 0 | } |
163 | |
|
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | |
public static void writeJavadocTask( XMLWriter writer, MavenProject project, ArtifactResolverWrapper wrapper ) |
173 | |
throws IOException |
174 | |
{ |
175 | 6 | List sources = new ArrayList(); |
176 | 6 | for ( Iterator it = project.getCompileSourceRoots().iterator(); it.hasNext(); ) |
177 | |
{ |
178 | 6 | String source = (String) it.next(); |
179 | |
|
180 | 6 | if ( new File( source ).exists() ) |
181 | |
{ |
182 | 0 | sources.add( source ); |
183 | |
} |
184 | |
} |
185 | |
|
186 | |
|
187 | 6 | if ( sources.size() == 0 ) |
188 | |
{ |
189 | 6 | return; |
190 | |
} |
191 | |
|
192 | 0 | writer.startElement( "javadoc" ); |
193 | 0 | String sourcepath = getMavenJavadocPluginBasicOption( project, "sourcepath", null ); |
194 | 0 | if ( sourcepath == null ) |
195 | |
{ |
196 | 0 | StringBuffer sb = new StringBuffer(); |
197 | 0 | String[] compileSourceRoots = (String[]) sources.toArray( new String[0] ); |
198 | 0 | for ( int i = 0; i < compileSourceRoots.length; i++ ) |
199 | |
{ |
200 | 0 | sb.append( "${maven.build.srcDir." ).append( i ).append( "}" ); |
201 | |
|
202 | 0 | if ( i < ( compileSourceRoots.length - 1 ) ) |
203 | |
{ |
204 | 0 | sb.append( File.pathSeparatorChar ); |
205 | |
} |
206 | |
} |
207 | 0 | writer.addAttribute( "sourcepath", sb.toString() ); |
208 | 0 | addWrapAttribute( writer, "javadoc", "packagenames", "*", 3 ); |
209 | |
} |
210 | |
else |
211 | |
{ |
212 | 0 | writer.addAttribute( "sourcepath", sourcepath ); |
213 | |
} |
214 | 0 | addWrapAttribute( writer, "javadoc", "destdir", |
215 | |
getMavenJavadocPluginBasicOption( project, "destdir", |
216 | |
"${maven.reporting.outputDirectory}/apidocs" ), 3 ); |
217 | 0 | addWrapAttribute( writer, "javadoc", "extdirs", getMavenJavadocPluginBasicOption( project, "extdirs", null ), 3 ); |
218 | |
|
219 | 0 | addWrapAttribute( writer, "javadoc", "overview", getMavenJavadocPluginBasicOption( project, "overview", null ), |
220 | |
3 ); |
221 | 0 | addWrapAttribute( writer, "javadoc", "access", |
222 | |
getMavenJavadocPluginBasicOption( project, "show", "protected" ), 3 ); |
223 | 0 | addWrapAttribute( writer, "javadoc", "old", getMavenJavadocPluginBasicOption( project, "old", "false" ), 3 ); |
224 | 0 | addWrapAttribute( writer, "javadoc", "verbose", |
225 | |
getMavenJavadocPluginBasicOption( project, "verbose", "false" ), 3 ); |
226 | 0 | addWrapAttribute( writer, "javadoc", "locale", getMavenJavadocPluginBasicOption( project, "locale", null ), 3 ); |
227 | 0 | addWrapAttribute( writer, "javadoc", "encoding", getMavenJavadocPluginBasicOption( project, "encoding", null ), |
228 | |
3 ); |
229 | 0 | addWrapAttribute( writer, "javadoc", "version", getMavenJavadocPluginBasicOption( project, "version", "true" ), |
230 | |
3 ); |
231 | 0 | addWrapAttribute( writer, "javadoc", "use", getMavenJavadocPluginBasicOption( project, "use", "true" ), 3 ); |
232 | 0 | addWrapAttribute( writer, "javadoc", "author", getMavenJavadocPluginBasicOption( project, "author", "true" ), 3 ); |
233 | 0 | addWrapAttribute( writer, "javadoc", "splitindex", getMavenJavadocPluginBasicOption( project, "splitindex", |
234 | |
"false" ), 3 ); |
235 | 0 | addWrapAttribute( writer, "javadoc", "windowtitle", getMavenJavadocPluginBasicOption( project, "windowtitle", |
236 | |
null ), 3 ); |
237 | 0 | addWrapAttribute( writer, "javadoc", "nodeprecated", getMavenJavadocPluginBasicOption( project, "nodeprecated", |
238 | |
"false" ), 3 ); |
239 | 0 | addWrapAttribute( writer, "javadoc", "nodeprecatedlist", getMavenJavadocPluginBasicOption( project, |
240 | |
"nodeprecatedlist", |
241 | |
"false" ), 3 ); |
242 | 0 | addWrapAttribute( writer, "javadoc", "notree", getMavenJavadocPluginBasicOption( project, "notree", "false" ), |
243 | |
3 ); |
244 | 0 | addWrapAttribute( writer, "javadoc", "noindex", |
245 | |
getMavenJavadocPluginBasicOption( project, "noindex", "false" ), 3 ); |
246 | 0 | addWrapAttribute( writer, "javadoc", "nohelp", getMavenJavadocPluginBasicOption( project, "nohelp", "false" ), |
247 | |
3 ); |
248 | 0 | addWrapAttribute( writer, "javadoc", "nonavbar", |
249 | |
getMavenJavadocPluginBasicOption( project, "nonavbar", "false" ), 3 ); |
250 | 0 | addWrapAttribute( writer, "javadoc", "serialwarn", getMavenJavadocPluginBasicOption( project, "serialwarn", |
251 | |
"false" ), 3 ); |
252 | 0 | addWrapAttribute( writer, "javadoc", "helpfile", getMavenJavadocPluginBasicOption( project, "helpfile", null ), |
253 | |
3 ); |
254 | 0 | addWrapAttribute( writer, "javadoc", "stylesheetfile", |
255 | |
getMavenJavadocPluginBasicOption( project, "stylesheetfile", null ), 3 ); |
256 | 0 | addWrapAttribute( writer, "javadoc", "charset", getMavenJavadocPluginBasicOption( project, "charset", |
257 | |
"ISO-8859-1" ), 3 ); |
258 | 0 | addWrapAttribute( writer, "javadoc", "docencoding", getMavenJavadocPluginBasicOption( project, "docencoding", |
259 | |
null ), 3 ); |
260 | 0 | addWrapAttribute( writer, "javadoc", "excludepackagenames", |
261 | |
getMavenJavadocPluginBasicOption( project, "excludepackagenames", null ), 3 ); |
262 | 0 | addWrapAttribute( writer, "javadoc", "source", getMavenJavadocPluginBasicOption( project, "source", null ), 3 ); |
263 | 0 | addWrapAttribute( writer, "javadoc", "linksource", getMavenJavadocPluginBasicOption( project, "linksource", |
264 | |
"false" ), 3 ); |
265 | 0 | addWrapAttribute( writer, "javadoc", "breakiterator", getMavenJavadocPluginBasicOption( project, |
266 | |
"breakiterator", |
267 | |
"false" ), 3 ); |
268 | 0 | addWrapAttribute( writer, "javadoc", "noqualifier", getMavenJavadocPluginBasicOption( project, "noqualifier", |
269 | |
null ), 3 ); |
270 | |
|
271 | 0 | addWrapAttribute( writer, "javadoc", "maxmemory", |
272 | |
getMavenJavadocPluginBasicOption( project, "maxmemory", null ), 3 ); |
273 | 0 | addWrapAttribute( writer, "javadoc", "additionalparam", getMavenJavadocPluginBasicOption( project, |
274 | |
"additionalparam", |
275 | |
null ), 3 ); |
276 | |
|
277 | |
|
278 | 0 | String doctitle = getMavenJavadocPluginBasicOption( project, "doctitle", null ); |
279 | 0 | if ( doctitle != null ) |
280 | |
{ |
281 | 0 | writer.startElement( "doctitle" ); |
282 | 0 | writer.writeText( "<![CDATA[" + doctitle + "]]>" ); |
283 | 0 | writer.endElement(); |
284 | |
} |
285 | 0 | String header = getMavenJavadocPluginBasicOption( project, "header", null ); |
286 | 0 | if ( header != null ) |
287 | |
{ |
288 | 0 | writer.startElement( "header" ); |
289 | 0 | writer.writeText( "<![CDATA[" + header + "]]>" ); |
290 | 0 | writer.endElement(); |
291 | |
} |
292 | 0 | String footer = getMavenJavadocPluginBasicOption( project, "footer", null ); |
293 | 0 | if ( footer != null ) |
294 | |
{ |
295 | 0 | writer.startElement( "footer" ); |
296 | 0 | writer.writeText( "<![CDATA[" + footer + "]]>" ); |
297 | 0 | writer.endElement(); |
298 | |
} |
299 | 0 | String bottom = getMavenJavadocPluginBasicOption( project, "bottom", null ); |
300 | 0 | if ( bottom != null ) |
301 | |
{ |
302 | 0 | writer.startElement( "bottom" ); |
303 | 0 | writer.writeText( "<![CDATA[" + bottom + "]]>" ); |
304 | 0 | writer.endElement(); |
305 | |
} |
306 | |
|
307 | 0 | Map[] links = getMavenJavadocPluginOptions( project, "links", null ); |
308 | 0 | if ( links != null ) |
309 | |
{ |
310 | 0 | for ( int i = 0; i < links.length; i++ ) |
311 | |
{ |
312 | 0 | writer.startElement( "link" ); |
313 | 0 | writer.addAttribute( "href", (String) links[i].get( "link" ) ); |
314 | 0 | writer.endElement(); |
315 | |
} |
316 | |
} |
317 | |
|
318 | 0 | Map[] offlineLinks = getMavenJavadocPluginOptions( project, "offlineLinks", null ); |
319 | 0 | if ( offlineLinks != null ) |
320 | |
{ |
321 | 0 | for ( int i = 0; i < offlineLinks.length; i++ ) |
322 | |
{ |
323 | 0 | writer.startElement( "link" ); |
324 | 0 | writer.addAttribute( "href", (String) offlineLinks[i].get( "url" ) ); |
325 | 0 | addWrapAttribute( writer, "javadoc", "offline", "true", 4 ); |
326 | 0 | writer.endElement(); |
327 | |
} |
328 | |
} |
329 | |
|
330 | 0 | Map[] groups = getMavenJavadocPluginOptions( project, "groups", null ); |
331 | 0 | if ( groups != null ) |
332 | |
{ |
333 | 0 | for ( int i = 0; i < groups.length; i++ ) |
334 | |
{ |
335 | 0 | Map group = (Map) groups[i].get( "group" ); |
336 | 0 | writer.startElement( "group" ); |
337 | 0 | writer.addAttribute( "title", (String) group.get( "title" ) ); |
338 | 0 | addWrapAttribute( writer, "javadoc", "package", (String) group.get( "package" ), 4 ); |
339 | 0 | writer.endElement(); |
340 | |
} |
341 | |
} |
342 | |
|
343 | |
|
344 | 0 | String doclet = getMavenJavadocPluginBasicOption( project, "doclet", null ); |
345 | 0 | if ( doclet != null ) |
346 | |
{ |
347 | 0 | String docletpath = getMavenJavadocPluginBasicOption( project, "docletpath", null ); |
348 | 0 | if ( StringUtils.isNotEmpty( docletpath ) ) |
349 | |
{ |
350 | 0 | writer.startElement( "doclet" ); |
351 | 0 | writer.addAttribute( "name", doclet ); |
352 | 0 | addWrapAttribute( writer, "javadoc", "path", docletpath, 4 ); |
353 | 0 | writer.endElement(); |
354 | |
} |
355 | |
else |
356 | |
{ |
357 | 0 | Map docletArtifact = getMavenJavadocPluginOption( project, "docletArtifact", null ); |
358 | 0 | String path = wrapper.getArtifactAbsolutePath( (String) docletArtifact.get( "groupId" ), |
359 | |
(String) docletArtifact.get( "artifactId" ), |
360 | |
(String) docletArtifact.get( "version" ) ); |
361 | 0 | path = StringUtils.replace( path, wrapper.getLocalRepository().getBasedir(), "${maven.repo.local}" ); |
362 | |
|
363 | 0 | writer.startElement( "doclet" ); |
364 | 0 | writer.addAttribute( "name", doclet ); |
365 | 0 | addWrapAttribute( writer, "javadoc", "path", path, 4 ); |
366 | 0 | writer.endElement(); |
367 | |
} |
368 | |
} |
369 | |
|
370 | |
|
371 | 0 | String taglet = getMavenJavadocPluginBasicOption( project, "taglet", null ); |
372 | 0 | if ( taglet != null ) |
373 | |
{ |
374 | 0 | String tagletpath = getMavenJavadocPluginBasicOption( project, "tagletpath", null ); |
375 | 0 | if ( StringUtils.isNotEmpty( tagletpath ) ) |
376 | |
{ |
377 | 0 | writer.startElement( "taglet" ); |
378 | 0 | writer.addAttribute( "name", taglet ); |
379 | 0 | addWrapAttribute( writer, "javadoc", "path", tagletpath, 4 ); |
380 | 0 | writer.endElement(); |
381 | |
} |
382 | |
else |
383 | |
{ |
384 | 0 | Map tagletArtifact = getMavenJavadocPluginOption( project, "tagletArtifact", null ); |
385 | 0 | String path = wrapper.getArtifactAbsolutePath( (String) tagletArtifact.get( "groupId" ), |
386 | |
(String) tagletArtifact.get( "artifactId" ), |
387 | |
(String) tagletArtifact.get( "version" ) ); |
388 | 0 | path = StringUtils.replace( path, wrapper.getLocalRepository().getBasedir(), "${maven.repo.local}" ); |
389 | |
|
390 | 0 | writer.startElement( "taglet" ); |
391 | 0 | writer.addAttribute( "name", taglet ); |
392 | 0 | addWrapAttribute( writer, "javadoc", "path", path, 4 ); |
393 | 0 | writer.endElement(); |
394 | |
} |
395 | |
} |
396 | |
|
397 | 0 | Map[] tags = getMavenJavadocPluginOptions( project, "tags", null ); |
398 | 0 | if ( tags != null ) |
399 | |
{ |
400 | 0 | for ( int i = 0; i < tags.length; i++ ) |
401 | |
{ |
402 | 0 | Map props = (Map) tags[i].get( "tag" ); |
403 | 0 | writer.startElement( "tag" ); |
404 | 0 | writer.addAttribute( "name", (String) props.get( "name" ) ); |
405 | 0 | addWrapAttribute( writer, "javadoc", "scope", (String) props.get( "placement" ), 4 ); |
406 | 0 | addWrapAttribute( writer, "javadoc", "description", (String) props.get( "head" ), 4 ); |
407 | 0 | writer.endElement(); |
408 | |
} |
409 | |
} |
410 | |
|
411 | 0 | writer.endElement(); |
412 | 0 | } |
413 | |
|
414 | |
|
415 | |
|
416 | |
|
417 | |
|
418 | |
|
419 | |
|
420 | |
|
421 | |
public static void writeJarTask( XMLWriter writer, MavenProject project ) |
422 | |
throws IOException |
423 | |
{ |
424 | 6 | writer.startElement( "jar" ); |
425 | 6 | writer.addAttribute( "jarfile", "${maven.build.dir}/${maven.build.finalName}.jar" ); |
426 | 6 | addWrapAttribute( writer, "jar", "compress", |
427 | |
getMavenJarPluginBasicOption( project, "archive//compress", "true" ), 3 ); |
428 | 6 | addWrapAttribute( writer, "jar", "index", getMavenJarPluginBasicOption( project, "archive//index", "false" ), 3 ); |
429 | 6 | if ( getMavenJarPluginBasicOption( project, "archive//manifestFile", null ) != null ) |
430 | |
{ |
431 | 0 | addWrapAttribute( writer, "jar", "manifest", getMavenJarPluginBasicOption( project, |
432 | |
"archive//manifestFile", null ), |
433 | |
3 ); |
434 | |
} |
435 | 6 | addWrapAttribute( writer, "jar", "basedir", "${maven.build.outputDir}", 3 ); |
436 | 6 | addWrapAttribute( writer, "jar", "excludes", "**/package.html", 3 ); |
437 | 6 | if ( getMavenPluginOption( project, "maven-jar-plugin", "archive//manifest", null ) != null ) |
438 | |
{ |
439 | 0 | writer.startElement( "manifest" ); |
440 | 0 | writer.startElement( "attribute" ); |
441 | 0 | writer.addAttribute( "name", "Main-Class" ); |
442 | 0 | addWrapAttribute( writer, "attribute", "value", |
443 | |
getMavenJarPluginBasicOption( project, "archive//manifest//mainClass", null ), 5 ); |
444 | 0 | writer.endElement(); |
445 | 0 | writer.endElement(); |
446 | |
} |
447 | 6 | writer.endElement(); |
448 | 6 | } |
449 | |
|
450 | |
|
451 | |
|
452 | |
|
453 | |
|
454 | |
|
455 | |
|
456 | |
|
457 | |
|
458 | |
public static void writeEarTask( XMLWriter writer, MavenProject project, |
459 | |
ArtifactResolverWrapper artifactResolverWrapper ) |
460 | |
throws IOException |
461 | |
{ |
462 | 0 | writeCopyLib( writer, project, artifactResolverWrapper, "${maven.build.dir}/${maven.build.finalName}" ); |
463 | |
|
464 | 0 | writer.startElement( "ear" ); |
465 | 0 | writer.addAttribute( "destfile", "${maven.build.dir}/${maven.build.finalName}.ear" ); |
466 | 0 | addWrapAttribute( writer, "ear", "basedir", "${maven.build.dir}/${maven.build.finalName}", 3 ); |
467 | 0 | addWrapAttribute( writer, "ear", "compress", |
468 | |
getMavenEarPluginBasicOption( project, "archive//compress", "true" ), 3 ); |
469 | 0 | addWrapAttribute( writer, "ear", "includes ", getMavenEarPluginBasicOption( project, "includes", null ), 3 ); |
470 | 0 | addWrapAttribute( writer, "ear", "excludes", getMavenEarPluginBasicOption( project, "excludes", null ), 3 ); |
471 | 0 | if ( getMavenEarPluginBasicOption( project, "applicationXml", null ) != null ) |
472 | |
{ |
473 | 0 | addWrapAttribute( writer, "ear", "appxml", getMavenEarPluginBasicOption( project, "applicationXml", null ), |
474 | |
3 ); |
475 | |
} |
476 | |
else |
477 | |
{ |
478 | |
|
479 | 0 | addWrapAttribute( writer, "ear", "appxml", "${maven.build.dir}/application.xml", 3 ); |
480 | |
} |
481 | 0 | if ( getMavenEarPluginBasicOption( project, "manifestFile", null ) != null ) |
482 | |
{ |
483 | 0 | addWrapAttribute( writer, "ear", "manifest", getMavenEarPluginBasicOption( project, "manifestFile", null ), |
484 | |
3 ); |
485 | |
} |
486 | 0 | writer.endElement(); |
487 | 0 | } |
488 | |
|
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
|
497 | |
public static void writeWarTask( XMLWriter writer, MavenProject project, |
498 | |
ArtifactResolverWrapper artifactResolverWrapper ) |
499 | |
throws IOException |
500 | |
{ |
501 | 0 | String webXml = |
502 | |
getMavenWarPluginBasicOption( project, "webXml", "${basedir}/src/main/webapp/WEB-INF/web.xml" ); |
503 | 0 | if ( webXml.startsWith( "${basedir}/" ) ) |
504 | |
{ |
505 | 0 | webXml = webXml.substring( "${basedir}/".length() ); |
506 | |
} |
507 | |
|
508 | 0 | writeCopyLib( writer, project, artifactResolverWrapper, "${maven.build.dir}/${maven.build.finalName}/WEB-INF/lib" ); |
509 | |
|
510 | 0 | writer.startElement( "war" ); |
511 | 0 | writer.addAttribute( "destfile", "${maven.build.dir}/${maven.build.finalName}.war" ); |
512 | 0 | addWrapAttribute( writer, "war", "compress", |
513 | |
getMavenWarPluginBasicOption( project, "archive//compress", "true" ), 3 ); |
514 | 0 | addWrapAttribute( writer, "war", "webxml", webXml, 3 ); |
515 | 0 | if ( getMavenWarPluginBasicOption( project, "manifestFile", null ) != null ) |
516 | |
{ |
517 | 0 | addWrapAttribute( writer, "war", "manifest", getMavenWarPluginBasicOption( project, "manifestFile", null ), |
518 | |
3 ); |
519 | |
} |
520 | 0 | writer.startElement( "lib" ); |
521 | 0 | writer.addAttribute( "dir", "${maven.build.dir}/${maven.build.finalName}/WEB-INF/lib" ); |
522 | 0 | writer.endElement(); |
523 | 0 | writer.startElement( "classes" ); |
524 | 0 | writer.addAttribute( "dir", "${maven.build.outputDir}" ); |
525 | 0 | writer.endElement(); |
526 | 0 | writer.startElement( "fileset" ); |
527 | 0 | writer.addAttribute( "dir", "src/main/webapp" ); |
528 | 0 | addWrapAttribute( writer, "fileset", "excludes", "WEB-INF/web.xml", 4 ); |
529 | 0 | writer.endElement(); |
530 | 0 | writer.endElement(); |
531 | 0 | } |
532 | |
|
533 | |
|
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
public static void addWrapAttribute( XMLWriter writer, String tag, String name, String value, int indent ) |
543 | |
{ |
544 | 114 | if ( StringUtils.isEmpty( value ) ) |
545 | |
{ |
546 | 0 | return; |
547 | |
} |
548 | |
|
549 | 114 | if ( indent < 0 ) |
550 | |
{ |
551 | 0 | writer.addAttribute( name, value ); |
552 | |
} |
553 | |
else |
554 | |
{ |
555 | 114 | writer.addAttribute( "\n" |
556 | |
+ StringUtils.repeat( " ", ( StringUtils.isEmpty( tag ) ? 0 : tag.length() ) + indent |
557 | |
* XmlWriterUtil.DEFAULT_INDENTATION_SIZE ) + name, value ); |
558 | |
} |
559 | 114 | } |
560 | |
|
561 | |
|
562 | |
|
563 | |
|
564 | |
|
565 | |
public static boolean isPomPackaging( MavenProject mavenProject ) |
566 | |
{ |
567 | 66 | return "pom".equals( mavenProject.getPackaging() ); |
568 | |
} |
569 | |
|
570 | |
|
571 | |
|
572 | |
|
573 | |
|
574 | |
|
575 | |
|
576 | |
public static boolean isJarPackaging( MavenProject mavenProject ) |
577 | |
{ |
578 | 6 | return "jar".equals( mavenProject.getPackaging() ) |
579 | |
|| isEjbPackaging( mavenProject ) |
580 | |
|| isMavenPluginPackaging( mavenProject ) |
581 | |
|| isBundlePackaging( mavenProject ) |
582 | |
; |
583 | |
} |
584 | |
|
585 | |
|
586 | |
|
587 | |
|
588 | |
|
589 | |
public static boolean isBundlePackaging( MavenProject mavenProject ) |
590 | |
{ |
591 | 0 | return "bundle".equals( mavenProject.getPackaging() ); |
592 | |
} |
593 | |
|
594 | |
|
595 | |
|
596 | |
|
597 | |
|
598 | |
public static boolean isEjbPackaging( MavenProject mavenProject ) |
599 | |
{ |
600 | 0 | return "ejb".equals( mavenProject.getPackaging() ); |
601 | |
} |
602 | |
|
603 | |
|
604 | |
|
605 | |
|
606 | |
|
607 | |
public static boolean isMavenPluginPackaging( MavenProject mavenProject ) |
608 | |
{ |
609 | 0 | return "maven-plugin".equals( mavenProject.getPackaging() ); |
610 | |
} |
611 | |
|
612 | |
|
613 | |
|
614 | |
|
615 | |
|
616 | |
public static boolean isEarPackaging( MavenProject mavenProject ) |
617 | |
{ |
618 | 0 | return "ear".equals( mavenProject.getPackaging() ); |
619 | |
} |
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
public static boolean isWarPackaging( MavenProject mavenProject ) |
626 | |
{ |
627 | 0 | return "war".equals( mavenProject.getPackaging() ); |
628 | |
} |
629 | |
|
630 | |
|
631 | |
|
632 | |
|
633 | |
|
634 | |
|
635 | |
|
636 | |
|
637 | |
|
638 | |
|
639 | |
public static String getMavenCompilerPluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
640 | |
throws IOException |
641 | |
{ |
642 | 2 | return getMavenPluginBasicOption( project, "maven-compiler-plugin", optionName, defaultValue ); |
643 | |
} |
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
|
650 | |
|
651 | |
|
652 | |
|
653 | |
|
654 | |
public static Map getMavenCompilerPluginOption( MavenProject project, String optionName, String defaultValue ) |
655 | |
throws IOException |
656 | |
{ |
657 | 0 | return getMavenPluginOption( project, "maven-compiler-plugin", optionName, defaultValue ); |
658 | |
} |
659 | |
|
660 | |
|
661 | |
|
662 | |
|
663 | |
|
664 | |
|
665 | |
|
666 | |
|
667 | |
|
668 | |
|
669 | |
public static Map[] getMavenCompilerPluginOptions( MavenProject project, String optionName, String defaultValue ) |
670 | |
throws IOException |
671 | |
{ |
672 | 8 | return getMavenPluginOptions( project, "maven-compiler-plugin", optionName, defaultValue ); |
673 | |
} |
674 | |
|
675 | |
|
676 | |
|
677 | |
|
678 | |
|
679 | |
|
680 | |
|
681 | |
|
682 | |
|
683 | |
|
684 | |
public static String getMavenSurefirePluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
685 | |
throws IOException |
686 | |
{ |
687 | 0 | return getMavenPluginBasicOption( project, "maven-surefire-plugin", optionName, defaultValue ); |
688 | |
} |
689 | |
|
690 | |
|
691 | |
|
692 | |
|
693 | |
|
694 | |
|
695 | |
|
696 | |
|
697 | |
|
698 | |
|
699 | |
public static Map getMavenSurefirePluginOption( MavenProject project, String optionName, String defaultValue ) |
700 | |
throws IOException |
701 | |
{ |
702 | 0 | return getMavenPluginOption( project, "maven-surefire-plugin", optionName, defaultValue ); |
703 | |
} |
704 | |
|
705 | |
|
706 | |
|
707 | |
|
708 | |
|
709 | |
|
710 | |
|
711 | |
|
712 | |
|
713 | |
|
714 | |
public static Map[] getMavenSurefirePluginOptions( MavenProject project, String optionName, String defaultValue ) |
715 | |
throws IOException |
716 | |
{ |
717 | 0 | return getMavenPluginOptions( project, "maven-surefire-plugin", optionName, defaultValue ); |
718 | |
} |
719 | |
|
720 | |
|
721 | |
|
722 | |
|
723 | |
|
724 | |
|
725 | |
|
726 | |
|
727 | |
|
728 | |
|
729 | |
public static String getMavenJavadocPluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
730 | |
throws IOException |
731 | |
{ |
732 | 2 | return getMavenPluginBasicOption( project, "maven-javadoc-plugin", optionName, defaultValue ); |
733 | |
} |
734 | |
|
735 | |
|
736 | |
|
737 | |
|
738 | |
|
739 | |
|
740 | |
|
741 | |
|
742 | |
|
743 | |
|
744 | |
public static Map getMavenJavadocPluginOption( MavenProject project, String optionName, String defaultValue ) |
745 | |
throws IOException |
746 | |
{ |
747 | 0 | return getMavenPluginOption( project, "maven-javadoc-plugin", optionName, defaultValue ); |
748 | |
} |
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
|
754 | |
|
755 | |
|
756 | |
|
757 | |
|
758 | |
|
759 | |
public static Map[] getMavenJavadocPluginOptions( MavenProject project, String optionName, String defaultValue ) |
760 | |
throws IOException |
761 | |
{ |
762 | 10 | return getMavenPluginOptions( project, "maven-javadoc-plugin", optionName, defaultValue ); |
763 | |
} |
764 | |
|
765 | |
|
766 | |
|
767 | |
|
768 | |
|
769 | |
|
770 | |
|
771 | |
|
772 | |
|
773 | |
|
774 | |
public static String getMavenJarPluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
775 | |
throws IOException |
776 | |
{ |
777 | 18 | return getMavenPluginBasicOption( project, "maven-jar-plugin", optionName, defaultValue ); |
778 | |
} |
779 | |
|
780 | |
|
781 | |
|
782 | |
|
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | |
public static String getMavenEarPluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
790 | |
throws IOException |
791 | |
{ |
792 | 0 | return getMavenPluginBasicOption( project, "maven-ear-plugin", optionName, defaultValue ); |
793 | |
} |
794 | |
|
795 | |
|
796 | |
|
797 | |
|
798 | |
|
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
|
804 | |
public static String getMavenWarPluginBasicOption( MavenProject project, String optionName, String defaultValue ) |
805 | |
throws IOException |
806 | |
{ |
807 | 4 | return getMavenPluginBasicOption( project, "maven-war-plugin", optionName, defaultValue ); |
808 | |
} |
809 | |
|
810 | |
|
811 | |
|
812 | |
|
813 | |
|
814 | |
|
815 | |
|
816 | |
|
817 | |
|
818 | |
|
819 | |
|
820 | |
|
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | |
|
830 | |
|
831 | |
|
832 | |
|
833 | |
|
834 | |
|
835 | |
|
836 | |
|
837 | |
private static String getMavenPluginBasicOption( MavenProject project, String pluginArtifactId, String optionName, |
838 | |
String defaultValue ) |
839 | |
throws IOException |
840 | |
{ |
841 | 26 | return (String) getMavenPluginConfigurationsImpl( project, pluginArtifactId, optionName, defaultValue ) |
842 | |
.get( optionName ); |
843 | |
} |
844 | |
|
845 | |
|
846 | |
|
847 | |
|
848 | |
|
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
|
855 | |
|
856 | |
|
857 | |
|
858 | |
|
859 | |
|
860 | |
|
861 | |
|
862 | |
|
863 | |
|
864 | |
|
865 | |
|
866 | |
|
867 | |
|
868 | |
|
869 | |
|
870 | |
|
871 | |
|
872 | |
|
873 | |
private static Map getMavenPluginOption( MavenProject project, String pluginArtifactId, String optionName, |
874 | |
String defaultValue ) |
875 | |
throws IOException |
876 | |
{ |
877 | 6 | return (Map) getMavenPluginConfigurationsImpl( project, pluginArtifactId, optionName, defaultValue ) |
878 | |
.get( optionName ); |
879 | |
} |
880 | |
|
881 | |
|
882 | |
|
883 | |
|
884 | |
|
885 | |
|
886 | |
|
887 | |
|
888 | |
|
889 | |
|
890 | |
|
891 | |
|
892 | |
|
893 | |
|
894 | |
|
895 | |
|
896 | |
|
897 | |
|
898 | |
|
899 | |
|
900 | |
|
901 | |
|
902 | |
|
903 | |
|
904 | |
|
905 | |
|
906 | |
|
907 | |
|
908 | |
|
909 | |
|
910 | |
|
911 | |
|
912 | |
|
913 | |
|
914 | |
|
915 | |
private static Map[] getMavenPluginOptions( MavenProject project, String pluginArtifactId, String optionName, |
916 | |
String defaultValue ) |
917 | |
throws IOException |
918 | |
{ |
919 | 18 | return (Map[]) getMavenPluginConfigurationsImpl( project, pluginArtifactId, optionName, defaultValue ) |
920 | |
.get( optionName ); |
921 | |
} |
922 | |
|
923 | |
|
924 | |
|
925 | |
|
926 | |
|
927 | |
|
928 | |
|
929 | |
|
930 | |
|
931 | |
|
932 | |
|
933 | |
|
934 | |
|
935 | |
|
936 | |
|
937 | |
|
938 | |
|
939 | |
|
940 | |
|
941 | |
|
942 | |
|
943 | |
|
944 | |
|
945 | |
|
946 | |
|
947 | |
|
948 | |
|
949 | |
|
950 | |
|
951 | |
|
952 | |
|
953 | |
|
954 | |
|
955 | |
|
956 | |
|
957 | |
|
958 | |
|
959 | |
|
960 | |
|
961 | |
|
962 | |
|
963 | |
|
964 | |
|
965 | |
|
966 | |
|
967 | |
|
968 | |
|
969 | |
|
970 | |
private static Map getMavenPluginConfigurationsImpl( MavenProject project, String pluginArtifactId, |
971 | |
String optionName, String defaultValue ) |
972 | |
throws IOException |
973 | |
{ |
974 | 50 | List plugins = new ArrayList(); |
975 | 50 | for ( Iterator it = project.getModel().getReporting().getPlugins().iterator(); it.hasNext(); ) |
976 | |
{ |
977 | 12 | plugins.add( it.next() ); |
978 | |
} |
979 | 50 | for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); ) |
980 | |
{ |
981 | 70 | plugins.add( it.next() ); |
982 | |
} |
983 | 50 | if ( project.getBuild().getPluginManagement() != null ) |
984 | |
{ |
985 | 0 | for ( Iterator it = project.getBuild().getPluginManagement().getPlugins().iterator(); it.hasNext(); ) |
986 | |
{ |
987 | 0 | plugins.add( it.next() ); |
988 | |
} |
989 | |
} |
990 | |
|
991 | 50 | for ( Iterator it = plugins.iterator(); it.hasNext(); ) |
992 | |
{ |
993 | 58 | Object next = it.next(); |
994 | |
|
995 | 58 | Object pluginConf = null; |
996 | |
|
997 | 58 | if ( next instanceof Plugin ) |
998 | |
{ |
999 | 46 | Plugin plugin = (Plugin) next; |
1000 | |
|
1001 | |
|
1002 | 46 | if ( !( ( plugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( plugin.getArtifactId() |
1003 | |
.equals( pluginArtifactId ) ) ) ) |
1004 | |
{ |
1005 | 32 | continue; |
1006 | |
} |
1007 | |
|
1008 | 14 | pluginConf = plugin.getConfiguration(); |
1009 | |
} |
1010 | |
|
1011 | 26 | if ( next instanceof ReportPlugin ) |
1012 | |
{ |
1013 | 12 | ReportPlugin reportPlugin = (ReportPlugin) next; |
1014 | |
|
1015 | |
|
1016 | 12 | if ( !( ( reportPlugin.getGroupId().equals( "org.apache.maven.plugins" ) ) && ( reportPlugin |
1017 | |
.getArtifactId().equals( pluginArtifactId ) ) ) ) |
1018 | |
{ |
1019 | 0 | continue; |
1020 | |
} |
1021 | |
|
1022 | 12 | pluginConf = reportPlugin.getConfiguration(); |
1023 | |
} |
1024 | |
|
1025 | 26 | if ( pluginConf == null ) |
1026 | |
{ |
1027 | 0 | continue; |
1028 | |
} |
1029 | |
|
1030 | |
try |
1031 | |
{ |
1032 | 26 | Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder() |
1033 | |
.parse( new ByteArrayInputStream( pluginConf.toString().getBytes( "UTF-8" ) ) ); |
1034 | |
|
1035 | 26 | NodeList nodeList = XPathAPI.eval( doc, "//configuration/" + optionName ).nodelist(); |
1036 | 26 | if ( nodeList.getLength() > 0 ) |
1037 | |
{ |
1038 | 26 | Node optionNode = nodeList.item( 0 ); |
1039 | |
|
1040 | 26 | if ( isList( optionNode ) ) |
1041 | |
{ |
1042 | |
|
1043 | |
|
1044 | |
|
1045 | |
|
1046 | |
|
1047 | |
|
1048 | |
|
1049 | |
|
1050 | 18 | Map options = new HashMap(); |
1051 | |
|
1052 | 18 | List optionNames = new ArrayList(); |
1053 | 18 | NodeList childs = optionNode.getChildNodes(); |
1054 | 96 | for ( int i = 0; i < childs.getLength(); i++ ) |
1055 | |
{ |
1056 | 78 | Node child = childs.item( i ); |
1057 | 78 | if ( child.getNodeType() == Node.ELEMENT_NODE ) |
1058 | |
{ |
1059 | 30 | Map option = new HashMap(); |
1060 | |
|
1061 | 30 | if ( isElementContent( child ) ) |
1062 | |
{ |
1063 | 10 | Map properties = new HashMap(); |
1064 | 10 | NodeList childs2 = child.getChildNodes(); |
1065 | 10 | if ( childs2.getLength() > 0 ) |
1066 | |
{ |
1067 | 80 | for ( int j = 0; j < childs2.getLength(); j++ ) |
1068 | |
{ |
1069 | 70 | Node child2 = childs2.item( j ); |
1070 | 70 | if ( child2.getNodeType() == Node.ELEMENT_NODE ) |
1071 | |
{ |
1072 | 30 | properties.put( child2.getNodeName(), getTextContent( child2 ) ); |
1073 | |
} |
1074 | |
} |
1075 | 10 | option.put( child.getNodeName(), properties ); |
1076 | |
} |
1077 | |
} |
1078 | |
else |
1079 | |
{ |
1080 | 20 | option.put( child.getNodeName(), getTextContent( child ) ); |
1081 | |
} |
1082 | |
|
1083 | 30 | optionNames.add( option ); |
1084 | |
} |
1085 | |
} |
1086 | |
|
1087 | 18 | options.put( optionName, optionNames.toArray( new Map[0] ) ); |
1088 | |
|
1089 | 18 | return options; |
1090 | |
} |
1091 | |
|
1092 | 8 | if ( isElementContent( optionNode ) ) |
1093 | |
{ |
1094 | |
|
1095 | |
|
1096 | |
|
1097 | |
|
1098 | |
|
1099 | |
|
1100 | 0 | Map option = new HashMap(); |
1101 | |
|
1102 | 0 | NodeList childs = optionNode.getChildNodes(); |
1103 | 0 | if ( childs.getLength() > 1 ) |
1104 | |
{ |
1105 | 0 | Map parameters = new HashMap(); |
1106 | |
|
1107 | 0 | for ( int i = 0; i < childs.getLength(); i++ ) |
1108 | |
{ |
1109 | 0 | Node child = childs.item( i ); |
1110 | 0 | if ( child.getNodeType() == Node.ELEMENT_NODE ) |
1111 | |
{ |
1112 | 0 | parameters.put( child.getNodeName(), getTextContent( child ) ); |
1113 | |
} |
1114 | |
} |
1115 | |
|
1116 | 0 | option.put( optionName, parameters ); |
1117 | |
} |
1118 | |
|
1119 | 0 | return option; |
1120 | |
} |
1121 | |
else |
1122 | |
{ |
1123 | |
|
1124 | |
|
1125 | |
|
1126 | 8 | Map option = new HashMap(); |
1127 | |
|
1128 | 8 | option.put( optionName, getTextContent( optionNode ) ); |
1129 | |
|
1130 | 8 | return option; |
1131 | |
} |
1132 | |
} |
1133 | |
} |
1134 | 0 | catch ( Exception e ) |
1135 | |
{ |
1136 | 0 | throw new IOException( "Exception occured: " + e.getMessage() ); |
1137 | 0 | } |
1138 | |
} |
1139 | |
|
1140 | 24 | Map properties = new HashMap(); |
1141 | 24 | properties.put( optionName, defaultValue ); |
1142 | |
|
1143 | 24 | return properties; |
1144 | |
} |
1145 | |
|
1146 | |
|
1147 | |
|
1148 | |
|
1149 | |
|
1150 | |
|
1151 | |
|
1152 | |
|
1153 | |
|
1154 | |
|
1155 | |
private static void writeCopyLib( XMLWriter writer, MavenProject project, |
1156 | |
ArtifactResolverWrapper artifactResolverWrapper, String outputDir ) |
1157 | |
{ |
1158 | 0 | writer.startElement( "mkdir" ); |
1159 | 0 | writer.addAttribute( "dir", outputDir ); |
1160 | 0 | writer.endElement(); |
1161 | |
|
1162 | 0 | if ( project.getArtifacts() != null ) |
1163 | |
{ |
1164 | 0 | for ( Iterator i = project.getArtifacts().iterator(); i.hasNext(); ) |
1165 | |
{ |
1166 | 0 | Artifact artifact = (Artifact) i.next(); |
1167 | |
|
1168 | 0 | if ( Artifact.SCOPE_COMPILE.equals( artifact.getScope() ) |
1169 | |
|| Artifact.SCOPE_RUNTIME.equals( artifact.getScope() ) ) |
1170 | |
{ |
1171 | 0 | String path = artifactResolverWrapper.getLocalArtifactPath( artifact ); |
1172 | 0 | if ( !new File( path ).isAbsolute() ) |
1173 | |
{ |
1174 | 0 | path = "${maven.repo.local}/" + path; |
1175 | |
} |
1176 | |
|
1177 | 0 | writer.startElement( "copy" ); |
1178 | 0 | writer.addAttribute( "file", path ); |
1179 | 0 | addWrapAttribute( writer, "copy", "todir", outputDir, 3 ); |
1180 | 0 | writer.endElement(); |
1181 | |
} |
1182 | |
} |
1183 | |
} |
1184 | 0 | } |
1185 | |
|
1186 | |
|
1187 | |
|
1188 | |
|
1189 | |
|
1190 | |
|
1191 | |
|
1192 | |
|
1193 | |
|
1194 | |
|
1195 | |
|
1196 | |
|
1197 | |
|
1198 | |
|
1199 | |
|
1200 | |
|
1201 | |
|
1202 | |
|
1203 | |
|
1204 | |
|
1205 | |
|
1206 | |
private static boolean isList( Node node ) |
1207 | |
{ |
1208 | 26 | if ( node == null ) |
1209 | |
{ |
1210 | 0 | return false; |
1211 | |
} |
1212 | |
|
1213 | 26 | NodeList children = node.getChildNodes(); |
1214 | |
|
1215 | 26 | boolean isList = false; |
1216 | 26 | String lastNodeName = null; |
1217 | 112 | for ( int i = 0; i < children.getLength(); i++ ) |
1218 | |
{ |
1219 | 86 | Node child = children.item( i ); |
1220 | 86 | if ( child.getNodeType() == Node.ELEMENT_NODE ) |
1221 | |
{ |
1222 | 30 | isList = isList || ( child.getNodeName().equals( lastNodeName ) ); |
1223 | 30 | lastNodeName = child.getNodeName(); |
1224 | |
} |
1225 | |
} |
1226 | 26 | if ( StringUtils.isNotEmpty( lastNodeName ) ) |
1227 | |
{ |
1228 | 18 | isList = isList || lastNodeName.equals( getSingularForm( node.getNodeName() ) ); |
1229 | |
} |
1230 | |
|
1231 | 26 | return isList; |
1232 | |
} |
1233 | |
|
1234 | |
|
1235 | |
|
1236 | |
|
1237 | |
|
1238 | |
|
1239 | |
|
1240 | |
private static boolean isElementContent( Node node ) |
1241 | |
{ |
1242 | 38 | if ( node == null ) |
1243 | |
{ |
1244 | 0 | return false; |
1245 | |
} |
1246 | 38 | NodeList children = node.getChildNodes(); |
1247 | 76 | for ( int i = 0; i < children.getLength(); i++ ) |
1248 | |
{ |
1249 | 48 | Node child = children.item( i ); |
1250 | 48 | if ( child.getNodeType() == Node.ELEMENT_NODE ) |
1251 | |
{ |
1252 | 10 | return true; |
1253 | |
} |
1254 | |
} |
1255 | 28 | return false; |
1256 | |
} |
1257 | |
|
1258 | |
|
1259 | |
|
1260 | |
|
1261 | |
|
1262 | |
|
1263 | |
|
1264 | |
private static String getTextContent( Node node ) |
1265 | |
{ |
1266 | 58 | StringBuffer buffer = new StringBuffer(); |
1267 | 58 | if ( node != null ) |
1268 | |
{ |
1269 | 58 | NodeList children = node.getChildNodes(); |
1270 | 116 | for ( int i = 0; i < children.getLength(); i++ ) |
1271 | |
{ |
1272 | 58 | Node child = children.item( i ); |
1273 | 58 | if ( child.getNodeType() == Node.TEXT_NODE || child.getNodeType() == Node.CDATA_SECTION_NODE ) |
1274 | |
{ |
1275 | 58 | buffer.append( child.getNodeValue() ); |
1276 | |
} |
1277 | |
} |
1278 | |
} |
1279 | 58 | return buffer.toString(); |
1280 | |
} |
1281 | |
|
1282 | |
|
1283 | |
|
1284 | |
|
1285 | |
|
1286 | |
|
1287 | |
|
1288 | |
|
1289 | |
|
1290 | |
|
1291 | |
|
1292 | |
|
1293 | |
|
1294 | |
|
1295 | |
static String getSingularForm( String pluralForm ) |
1296 | |
{ |
1297 | 16 | String singularForm = ""; |
1298 | 16 | if ( StringUtils.isNotEmpty( pluralForm ) ) |
1299 | |
{ |
1300 | 14 | if ( pluralForm.endsWith( "ies" ) ) |
1301 | |
{ |
1302 | 2 | singularForm = pluralForm.substring( 0, pluralForm.length() - 3 ) + 'y'; |
1303 | |
} |
1304 | 12 | else if ( pluralForm.endsWith( "ches" ) ) |
1305 | |
{ |
1306 | 2 | singularForm = pluralForm.substring( 0, pluralForm.length() - 2 ); |
1307 | |
} |
1308 | 10 | else if ( pluralForm.endsWith( "s" ) && pluralForm.length() > 1 ) |
1309 | |
{ |
1310 | 8 | singularForm = pluralForm.substring( 0, pluralForm.length() - 1 ); |
1311 | |
} |
1312 | |
} |
1313 | 16 | return singularForm; |
1314 | |
} |
1315 | |
|
1316 | |
|
1317 | |
|
1318 | |
|
1319 | |
|
1320 | |
|
1321 | |
|
1322 | |
|
1323 | |
|
1324 | |
|
1325 | |
|
1326 | |
|
1327 | |
|
1328 | |
|
1329 | |
|
1330 | |
|
1331 | |
|
1332 | |
|
1333 | |
|
1334 | |
|
1335 | |
|
1336 | |
|
1337 | |
|
1338 | |
|
1339 | |
|
1340 | |
|
1341 | |
|
1342 | |
|
1343 | |
|
1344 | |
|
1345 | |
|
1346 | |
|
1347 | |
|
1348 | |
|
1349 | |
|
1350 | |
|
1351 | |
|
1352 | |
|
1353 | |
|
1354 | |
|
1355 | |
|
1356 | |
|
1357 | |
|
1358 | |
|
1359 | |
static String toRelative( File basedir, String path ) |
1360 | |
{ |
1361 | 110 | String result = null; |
1362 | 110 | if ( new File( path ).isAbsolute() ) |
1363 | |
{ |
1364 | 102 | String pathNormalized = path.replace( '/', File.separatorChar ).replace( '\\', File.separatorChar ); |
1365 | 102 | result = PathTool.getRelativeFilePath( basedir.getAbsolutePath(), pathNormalized ); |
1366 | |
} |
1367 | 110 | if ( result == null ) |
1368 | |
{ |
1369 | 8 | result = path; |
1370 | |
} |
1371 | 110 | result = result.replace( '\\', '/' ); |
1372 | 110 | if ( result.length() <= 0 || "/".equals( result ) ) |
1373 | |
{ |
1374 | 4 | result = '.' + result; |
1375 | |
} |
1376 | 110 | return result; |
1377 | |
} |
1378 | |
|
1379 | |
} |