Coverage Report - org.apache.maven.plugin.eclipse.writers.rad.RadApplicationXMLWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
RadApplicationXMLWriter
0%
0/179
0%
0/90
6
 
 1  
 /*
 2  
  * Licensed to the Apache Software Foundation (ASF) under one
 3  
  * or more contributor license agreements.  See the NOTICE file
 4  
  * distributed with this work for additional information
 5  
  * regarding copyright ownership.  The ASF licenses this file
 6  
  * to you under the Apache License, Version 2.0 (the
 7  
  * "License"); you may not use this file except in compliance
 8  
  * with the License.  You may obtain a copy of the License at
 9  
  *
 10  
  *   http://www.apache.org/licenses/LICENSE-2.0
 11  
  *
 12  
  * Unless required by applicable law or agreed to in writing,
 13  
  * software distributed under the License is distributed on an
 14  
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 15  
  * KIND, either express or implied.  See the License for the
 16  
  * specific language governing permissions and limitations
 17  
  * under the License.
 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  
  * This writer creates the application.xml and the .modulemaps files for RAD6 in the META-INF directory in the project
 50  
  * root. this is where RAD6 requires the files to be. These will be independent of the real application.xml witch will
 51  
  * be generated the stad. maven way.
 52  
  * 
 53  
  * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
 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  
      * write the application.xml and the .modulemaps file to the META-INF directory.
 125  
      * 
 126  
      * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
 127  
      * @param sourceDirs all eclipse source directorys
 128  
      * @param localRepository the local reposetory
 129  
      * @param buildOutputDirectory build output directory (target)
 130  
      * @throws MojoExecutionException when writing the config files was not possible
 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.getDeps();
 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  
      * there is no existing application.xml file so create a new one.
 175  
      * 
 176  
      * @return the domtree representing the contents of application.xml
 177  
      */
 178  
     private Xpp3Dom createNewApplicationXml()
 179  
     {
 180  
         String jeeVersion;
 181  0
         if ( config.getJeeVersion() != null )
 182  
         {
 183  0
             jeeVersion = JeeUtils.getJeeDescriptorFromJeeVersion( config.getJeeVersion() ).getJeeVersion();
 184  
         }
 185  
         else
 186  
         {
 187  0
             jeeVersion = JeeUtils.resolveJeeVersion( config.getProject() );
 188  
         }
 189  
         // By default J2EE version is in the format X.X
 190  
         // Must be fixed for JEE < 1.4. Schemas didn't exist
 191  0
         Xpp3Dom result = new Xpp3Dom( APPLICATION_XML_APPLICATION );
 192  0
         result.setAttribute( ID, "Application_ID" );
 193  0
         result.setAttribute( VERSION, jeeVersion );
 194  0
         result.setAttribute( XMLNS, "http://java.sun.com/xml/ns/j2ee" );
 195  0
         result.setAttribute( XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" );
 196  0
         result.setAttribute( XMLNS_SCHEMA_LOCATION,
 197  
                              "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_"
 198  
                                  + jeeVersion.charAt( 0 ) + "_" + jeeVersion.charAt( 2 ) + ".xsd" );
 199  0
         result.addChild( new Xpp3Dom( APPLICATION_XML_DESCRIPTION ) );
 200  0
         Xpp3Dom name = new Xpp3Dom( APPLICATION_XML_DISPLAY_NAME );
 201  0
         name.setValue( config.getProject().getArtifactId() );
 202  0
         result.addChild( name );
 203  0
         return result;
 204  
     }
 205  
 
 206  
     /**
 207  
      * there is no existing .modulemaps file so create a new one.
 208  
      * 
 209  
      * @return the domtree representing the contents of the .modulemaps file
 210  
      */
 211  
     private Xpp3Dom createNewModulemaps()
 212  
     {
 213  0
         Xpp3Dom result = new Xpp3Dom( MODULEMAP_EARPROJECT_MAP );
 214  0
         result.setAttribute( XMI_VERSION, "2.0" );
 215  0
         result.setAttribute( XMLNS_XMI, "http://www.omg.org/XMI" );
 216  0
         result.setAttribute( XMLNS_APPLICATION, "application.xmi" );
 217  0
         result.setAttribute( XMLNS_MODULEMAP, "modulemap.xmi" );
 218  0
         result.setAttribute( XMI_ID, "EARProjectMap_" + ( this.baseId++ ) );
 219  0
         return result;
 220  
     }
 221  
 
 222  
     /**
 223  
      * find an existing module entry in the application.xml file by looking up the id in the modulemaps file and then
 224  
      * using that to locate the entry in the application.xml file.
 225  
      * 
 226  
      * @param applicationXmlDom application.xml dom tree
 227  
      * @param mapping .modulemaps dom tree
 228  
      * @return dom tree representing the module
 229  
      */
 230  
     private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping )
 231  
     {
 232  0
         String id = getIdFromMapping( mapping );
 233  0
         Xpp3Dom[] children = applicationXmlDom.getChildren();
 234  0
         for ( int index = 0; index < children.length; index++ )
 235  
         {
 236  0
             String childId = children[index].getAttribute( ID );
 237  0
             if ( childId != null && childId.equals( id ) )
 238  
             {
 239  0
                 return children[index];
 240  
             }
 241  
         }
 242  0
         return null;
 243  
     }
 244  
 
 245  
     /**
 246  
      * find an artifact in the modulemaps dom tree, if it is missing create a new entry in the modulemaps dom tree.
 247  
      * 
 248  
      * @param dependency dependency to find
 249  
      * @param modulemapXmlDom dom-tree of modulemaps
 250  
      * @return dom-tree representing the artifact
 251  
      */
 252  
     private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom )
 253  
     {
 254  
         // first try to find it
 255  0
         Xpp3Dom[] children = modulemapXmlDom.getChildren();
 256  0
         for ( int index = 0; index < children.length; index++ )
 257  
         {
 258  0
             if ( children[index].getAttribute( MODULEMAPS_PROJECT_NAME ).equals( dependency.getArtifactId() ) )
 259  
             {
 260  0
                 if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB )
 261  
                     && children[index].getName().equals( MODULEMAPS_MAPPINGS )
 262  
                     && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
 263  
                                                                                                            MODULEMAPS_APPLICATION_EJB_MODULE ) )
 264  
                 {
 265  0
                     return children[index];
 266  
                 }
 267  0
                 else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR )
 268  
                     && children[index].getName().equals( MODULEMAPS_MAPPINGS )
 269  
                     && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
 270  
                                                                                                            MODULEMAPS_APPLICATION_WEB_MODULE ) )
 271  
                 {
 272  0
                     return children[index];
 273  
                 }
 274  0
                 else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR )
 275  
                     && children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) )
 276  
                 {
 277  0
                     return children[index];
 278  
                 }
 279  
                 else
 280  
                 {
 281  0
                     modulemapXmlDom.removeChild( index );
 282  0
                     break;
 283  
                 }
 284  
             }
 285  
         }
 286  
         // ok, its missing (or it changed type). create a new one based on its
 287  
         // type
 288  0
         long id = this.baseId++;
 289  0
         if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) )
 290  
         {
 291  0
             Xpp3Dom mapping = new Xpp3Dom( MODULEMAPS_MAPPINGS );
 292  0
             mapping.setAttribute( XMI_ID, "ModuleMapping_" + id );
 293  0
             mapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() );
 294  0
             Xpp3Dom module = new Xpp3Dom( APPLICATION_XML_MODULE );
 295  0
             module.setAttribute( XMI_TYPE, MODULEMAPS_APPLICATION_EJB_MODULE );
 296  0
             module.setAttribute( HREF, "META-INF/application.xml#EjbModule_" + id );
 297  0
             mapping.addChild( module );
 298  0
             modulemapXmlDom.addChild( mapping );
 299  0
             return mapping;
 300  
         }
 301  0
         else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) )
 302  
         {
 303  0
             Xpp3Dom mapping = new Xpp3Dom( MODULEMAPS_MAPPINGS );
 304  0
             mapping.setAttribute( XMI_ID, "ModuleMapping_" + id );
 305  0
             mapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() );
 306  0
             Xpp3Dom module = new Xpp3Dom( APPLICATION_XML_MODULE );
 307  0
             module.setAttribute( XMI_TYPE, MODULEMAPS_APPLICATION_WEB_MODULE );
 308  0
             module.setAttribute( HREF, "META-INF/application.xml#WebModule_" + id );
 309  0
             mapping.addChild( module );
 310  0
             modulemapXmlDom.addChild( mapping );
 311  0
             return mapping;
 312  
         }
 313  
         else
 314  
         {
 315  0
             Xpp3Dom utilityJARMapping = new Xpp3Dom( MODULEMAPS_UTILITY_JARMAPPINGS );
 316  0
             utilityJARMapping.setAttribute( XMI_ID, "UtilityJARMapping_" + id );
 317  0
             utilityJARMapping.setAttribute( MODULEMAPS_PROJECT_NAME, dependency.getArtifactId() );
 318  0
             utilityJARMapping.setAttribute( URI, dependency.getArtifactId() + ".jar" );
 319  0
             modulemapXmlDom.addChild( utilityJARMapping );
 320  0
             return utilityJARMapping;
 321  
         }
 322  
     }
 323  
 
 324  
     /**
 325  
      * get the id from the href of a modulemap.
 326  
      * 
 327  
      * @param mapping the dom-tree of modulemaps
 328  
      * @return module identifier
 329  
      */
 330  
     private String getIdFromMapping( Xpp3Dom mapping )
 331  
     {
 332  0
         if ( mapping.getChildCount() < 1 )
 333  
         {
 334  0
             return "";
 335  
         }
 336  0
         String href = mapping.getChild( 0 ).getAttribute( HREF );
 337  0
         String id = href.substring( href.indexOf( '#' ) + 1 );
 338  0
         return id;
 339  
     }
 340  
 
 341  
     /**
 342  
      * mark the domtree entry as handled (all not handled ones will be deleted).
 343  
      * 
 344  
      * @param xpp3Dom dom element to mark handled
 345  
      */
 346  
     private void handled( Xpp3Dom xpp3Dom )
 347  
     {
 348  0
         for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
 349  
         {
 350  0
             if ( this.applicationXmlDomChildren[index] == xpp3Dom )
 351  
             {
 352  0
                 this.applicationXmlDomChildren[index] = null;
 353  
             }
 354  
         }
 355  0
         for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
 356  
         {
 357  0
             if ( this.modulemapsXmlDomChildren[index] == xpp3Dom )
 358  
             {
 359  0
                 this.modulemapsXmlDomChildren[index] = null;
 360  
             }
 361  
         }
 362  0
     }
 363  
 
 364  
     /**
 365  
      * read an xml file (application.xml or .modulemaps).
 366  
      * 
 367  
      * @param xmlFile an xmlfile
 368  
      * @return dom-tree representing the file contents
 369  
      */
 370  
     private Xpp3Dom readXMLFile( File xmlFile )
 371  
     {
 372  
         try
 373  
         {
 374  0
             Reader reader = new InputStreamReader( new FileInputStream( xmlFile ), "UTF-8" );
 375  0
             Xpp3Dom applicationXmlDom = Xpp3DomBuilder.build( reader );
 376  0
             return applicationXmlDom;
 377  
         }
 378  0
         catch ( FileNotFoundException e )
 379  
         {
 380  0
             return null;
 381  
         }
 382  0
         catch ( Exception e )
 383  
         {
 384  0
             log.error( Messages.getString( "EclipsePlugin.cantreadfile", xmlFile.getAbsolutePath() ) );
 385  
             // this will trigger creating a new file
 386  0
             return null;
 387  
         }
 388  
     }
 389  
 
 390  
     /**
 391  
      * delete all unused entries from the dom-trees.
 392  
      * 
 393  
      * @param applicationXmlDom dom-tree of application.xml
 394  
      * @param modulemapsXmlDom dom-tree of modulemaps
 395  
      */
 396  
     private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom )
 397  
     {
 398  0
         for ( int index = 0; index < this.modulemapsXmlDomChildren.length; index++ )
 399  
         {
 400  0
             if ( this.modulemapsXmlDomChildren[index] != null )
 401  
             {
 402  0
                 Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
 403  0
                 for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ )
 404  
                 {
 405  0
                     if ( ( newModulemapsXmlDomChildren[newIndex] != null )
 406  
                         && ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) )
 407  
                     {
 408  0
                         modulemapsXmlDom.removeChild( newIndex );
 409  0
                         break;
 410  
                     }
 411  
                 }
 412  
             }
 413  
         }
 414  0
         for ( int index = 0; index < this.applicationXmlDomChildren.length; index++ )
 415  
         {
 416  0
             if ( this.applicationXmlDomChildren[index] != null )
 417  
             {
 418  0
                 Xpp3Dom[] newApplicationXmlDomChildren = applicationXmlDom.getChildren();
 419  0
                 for ( int newIndex = 0; newIndex < newApplicationXmlDomChildren.length; newIndex++ )
 420  
                 {
 421  0
                     if ( newApplicationXmlDomChildren[newIndex] == this.applicationXmlDomChildren[index] )
 422  
                     {
 423  0
                         applicationXmlDom.removeChild( newIndex );
 424  0
                         break;
 425  
                     }
 426  
                 }
 427  
             }
 428  
         }
 429  0
     }
 430  
 
 431  
     /**
 432  
      * update the application.xml and the .modulemaps file for a specified dependency.all WAR an EJB dependencies will
 433  
      * go in both files all others only in the modulemaps files. Webapplications contextroots are corrected to the
 434  
      * contextRoot specified in the pom.
 435  
      * 
 436  
      * @param applicationXmlDom dom-tree of application.xml
 437  
      * @param modulemapXmlDom dom-tree of modulemaps
 438  
      * @param dependency the eclipse dependency to handle
 439  
      */
 440  
     private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency )
 441  
     {
 442  0
         boolean isEar = Constants.PROJECT_PACKAGING_EJB.equals( dependency.getType() );
 443  0
         boolean isWar = Constants.PROJECT_PACKAGING_WAR.equals( dependency.getType() );
 444  
 
 445  0
         if ( dependency.isReferencedProject() || isEar || isWar )
 446  
         {
 447  0
             Xpp3Dom mapping = findOrCreateArtifact( dependency, modulemapXmlDom );
 448  0
             handled( mapping );
 449  0
             if ( isEar )
 450  
             {
 451  0
                 Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
 452  0
                 if ( module == null )
 453  
                 {
 454  0
                     module = new Xpp3Dom( APPLICATION_XML_MODULE );
 455  0
                     module.setAttribute( ID, getIdFromMapping( mapping ) );
 456  0
                     Xpp3Dom ejb = new Xpp3Dom( Constants.PROJECT_PACKAGING_EJB );
 457  0
                     ejb.setValue( dependency.getArtifactId() + ".jar" );
 458  0
                     module.addChild( ejb );
 459  0
                     applicationXmlDom.addChild( module );
 460  0
                 }
 461  
                 else
 462  
                 {
 463  0
                     handled( module );
 464  0
                     module.getChild( Constants.PROJECT_PACKAGING_EJB ).setValue( dependency.getArtifactId() + ".jar" );
 465  
                 }
 466  0
             }
 467  0
             else if ( isWar )
 468  
             {
 469  0
                 String contextRootInPom = getContextRootFor( dependency.getArtifactId() );
 470  0
                 Xpp3Dom module = findModuleInApplicationXml( applicationXmlDom, mapping );
 471  0
                 if ( module == null )
 472  
                 {
 473  0
                     module = new Xpp3Dom( APPLICATION_XML_MODULE );
 474  0
                     module.setAttribute( ID, getIdFromMapping( mapping ) );
 475  0
                     Xpp3Dom web = new Xpp3Dom( APPLICATION_XML_WEB );
 476  0
                     Xpp3Dom webUri = new Xpp3Dom( APPLICATION_XML_WEB_URI );
 477  0
                     webUri.setValue( dependency.getArtifactId() + ".war" );
 478  0
                     Xpp3Dom contextRoot = new Xpp3Dom( APPLICATION_XML_CONTEXT_ROOT );
 479  0
                     contextRoot.setValue( contextRootInPom );
 480  0
                     web.addChild( webUri );
 481  0
                     web.addChild( contextRoot );
 482  0
                     module.addChild( web );
 483  0
                     applicationXmlDom.addChild( module );
 484  0
                 }
 485  
                 else
 486  
                 {
 487  0
                     handled( module );
 488  0
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_WEB_URI ).setValue(
 489  
                                                                                                          dependency.getArtifactId()
 490  
                                                                                                              + ".war" );
 491  0
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_CONTEXT_ROOT ).setValue(
 492  
                                                                                                               contextRootInPom );
 493  
                 }
 494  
             }
 495  
         }
 496  0
     }
 497  
 
 498  
     /**
 499  
      * Find the contextRoot specified in the pom and convert it into contextroot for the application.xml.
 500  
      * 
 501  
      * @param artifactId the artifactid to search
 502  
      * @return string with the context root
 503  
      */
 504  
     private String getContextRootFor( String artifactId )
 505  
     {
 506  0
         for ( int index = 0; index < webModulesFromPoms.length; index++ )
 507  
         {
 508  0
             if ( webModulesFromPoms[index].getChild( "artifactId" ).getValue().equals( artifactId ) )
 509  0
                 return new File( webModulesFromPoms[index].getChild( "contextRoot" ).getValue() ).getName();
 510  
         }
 511  0
         return artifactId;
 512  
     }
 513  
 
 514  
     /**
 515  
      * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable.
 516  
      * 
 517  
      * @param xmlFile file to write to
 518  
      * @param xmlDomTree dom-tree to write
 519  
      * @throws MojoExecutionException if the file could not be written
 520  
      */
 521  
     private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree )
 522  
         throws MojoExecutionException
 523  
     {
 524  0
         Xpp3Dom original = readXMLFile( xmlFile );
 525  0
         if ( original != null && original.equals( xmlDomTree ) )
 526  
         {
 527  0
             log.info( Messages.getString( "EclipsePlugin.unchangedmanifest", xmlFile.getAbsolutePath() ) );
 528  0
             return;
 529  
         }
 530  0
         Writer w = null;
 531  0
         xmlFile.getParentFile().mkdirs();
 532  
         try
 533  
         {
 534  0
             w = new OutputStreamWriter( new FileOutputStream( xmlFile ), "UTF-8" );
 535  
         }
 536  0
         catch ( IOException ex )
 537  
         {
 538  0
             throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
 539  0
         }
 540  0
         XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null );
 541  0
         Xpp3DomWriter.write( writer, xmlDomTree );
 542  0
         IOUtil.close( w );
 543  0
     }
 544  
 }