You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by fg...@apache.org on 2005/11/26 11:48:12 UTC

svn commit: r349104 - in /maven/plugins/trunk/maven-eclipse-plugin/src: main/java/org/apache/maven/plugin/eclipse/ main/resources/org/apache/maven/plugin/eclipse/ test/java/org/apache/maven/plugin/eclipse/ test/projects/master-test/module-1/ test/proje...

Author: fgiust
Date: Sat Nov 26 02:47:54 2005
New Revision: 349104

URL: http://svn.apache.org/viewcvs?rev=349104&view=rev
Log:
PR: MNG-1430
Submitted by: Dan Allen
Reviewed by: Fabrizio Giustina
add j2ee project nature/builders to generated .project file.
By default dds wtp R7 natures/builders to projects. A new "wtpversion" flag is added for forward compatibility with wtp 1.0.

Modified:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-1/project
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-2/project

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?rev=349104&r1=349103&r2=349104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Sat Nov 26 02:47:54 2005
@@ -16,6 +16,11 @@
  * limitations under the License.
  */
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
@@ -24,15 +29,11 @@
 import org.apache.maven.plugin.MojoFailureException;
 import org.apache.maven.project.MavenProject;
 
-import java.io.File;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
 /**
  * A Maven2 plugin which integrates the use of Maven2 with Eclipse.
  *
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
  * @version $Id$
  * @goal eclipse
  * @requiresDependencyResolution test
@@ -102,8 +103,8 @@
     private List remoteArtifactRepositories;
 
     /**
-     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature is added.
-     * Configuration example:
+     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature plus the
+     * needed WTP natures are added.
      * <pre>
      *    &lt;projectnatures>
      *      &lt;java.lang.String>org.eclipse.jdt.core.javanature&lt;/java.lang.String>
@@ -112,12 +113,12 @@
      * </pre>
      *
      * @parameter
-     * @todo default-value="<java.lang.String>org.eclipse.jdt.core.javanature</java.lang.String>"
      */
     private List projectnatures;
 
     /**
-     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> nature is added.
+     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the
+     * needed WTP builders are added.
      * Configuration example:
      * <pre>
      *    &lt;buildcommands>
@@ -128,7 +129,6 @@
      * </pre>
      *
      * @parameter
-     * @todo default-value="org.eclipse.jdt.core.javabuilder"
      */
     private List buildcommands;
 
@@ -143,7 +143,6 @@
      * </pre>
      *
      * @parameter
-     * @todo default-value=empty list
      */
     private List classpathContainers;
 
@@ -152,7 +151,7 @@
      *
      * @parameter expression="${eclipse.downloadSources}"
      */
-    private boolean downloadSources = false;
+    private boolean downloadSources;
 
     /**
      * Eclipse workspace directory.
@@ -160,7 +159,7 @@
      * @parameter expression="${eclipse.workspace}"
      */
     private File outputDir;
