Coverage Report - org.apache.maven.plugin.eclipse.RadPlugin
 
Classes in this File Line Coverage Branch Coverage Complexity
RadPlugin
0%
0/86
0%
0/46
2.778
 
 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;
 20  
 
 21  
 import java.io.File;
 22  
 import java.util.ArrayList;
 23  
 import java.util.Iterator;
 24  
 
 25  
 import org.apache.maven.artifact.Artifact;
 26  
 import org.apache.maven.model.Resource;
 27  
 import org.apache.maven.plugin.MojoExecutionException;
 28  
 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
 29  
 import org.apache.maven.plugin.eclipse.writers.rad.RadApplicationXMLWriter;
 30  
 import org.apache.maven.plugin.eclipse.writers.rad.RadEjbClasspathWriter;
 31  
 import org.apache.maven.plugin.eclipse.writers.rad.RadJ2EEWriter;
 32  
 import org.apache.maven.plugin.eclipse.writers.rad.RadLibCopier;
 33  
 import org.apache.maven.plugin.eclipse.writers.rad.RadManifestWriter;
 34  
 import org.apache.maven.plugin.eclipse.writers.rad.RadWebSettingsWriter;
 35  
 import org.apache.maven.plugin.eclipse.writers.rad.RadWebsiteConfigWriter;
 36  
 import org.apache.maven.plugin.ide.IdeDependency;
 37  
 import org.apache.maven.plugin.ide.IdeUtils;
 38  
 import org.apache.maven.plugin.ide.JeeUtils;
 39  
 import org.apache.maven.project.MavenProject;
 40  
 
 41  
 /**
 42  
  * Generates the rad-6 configuration files.
 43  
  * 
 44  
  * @author Richard van Nieuwenhoven (patch submission)
 45  
  * @author jdcasey
 46  
  * @goal rad
 47  
  * @execute phase="generate-resources"
 48  
  */
 49  0
 public class RadPlugin
 50  
     extends EclipsePlugin
 51  
 {
 52  
 
 53  
     private static final String COM_IBM_ETOOLS_J2EE_UI_LIB_DIR_BUILDER = "com.ibm.etools.j2ee.ui.LibDirBuilder";
 54  
 
 55  
     private static final String COM_IBM_ETOOLS_SITEEDIT_SITE_NAV_BUILDER = "com.ibm.etools.siteedit.SiteNavBuilder";
 56  
 
 57  
     private static final String COM_IBM_ETOOLS_SITEEDIT_SITE_UPDATE_BUILDER =
 58  
         "com.ibm.etools.siteedit.SiteUpdateBuilder";
 59  
 
 60  
     private static final String COM_IBM_ETOOLS_SITEEDIT_WEB_SITE_NATURE = "com.ibm.etools.siteedit.WebSiteNature";
 61  
 
 62  
     private static final String COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER =
 63  
         "com.ibm.etools.validation.validationbuilder";
 64  
 
 65  
     private static final String COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATEBUILDER =
 66  
         "com.ibm.etools.webpage.template.templatebuilder";
 67  
 
 68  
     private static final String COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATENATURE =
 69  
         "com.ibm.etools.webpage.template.templatenature";
 70  
 
 71  
     private static final String COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_JSPCOMPILATIONBUILDER =
 72  
         "com.ibm.etools.webtools.additions.jspcompilationbuilder";
 73  
 
 74  
     private static final String COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_LINKSBUILDER =
 75  
         "com.ibm.etools.webtools.additions.linksbuilder";
 76  
 
 77  
     private static final String COM_IBM_SSE_MODEL_STRUCTUREDBUILDER = "com.ibm.sse.model.structuredbuilder";
 78  
 
 79  
     private static final String COM_IBM_WTP_EJB_EJBNATURE = "com.ibm.wtp.ejb.EJBNature";
 80  
 
 81  
     private static final String COM_IBM_WTP_J2EE_EARNATURE = "com.ibm.wtp.j2ee.EARNature";
 82  
 
 83  
     private static final String COM_IBM_WTP_J2EE_LIB_COPY_BUILDER = "com.ibm.wtp.j2ee.LibCopyBuilder";
 84  
 
 85  
     private static final String COM_IBM_WTP_MIGRATION_MIGRATION_BUILDER = "com.ibm.wtp.migration.MigrationBuilder";
 86  
 
 87  
     private static final String COM_IBM_WTP_WEB_WEB_NATURE = "com.ibm.wtp.web.WebNature";
 88  
 
 89  
     private static final String NO_GENERATED_RESOURCE_DIRNAME = "none";
 90  
 
 91  
     private static final String ORG_ECLIPSE_JDT_CORE_JAVABUILDER = "org.eclipse.jdt.core.javabuilder";
 92  
 
 93  
     private static final String ORG_ECLIPSE_JDT_CORE_JAVANATURE = "org.eclipse.jdt.core.javanature";
 94  
 
 95  
     /**
 96  
      * The context root of the webapplication. This parameter is only used when the current project is a war project,
 97  
      * else it will be ignored.
 98  
      * 
 99  
      * @parameter
 100  
      */
 101  
     private String warContextRoot;
 102  
 
 103  
     /**
 104  
      * Use this to specify a different generated resources folder than target/generated-resources/rad6. Set to "none" to
 105  
      * skip this folder generation.
 106  
      * 
 107  
      * @parameter expression="${generatedResourceDirName}" default-value="target/generated-resources/rad6" since="2.4"
 108  
      */
 109  
     private String generatedResourceDirName;
 110  
 
 111  
     /**
 112  
      * @return Returns the warContextRoot.
 113  
      */
 114  
     public String getWarContextRoot()
 115  
     {
 116  0
         return warContextRoot;
 117  
     }
 118  
 
 119  
     /**
 120  
      * @param warContextRoot The warContextRoot to set.
 121  
      */
 122  
     public void setWarContextRoot( String warContextRoot )
 123  
     {
 124  0
         this.warContextRoot = warContextRoot;
 125  0
     }
 126  
 
 127  
     /**
 128  
      * write all rad6 configuration files. <br/> <b> NOTE: This could change the config! </b>
 129  
      * 
 130  
      * @see EclipsePlugin#writeConfiguration()
 131  
      * @param deps resolved dependencies to handle
 132  
      * @throws MojoExecutionException if the config files could not be written.
 133  
      */
 134  
     protected void writeExtraConfiguration( EclipseWriterConfig config )
 135  
         throws MojoExecutionException
 136  
     {
 137  0
         super.writeExtraConfiguration( config );
 138  
 
 139  0
         new RadJ2EEWriter().init( getLog(), config ).write();
 140  
 
 141  0
         new RadWebSettingsWriter( this.warContextRoot ).init( getLog(), config ).write();
 142  
 
 143  0
         new RadWebsiteConfigWriter().init( getLog(), config ).write();
 144  
 
 145  0
         new RadApplicationXMLWriter().init( getLog(), config ).write();
 146  
 
 147  0
         new RadLibCopier().init( getLog(), config ).write();
 148  
 
 149  0
         new RadEjbClasspathWriter().init( getLog(), config ).write();
 150  0
     }
 151  
 
 152  
     /**
 153  
      * make room for a Manifest file. use a generated resource for JARS and for WARS use the manifest in the
 154  
      * webapp/meta-inf directory.
 155  
      * 
 156  
      * @throws MojoExecutionException
 157  
      */
 158  
     private void addManifestResource( EclipseWriterConfig config )
 159  
         throws MojoExecutionException
 160  
     {
 161  0
         if ( isJavaProject() )
 162  
         {
 163  
             // special case must be done first because it can add stuff to the classpath that will be
 164  
             // written by the superclass
 165  0
             new RadManifestWriter().init( getLog(), config ).write();
 166  
         }
 167  
 
 168  0
         if ( isJavaProject() && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) &&
 169  
             !Constants.PROJECT_PACKAGING_WAR.equals( packaging ) &&
 170  
             !Constants.PROJECT_PACKAGING_EJB.equals( packaging ) &&
 171  
             !NO_GENERATED_RESOURCE_DIRNAME.equals( this.generatedResourceDirName ) )
 172  
         {
 173  
 
 174  0
             String generatedResourceDir =
 175  
                 this.project.getBasedir().getAbsolutePath() + File.separatorChar + this.generatedResourceDirName;
 176  
 
 177  0
             String metainfDir = generatedResourceDir + File.separatorChar + "META-INF";
 178  
 
 179  0
             new File( metainfDir ).mkdirs();
 180  
 
 181  0
             final Resource resource = new Resource();
 182  
 
 183  0
             getLog().debug( "Adding " + this.generatedResourceDirName + " to resources" );
 184  
 
 185  0
             resource.setDirectory( generatedResourceDir );
 186  
 
 187  0
             this.executedProject.addResource( resource );
 188  
         }
 189  
 
 190  0
         if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 191  
         {
 192  0
             new File( getWebContentBaseDirectory( config ) + File.separatorChar + "META-INF" ).mkdirs();
 193  
         }
 194  0
     }
 195  
 
 196  
     /**
 197  
      * Returns absolute path to the web content directory based on configuration of the war plugin or default one
 198  
      * otherwise.
 199  
      * 
 200  
      * @param project
 201  
      * @return absolute directory path as String
 202  
      * @throws MojoExecutionException
 203  
      */
 204  
     private static String getWebContentBaseDirectory( EclipseWriterConfig config )
 205  
         throws MojoExecutionException
 206  
     {
 207  
         // getting true location of web source dir from config
 208  0
         File warSourceDirectory =
 209  
             new File( IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
 210  
                                                  "warSourceDirectory", "src/main/webapp" ) );
 211  
         // getting real and correct path to the web source dir
 212  0
         String webContentDir =
 213  
             IdeUtils.toRelativeAndFixSeparator( config.getEclipseProjectDirectory(), warSourceDirectory, false );
 214  
 
 215  
         // getting the path to meta-inf base dir
 216  0
         String result = config.getProject().getBasedir().getAbsolutePath() + File.separatorChar + webContentDir;
 217  
 
 218  0
         return result;
 219  
     }
 220  
 
 221  
     /**
 222  
      * overwite the default builders with the builders required by RAD6.
 223  
      * 
 224  
      * @param packaging packaging-type (jar,war,ejb,ear)
 225  
      */
 226  
     protected void fillDefaultBuilders( String packaging )
 227  
     {
 228  0
         super.fillDefaultBuilders( packaging );
 229  
 
 230  0
         ArrayList buildcommands = new ArrayList();
 231  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 232  
         {
 233  0
             buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
 234  0
             buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
 235  
         }
 236  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 237  
         {
 238  0
             buildcommands.add( COM_IBM_WTP_MIGRATION_MIGRATION_BUILDER );
 239  0
             buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
 240  0
             buildcommands.add( COM_IBM_ETOOLS_J2EE_UI_LIB_DIR_BUILDER );
 241  0
             buildcommands.add( COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_LINKSBUILDER );
 242  0
             buildcommands.add( COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATEBUILDER );
 243  0
             buildcommands.add( COM_IBM_ETOOLS_SITEEDIT_SITE_NAV_BUILDER );
 244  0
             buildcommands.add( COM_IBM_ETOOLS_SITEEDIT_SITE_UPDATE_BUILDER );
 245  0
             buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
 246  0
             buildcommands.add( COM_IBM_WTP_J2EE_LIB_COPY_BUILDER );
 247  0
             buildcommands.add( COM_IBM_ETOOLS_WEBTOOLS_ADDITIONS_JSPCOMPILATIONBUILDER );
 248  0
             buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
 249  
         }
 250  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 251  
         {
 252  0
             buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
 253  0
             buildcommands.add( COM_IBM_ETOOLS_VALIDATION_VALIDATIONBUILDER );
 254  0
             buildcommands.add( COM_IBM_WTP_J2EE_LIB_COPY_BUILDER );
 255  0
             buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
 256  
         }
 257  0
         else if ( isJavaProject() )
 258  
         {
 259  0
             buildcommands.add( ORG_ECLIPSE_JDT_CORE_JAVABUILDER );
 260  0
             buildcommands.add( COM_IBM_SSE_MODEL_STRUCTUREDBUILDER );
 261  
         }
 262  0
         setBuildcommands( buildcommands );
 263  0
     }
 264  
 
 265  
     /**
 266  
      * overwite the default natures with the natures required by RAD6.
 267  
      * 
 268  
      * @param packaging packaging-type (jar,war,ejb,ear)
 269  
      */
 270  
     protected void fillDefaultNatures( String packaging )
 271  
     {
 272  0
         super.fillDefaultNatures( packaging );
 273  
 
 274  0
         ArrayList projectnatures = new ArrayList();
 275  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 276  
         {
 277  0
             projectnatures.add( COM_IBM_WTP_J2EE_EARNATURE );
 278  
         }
 279  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 280  
         {
 281  0
             projectnatures.add( COM_IBM_WTP_WEB_WEB_NATURE );
 282  0
             projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
 283  0
             projectnatures.add( COM_IBM_ETOOLS_SITEEDIT_WEB_SITE_NATURE );
 284  0
             projectnatures.add( COM_IBM_ETOOLS_WEBPAGE_TEMPLATE_TEMPLATENATURE );
 285  
         }
 286  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 287  
         {
 288  0
             projectnatures.add( COM_IBM_WTP_EJB_EJBNATURE );
 289  0
             projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
 290  
         }
 291  0
         else if ( isJavaProject() )
 292  
         {
 293  0
             projectnatures.add( ORG_ECLIPSE_JDT_CORE_JAVANATURE );
 294  
         }
 295  0
         setProjectnatures( projectnatures );
 296  0
     }
 297  
 
 298  
     /**
 299  
      * Utility method that locates a project producing the given artifact.
 300  
      * 
 301  
      * @param artifact the artifact a project should produce.
 302  
      * @return <code>true</code> if the artifact is produced by a reactor projectart.
 303  
      */
 304  
     protected boolean isAvailableAsAReactorProject( Artifact artifact )
 305  
     {
 306  0
         if ( this.reactorProjects != null &&
 307  
             ( Constants.PROJECT_PACKAGING_JAR.equals( artifact.getType() ) ||
 308  
                 Constants.PROJECT_PACKAGING_EJB.equals( artifact.getType() ) || Constants.PROJECT_PACKAGING_WAR.equals( artifact.getType() ) ) )
 309  
         {
 310  0
             for ( Iterator iter = this.reactorProjects.iterator(); iter.hasNext(); )
 311  
             {
 312  0
                 MavenProject reactorProject = (MavenProject) iter.next();
 313  
 
 314  0
                 if ( reactorProject.getGroupId().equals( artifact.getGroupId() ) &&
 315  
                     reactorProject.getArtifactId().equals( artifact.getArtifactId() ) )
 316  
                 {
 317  0
                     if ( reactorProject.getVersion().equals( artifact.getVersion() ) )
 318  
                     {
 319  0
                         return true;
 320  
                     }
 321  
                     else
 322  
                     {
 323  0
                         getLog().info(
 324  
                                        "Artifact " +
 325  
                                            artifact.getId() +
 326  
                                            " already available as a reactor project, but with different version. Expected: " +
 327  
                                            artifact.getVersion() + ", found: " + reactorProject.getVersion() );
 328  
                     }
 329  
                 }
 330  0
             }
 331  
         }
 332  0
         return false;
 333  
     }
 334  
 
 335  
     /**
 336  
      * WARNING: The manifest resources added here will not have the benefit of the dependencies of the project, since
 337  
      * that's not provided in the setup() apis...
 338  
      */
 339  
     protected void setupExtras()
 340  
         throws MojoExecutionException
 341  
     {
 342  0
         super.setupExtras();
 343  
 
 344  0
         IdeDependency[] deps = doDependencyResolution();
 345  
 
 346  0
         EclipseWriterConfig config = createEclipseWriterConfig( deps );
 347  
 
 348  0
         addManifestResource( config );
 349  0
     }
 350  
 }