1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
package org.apache.maven.plugin.eclipse.writers.rad; |
20 | |
|
21 | |
import java.io.File; |
22 | |
import java.io.FileInputStream; |
23 | |
import java.io.FileNotFoundException; |
24 | |
import java.io.FileOutputStream; |
25 | |
import java.io.IOException; |
26 | |
import java.io.InputStreamReader; |
27 | |
import java.io.OutputStreamWriter; |
28 | |
import java.io.Reader; |
29 | |
import java.io.Writer; |
30 | |
|
31 | |
import org.apache.maven.artifact.repository.ArtifactRepository; |
32 | |
import org.apache.maven.plugin.MojoExecutionException; |
33 | |
import org.apache.maven.plugin.eclipse.Constants; |
34 | |
import org.apache.maven.plugin.eclipse.EclipseSourceDir; |
35 | |
import org.apache.maven.plugin.eclipse.Messages; |
36 | |
import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter; |
37 | |
import org.apache.maven.plugin.eclipse.writers.wtp.AbstractWtpResourceWriter; |
38 | |
import org.apache.maven.plugin.ide.IdeDependency; |
39 | |
import org.apache.maven.plugin.ide.IdeUtils; |
40 | |
import org.apache.maven.plugin.ide.JeeUtils; |
41 | |
import org.codehaus.plexus.util.IOUtil; |
42 | |
import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter; |
43 | |
import org.codehaus.plexus.util.xml.XMLWriter; |
44 | |
import org.codehaus.plexus.util.xml.Xpp3Dom; |
45 | |
import org.codehaus.plexus.util.xml.Xpp3DomBuilder; |
46 | |
import org.codehaus.plexus.util.xml.Xpp3DomWriter; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | 0 | public class RadApplicationXMLWriter |
56 | |
extends AbstractEclipseWriter |
57 | |
{ |
58 | |
|
59 | |
private static final String APPLICATION_XML_APPLICATION = "application"; |
60 | |
|
61 | |
private static final String APPLICATION_XML_CONTEXT_ROOT = "context-root"; |
62 | |
|
63 | |
private static final String APPLICATION_XML_DESCRIPTION = "description"; |
64 | |
|
65 | |
private static final String APPLICATION_XML_DISPLAY_NAME = "display-name"; |
66 | |
|
67 | |
private static final String APPLICATION_XML_FILENAME = "application.xml"; |
68 | |
|
69 | |
private static final String APPLICATION_XML_MODULE = "module"; |
70 | |
|
71 | |
private static final String APPLICATION_XML_WEB = "web"; |
72 | |
|
73 | |
private static final String APPLICATION_XML_WEB_URI = "web-uri"; |
74 | |
|
75 | |
private static final String HREF = "href"; |
76 | |
|
77 | |
private static final String ID = "id"; |
78 | |
|
79 | |
private static final String MODULEMAP_EARPROJECT_MAP = "modulemap:EARProjectMap"; |
80 | |
|
81 | |
private static final String MODULEMAPS_APPLICATION_EJB_MODULE = "application:EjbModule"; |
82 | |
|
83 | |
private static final String MODULEMAPS_APPLICATION_WEB_MODULE = "application:WebModule"; |
84 | |
|
85 | |
private static final String MODULEMAPS_FILENAME = ".modulemaps"; |
86 | |
|
87 | |
private static final String MODULEMAPS_MAPPINGS = "mappings"; |
88 | |
|
89 | |
private static final String MODULEMAPS_PROJECT_NAME = "projectName"; |
90 | |
|
91 | |
private static final String MODULEMAPS_UTILITY_JARMAPPINGS = "utilityJARMappings"; |
92 | |
|
93 | |
private static final String URI = "uri"; |
94 | |
|
95 | |
private static final String VERSION = "version"; |
96 | |
|
97 | |
private static final String XMI_ID = "xmi:id"; |
98 | |
|
99 | |
private static final String XMI_TYPE = "xmi:type"; |
100 | |
|
101 | |
private static final String XMI_VERSION = "xmi:version"; |
102 | |
|
103 | |
private static final String XMLNS = "xmlns"; |
104 | |
|
105 | |
private static final String XMLNS_APPLICATION = "xmlns:application"; |
106 | |
|
107 | |
private static final String XMLNS_MODULEMAP = "xmlns:modulemap"; |
108 | |
|
109 | |
private static final String XMLNS_SCHEMA_LOCATION = "xsi:schemaLocation"; |
110 | |
|
111 | |
private static final String XMLNS_XMI = "xmlns:xmi"; |
112 | |
|
113 | |
private static final String XMLNS_XSI = "xmlns:xsi"; |
114 | |
|
115 | |
private Xpp3Dom[] applicationXmlDomChildren; |
116 | |
|
117 | 0 | private long baseId = System.currentTimeMillis(); |
118 | |
|
119 | |
private Xpp3Dom[] modulemapsXmlDomChildren; |
120 | |
|
121 | |
private Xpp3Dom[] webModulesFromPoms; |
122 | |
|
123 | |
|
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
public void write() |
133 | |
throws MojoExecutionException |
134 | |
{ |
135 | 0 | String packaging = config.getPackaging(); |
136 | 0 | if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) ) |
137 | |
{ |
138 | 0 | File applicationXmlFile = |
139 | |
new File( config.getEclipseProjectDirectory(), "META-INF" + File.separator + APPLICATION_XML_FILENAME ); |
140 | 0 | Xpp3Dom applicationXmlDom = readXMLFile( applicationXmlFile ); |
141 | 0 | if ( applicationXmlDom == null ) |
142 | |
{ |
143 | 0 | applicationXmlDom = createNewApplicationXml(); |
144 | |
} |
145 | 0 | this.applicationXmlDomChildren = applicationXmlDom.getChildren( APPLICATION_XML_MODULE ); |
146 | |
|
147 | 0 | File modulemapsXmlFile = |
148 | |
new File( config.getEclipseProjectDirectory(), "META-INF" + File.separator + MODULEMAPS_FILENAME ); |
149 | 0 | Xpp3Dom modulemapsXmlDom = readXMLFile( modulemapsXmlFile ); |
150 | 0 | if ( modulemapsXmlDom == null ) |
151 | |
{ |
152 | 0 | modulemapsXmlDom = createNewModulemaps(); |
153 | |
} |
154 | 0 | this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren(); |
155 | |
|
156 | 0 | this.webModulesFromPoms = |
157 | |
IdeUtils.getPluginConfigurationDom( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN, |
158 | |
new String[] { "modules", "webModule" } ); |
159 | |
|
160 | 0 | IdeDependency[] deps = config.getDepsOrdered(); |
161 | 0 | for ( int index = 0; index < deps.length; index++ ) |
162 | |
{ |
163 | 0 | updateApplicationXml( applicationXmlDom, modulemapsXmlDom, deps[index] ); |
164 | |
} |
165 | |
|
166 | 0 | removeUnusedEntries( applicationXmlDom, modulemapsXmlDom ); |
167 | |
|
168 | 0 | writePrettyXmlFile( applicationXmlFile, applicationXmlDom ); |
169 | 0 | writePrettyXmlFile( modulemapsXmlFile, modulemapsXmlDom ); |
170 | |
} |
171 | 0 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
private Xpp3Dom createNewApplicationXml() |
179 | |
{ |
180 | 0 | String j2eeVersion = JeeUtils.resolveJeeVersion( config.getProject() ); |
181 | |
|
182 | |
|
183 | 0 | Xpp3Dom result = new Xpp3Dom( APPLICATION_XML_APPLICATION ); |
184 | 0 | result.setAttribute( ID, "Application_ID" ); |
185 | 0 | result.setAttribute( VERSION, j2eeVersion ); |
186 | 0 | result.setAttribute( XMLNS, "http://java.sun.com/xml/ns/j2ee" ); |
187 | 0 | result.setAttribute( XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" ); |
188 | 0 | result.setAttribute( XMLNS_SCHEMA_LOCATION, |
189 | |
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_" |
190 | |
+ j2eeVersion.charAt( 0 ) + "_" + j2eeVersion.charAt( 2 ) + ".xsd" ); |
191 | 0 | result.addChild( new Xpp3Dom( APPLICATION_XML_DESCRIPTION ) ); |
192 | 0 | Xpp3Dom name = new Xpp3Dom( APPLICATION_XML_DISPLAY_NAME ); |
193 | 0 | name.setValue( config.getProject().getArtifactId() ); |
194 | 0 | result.addChild( name ); |
195 | 0 | return result; |
196 | |
} |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
private Xpp3Dom createNewModulemaps() |
204 | |
{ |
205 | 0 | Xpp3Dom result = new Xpp3Dom( MODULEMAP_EARPROJECT_MAP ); |
206 | 0 | result.setAttribute( XMI_VERSION, "2.0" ); |
207 | 0 | result.setAttribute( XMLNS_XMI, "http://www.omg.org/XMI" ); |
208 | 0 | result.setAttribute( XMLNS_APPLICATION, "application.xmi" ); |
209 | 0 | result.setAttribute( XMLNS_MODULEMAP, "modulemap.xmi" ); |
210 | 0 | result.setAttribute( XMI_ID, "EARProjectMap_" + ( this.baseId++ ) ); |
211 | 0 | return result; |
212 | |
} |
213 | |
|
214 | |
|
215 | |
|
216 | |
|
217 | |
|
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping ) |
223 | |
{ |
224 | 0 | String id = getIdFromMapping( mapping ); |
225 | 0 | Xpp3Dom[] children = applicationXmlDom.getChildren(); |
226 | 0 | for ( int index = 0; index < children.length; index++ ) |
227 | |
{ |
228 | 0 | String childId = children[index].getAttribute( ID ); |
229 | 0 | if ( childId != null && childId.equals( id ) ) |
230 | |
{ |
231 | 0 | return children[index]; |
232 | |
} |
233 | |
} |
234 | 0 | return null; |
235 | |
} |
236 | |
|
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom ) |
245 | |
{ |
246 | |
|
247 | 0 | Xpp3Dom[] children = modulemapXmlDom.getChildren(); |
248 | 0 | for ( int index = 0; index < children.length; index++ ) |
249 | |
{ |
250 | 0 | if ( children[index].getAttribute( MODULEMAPS_PROJECT_NAME ).equals( dependency.getArtifactId() ) ) |
251 | |
{ |
252 | 0 | if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) |
253 | |
&& children[index].getName().equals( MODULEMAPS_MAPPINGS ) |
254 | |
&& children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals( |
255 | |
MODULEMAPS_APPLICATION_EJB_MODULE ) ) |
256 | |
{ |
257 | 0 | return children[index]; |
258 | |
} |
259 | 0 | else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) |
260 | |
&& children[index].getName().equals( MODULEMAPS_MAPPINGS ) |
261 | |
&& children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals( |
262 | |
MODULEMAPS_APPLICATION_WEB_MODULE ) ) |
263 | |
{ |
264 | 0 | return children[index]; |
265 | |
} |
266 | 0 | else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR ) |
267 | |
&& children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) ) |
268 | |
{ |
269 | 0 | return children[index]; |
270 | |
} |
271 | |
else |
272 | |
{ |
273 | 0 | modulemapXmlDom.removeChild( index ); |
274 | 0 | break; |
275 | |
} |
276 | |
} |
277 | |
} |
278 | |
|
279 | |
|
280 | 0 | long id = this.baseId++; |
281 | 0 | if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) ) |
282 | |
{ |
283 | 0 | Xpp3Dom mapping = new Xpp3Dom( MODULEMAPS_MAPPINGS ); |
284 | 0 | mapping.setAttribute( XMI_ID, "ModuleMapping_" + id ); |
285 | 0 | mapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() ); |
286 | 0 | Xpp3Dom module = new Xpp3Dom( APPLICATION_XML_MODULE ); |
287 | 0 | module.setAttribute( XMI_TYPE, MODULEMAPS_APPLICATION_EJB_MODULE ); |
288 | 0 | module.setAttribute( HREF, "META-INF/application.xml#EjbModule_" + id ); |
289 | 0 | mapping.addChild( module ); |
290 | 0 | modulemapXmlDom.addChild( mapping ); |
291 | 0 | return mapping; |
292 | |
} |
293 | 0 | else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) ) |
294 | |
{ |
295 | 0 | Xpp3Dom mapping = new Xpp3Dom( MODULEMAPS_MAPPINGS ); |
296 | 0 | mapping.setAttribute( XMI_ID, "ModuleMapping_" + id ); |
297 | 0 | mapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() ); |
298 | 0 | Xpp3Dom module = new Xpp3Dom( APPLICATION_XML_MODULE ); |
299 | 0 | module.setAttribute( XMI_TYPE, MODULEMAPS_APPLICATION_WEB_MODULE ); |
300 | 0 | module.setAttribute( HREF, "META-INF/application.xml#WebModule_" + id ); |
301 | 0 | mapping.addChild( module ); |
302 | 0 | modulemapXmlDom.addChild( mapping ); |
303 | 0 | return mapping; |
304 | |
} |
305 | |
else |
306 | |
{ |
307 | 0 | Xpp3Dom utilityJARMapping = new Xpp3Dom( MODULEMAPS_UTILITY_JARMAPPINGS ); |
308 | 0 | utilityJARMapping.setAttribute( XMI_ID, "UtilityJARMapping_" + id ); |
309 | 0 | utilityJARMapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() ); |
310 | 0 | utilityJARMapping.setAttribute( URI, dependency.getArtifactId() + ".jar" ); |
311 | 0 | modulemapXmlDom.addChild( utilityJARMapping ); |
312 | 0 | return utilityJARMapping; |
313 | |
} |
314 | |
} |
315 | |
|
316 | |
|
317 | |
|
318 | |
|
319 | |
|
320 | |
|
321 | |
|
322 | |
private String getIdFromMapping( Xpp3Dom mapping ) |
323 | |
{ |
324 | 0 | if ( mapping.getChildCount() < 1 ) |
325 | |
{ |
326 | 0 | return ""; |
327 | |
} |
328 | 0 | String href = mapping.getChild( 0 ).getAttribute( HREF ); |
329 | 0 | String id = href.substring( href.indexOf( '#' ) + 1 ); |
330 | 0 | return id; |
331 | |
} |
332 | |
|
333 | |
|
334 | |
|
335 | |
|
336 | |
|
337 | |
|
338 | |
private void handled( Xpp3Dom xpp3Dom ) |
339 | |
{ |
340 | 0 | for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ ) |
341 | |
{ |
342 | 0 | if ( this.applicationXmlDomChildren[index] == xpp3Dom ) |
343 | |
{ |
344 | 0 | this.applicationXmlDomChildren[index] = null; |
345 | |
} |
346 | |
} |
347 | 0 | for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ ) |
348 | |
{ |
349 | 0 | if ( this.modulemapsXmlDomChildren[index] == xpp3Dom ) |
350 | |
{ |
351 | 0 | this.modulemapsXmlDomChildren[index] = null; |
352 | |
} |
353 | |
} |
354 | 0 | } |
355 | |
|
356 | |
|
357 | |
|
358 | |
|
359 | |
|
360 | |
|
361 | |
|
362 | |
private Xpp3Dom readXMLFile( File xmlFile ) |
363 | |
{ |
364 | |
try |
365 | |
{ |
366 | 0 | Reader reader = new InputStreamReader( new FileInputStream( xmlFile ), "UTF-8" ); |
367 | 0 | Xpp3Dom applicationXmlDom = Xpp3DomBuilder.build( reader ); |
368 | 0 | return applicationXmlDom; |
369 | |
} |
370 | 0 | catch ( FileNotFoundException e ) |
371 | |
{ |
372 | 0 | return null; |
373 | |
} |
374 | 0 | catch ( Exception e ) |
375 | |
{ |
376 | 0 | log.error( Messages.getString( "EclipsePlugin.cantreadfile", xmlFile.getAbsolutePath() ) ); |
377 | |
|
378 | 0 | return null; |
379 | |
} |
380 | |
} |
381 | |
|
382 | |
|
383 | |
|
384 | |
|
385 | |
|
386 | |
|
387 | |
|
388 | |
private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom ) |
389 | |
{ |
390 | 0 | for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ ) |
391 | |
{ |
392 | 0 | if ( this.modulemapsXmlDomChildren[index] != null ) |
393 | |
{ |
394 | 0 | Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren(); |
395 | 0 | for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ ) |
396 | |
{ |
397 | 0 | if ( ( newModulemapsXmlDomChildren[newIndex] != null ) |
398 | |
&& ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) ) |
399 | |
{ |
400 | 0 | modulemapsXmlDom.removeChild( newIndex ); |
401 | 0 | break; |
402 | |
} |
403 | |
} |
404 | |
} |
405 | |
} |
406 | 0 | for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ ) |
407 | |
{ |
408 | 0 | if ( this.applicationXmlDomChildren[index] != null ) |
409 | |
{ |
410 | 0 | Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren(); |
411 | 0 | for ( int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++ ) |
412 | |
{ |
413 | 0 | if ( newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index] ) |
414 | |
{ |
415 | 0 | applicationXmlDom.removeChild( newIndex ); |
416 | 0 | break; |
417 | |
} |
418 | |
} |
419 | |
} |
420 | |
} |
421 | 0 | } |
422 | |
|
423 | |
|
424 | |
|
425 | |
|
426 | |
|
427 | |
|
428 | |
|
429 | |
|
430 | |
|
431 | |
|
432 | |
private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency ) |
433 | |
{ |
434 | 0 | boolean isEar = Constants.PROJECT_PACKAGING_EJB.equals( dependency.getType() ); |
435 | 0 | boolean isWar = Constants.PROJECT_PACKAGING_WAR.equals( dependency.getType() ); |
436 | |
|
437 | 0 | if ( dependency.isReferencedProject() || isEar || isWar ) |
438 | |
{ |
439 | 0 | Xpp3Dom mapping = findOrCreateArtifact( dependency, modulemapXmlDom ); |
440 | 0 | handled( mapping ); |
441 | 0 | if ( isEar ) |
442 | |
{ |
443 | 0 | Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping ); |
444 | 0 | if ( module == null ) |
445 | |
{ |
446 | 0 | module = new Xpp3Dom( APPLICATION_XML_MODULE ); |
447 | 0 | module.setAttribute( ID, getIdFromMapping( mapping ) ); |
448 | 0 | Xpp3Dom ejb = new Xpp3Dom( Constants.PROJECT_PACKAGING_EJB ); |
449 | 0 | ejb.setValue( dependency.getArtifactId() + ".jar" ); |
450 | 0 | module.addChild( ejb ); |
451 | 0 | applicationXmlDom.addChild( module ); |
452 | 0 | } |
453 | |
else |
454 | |
{ |
455 | 0 | handled( module ); |
456 | 0 | module.getChild( Constants.PROJECT_PACKAGING_EJB ).setValue( dependency.getArtifactId() + ".jar" ); |
457 | |
} |
458 | 0 | } |
459 | 0 | else if ( isWar ) |
460 | |
{ |
461 | 0 | String contextRootInPom = getContextRootFor( dependency.getArtifactId() ); |
462 | 0 | Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping ); |
463 | 0 | if ( module == null ) |
464 | |
{ |
465 | 0 | module = new Xpp3Dom( APPLICATION_XML_MODULE ); |
466 | 0 | module.setAttribute( ID, getIdFromMapping( mapping ) ); |
467 | 0 | Xpp3Dom web = new Xpp3Dom( APPLICATION_XML_WEB ); |
468 | 0 | Xpp3Dom webUri = new Xpp3Dom( APPLICATION_XML_WEB_URI ); |
469 | 0 | webUri.setValue( dependency.getArtifactId() + ".war" ); |
470 | 0 | Xpp3Dom contextRoot = new Xpp3Dom( APPLICATION_XML_CONTEXT_ROOT ); |
471 | 0 | contextRoot.setValue( contextRootInPom ); |
472 | 0 | web.addChild( webUri ); |
473 | 0 | web.addChild( contextRoot ); |
474 | 0 | module.addChild( web ); |
475 | 0 | applicationXmlDom.addChild( module ); |
476 | 0 | } |
477 | |
else |
478 | |
{ |
479 | 0 | handled( module ); |
480 | 0 | module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_WEB_URI ).setValue( |
481 | |
dependency.getArtifactId() |
482 | |
+ ".war" ); |
483 | 0 | module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_CONTEXT_ROOT ).setValue( |
484 | |
contextRootInPom ); |
485 | |
} |
486 | |
} |
487 | |
} |
488 | 0 | } |
489 | |
|
490 | |
|
491 | |
|
492 | |
|
493 | |
|
494 | |
|
495 | |
|
496 | |
private String getContextRootFor( String artifactId ) |
497 | |
{ |
498 | 0 | for ( int index = 0; index < webModulesFromPoms.length; index++ ) |
499 | |
{ |
500 | 0 | if ( webModulesFromPoms[index].getChild( "artifactId" ).getValue().equals( artifactId ) ) |
501 | 0 | return new File( webModulesFromPoms[index].getChild( "contextRoot" ).getValue() ).getName(); |
502 | |
} |
503 | 0 | return artifactId; |
504 | |
} |
505 | |
|
506 | |
|
507 | |
|
508 | |
|
509 | |
|
510 | |
|
511 | |
|
512 | |
|
513 | |
private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree ) |
514 | |
throws MojoExecutionException |
515 | |
{ |
516 | 0 | Xpp3Dom original = readXMLFile( xmlFile ); |
517 | 0 | if ( original != null && original.equals( xmlDomTree ) ) |
518 | |
{ |
519 | 0 | log.info( Messages.getString( "EclipsePlugin.unchangedmanifest", xmlFile.getAbsolutePath() ) ); |
520 | 0 | return; |
521 | |
} |
522 | 0 | Writer w = null; |
523 | 0 | xmlFile.getParentFile().mkdirs(); |
524 | |
try |
525 | |
{ |
526 | 0 | w = new OutputStreamWriter( new FileOutputStream( xmlFile ), "UTF-8" ); |
527 | |
} |
528 | 0 | catch ( IOException ex ) |
529 | |
{ |
530 | 0 | throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); |
531 | 0 | } |
532 | 0 | XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null ); |
533 | 0 | Xpp3DomWriter.write( writer, xmlDomTree ); |
534 | 0 | IOUtil.close( w ); |
535 | 0 | } |
536 | |
} |