-    
+
     /**
      * When set to false, the plugin will not create sub-projects and instead reference those sub-projects 
      * using the installed package in the local repository
@@ -178,6 +177,15 @@
     String outputDirectory;
 
     /**
+     * The version of WTP for which configuration files will be generated. At the moment the only supported version is "R7",
+     * and generated files will not be compatible with the upcoming 1.0 release and with WTP milestones &gt; M8.
+     * As soon as WTP 1.0 will be released the default will be switched to 1.0.
+     *
+     * @parameter expression="${wtpversion}" default-value="R7"
+     */
+    String wtpversion;
+
+    /**
      * Setter for <code>project</code>. Needed for tests.
      *
      * @param project The MavenProject to set.
@@ -268,11 +276,45 @@
     }
 
     /**
+     * Setter for <code>downloadSources</code>.
+     * @param downloadSources The downloadSources to set.
+     */
+    public void setDownloadSources( boolean downloadSources )
+    {
+        this.downloadSources = downloadSources;
+    }
+
+    /**
+     * Setter for <code>outputDirectory</code>.
+     * @param outputDirectory The outputDirectory to set.
+     */
+    public void setOutputDirectory( String outputDirectory )
+    {
+        this.outputDirectory = outputDirectory;
+    }
+
+    /**
+     * Setter for <code>wtpversion</code>.
+     * @param wtpversion The wtpversion to set.
+     */
+    public void setWtpversion( String wtpversion )
+    {
+        this.wtpversion = wtpversion;
+    }
+
+    /**
      * @see org.apache.maven.plugin.Mojo#execute()
      */
     public void execute()
         throws MojoExecutionException, MojoFailureException
     {
+
+        if ( !"R7".equalsIgnoreCase( wtpversion ) )
+        {
+            throw new MojoExecutionException( Messages
+                .getString( "EclipsePlugin.unsupportedwtp", new Object[] { wtpversion, "R7" } ) ); //$NON-NLS-1$
+        }
+
         if ( executedProject == null )
         {
             // backwards compat with alpha-2 only
@@ -283,17 +325,15 @@
         assertNotEmpty( executedProject.getArtifactId(), "artifactId" ); //$NON-NLS-1$
 
         // defaults
-        // @todo how set List values in @default-value??
+        String packaging = executedProject.getPackaging();
         if ( projectnatures == null )
         {
-            projectnatures = new ArrayList();
-            projectnatures.add( "org.eclipse.jdt.core.javanature" );
+            fillDefaultNatures( packaging );
         }
 
         if ( buildcommands == null )
         {
-            buildcommands = new ArrayList();
-            buildcommands.add( "org.eclipse.jdt.core.javabuilder" );
+            fillDefaultBuilders( packaging );
         }
 
         if ( classpathContainers == null )
@@ -321,22 +361,19 @@
         {
             if ( !outputDir.isDirectory() )
             {
-                throw new MojoExecutionException(
-                    Messages.getString( "EclipsePlugin.notadir", outputDir ) ); //$NON-NLS-1$
+                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", outputDir ) ); //$NON-NLS-1$
             }
 
             outputDir = new File( outputDir, executedProject.getArtifactId() );
 
             if ( !outputDir.isDirectory() && !outputDir.mkdir() )
             {
-                throw new MojoExecutionException(
-                    Messages.getString( "EclipsePlugin.cantcreatedir", outputDir ) ); //$NON-NLS-1$
+                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", outputDir ) ); //$NON-NLS-1$
             }
         }
 
         // ready to start
         write();
-
     }
 
     public void write()
@@ -352,8 +389,8 @@
             reactorArtifacts = Collections.EMPTY_LIST;
 
         // build a list of UNIQUE source dirs (both src and resources) to be used in classpath and wtpmodules
-        EclipseSourceDir[] sourceDirs =
-            EclipseUtils.buildDirectoryList( executedProject, outputDir, getLog(), outputDirectory );
+        EclipseSourceDir[] sourceDirs = EclipseUtils.buildDirectoryList( executedProject, outputDir, getLog(),
+                                                                         outputDirectory );
 
         // use project since that one has all artifacts resolved.
         new EclipseClasspathWriter( getLog() ).write( projectBaseDir, outputDir, project, reactorArtifacts, sourceDirs,
@@ -367,11 +404,10 @@
         new EclipseSettingsWriter( getLog() ).write( projectBaseDir, outputDir, project );
 
         new EclipseWtpmodulesWriter( getLog() ).write( outputDir, project, reactorArtifacts, sourceDirs,
-                                                       localRepository,artifactResolver,
-                                                       remoteArtifactRepositories );
+                                                       localRepository, artifactResolver, remoteArtifactRepositories );
 
         getLog().info( Messages.getString( "EclipsePlugin.wrote", //$NON-NLS-1$
-                                           new Object[]{project.getArtifactId(), outputDir.getAbsolutePath()} ) );
+                                           new Object[] { project.getArtifactId(), outputDir.getAbsolutePath() } ) );
     }
 
     private void assertNotEmpty( String string, String elementName )
