Coverage Report - org.apache.maven.plugin.eclipse.MyEclipsePlugin
 
Classes in this File Line Coverage Branch Coverage Complexity
MyEclipsePlugin
0%
0/81
0%
0/60
4
 
 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 <p/>
 63  
      *
 64  
      * <pre>
 65  
      *   &lt;spring&gt;
 66  
      *     &lt;version&gt;1.0/2.0&lt;/version&gt;
 67  
      *     &lt;file-pattern&gt;applicationContext-*.xml&lt;/file-pattern&gt;
 68  
      *     &lt;basedir&gt;src/main/resources&lt;/basedir&gt;
 69  
      *   &lt;/spring&gt;
 70  
      * </pre>
 71  
      *
 72  
      * @parameter
 73  
      */
 74  
     private Map spring;
 75  
 
 76  
     /**
 77  
      * Hibernate configuration placeholder <p/>
 78  
      *
 79  
      * <pre>
 80  
      *   &lt;hibernate&gt;
 81  
      *     &lt;config-file&gt;src/main/resources/applicationContext-persistence.xml&lt;/config-file&gt;
 82  
      *     &lt;session-factory-id&gt;mySessionFactory&lt;/session-factory-id&gt;
 83  
      *   &lt;/hibernate&gt;
 84  
      * </pre>
 85  
      *
 86  
      * @parameter
 87  
      */
 88  
     private Map hibernate;
 89  
 
 90  
     /**
 91  
      * Allow declaration of struts properties for MyEclipse <p/>
 92  
      *
 93  
      * <pre>
 94  
      *   &lt;struts&gt;
 95  
      *     &lt;version&gt;1.2.9&lt;/version&gt;
 96  
      *     &lt;servlet-name&gt;action&lt;/servlet-name&gt;
 97  
      *     &lt;pattern&gt;*.do&lt;/pattern&gt;
 98  
      *     &lt;base-package&gt;1.2.9&lt;/base-package&gt;
 99  
      *   &lt;/struts&gt;
 100  
      * </pre>
 101  
      *
 102  
      * @parameter
 103  
      */
 104  
     private Map struts;
 105  
 
 106  
     /**
 107  
      * {@inheritDoc}
 108  
      */
 109  
     protected void writeConfigurationExtras( EclipseWriterConfig config )
 110  
         throws MojoExecutionException
 111  
     {
 112  0
         super.writeConfigurationExtras( config );
 113  0
         if ( isJavaProject() )
 114  
         {
 115  
             // If the project is a Web Project, make it compile in WEB-INF/classes
 116  0
             if ( Constants.PROJECT_PACKAGING_WAR.equals( project.getPackaging() ) )
 117  
             {
 118  0
                 String warSourceDirectory =
 119  
                     IdeUtils.getPluginSetting( config.getProject(), JeeUtils.ARTIFACT_MAVEN_WAR_PLUGIN,
 120  
                                                "warSourceDirectory",//$NON-NLS-1$
 121  
                                                "/src/main/webapp" ); //$NON-NLS-1$
 122  
 
 123  0
                 EclipseSourceDir[] sourceDirs = config.getSourceDirs();
 124  0
                 for ( int i = 0; i < sourceDirs.length; i++ )
 125  
                 {
 126  0
                     if ( !sourceDirs[i].isTest() )
 127  
                     {
 128  0
                         sourceDirs[i].setOutput( warSourceDirectory + "/WEB-INF/classes" );
 129  
                     }
 130  
                 }
 131  
             }
 132  
         }
 133  
 
 134  
         // the MyEclipse part ...
 135  
 
 136  0
         new MyEclipseMetadataWriter().init( getLog(), config ).write();
 137  
 
 138  0
         if ( getStruts() != null )
 139  
         {
 140  0
             new MyEclipseStrutsDataWriter( getStruts() ).init( getLog(), config ).write();
 141  
         }
 142  0
         if ( getSpring() != null )
 143  
         {
 144  0
             new MyEclipseSpringBeansWriter( getSpring() ).init( getLog(), config ).write();
 145  
         }
 146  0
         if ( getHibernate() != null )
 147  
         {
 148  
             // Only Spring configuration file is currently supported
 149  0
             String hbmCfgFile = (String) getHibernate().get( "config-file" );
 150  
 
 151  0
             if ( "".equals( hbmCfgFile ) )
 152  
             {
 153  0
                 hbmCfgFile = MYECLIPSE_DEFAULT_HIBERNATE_CFG_XML;
 154  
             }
 155  
 
 156  0
             new MyEclipseHibernateWriter( getHibernate() ).init( getLog(), config ).write();
 157  
         }
 158  0
     }
 159  
 
 160  
     /**
 161  
      * Override the default builders with the builders used by MyEclipse
 162  
      *
 163  
      * @param packaging packaging-type (jar,war,ejb,ear)
 164  
      */
 165  
     protected void fillDefaultBuilders( String packaging )
 166  
     {
 167  0
         List commands = new ArrayList();
 168  
 
 169  0
         super.fillDefaultBuilders( packaging );
 170  
 
 171  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 172  
         {
 173  0
             if ( getLog().isDebugEnabled() )
 174  
             {
 175  0
                 getLog().debug( "EAR packaging does not need specific builders" );
 176  
             }
 177  
         }
 178  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 179  
         {
 180  0
             commands.add( MYECLIPSE_DEPLOYMENT_DESCRIPTOR_VALIDATOR_BUILDER );
 181  0
             commands.add( MYECLIPSE_J2EE_PROJECT_VALIDATOR_BUILDER );
 182  0
             commands.add( MYECLIPSE_WEB_CLASSPATH_BUILDER );
 183  
 
 184  
             // WST Validation Builder : may be added by super.fillDefaultBuilders so check before adding it
 185  0
             if ( !getBuildcommands().contains( new BuildCommand( BUILDER_WST_VALIDATION ) ) )
 186  
             {
 187  0
                 commands.add( BUILDER_WST_VALIDATION );
 188  
             }
 189  
         }
 190  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 191  
         {
 192  0
             if ( getLog().isInfoEnabled() )
 193  
             {
 194  0
                 getLog().info( "EJB packaging is not implemented yet" );
 195  
             }
 196  
         }
 197  0
         else if ( isJavaProject() )
 198  
         {
 199  0
             if ( getLog().isDebugEnabled() )
 200  
             {
 201  0
                 getLog().debug( "JAR packaging does not need specific builders" );
 202  
             }
 203  
         }
 204  
 
 205  0
         if ( getSpring() != null )
 206  
         {
 207  0
             commands.add( MYECLIPSE_SPRING_BUILDER );
 208  
         }
 209  0
         if ( getHibernate() != null )
 210  
         {
 211  0
             commands.add( MYECLIPSE_HIBERNATE_BUILDER );
 212  
         }
 213  
 
 214  0
         convertBuildCommandList( commands );
 215  0
         getBuildcommands().addAll( commands );
 216  0
     }
 217  
 
 218  
     /**
 219  
      * Override the default natures with the natures used by MyEclipse
 220  
      *
 221  
      * @param packaging packaging-type (jar,war,ejb,ear)
 222  
      */
 223  
     protected void fillDefaultNatures( String packaging )
 224  
     {
 225  0
         List natures = new ArrayList();
 226  
 
 227  0
         super.fillDefaultNatures( packaging );
 228  
 
 229  0
         if ( Constants.PROJECT_PACKAGING_EAR.equals( packaging ) )
 230  
         {
 231  0
             natures.add( MYECLIPSE_EAR_NATURE );
 232  
         }
 233  0
         else if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 234  
         {
 235  0
             natures.add( MYECLIPSE_WEB_NATURE );
 236  
         }
 237  0
         else if ( Constants.PROJECT_PACKAGING_EJB.equals( packaging ) )
 238  
         {
 239  0
             if ( getLog().isInfoEnabled() )
 240  
             {
 241  0
                 getLog().info( "EJB packaging is not implemented yet" );
 242  
             }
 243  
         }
 244  0
         else if ( isJavaProject() )
 245  
         {
 246  0
             if ( getLog().isDebugEnabled() )
 247  
             {
 248  0
                 getLog().debug( "JAR projects does not need specific natures" );
 249  
             }
 250  
         }
 251  
 
 252  
         // Spring
 253  0
         if ( getSpring() != null )
 254  
         {
 255  0
             natures.add( MYECLISPE_SPRING_NATURE );
 256  
         }
 257  
         // Struts
 258  0
         if ( getStruts() != null )
 259  
         {
 260  0
             natures.add( MYECLIPSE_STRUTS_NATURE );
 261  
         }
 262  
 
 263  
         // Hibernate
 264  0
         if ( getHibernate() != null )
 265  
         {
 266  0
             natures.add( MYECLIPSE_HIBERNATE_NATURE );
 267  
         }
 268  
 
 269  0
         getProjectnatures().addAll( natures );
 270  0
     }
 271  
 
 272  
     protected void fillDefaultClasspathContainers( String packaging )
 273  
     {
 274  0
         super.fillDefaultClasspathContainers( packaging );
 275  
 
 276  0
         if ( Constants.PROJECT_PACKAGING_WAR.equals( packaging ) )
 277  
         {
 278  0
             String jeeVersion =
 279  
                 JeeUtils.getJeeDescriptorFromServletVersion( JeeUtils.resolveServletVersion( project ) ).getJeeVersion();
 280  
 
 281  0
             if ( "1.3".equals( jeeVersion ) )
 282  
             {
 283  0
                 getClasspathContainers().add( MYECLIPSE_J2EE_13_CLASSPATH_CONTAINER );
 284  
             }
 285  0
             else if ( "1.4".equals( jeeVersion ) )
 286  
             {
 287  0
                 getClasspathContainers().add( MYECLIPSE_J2EE_14_CLASSPATH_CONTAINER );
 288  
             }
 289  
         }
 290  0
     }
 291  
 
 292  
     public Map getSpring()
 293  
     {
 294  0
         return spring;
 295  
     }
 296  
 
 297  
     public void setSpring( Map spring )
 298  
     {
 299  0
         this.spring = spring;
 300  0
     }
 301  
 
 302  
     public Map getHibernate()
 303  
     {
 304  0
         return hibernate;
 305  
     }
 306  
 
 307  
     public void setHibernate( Map hibernate )
 308  
     {
 309  0
         this.hibernate = hibernate;
 310  0
     }
 311  
 
 312  
     public Map getStruts()
 313  
     {
 314  0
         return struts;
 315  
     }
 316  
 
 317  
     public void setStruts( Map struts )
 318  
     {
 319  0
         this.struts = struts;
 320  0
     }
 321  
 
 322  
 }