Coverage Report - org.apache.maven.plugin.eclipse.writers.EclipseWtpmodulesWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
EclipseWtpmodulesWriter
62% 
100% 
7
 
 1  
 package org.apache.maven.plugin.eclipse.writers;
 2  
 
 3  
 /*
 4  
  * Copyright 2001-2005 The Apache Software Foundation.
 5  
  *
 6  
  * Licensed under the Apache License, Version 2.0 (the "License");
 7  
  * you may not use this file except in compliance with the License.
 8  
  * 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, software
 13  
  * distributed under the License is distributed on an "AS IS" BASIS,
 14  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 15  
  * See the License for the specific language governing permissions and
 16  
  * limitations under the License.
 17  
  */
 18  
 
 19  
 import java.io.File;
 20  
 import java.io.FileWriter;
 21  
 import java.io.IOException;
 22  
 
 23  
 import org.apache.maven.plugin.MojoExecutionException;
 24  
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 25  
 import org.apache.maven.plugin.eclipse.Messages;
 26  
 import org.apache.maven.plugin.ide.IdeUtils;
 27  
 import org.codehaus.plexus.util.IOUtil;
 28  
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 29  
 import org.codehaus.plexus.util.xml.XMLWriter;
 30  
 
 31  
 /**
 32  
  * Writes eclipse .wtpmodules file.
 33  
  *
 34  
  * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
 35  
  * @version $Id: EclipseWtpmodulesWriter.java 472126 2006-11-07 14:34:59Z kenney $
 36  
  */
 37  1
 public class EclipseWtpmodulesWriter
 38  
     extends AbstractWtpResourceWriter
 39  
 {
 40  
 
 41  
     protected static final String FILE_DOT_WTPMODULES = ".wtpmodules"; //$NON-NLS-1$
 42  
 
 43  
     /**
 44  
      * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write()
 45  
      */
 46  
     public void write()
 47  
         throws MojoExecutionException
 48  
     {
 49  
         FileWriter w;
 50  
 
 51  
         try
 52  
         {
 53  1
             w = new FileWriter( new File( config.getEclipseProjectDirectory(), FILE_DOT_WTPMODULES ) );
 54  
         }
 55  0
         catch ( IOException ex )
 56  
         {
 57  0
             throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
 58  1
         }
 59  
 
 60  1
         XMLWriter writer = new PrettyPrintXMLWriter( w );
 61  1
         writer.startElement( ELT_PROJECT_MODULES );
 62  1
         writer.addAttribute( ATTR_MODULE_ID, "moduleCoreId" ); //$NON-NLS-1$
 63  
 
 64  1
         writer.startElement( ELT_WB_MODULE );
 65  1
         writer.addAttribute( ATTR_DEPLOY_NAME, config.getProject().getArtifactId() );
 66  
 
 67  1
         writer.startElement( ELT_MODULE_TYPE );
 68  1
         writeModuleTypeAccordingToPackaging( config.getProject(), writer, config.getBuildOutputDirectory() );
 69  1
         writer.endElement(); // module-type
 70  
 
 71  
         // source and resource paths.
 72  
         // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
 73  
 
 74  1
         String target = "/"; //$NON-NLS-1$
 75  1
         if ( "war".equals( config.getProject().getPackaging() ) ) //$NON-NLS-1$
 76  
         {
 77  0
             String warSourceDirectory = IdeUtils.getPluginSetting( config.getProject(), ARTIFACT_MAVEN_WAR_PLUGIN,
 78  
                                                                    "warSourceDirectory", //$NON-NLS-1$
 79  
                                                                    "/src/main/webapp" ); //$NON-NLS-1$
 80  
 
 81  0
             writer.startElement( ELT_WB_RESOURCE );
 82  0
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
 83  0
             writer.addAttribute( ATTR_SOURCE_PATH, "/" //$NON-NLS-1$
 84  
                 + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), new File( config
 85  
                     .getEclipseProjectDirectory(), warSourceDirectory ), false ) );
 86  0
             writer.endElement();
 87  
 
 88  0
             writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
 89  
 
 90  0
             target = "/WEB-INF/classes"; //$NON-NLS-1$
 91  0
         }
 92  1
         else if ( "ear".equals( config.getProject().getPackaging() ) ) //$NON-NLS-1$
 93  
         {
 94  0
             writer.startElement( ELT_WB_RESOURCE );
 95  0
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
 96  0
             writer.addAttribute( ATTR_SOURCE_PATH, "/" ); //$NON-NLS-1$
 97  0
             writer.endElement();
 98  
 
 99  0
             writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
 100  
         }
 101  
 
 102  2
         for ( int j = 0; j < config.getSourceDirs().length; j++ )
 103  
         {
 104  1
             EclipseSourceDir dir = config.getSourceDirs()[j];
 105  
             // test src/resources are not added to wtpmodules
 106  1
             if ( !dir.isTest() )
 107  
             {
 108  
                 // <wb-resource deploy-path="/" source-path="/src/java" />
 109  1
                 writer.startElement( ELT_WB_RESOURCE );
 110  1
                 writer.addAttribute( ATTR_DEPLOY_PATH, target );
 111  1
                 writer.addAttribute( ATTR_SOURCE_PATH, dir.getPath() );
 112  1
                 writer.endElement();
 113  
             }
 114  
         }
 115  
 
 116  1
         writer.endElement(); // wb-module
 117  1
         writer.endElement(); // project-modules
 118  
 
 119  1
         IOUtil.close( w );
 120  1
     }
 121  
 
 122  
 }