@@ -379,18 +415,27 @@
     {
         if ( string == null )
         {
-            throw new MojoFailureException(
-                Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
+            throw new MojoFailureException( Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
         }
     }
 
-    public void setDownloadSources( boolean downloadSources )
+    private void fillDefaultBuilders( String packaging )
     {
-        this.downloadSources = downloadSources;
+        buildcommands = new ArrayList();
+        // default builders for WTP R7, 1.0 may change
+        buildcommands.add( "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder" );
+        buildcommands.add( "org.eclipse.jdt.core.javabuilder" );
+        buildcommands.add( "org.eclipse.wst.validation.validationbuilder" );
+        buildcommands.add( "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver" );
+    }
+
+    private void fillDefaultNatures( String packaging )
+    {
+        projectnatures = new ArrayList();
+        // default natures for WTP R7, 1.0 may change
+        projectnatures.add( "org.eclipse.jem.workbench.JavaEMFNature" );
+        projectnatures.add( "org.eclipse.jdt.core.javanature" );
+        projectnatures.add( "org.eclipse.wst.common.modulecore.ModuleCoreNature" );
     }
 
-    public void setOutputDirectory( String outputDirectory )
-    {
-        this.outputDirectory = outputDirectory;
-    }
 }

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=349104&r1=349103&r2=349104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties Sat Nov 26 02:47:54 2005
@@ -16,6 +16,7 @@
 EclipsePlugin.excludenotsupported=This plugin currently doesn't support exclude patterns for resources. Adding the entire directory.
 EclipsePlugin.artifactpathisnull=The artifact path was null. Artifact id: {0}
 EclipsePlugin.artifactissystemscoped=The artifact has scope ''system''. Artifact id: {0}. System path: {1}
+EclipsePlugin.unsupportedwtp=Unsupported WTP version: {0}. This plugin currently supports only the following versions: {1}.
 
 EclipseSettingsWriter.wrotesettings=Wrote settings to {0}
 EclipseSettingsWriter.cannotcreatesettings=Cannot create settings file

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java?rev=349104&r1=349103&r2=349104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java Sat Nov 26 02:47:54 2005
@@ -117,7 +117,7 @@
 
         plugin.setDownloadSources( true );
 
-        // @todo how to test injected parameters?
+        plugin.setWtpversion( "R7" );
 
         plugin.execute();
 
@@ -143,7 +143,7 @@
         List expectedLines = getLines( mavenRepo, expectedFile );
 
         List actualLines = getLines( mavenRepo, actualFile );
-        
+
         String basedir = getBasedir().replace( '\\', '/' );
 
         for ( int i = 0; i < expectedLines.size(); i++ )
@@ -153,7 +153,7 @@
             // replace some vars in the expected line, to account
             // for absolute paths that are different on each installation.
 
-            expected = StringUtils.replace(expected, "${basedir}", basedir);
+            expected = StringUtils.replace( expected, "${basedir}", basedir );
 
             if ( actualLines.size() <= i )
             {

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-1/project
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-1/project?rev=349104&r1=349103&r2=349104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-1/project (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-1/project Sat Nov 26 02:47:54 2005
@@ -1,14 +1,28 @@
-<projectDescription>
-  <name>module-1</name>
-  <comment/>
-  <projects/>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-      <arguments/>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-  </natures>
+<projectDescription>
+  <name>module-1</name>
+  <comment/>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.wst.validation.validationbuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</name>
+      <arguments/>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+  </natures>
 </projectDescription>

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-2/project
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-2/project?rev=349104&r1=349103&r2=349104&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-2/project (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/master-test/module-2/project Sat Nov 26 02:47:54 2005
@@ -1,16 +1,30 @@
-<projectDescription>
-  <name>module-2</name>
-  <comment/>
-  <projects>
-    <project>module-1</project>
-  </projects>
-  <buildSpec>
-    <buildCommand>
-      <name>org.eclipse.jdt.core.javabuilder</name>
-      <arguments/>
-    </buildCommand>
-  </buildSpec>
-  <natures>
-    <nature>org.eclipse.jdt.core.javanature</nature>
-  </natures>
+<projectDescription>
+  <name>module-2</name>
+  <comment/>
+  <projects>
+    <project>module-1</project>
+  </projects>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.wst.validation.validationbuilder</name>
+      <arguments/>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver</name>
+      <arguments/>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
+  </natures>
 </projectDescription>