Coverage Report - org.apache.maven.plugin.eclipse.MyEclipsePlugin
 
Classes in this File Line Coverage Branch Coverage Complexity
MyEclipsePlugin
0%
0/83
0%
0/62
4.1
 
 1  
 package org.apache.maven.plugin.eclipse;
 2  
 
 3  
 import java.util.ArrayList;
 4  
 import java.util.List;
 5  
 import java.util.Map;
 6  
 
 7  
 import org.apache.maven.plugin.MojoExecutionException;
 8  
 import org.apache.maven.plugin.eclipse.writers.EclipseWriterConfig;
 9  
 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseHibernateWriter;
 10  
 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseMetadataWriter;
 11  
 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseSpringBeansWriter;
 12  
 import org.apache.maven.plugin.eclipse.writers.myeclipse.MyEclipseStrutsDataWriter;
 13  
 import org.apache.maven.plugin.ide.IdeUtils;
 14  
 import org.apache.maven.plugin.ide.JeeUtils;
 15  
 
 16  
 /**
 17  
  * Generates MyEclipse configuration files
 18  
  * 
 19  
  * @author <a href="mailto:olivier.jacob@gmail.com">Olivier Jacob</a>
 20  
  * @goal myeclipse
 21  
  * @since 2.5
 22  
  * @execute phase="generate-resources"
 23  
  */
 24  0
 public class MyEclipsePlugin
 25  
     extends EclipsePlugin
 26  
 {
 27  
     /* MyEclipse project natures */
 28  
     private static final String MYECLIPSE_EAR_NATURE = "com.genuitec.eclipse.j2eedt.core.earnature";
 29  
 
 30  
     private static final String MYECLIPSE_WEB_NATURE = "com.genuitec.eclipse.j2eedt.core.webnature";
 31  
 
 32  
     private static final String MYECLISPE_SPRING_NATURE = "com.genuitec.eclipse.springframework.springnature";
 33  
 
 34  
     private static final String MYECLIPSE_STRUTS_NATURE =
 35  
         "com.genuitec.eclipse.cross.easystruts.eclipse.easystrutsnature";
 36  
 
 37  
     private static final String MYECLIPSE_HIBERNATE_NATURE = "com.genuitec.eclipse.hibernate.hibernatenature";
 38  
 
 39  
     /* MyEclipse builders */
 40  
     private static final String MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER =
 41  
         "com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator";
 42  
 
 43  
     private static final String MYECLIPSE_WEB_CLASSPATH_BUILDER =
 44  
         "com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder";
 45  
 
 46  
     private static final String MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER =
 47  
         "com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator";
 48  
 
 49  
     private static final String MYECLIPSE_SPRING_BUILDER = "com.genuitec.eclipse.springframework.springbuilder";
 50  
 
 51  
     private static final String MYECLIPSE_HIBERNATE_BUILDER = "com.genuitec.eclipse.hibernate.HibernateBuilder";
 52  
 
 53  
     private static final String MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER =
 54  
         "com.genuitec.eclipse.j2eedt.core.J2EE14_CONTAINER";
 55  
 
 56  
     private static final String MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER =
 57  
         "com.genuitec.eclipse.j2eedt.core.J2EE13_CONTAINER";
 58  
 
 59  
     private static final String MYECLIPSE_DEFAULT_HIBERNATE_CFG_XML = "src/main/resources/applicationContext.xml";
 60  
 
 61  
     /**
 62  
      * Spring configuration placeholder
 63  
      * <p/>
 64  
      * 
 65  
      * <pre>
 66  
      *   &lt;spring&gt;
 67  
      *     &lt;version&gt;1.0/2.0&lt;/version&gt;
 68  
      *     &lt;file-pattern&gt;applicationContext-*.xml&lt;/file-pattern&gt;
 69  
      *     &lt;basedir&gt;src/main/resources&lt;/basedir&gt;
 70  
      *   &lt;/spring&gt;
 71  
      * </pre>
 72  
      * 
 73  
      * @parameter
 74  
      */
 75  
     private Map spring;
 76  
 
 77  
     /**
 78  
      * Hibernate configuration placeholder
 79  
      * <p/>
 80  
      * 
 81  
      * <pre>
 82  
      *   &lt;hibernate&gt;
 83  
      *     &lt;config-file&gt;src/main/resources/applicationContext-persistence.xml&lt;/config-file&gt;
 84  
      *     &lt;session-factory-id&gt;mySessionFactory&lt;/session-factory-id&gt;
 85  
      *   &lt;/hibernate&gt;
 86  
      * </pre>
 87  
      * 
 88  
      * @parameter
 89  
      */
 90  
     private Map hibernate;
 91  
 
 92  
     /**
 93  
      * Allow declaration of struts properties for MyEclipse
 94  
      * <p/>
 95  
      * 
 96  
      * <pre>
 97  
      *   &lt;struts&gt;
 98  
      *     &lt;version&gt;1.2.9&lt;/version&gt;
 99  
      *     &lt;servlet-name&gt;action&lt;/servlet-name&gt;
 100  
      *     &lt;pattern&gt;*.do&lt;/pattern&gt;
 101  
      *     &lt;base-package&gt;1.2.9&lt;/base-package&gt;
 102  
      *   &lt;/struts&gt;
 103  
      * </pre>
 104  
      * 
 105  
      * @parameter
 106  
      */
 107  
     private Map struts;
 108  
 
 109  
     /**
 110  
      * {@inheritDoc}
 111  
      */
 112  
     protected void writeConfigurationExtras( EclipseWriterConfig config )
 113  
         throws MojoExecutionException
 114  
     {
 115  0
         super.writeConfigurationExtras( config );
 116  0
         if ( isJavaProject() )
 117  
         {
 118  
             // If the project is a Web Project, make it compile in WEB-INF/classes
 119  0
             if ( Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
 120  
             {
 121  0
                 String warSourceDirectory =
 122  
                     IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
 123  
                                                "warSourceDirectory",//$NON-NLS-1$
 124  
                                                "/src/main/webapp" ); //$NON-NLS-1$
 125  
 
 126  0
                 EclipseSourceDir[] sourceDirs = config.getSourceDirs();
 127  0
                 for ( int i = 0; i < sourceDirs.length; i++ )
 128  
                 {
 129  0
                     if ( !sourceDirs[i].isTest() )
 130  
                     {
 131  0
                         sourceDirs[i].setOutput( warSourceDirectory + "/WEB-INF/classes" );
 132  
                     }
 133  
                 }
 134  
             }
 135  
         }
 136  
 
 137  
         // the MyEclipse part ...
 138  
 
 139  0
         new MyEclipseMetadataWriter().init( getLog(), config ).write();
 140  
 
 141  0
         if ( getStruts() != null )
 142  
         {
 143  0
             new MyEclipseStrutsDataWriter( getStruts() ).init( getLog(), config ).write();
 144  
         }
 145  0
         if ( getSpring() != null )
 146  
         {
 147  0
             new MyEclipseSpringBeansWriter( getSpring() ).init( getLog(), config ).write();
 148  
         }
 149  0
         if ( getHibernate() != null )
 150  
         {
 151  
             // Only Spring configuration file is currently supported
 152  0
             String hbmCfgFile = (String) getHibernate().get( "config-file" );
 153  
 
 154  0
             if ( "".equals( hbmCfgFile ) )
 155  
             {
 156  0
                 hbmCfgFile = MYECLIPSE_DEFAULT_HIBERNATE_CFG_XML;
 157  
             }
 158  
 
 159  0
             new MyEclipseHibernateWriter( getHibernate() ).init( getLog(), config ).write();
 160  
         }
 161  0
     }
 162  
 
 163  
     /**
 164  
      * Override the default builders with the builders used by MyEclipse
 165  
      * 
 166  
      * @param packaging packaging-type (jar,war,ejb,ear)
 167  
      */
 168  
     protected void fillDefaultBuilders( String packaging )
 169  
     {
 170  0
         List commands = new ArrayList();
 171  
 
 172  0
         super.fillDefaultBuilders( packaging );
 173  
 
 174  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 175  
         {
 176  0
             if ( getLog().isDebugEnabled() )
 177  
             {
 178  0
                 getLog().debug( "EAR packaging does not need specific builders" );
 179  
             }
 180  
         }
 181  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 182  
         {
 183  0
             commands.add( MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER );
 184  0
             commands.add( MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER );
 185  0
             commands.add( MYECLIPSE_WEB_CLASSPATH_BUILDER );
 186  
 
 187  
             // WST Validation Builder : may be added by super.fillDefaultBuilders so check before adding it
 188  0
             if ( !getBuildcommands().contains( new BuildCommand( BUILDER_WST_VALIDATION ) ) )
 189  
             {
 190  0
                 commands.add( BUILDER_WST_VALIDATION );
 191  
             }
 192  
         }
 193  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 194  
         {
 195  0
             if ( getLog().isInfoEnabled() )
 196  
             {
 197  0
                 getLog().info( "EJB packaging is not implemented yet" );
 198  
             }
 199  
         }
 200  0
         else if ( isJavaProject() )
 201  
         {
 202  0
             if ( getLog().isDebugEnabled() )
 203  
             {
 204  0
                 getLog().debug( "JAR packaging does not need specific builders" );
 205  
             }
 206  
         }
 207  
 
 208  0
         if ( getSpring() != null )
 209  
         {
 210  0
             commands.add( MYECLIPSE_SPRING_BUILDER );
 211  
         }
 212  0
         if ( getHibernate() != null )
 213  
         {
 214  0
             commands.add( MYECLIPSE_HIBERNATE_BUILDER );
 215  
         }
 216  
 
 217  0
         convertBuildCommandList( commands );
 218  0
         getBuildcommands().addAll( commands );
 219  0
     }
 220  
 
 221  
     /**
 222  
      * Override the default natures with the natures used by MyEclipse
 223  
      * 
 224  
      * @param packaging packaging-type (jar,war,ejb,ear)
 225  
      */
 226  
     protected void fillDefaultNatures( String packaging )
 227  
     {
 228  0
         List natures = new ArrayList();
 229  
 
 230  0
         super.fillDefaultNatures( packaging );
 231  
 
 232  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 233  
         {
 234  0
             natures.add( MYECLIPSE_EAR_NATURE );
 235  
         }
 236  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 237  
         {
 238  0
             natures.add( MYECLIPSE_WEB_NATURE );
 239  
         }
 240  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 241  
         {
 242  0
             if ( getLog().isInfoEnabled() )
 243  
             {
 244  0
                 getLog().info( "EJB packaging is not implemented yet" );
 245  
             }
 246  
         }
 247  0
         else if ( isJavaProject() )
 248  
         {
 249  0
             if ( getLog().isDebugEnabled() )
 250  
             {
 251  0
                 getLog().debug( "JAR projects does not need specific natures" );
 252  
             }
 253  
         }
 254  
 
 255  
         // Spring
 256  0
         if ( getSpring() != null )
 257  
         {
 258  0
             natures.add( MYECLISPE_SPRING_NATURE );
 259  
         }
 260  
         // Struts
 261  0
         if ( getStruts() != null )
 262  
         {
 263  0
             natures.add( MYECLIPSE_STRUTS_NATURE );
 264  
         }
 265  
 
 266  
         // Hibernate
 267  0
         if ( getHibernate() != null )
 268  
         {
 269  0
             natures.add( MYECLIPSE_HIBERNATE_NATURE );
 270  
         }
 271  
 
 272  0
         getProjectnatures().addAll( natures );
 273  0
     }
 274  
 
 275  
     protected void fillDefaultClasspathContainers( String packaging )
 276  
     {
 277  0
         super.fillDefaultClasspathContainers( packaging );
 278  
 
 279  0
         if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 280  
         {
 281  
             String j2eeVersion;
 282  0
             if ( this.jeeversion != null )
 283  
             {
 284  0
                 j2eeVersion = JeeUtils.getJeeDescriptorFromJeeVersion( this.jeeversion ).getJeeVersion();
 285  
             }
 286  
             else
 287  
             {
 288  0
                 j2eeVersion =
 289  
                     JeeUtils.getJeeDescriptorFromServletVersion( JeeUtils.resolveServletVersion( project ) ).getJeeVersion();
 290  
             }
 291  
 
 292  0
             if ( "1.3".equals( j2eeVersion ) )
 293  
             {
 294  0
                 getClasspathContainers().add( MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER );
 295  
             }
 296  0
             else if ( "1.4".equals( j2eeVersion ) )
 297  
             {
 298  0
                 getClasspathContainers().add( MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER );
 299  
             }
 300  
         }
 301  0
     }
 302  
 
 303  
     public Map getSpring()
 304  
     {
 305  0
         return spring;
 306  
     }
 307  
 
 308  
     public void setSpring( Map spring )
 309  
     {
 310  0
         this.spring = spring;
 311  0
     }
 312  
 
 313  
     public Map getHibernate()
 314  
     {
 315  0
         return hibernate;
 316  
     }
 317  
 
 318  
     public void setHibernate( Map hibernate )
 319  
     {
 320  0
         this.hibernate = hibernate;
 321  0
     }
 322  
 
 323  
     public Map getStruts()
 324  
     {
 325  0
         return struts;
 326  
     }
 327  
 
 328  
     public void setStruts( Map struts )
 329  
     {
 330  0
         this.struts = struts;
 331  0
     }
 332  
 
 333  
 }