Coverage Report - org.apache.maven.plugin.eclipse.writers.wtp.EclipseWtpmodulesWriter
 
Classes in this File Line Coverage Branch Coverage Complexity
EclipseWtpmodulesWriter
0%
0/39
0%
0/8
7
 
 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.wtp;
 20  
 
 21  
 import java.io.File;
 22  
 import java.io.FileOutputStream;
 23  
 import java.io.IOException;
 24  
 import java.io.OutputStreamWriter;
 25  
 import java.io.Writer;
 26  
 
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.eclipse.Constants;
 29  
 import org.apache.maven.plugin.eclipse.EclipseSourceDir;
 30  
 import org.apache.maven.plugin.eclipse.Messages;
 31  
 import org.apache.maven.plugin.ide.IdeUtils;
 32  
 import org.apache.maven.plugin.ide.JeeUtils;
 33  
 import org.codehaus.plexus.util.IOUtil;
 34  
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
 35  
 import org.codehaus.plexus.util.xml.XMLWriter;
 36  
 
 37  
 /**
 38  
  * Writes eclipse .wtpmodules file.
 39  
  * 
 40  
  * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
 41  
  * @version $Id: EclipseWtpmodulesWriter.java 728546 2008-12-21 22:56:51Z bentmann $
 42  
  */
 43  0
 public class EclipseWtpmodulesWriter
 44  
     extends AbstractWtpResourceWriter
 45  
 {
 46  
 
 47  
     protected static final String FILE_DOT_WTPMODULES = ".wtpmodules"; //$NON-NLS-1$
 48  
 
 49  
     /**
 50  
      * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write()
 51  
      */
 52  
     public void write()
 53  
         throws MojoExecutionException
 54  
     {
 55  
         Writer w;
 56  
 
 57  
         try
 58  
         {
 59  0
             w =
 60  
                 new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
 61  
                                                                         FILE_DOT_WTPMODULES ) ), "UTF-8" );
 62  
         }
 63  0
         catch ( IOException ex )
 64  
         {
 65  0
             throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
 66  0
         }
 67  
 
 68  0
         XMLWriter writer = new PrettyPrintXMLWriter( w );
 69  0
         writer.startElement( ELT_PROJECT_MODULES );
 70  0
         writer.addAttribute( ATTR_MODULE_ID, "moduleCoreId" ); //$NON-NLS-1$
 71  
 
 72  0
         writer.startElement( ELT_WB_MODULE );
 73  
         // we should use the configured eclipse project name.
 74  0
         writer.addAttribute( ATTR_DEPLOY_NAME, this.config.getEclipseProjectName() );
 75  
 
 76  0
         writer.startElement( ELT_MODULE_TYPE );
 77  0
         writeModuleTypeAccordingToPackaging( config.getProject(), writer, config.getBuildOutputDirectory() );
 78  0
         writer.endElement(); // module-type
 79  
 
 80  
         // source and resource paths.
 81  
         // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
 82  
 
 83  0
         String target = "/"; //$NON-NLS-1$
 84  0
         if ( Constants.PROJECT_PACKAGING_WAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
 85  
         {
 86  0
             String warSourceDirectory =
 87  
                 IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
 88  
                                            "warSourceDirectory", //$NON-NLS-1$
 89  
                                            config.getProject().getBasedir() + "/src/main/webapp" ); //$NON-NLS-1$
 90  
 
 91  0
             writer.startElement( ELT_WB_RESOURCE );
 92  0
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
 93  0
             writer.addAttribute( ATTR_SOURCE_PATH, "/" //$NON-NLS-1$
 94  
                 + IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(),
 95  
                                                       new File( warSourceDirectory ), false ) );
 96  0
             writer.endElement();
 97  
 
 98  0
             writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
 99  
 
 100  0
             target = "/WEB-INF/classes"; //$NON-NLS-1$
 101  
         }
 102  0
         else if ( Constants.PROJECT_PACKAGING_EAR.equals( config.getPackaging() ) ) //$NON-NLS-1$
 103  
         {
 104  0
             writer.startElement( ELT_WB_RESOURCE );
 105  0
             writer.addAttribute( ATTR_DEPLOY_PATH, "/" ); //$NON-NLS-1$
 106  0
             writer.addAttribute( ATTR_SOURCE_PATH, "/" ); //$NON-NLS-1$
 107  0
             writer.endElement();
 108  
 
 109  0
             writeWarOrEarResources( writer, config.getProject(), config.getLocalRepository() );
 110  
         }
 111  
 
 112  0
         for ( int j = 0; j < config.getSourceDirs().length; j++ )
 113  
         {
 114  0
             EclipseSourceDir dir = config.getSourceDirs()[j];
 115  
             // test src/resources are not added to wtpmodules
 116  0
             if ( !dir.isTest() )
 117  
             {
 118  
                 // <wb-resource deploy-path="/" source-path="/src/java" />
 119  0
                 writer.startElement( ELT_WB_RESOURCE );
 120  0
                 writer.addAttribute( ATTR_DEPLOY_PATH, target );
 121  0
                 writer.addAttribute( ATTR_SOURCE_PATH, dir.getPath() );
 122  0
                 writer.endElement();
 123  
             }
 124  
         }
 125  
 
 126  0
         writer.endElement(); // wb-module
 127  0
         writer.endElement(); // project-modules
 128  
 
 129  0
         IOUtil.close( w );
 130  0
     }
 131  
 
 132  
 }