maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fgi...@apache.org
Subject svn commit: r359477 [1/2] - in /maven/plugins/trunk/maven-eclipse-plugin/src: main/java/org/apache/maven/plugin/eclipse/ main/java/org/apache/maven/plugin/eclipse/writers/ test/java/org/apache/maven/plugin/eclipse/ test/projects/project-1/ test/project...
Date Wed, 28 Dec 2005 10:51:40 GMT
Author: fgiust
Date: Wed Dec 28 02:51:19 2005
New Revision: 359477

URL: http://svn.apache.org/viewcvs?rev=359477&view=rev
Log:
PR: MECLIPSE-47
Submitted by: Rahul Thakur
Reviewed by: Fabrizio Giustina
Partial patch for WTP 1.0 support, with some changes from the initial contribution. WTP r7 is still the default.

Added:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java   (with props)
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java   (with props)
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpSettingsWriter.java   (with props)
Modified:
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWtpmodulesWriter.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginMasterProjectTest.java
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-1/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-10/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-2/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-3/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-4/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-5/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-6/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-7/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-8/pom.xml
    maven/plugins/trunk/maven-eclipse-plugin/src/test/projects/project-9/pom.xml

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/AddMavenRepoMojo.java Wed Dec 28 02:51:19 2005
@@ -30,21 +30,46 @@
 import org.codehaus.plexus.util.StringUtils;
 
 /**
- * A Maven2 plugin to ensure that the classpath variable MAVEN_REPO exists in the Eclipse environment.
- *
+ * A Maven2 plugin to ensure that the classpath variable MAVEN_REPO exists in
+ * the Eclipse environment.
+ * 
  * @goal add-maven-repo
  * @requiresProject false
  */
 public class AddMavenRepoMojo
     extends AbstractMojo
 {
+
+    /**
+     * Path under Eclipse workspace where Eclipse Plugin metadata/config is
+     * stored.
+     */
+    private static final String DIR_ECLIPSE_PLUGINS_METADATA = ".metadata/.plugins";
+
+    /**
+     * Path under {@value #DIR_ECLIPSE_PLUGINS_METADATA } folder where Eclipse
+     * Workspace Runtime settings are stored.
+     */
+    private static final String DIR_ECLIPSE_CORE_RUNTIME_SETTINGS = DIR_ECLIPSE_PLUGINS_METADATA
+        + "/org.eclipse.core.runtime/.settings";
+
+    /**
+     * File that stores the Eclipse JDT Core preferences.
+     */
+    private static final String FILE_ECLIPSE_JDT_CORE_PREFS = "org.eclipse.jdt.core.prefs";
+
+    /**
+     * Property constant under which Variable 'M2_REPO' is setup.
+     */
+    private static final String CLASSPATH_VARIABLE_M2_REPO = "org.eclipse.jdt.core.classpathVariable.M2_REPO";
+
     /**
-     * Location of the <code>Eclipse</code> workspace that holds your configuration and source.
+     * Location of the <code>Eclipse</code> workspace that holds your
+     * configuration and source. On Windows, this will be the
+     * <code>workspace</code> directory under your eclipse installation. For
+     * example, if you installed eclipse into <code>c:\eclipse</code>, the
+     * workspace is <code>c:\eclipse\workspace</code>.
      * 
-     * On Windows, this will be the <code>workspace</code> directory under your eclipse
-     *     installation. For example, if you installed eclipse into <code>c:\eclipse</code>, the
-     *     workspace is <code>c:\eclipse\workspace</code>.
-     *
      * @parameter expression="${eclipse.workspace}"
      * @required
      */
@@ -61,12 +86,12 @@
         throws MojoExecutionException
     {
 
-        File workDir = new File( workspace, ".metadata/.plugins/org.eclipse.core.runtime/.settings" ); //$NON-NLS-1$
+        File workDir = new File( workspace, DIR_ECLIPSE_CORE_RUNTIME_SETTINGS ); //$NON-NLS-1$
         workDir.mkdirs();
 
         Properties props = new Properties();
 
-        File f = new File( workDir, "org.eclipse.jdt.core.prefs" ); //$NON-NLS-1$
+        File f = new File( workDir, FILE_ECLIPSE_JDT_CORE_PREFS ); //$NON-NLS-1$
 
         // preserve old settings
         if ( f.exists() )
@@ -87,7 +112,7 @@
             }
         }
 
-        props.put( "org.eclipse.jdt.core.classpathVariable.M2_REPO", //$NON-NLS-1$
+        props.put( CLASSPATH_VARIABLE_M2_REPO, //$NON-NLS-1$
                    StringUtils.replace( localRepository.getBasedir(), ":", "\\:" ) ); //$NON-NLS-1$  //$NON-NLS-2$
 
         try

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseCleanMojo.java Wed Dec 28 02:51:19 2005
@@ -17,19 +17,44 @@
  */
 
 import java.io.File;
+import java.io.IOException;
 import java.text.MessageFormat;
 
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.codehaus.plexus.util.FileUtils;
 
 /**
- * A Maven2 plugin to delete the .project, .classpath and .wtpmodules files needed for Eclipse.
- *
+ * A Maven2 plugin to delete the .project, .classpath, .wtpmodules files and
+ * .settings folder needed for Eclipse.
+ * 
  * @goal clean
  */
 public class EclipseCleanMojo
     extends AbstractMojo
 {
+
+    /**
+     * Definition file for Eclipse Web Tools project.
+     */
+    private static final String FILE_DOT_WTPMODULES = ".wtpmodules";
+
+    /**
+     * Classpath definition file for an Eclipse Java project.
+     */
+    private static final String FILE_DOT_CLASSPATH = ".classpath";
+
+    /**
+     * Project definition file for an Eclipse Project.
+     */
+    private static final String FILE_DOT_PROJECT = ".project";
+
+    /**
+     * Web Project definition file for Eclipse Web Tools Project (Release 1.0RC5
+     * compatible).
+     */
+    private static final String DIR_DOT_SETTINGS = ".settings";
+
     /**
      * @parameter expression="${basedir}"
      */
@@ -38,15 +63,19 @@
     public void execute()
         throws MojoExecutionException
     {
-        delete( new File( basedir, ".project" ) );
-        delete( new File( basedir, ".classpath" ) );
-        delete( new File( basedir, ".wtpmodules" ) );
+        delete( new File( basedir, FILE_DOT_PROJECT ) );
+        delete( new File( basedir, FILE_DOT_CLASSPATH ) );
+        delete( new File( basedir, FILE_DOT_WTPMODULES ) );
+        delete( new File( basedir, DIR_DOT_SETTINGS ) );
     }
 
     /**
      * Delete a file, handling log messages and exceptions
-     * @param f File to be deleted
-     * @throws MojoExecutionException only if a file exists and can't be deleted
+     * 
+     * @param f
+     *            File to be deleted
+     * @throws MojoExecutionException
+     *             only if a file exists and can't be deleted
      */
     private void delete( File f )
         throws MojoExecutionException
@@ -57,11 +86,23 @@
         {
             if ( !f.delete() )
             {
-                throw new MojoExecutionException( MessageFormat.format( "Failed to delete {0} file: {0}", new Object[] {
-                    f.getName(),
-                    f.getAbsolutePath() } ) )
+                try
+                {
+                    if ( getLog().isDebugEnabled() )
+                        getLog().debug(
+                                        MessageFormat.format( "Forcibly deleting {0} file...", new Object[] { f
+                                            .getName() } ) );
+                    FileUtils.forceDelete( f );
+                }
+                catch ( IOException e )
                 {
-                };
+                    throw new MojoExecutionException( MessageFormat.format( "Failed to delete {0} file: {0}",
+                                                                            new Object[] {
+                                                                                f.getName(),
+                                                                                f.getAbsolutePath() } ) )
+                    {
+                    };
+                }
             }
         }
         else

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=359477&r1=359476&r2=359477&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 Wed Dec 28 02:51:19 2005
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Iterator;
@@ -33,8 +34,10 @@
 import org.apache.maven.plugin.eclipse.writers.EclipseClasspathWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseProjectWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseSettingsWriter;
+import org.apache.maven.plugin.eclipse.writers.EclipseWtpSettingsWriter;
 import org.apache.maven.plugin.eclipse.writers.EclipseWtpmodulesWriter;
 import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * A Maven2 plugin which integrates the use of Maven2 with Eclipse.
@@ -49,9 +52,41 @@
 public class EclipsePlugin
     extends AbstractMojo
 {
+
+    private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature";
+
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver";
+
+    private static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder";
+
+    private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder";
+
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder";
+
+    private static final String NATURE_WST_MODULE_CORE_NATURE = "org.eclipse.wst.common.modulecore.ModuleCoreNature";
+
+    private static final String NATURE_JDT_CORE_JAVA = "org.eclipse.jdt.core.javanature";
+
+    private static final String NATURE_JEM_WORKBENCH_JAVA_EMF = "org.eclipse.jem.workbench.JavaEMFNature";
+
+    private static final String COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER = "org.eclipse.jdt.launching.JRE_CONTAINER";
+
+    //  warning, order is important for binary search
+    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "R7" };
+
+    /**
+     * Constant for 'artifactId' element in POM.xml.
+     */
+    private static final String POM_ELT_ARTIFACT_ID = "artifactId";
+
+    /**
+     * Constant for 'groupId' element in POM.xml.
+     */
+    private static final String POM_ELT_GROUP_ID = "groupId";
+
     /**
      * The project whose project files to create.
-     *
+     * 
      * @parameter expression="${project}"
      * @required
      */
@@ -59,14 +94,14 @@
 
     /**
      * The currently executed project (can be a reactor project).
-     *
+     * 
      * @parameter expression="${executedProject}"
      */
     private MavenProject executedProject;
 
     /**
      * Local maven repository.
-     *
+     * 
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -74,8 +109,9 @@
     private ArtifactRepository localRepository;
 
     /**
-     * If the executed project is a reactor project, this will contains the full list of projects in the reactor.
-     *
+     * If the executed project is a reactor project, this will contains the full
+     * list of projects in the reactor.
+     * 
      * @parameter expression="${reactorProjects}"
      * @required
      * @readonly
@@ -83,8 +119,9 @@
     private List reactorProjects;
 
     /**
-     * Artifact resolver, needed to download source jars for inclusion in classpath.
-     *
+     * Artifact resolver, needed to download source jars for inclusion in
+     * classpath.
+     * 
      * @component role="org.apache.maven.artifact.resolver.ArtifactResolver"
      * @required
      * @readonly
@@ -92,8 +129,9 @@
     private ArtifactResolver artifactResolver;
 
     /**
-     * Artifact factory, needed to download source jars for inclusion in classpath.
-     *
+     * Artifact factory, needed to download source jars for inclusion in
+     * classpath.
+     * 
      * @component role="org.apache.maven.artifact.factory.ArtifactFactory"
      * @required
      * @readonly
@@ -102,7 +140,7 @@
 
     /**
      * Remote repositories which will be searched for source attachments.
-     *
+     * 
      * @parameter expression="${project.remoteArtifactRepositories}"
      * @required
      * @readonly
@@ -110,92 +148,97 @@
     private List remoteArtifactRepositories;
 
     /**
-     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature plus the
-     * needed WTP natures are added.
+     * 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;projectnature>org.eclipse.jdt.core.javanature&lt;/projectnature>
-     *      &lt;projectnature>org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/projectnature>
-     *    &lt;/projectnatures>
+     * &lt;projectnatures&gt;
+     *    &lt;projectnature&gt;org.eclipse.jdt.core.javanature&lt;/projectnature&gt;
+     *    &lt;projectnature&gt;org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/projectnature&gt;
+     * &lt;/projectnatures&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List projectnatures;
 
     /**
-     * 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:
+     * 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>
-     *      &lt;java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilder&lt;/java.lang.String>
-     *      &lt;java.lang.String>org.eclipse.jdt.core.javabuilder&lt;/java.lang.String>
-     *      &lt;java.lang.String>org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/java.lang.String>
-     *    &lt;/buildcommands>
+     * &lt;buildcommands&gt;
+     *    &lt;java.lang.String&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilder&lt;/java.lang.String&gt;
+     *    &lt;java.lang.String&gt;org.eclipse.jdt.core.javabuilder&lt;/java.lang.String&gt;
+     *    &lt;java.lang.String&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/java.lang.String&gt;
+     * &lt;/buildcommands&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List buildcommands;
 
     /**
      * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code> classpath
-     * container is added.
-     * Configuration example:
+     * container is added. Configuration example: 
      * <pre>
-     *    &lt;classpathContainers>
-     *      &lt;buildcommand>org.eclipse.jdt.launching.JRE_CONTAINER&lt;/buildcommand>
-     *      &lt;buildcommand>org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5&lt;/buildcommand>
-     *      &lt;buildcommand>org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/buildcommand>
-     *    &lt;/classpathContainers>
+     * &lt;classpathContainers&gt;
+     *    &lt;buildcommand&gt;org.eclipse.jdt.launching.JRE_CONTAINER&lt;/buildcommand&gt;
+     *    &lt;buildcommand&gt;org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5&lt;/buildcommand&gt;
+     *    &lt;buildcommand&gt;org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/buildcommand&gt;
+     * &lt;/classpathContainers&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List classpathContainers;
 
     /**
-     * Enables/disables the downloading of source attachments. Defaults to false.
-     *
+     * Enables/disables the downloading of source attachments. Defaults to
+     * false.
+     * 
      * @parameter expression="${eclipse.downloadSources}"
      */
     private boolean downloadSources;
 
     /**
      * Eclipse workspace directory.
-     *
+     * 
      * @parameter expression="${eclipse.workspace}" alias="outputDir"
      */
     private File eclipseProjectDir;
 
     /**
-     * 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
-     *
-     * @parameter expression="${eclipse.useProjectReferences}" default-value="true"
+     * 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
+     * 
+     * @parameter expression="${eclipse.useProjectReferences}"
+     *            default-value="true"
      * @required
      */
     private boolean useProjectReferences;
 
     /**
      * The default output directory
-     *
-     * @parameter expression="${project.build.outputDirectory}" alias="outputDirectory"
+     * 
+     * @parameter expression="${project.build.outputDirectory}"
+     *            alias="outputDirectory"
      */
     private File buildOutputDirectory;
 
     /**
-     * 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.
-     *
+     * The version of WTP for which configuration files will be generated.
+     * The default value is "R7", supported versions are "R7" and "1.0"
+     * 
      * @parameter expression="${wtpversion}" default-value="R7"
      */
     private String wtpversion;
 
     /**
-     * Not a plugin parameter. Collect missing source artifact for the final report.
+     * Not a plugin parameter. Collect missing source artifact for the final
+     * report.
      */
     private List missingSourceArtifacts = new ArrayList();
 
@@ -206,10 +249,11 @@
         throws MojoExecutionException, MojoFailureException
     {
 
-        if ( !"R7".equalsIgnoreCase( wtpversion ) )
+        if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 )
         {
-            throw new MojoExecutionException( Messages
-                .getString( "EclipsePlugin.unsupportedwtp", new Object[] { wtpversion, "R7" } ) ); //$NON-NLS-1$
+            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] {
+                wtpversion,
+                StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) );
         }
 
         if ( executedProject == null )
@@ -218,42 +262,18 @@
             executedProject = project;
         }
 
-        assertNotEmpty( executedProject.getGroupId(), "groupId" ); //$NON-NLS-1$
-        assertNotEmpty( executedProject.getArtifactId(), "artifactId" ); //$NON-NLS-1$
-
-        // defaults
         String packaging = executedProject.getPackaging();
-        if ( projectnatures == null )
-        {
-            fillDefaultNatures( packaging );
-        }
 
-        if ( buildcommands == null )
-        {
-            fillDefaultBuilders( packaging );
-        }
-
-        if ( classpathContainers == null )
-        {
-            fillDefaultClasspathContainers( packaging );
-        }
-        else if ( !classpathContainers.contains( "org.eclipse.jdt.launching.JRE_CONTAINER" ) )
-        {
-            getLog()
-                .warn(
-                       "You did specify a list of classpath containers without the base org.eclipse.jdt.launching.JRE_CONTAINER.\n"
-                           + "If you specify custom classpath containers you should also add org.eclipse.jdt.launching.JRE_CONTAINER to the list" );
-            classpathContainers.add( 0, "org.eclipse.jdt.launching.JRE_CONTAINER" );
-        }
-
-        // end defaults
+        // validate sanity of the current m2 project
+        assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID ); //$NON-NLS-1$
+        assertNotEmpty( executedProject.getArtifactId(), POM_ELT_ARTIFACT_ID ); //$NON-NLS-1$
 
         if ( executedProject.getFile() == null || !executedProject.getFile().exists() )
         {
             throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingpom" ) ); //$NON-NLS-1$
         }
 
-        if ( "pom".equals( executedProject.getPackaging() ) && eclipseProjectDir == null ) //$NON-NLS-1$
+        if ( "pom".equals( packaging ) && eclipseProjectDir == null ) //$NON-NLS-1$
         {
             getLog().info( Messages.getString( "EclipsePlugin.pompackaging" ) ); //$NON-NLS-1$
             return;
@@ -269,15 +289,41 @@
             {
                 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", eclipseProjectDir ) ); //$NON-NLS-1$
             }
-
             eclipseProjectDir = new File( eclipseProjectDir, executedProject.getArtifactId() );
-
             if ( !eclipseProjectDir.isDirectory() && !eclipseProjectDir.mkdirs() )
             {
                 throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", eclipseProjectDir ) ); //$NON-NLS-1$
             }
         }
 
+        // end validate
+
+        // defaults
+        if ( projectnatures == null )
+        {
+            fillDefaultNatures( packaging );
+        }
+
+        if ( buildcommands == null )
+        {
+            fillDefaultBuilders( packaging );
+        }
+
+        if ( classpathContainers == null )
+        {
+            fillDefaultClasspathContainers( packaging );
+        }
+        else if ( !classpathContainers.contains( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER ) )
+        {
+            getLog()
+                .warn(
+                       "You did specify a list of classpath containers without the base org.eclipse.jdt.launching.JRE_CONTAINER.\n"
+                           + "If you specify custom classpath containers you should also add org.eclipse.jdt.launching.JRE_CONTAINER to the list" );
+            classpathContainers.add( 0, COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
+        }
+
+        // end defaults
+
         // ready to start
         write();
     }
@@ -298,7 +344,8 @@
             reactorArtifacts = Collections.EMPTY_LIST;
         }
 
-        // build a list of UNIQUE source dirs (both src and resources) to be used in classpath and wtpmodules
+        // build a list of UNIQUE source dirs (both src and resources) to be
+        // used in classpath and wtpmodules
         EclipseSourceDir[] sourceDirs = EclipseUtils.buildDirectoryList( executedProject, eclipseProjectDir, getLog(),
                                                                          buildOutputDirectory );
 
@@ -306,6 +353,26 @@
 
         downloadSourceArtifacts( artifacts, reactorArtifacts );
 
+        if ( "R7".equalsIgnoreCase( wtpversion ) )
+        {
+            new EclipseWtpmodulesWriter( getLog(), eclipseProjectDir, project, artifacts ).write( reactorArtifacts,
+                                                                                                  sourceDirs,
+                                                                                                  localRepository,
+                                                                                                  buildOutputDirectory );
+        }
+        else if ( "1.0".equals( wtpversion ) )
+        {
+            // Check and write out a WTP Project if this was required.
+            if ( "war".equalsIgnoreCase( project.getPackaging() ) || "ear".equalsIgnoreCase( project.getPackaging() )
+                || "ejb".equalsIgnoreCase( project.getPackaging() ) )
+            {
+                // we assume we have a version 1.0 for WTP
+                getLog().info( "Generating Eclipse web facet assuming version 1.0 for WTP..." );
+                new EclipseWtpSettingsWriter( getLog(), eclipseProjectDir, project, artifacts )
+                    .write( reactorArtifacts, sourceDirs, localRepository, buildOutputDirectory );
+            }
+        }
+
         new EclipseProjectWriter( getLog(), eclipseProjectDir, project ).write( projectBaseDir, executedProject,
                                                                                 reactorArtifacts, projectnatures,
                                                                                 buildcommands );
@@ -321,11 +388,6 @@
                                                                                              artifactFactory,
                                                                                              buildOutputDirectory );
 
-        new EclipseWtpmodulesWriter( getLog(), eclipseProjectDir, project, artifacts ).write( reactorArtifacts,
-                                                                                              sourceDirs,
-                                                                                              localRepository,
-                                                                                              buildOutputDirectory );
-
         reportMissingSources();
 
         getLog().info(
@@ -355,32 +417,41 @@
     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" );
+
+        projectnatures.add( NATURE_JEM_WORKBENCH_JAVA_EMF ); // WTP nature
+
+        projectnatures.add( NATURE_JDT_CORE_JAVA );
+
+        projectnatures.add( NATURE_WST_MODULE_CORE_NATURE ); // WTP nature
+        if ( !"R7".equalsIgnoreCase( wtpversion ) )
+        {
+            projectnatures.add( NATURE_WST_FACET_CORE_NATURE ); // WTP nature
+        }
     }
 
     private void fillDefaultClasspathContainers( String packaging )
     {
         classpathContainers = new ArrayList();
-        classpathContainers.add( "org.eclipse.jdt.launching.JRE_CONTAINER" );
+        classpathContainers.add( COMMON_PATH_JDT_LAUNCHING_JRE_CONTAINER );
     }
 
     private void fillDefaultBuilders( String packaging )
     {
         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" );
+
+        buildcommands.add( BUILDER_WST_COMPONENT_STRUCTURAL ); // WTP builder
+
+        buildcommands.add( BUILDER_JDT_CORE_JAVA );
+
+        buildcommands.add( BUILDER_WST_VALIDATION ); // WTP builder
+        buildcommands.add( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ); // WTP builder
     }
 
     private void downloadSourceArtifacts( Collection artifacts, Collection reactorArtifacts )
         throws MojoExecutionException
     {
-        // if downloadSources is off, just check local repository for reporting missing jars
+        // if downloadSources is off, just check local repository for reporting
+        // missing jars
         List remoteRepos = downloadSources ? remoteArtifactRepositories : new ArrayList( 0 );
         for ( Iterator it = artifacts.iterator(); it.hasNext(); )
         {

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java Wed Dec 28 02:51:19 2005
@@ -47,6 +47,7 @@
 
     /**
      * Getter for <code>exclude</code>.
+     * 
      * @return Returns the exclude.
      */
     public String getExclude()
@@ -56,7 +57,9 @@
 
     /**
      * Setter for <code>exclude</code>.
-     * @param exclude The exclude to set.
+     * 
+     * @param exclude
+     *            The exclude to set.
      */
     public void setExclude( String exclude )
     {
@@ -65,6 +68,7 @@
 
     /**
      * Getter for <code>include</code>.
+     * 
      * @return Returns the include.
      */
     public String getInclude()
@@ -74,7 +78,9 @@
 
     /**
      * Setter for <code>include</code>.
-     * @param include The include to set.
+     * 
+     * @param include
+     *            The include to set.
      */
     public void setInclude( String include )
     {
@@ -83,6 +89,7 @@
 
     /**
      * Getter for <code>output</code>.
+     * 
      * @return Returns the output.
      */
     public String getOutput()
@@ -92,7 +99,9 @@
 
     /**
      * Setter for <code>output</code>.
-     * @param output The output to set.
+     * 
+     * @param output
+     *            The output to set.
      */
     public void setOutput( String output )
     {
@@ -101,6 +110,7 @@
 
     /**
      * Getter for <code>path</code>.
+     * 
      * @return Returns the path.
      */
     public String getPath()
@@ -110,7 +120,9 @@
 
     /**
      * Setter for <code>path</code>.
-     * @param path The path to set.
+     * 
+     * @param path
+     *            The path to set.
      */
     public void setPath( String path )
     {
@@ -119,6 +131,7 @@
 
     /**
      * Getter for <code>test</code>.
+     * 
      * @return Returns the test.
      */
     public boolean isTest()
@@ -128,7 +141,9 @@
 
     /**
      * Setter for <code>test</code>.
-     * @param test The test to set.
+     * 
+     * @param test
+     *            The test to set.
      */
     public void setTest( boolean test )
     {
@@ -159,4 +174,4 @@
         return this.path.compareTo( ( (EclipseSourceDir) obj ).path );
     }
 
-}
\ No newline at end of file
+}

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java Wed Dec 28 02:51:19 2005
@@ -143,7 +143,8 @@
         EclipseUtils.extractResourceDirs( directories, project.getBuild().getResources(), project, basedir,
                                           projectBaseDir, false, null, log );
 
-        // If using the standard output location, don't mix the test output into it.
+        // If using the standard output location, don't mix the test output into
+        // it.
         String testOutput = null;
         boolean useFixedOutputDir = !buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) );
         if ( !useFixedOutputDir )
@@ -202,25 +203,27 @@
                 log.warn( Messages.getString( "EclipsePlugin.excludenotsupported" ) ); //$NON-NLS-1$
             }
 
-            //          Example of setting include/exclude patterns for future reference.
+            // Example of setting include/exclude patterns for future reference.
             //
-            //          TODO: figure out how to merge if the same dir is specified twice
-            //          with different in/exclude patterns. We can't write them now,
-            //                      since only the the first one would be included.
+            // TODO: figure out how to merge if the same dir is specified twice
+            // with different in/exclude patterns. We can't write them now,
+            // since only the the first one would be included.
             //
-            //          if ( resource.getIncludes().size() != 0 )
-            //          {
-            //              writer.addAttribute(
-            //                      "including", StringUtils.join( resource.getIncludes().iterator(), "|" )
-            //                      );
-            //          }
+            // if ( resource.getIncludes().size() != 0 )
+            // {
+            // writer.addAttribute(
+            // "including", StringUtils.join( resource.getIncludes().iterator(),
+            // "|" )
+            // );
+            // }
             //
-            //          if ( resource.getExcludes().size() != 0 )
-            //          {
-            //              writer.addAttribute(
-            //                      "excluding", StringUtils.join( resource.getExcludes().iterator(), "|" )
-            //              );
-            //          }
+            // if ( resource.getExcludes().size() != 0 )
+            // {
+            // writer.addAttribute(
+            // "excluding", StringUtils.join( resource.getExcludes().iterator(),
+            // "|" )
+            // );
+            // }
 
             if ( !StringUtils.isEmpty( resource.getTargetPath() ) )
             {
@@ -251,9 +254,11 @@
 
     /**
      * Utility method that locates a project producing the given artifact.
-     *
-     * @param reactorProjects a list of projects to search.
-     * @param artifact the artifact a project should produce.
+     * 
+     * @param reactorProjects
+     *            a list of projects to search.
+     * @param artifact
+     *            the artifact a project should produce.
      * @return null or the first project found producing the artifact.
      */
     public static MavenProject findReactorProject( List reactorProjects, Artifact artifact )
@@ -280,6 +285,7 @@
 
     /**
      * Returns the list of referenced artifacts produced by reactor projects.
+     * 
      * @return List of Artifacts
      */
     public static List resolveReactorArtifacts( MavenProject project, List reactorProjects )
@@ -334,10 +340,12 @@
     }
 
     /**
-     * @todo MNG-1384 optional dependencies not resolved while compiling from a master project 
-     * Direct optional artifacts are not included in the list returned by project.getTestArtifacts()
-     * .classpath should include ANY direct dependency, and optional dependencies are required to compile
-     * This is fixed in mvn 2.0.1 but this method is needed for compatibility with the 2.0 release. Do not remove!
+     * @todo MNG-1384 optional dependencies not resolved while compiling from a
+     *       master project Direct optional artifacts are not included in the
+     *       list returned by project.getTestArtifacts() .classpath should
+     *       include ANY direct dependency, and optional dependencies are
+     *       required to compile This is fixed in mvn 2.0.1 but this method is
+     *       needed for compatibility with the 2.0 release. Do not remove!
      */
     public static void fixMissingOptionalArtifacts( Collection artifacts, Collection depArtifacts,
                                                    ArtifactRepository localRepository,
@@ -421,4 +429,32 @@
         return resolvedArtifact;
     }
 
+    /**
+     * Extracts the
+     * 
+     * @param artifactNames
+     *            artifact names to compare against for extracting version
+     * @param artifacts
+     *            Collection of dependencies for our project
+     * @param offset
+     *            start position to extract version
+     * @param len
+     *            expected length of the version sub-string
+     * @return
+     */
+    public static String getDependencyVersion( List artifactNames, Set artifacts, int offset, int len )
+    {
+        for ( Iterator itr = artifacts.iterator(); itr.hasNext(); )
+        {
+            Artifact artifact = (Artifact) itr.next();
+            for ( Iterator itArtNames = artifactNames.iterator(); itArtNames.hasNext(); )
+            {
+                String name = (String) itArtNames.next();
+                if ( name.equals( artifact.getArtifactId() ) )
+                    return StringUtils.substring( artifact.getVersion(), offset, len );
+            }
+        }
+        // shouldn't be the case.
+        return "";
+    }
 }

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java Wed Dec 28 02:51:19 2005
@@ -26,6 +26,7 @@
  */
 public class Messages
 {
+
     private static final String BUNDLE_NAME = "org.apache.maven.plugin.eclipse.messages"; //$NON-NLS-1$
 
     private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle( BUNDLE_NAME );

Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java?rev=359477&view=auto
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java Wed Dec 28 02:51:19 2005
@@ -0,0 +1,62 @@
+/**
+ * 
+ */
+package org.apache.maven.plugin.eclipse.writers;
+
+import java.io.File;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * Common base class for all Eclipse Writers.
+ * 
+ * @author <a href="mailto:rahul.thakur.xdev@gmail.com">Rahul Thakur</a>
+ * @version $Id$
+ */
+public abstract class AbstractEclipseResourceWriter
+{
+
+    private Log log;
+
+    private File eclipseProjectDir;
+
+    private MavenProject project;
+
+    /**
+     * @param log
+     * @param eclipseProjectDir
+     * @param project
+     */
+    public AbstractEclipseResourceWriter( Log log, File eclipseProjectDir, MavenProject project )
+    {
+        this.log = log;
+        this.eclipseProjectDir = eclipseProjectDir;
+        this.project = project;
+    }
+
+    /**
+     * @return the eclipseProjectDir
+     */
+    public File getEclipseProjectDirectory()
+    {
+        return eclipseProjectDir;
+    }
+
+    /**
+     * @return the log
+     */
+    public Log getLog()
+    {
+        return log;
+    }
+
+    /**
+     * @return the project
+     */
+    public MavenProject getProject()
+    {
+        return project;
+    }
+
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractEclipseResourceWriter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java?rev=359477&view=auto
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java (added)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java Wed Dec 28 02:51:19 2005
@@ -0,0 +1,273 @@
+/**
+ * 
+ */
+package org.apache.maven.plugin.eclipse.writers;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.filter.ScopeArtifactFilter;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.eclipse.EclipseSourceDir;
+import org.apache.maven.plugin.eclipse.EclipseUtils;
+import org.apache.maven.plugin.eclipse.Messages;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Base class to hold common constants used by extending classes.
+ * 
+ * @author <a href="mailto:rahul.thakur.xdev@gmail.com">Rahul Thakur</a>
+ */
+public abstract class AbstractWtpResourceWriter
+    extends AbstractEclipseResourceWriter
+{
+
+    private static final String ELT_DEPENDENCY_TYPE = "dependency-type";
+
+    private static final String ATTR_HANDLE = "handle";
+
+    private static final String ELT_DEPENDENT_MODULE = "dependent-module";
+
+    protected static final String ATTR_VALUE = "value";
+
+    protected static final String ATTR_NAME = "name";
+
+    protected static final String ELT_PROPERTY = "property";
+
+    protected static final String ELT_VERSION = "version";
+
+    protected static final String ATTR_MODULE_TYPE_ID = "module-type-id";
+
+    protected static final String ATTR_SOURCE_PATH = "source-path";
+
+    protected static final String ATTR_DEPLOY_PATH = "deploy-path";
+
+    protected static final String ELT_WB_RESOURCE = "wb-resource";
+
+    protected static final String ELT_MODULE_TYPE = "module-type";
+
+    protected static final String ATTR_DEPLOY_NAME = "deploy-name";
+
+    protected static final String ELT_WB_MODULE = "wb-module";
+
+    protected static final String ATTR_MODULE_ID = "id";
+
+    protected static final String ELT_PROJECT_MODULES = "project-modules";
+
+    protected static final String ARTIFACT_MAVEN_WAR_PLUGIN = "maven-war-plugin";
+
+    /**
+     * Dependencies for our project.
+     */
+    private Collection artifacts;
+
+    public AbstractWtpResourceWriter( Log log, File eclipseProjectDir, MavenProject project, Collection artifacts )
+    {
+        super( log, eclipseProjectDir, project );
+        this.artifacts = artifacts;
+    }
+
+    /**
+     * Returns Dependent artifacts for our project.
+     * 
+     * @return
+     */
+    protected Collection getDependencies()
+    {
+        return this.artifacts;
+    }
+
+    /**
+     * Common elements of configuration are handled here.
+     * 
+     * @param referencedReactorArtifacts
+     * @param sourceDirs
+     * @param localRepository
+     * @param buildOutputDirectory
+     * @throws MojoExecutionException
+     */
+    public abstract void write( List referencedReactorArtifacts, EclipseSourceDir[] sourceDirs,
+                               ArtifactRepository localRepository, File buildOutputDirectory )
+        throws MojoExecutionException;
+
+    /**
+     * @param project
+     * @param writer
+     * @param packaging
+     * @throws MojoExecutionException
+     */
+    protected void writeModuleTypeAccordingToPackaging( MavenProject project, XMLWriter writer, String packaging,
+                                                       File buildOutputDirectory )
+        throws MojoExecutionException
+    {
+        if ( "war".equals( packaging ) ) //$NON-NLS-1$
+        {
+            writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.web" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( ELT_VERSION ); //$NON-NLS-1$
+
+            // defaults to 2.4, try to detect real version from dependencies
+            String servletVersion = "2.4"; //$NON-NLS-1$
+            List artifactNames = new ArrayList();
+            artifactNames.add( "servlet-api" );
+            artifactNames.add( "servletapi" );
+            artifactNames.add( "geronimo-spec-servlet" );
+            String version = EclipseUtils.getDependencyVersion( artifactNames, project.getArtifacts(), 0, 3 );
+            if ( version.trim().equals( "" ) )
+            {
+                // none of the above specified matched, try geronimo-spec-j2ee
+                artifactNames.clear();
+                artifactNames.add( "geronimo-spec-j2ee" );
+                version = EclipseUtils.getDependencyVersion( artifactNames, project.getArtifacts(), 0, 3 );
+                if ( !version.trim().equals( "" ) )
+                {
+                    String j2eeMinorVersion = StringUtils.substring( version, 2, 3 );
+                    servletVersion = "2." + j2eeMinorVersion;
+                }
+            }
+
+            writer.writeText( servletVersion );
+            writer.endElement();
+
+            writer.startElement( ELT_PROPERTY ); //$NON-NLS-1$
+            writer.addAttribute( ATTR_NAME, "context-root" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( ATTR_VALUE, getProject().getArtifactId() ); //$NON-NLS-1$
+            writer.endElement();
+        }
+        else if ( "ejb".equals( packaging ) ) //$NON-NLS-1$
+        {
+            writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ejb" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( ELT_VERSION ); //$NON-NLS-1$
+            writer.writeText( "2.1" ); //$NON-NLS-1$
+            // @todo this is the default, find real ejb version from dependencies
+            writer.endElement();
+
+            writer.startElement( ELT_PROPERTY ); //$NON-NLS-1$
+            writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$ //$NON-NLS-2$
+                EclipseUtils.toRelativeAndFixSeparator( getProject().getBasedir(), buildOutputDirectory, false ) );
+            writer.endElement();
+        }
+        else if ( "ear".equals( packaging ) )
+        {
+            writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.ear" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( ELT_VERSION ); //$NON-NLS-1$
+            writer.writeText( "1.3" ); //$NON-NLS-1$
+            // @todo 1.3 is the default
+            writer.endElement();
+        }
+        else
+        {
+            // jar
+            writer.addAttribute( ATTR_MODULE_TYPE_ID, "jst.utility" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( ELT_PROPERTY ); //$NON-NLS-1$
+            writer.addAttribute( ATTR_NAME, "java-output-path" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( ATTR_VALUE, "/" + //$NON-NLS-1$ //$NON-NLS-2$
+                EclipseUtils.toRelativeAndFixSeparator( getProject().getBasedir(), buildOutputDirectory, false ) );
+            writer.endElement();
+        }
+    }
+
+    /**
+     * Adds dependency for Eclipse WTP project.
+     * 
+     * @param writer
+     * @param artifact
+     * @param referencedReactorProjects
+     * @param localRepository
+     * @param basedir
+     * @throws MojoExecutionException
+     */
+    protected void addDependency( XMLWriter writer, Artifact artifact, List referencedReactorProjects,
+                                 ArtifactRepository localRepository, File basedir )
+        throws MojoExecutionException
+    {
+        String handle;
+
+        if ( referencedReactorProjects.contains( artifact ) )
+        {
+            // <dependent-module deploy-path="/WEB-INF/lib"
+            // handle="module:/resource/artifactid/artifactid">
+            // <dependency-type>uses</dependency-type>
+            // </dependent-module>
+
+            handle = "module:/resource/" + artifact.getArtifactId() + "/" + artifact.getArtifactId(); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+        else
+        {
+            // <dependent-module deploy-path="/WEB-INF/lib"
+            // handle="module:/classpath/var/M2_REPO/cl/cl/2.1/cl-2.1.jar">
+            // <dependency-type>uses</dependency-type>
+            // </dependent-module>
+
+            File artifactPath = artifact.getFile();
+
+            if ( artifactPath == null )
+            {
+                getLog().error( Messages.getString( "EclipsePlugin.artifactpathisnull", artifact.getId() ) ); //$NON-NLS-1$
+                return;
+            }
+
+            String fullPath = artifactPath.getPath();
+            File repoFile = new File( fullPath );
+
+            if ( Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+            {
+                handle = "module:/classpath/lib/" //$NON-NLS-1$
+                    + EclipseUtils.toRelativeAndFixSeparator( basedir, repoFile, false );
+            }
+            else
+            {
+                File localRepositoryFile = new File( localRepository.getBasedir() );
+
+                handle = "module:/classpath/var/M2_REPO/" //$NON-NLS-1$
+                    + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, repoFile, false );
+            }
+        }
+
+        writer.startElement( ELT_DEPENDENT_MODULE ); //$NON-NLS-1$
+
+        writer.addAttribute( ATTR_DEPLOY_PATH, "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( ATTR_HANDLE, handle ); //$NON-NLS-1$
+
+        writer.startElement( ELT_DEPENDENCY_TYPE ); //$NON-NLS-1$
+        writer.writeText( "uses" ); //$NON-NLS-1$
+        writer.endElement();
+
+        writer.endElement();
+    }
+
+    protected void writeWarOrEarResources( XMLWriter writer, MavenProject project, List referencedReactorArtifacts,
+                                          ArtifactRepository localRepository )
+        throws MojoExecutionException
+    {
+
+        ScopeArtifactFilter scopeFilter = new ScopeArtifactFilter( Artifact.SCOPE_RUNTIME );
+
+        // dependencies
+        for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+            String type = artifact.getType();
+
+            // NB war is needed for ear projects, we suppose nobody adds a war
+            // dependency to a war/jar project
+            if ( ( scopeFilter.include( artifact ) || Artifact.SCOPE_SYSTEM.equals( artifact.getScope() ) )
+                && ( "jar".equals( type ) || "ejb".equals( type ) || "ejb-client".equals( type ) || "war".equals( type ) ) )
+            {
+                addDependency( writer, artifact, referencedReactorArtifacts, localRepository, getProject().getBasedir() );
+            }
+        }
+    }
+}

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/AbstractWtpResourceWriter.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java Wed Dec 28 02:51:19 2005
@@ -47,21 +47,61 @@
  * @version $Id$
  */
 public class EclipseClasspathWriter
+    extends AbstractEclipseResourceWriter
 {
 
-    private Log log;
+    /**
+     * Eclipse build path variable M2_REPO
+     */
+    private static final String M2_REPO = "M2_REPO";
 
     private File eclipseProjectDir;
 
+    /**
+     * Attribute for sourcepath.
+     */
+    private static final String ATTR_SOURCEPATH = "sourcepath";
+
     private MavenProject project;
 
+    /**
+     * Attribute for output.
+     */
+    private static final String ATTR_OUTPUT = "output";
+
+    /**
+     * Attribute for path.
+     */
+    private static final String ATTR_PATH = "path";
+
+    /**
+     * Attribute for kind - Container (con), Variable (var)..etc.
+     */
+    private static final String ATTR_KIND = "kind";
+
+    /**
+     * Element for classpathentry.
+     */
+    private static final String ELT_CLASSPATHENTRY = "classpathentry";
+
+    /**
+     * Element for classpath.
+     */
+    private static final String ELT_CLASSPATH = "classpath";
+
+    /**
+     * File name that stores project classpath settings.
+     */
+    private static final String FILE_DOT_CLASSPATH = ".classpath";
+
+    /**
+     * Dependencies for our project.
+     */
     private Collection artifacts;
 
     public EclipseClasspathWriter( Log log, File eclipseProjectDir, MavenProject project, Collection artifacts )
     {
-        this.log = log;
-        this.eclipseProjectDir = eclipseProjectDir;
-        this.project = project;
+        super( log, eclipseProjectDir, project );
         this.artifacts = artifacts;
     }
 
@@ -75,7 +115,7 @@
 
         try
         {
-            w = new FileWriter( new File( eclipseProjectDir, ".classpath" ) ); //$NON-NLS-1$
+            w = new FileWriter( new File( getEclipseProjectDirectory(), FILE_DOT_CLASSPATH ) ); //$NON-NLS-1$
         }
         catch ( IOException ex )
         {
@@ -84,7 +124,7 @@
 
         XMLWriter writer = new PrettyPrintXMLWriter( w );
 
-        writer.startElement( "classpath" ); //$NON-NLS-1$
+        writer.startElement( ELT_CLASSPATH ); //$NON-NLS-1$
 
         // ----------------------------------------------------------------------
         // Source roots and resources
@@ -94,13 +134,13 @@
         {
             EclipseSourceDir dir = sourceDirs[j];
 
-            writer.startElement( "classpathentry" ); //$NON-NLS-1$
+            writer.startElement( ELT_CLASSPATHENTRY ); //$NON-NLS-1$
 
-            writer.addAttribute( "kind", "src" ); //$NON-NLS-1$ //$NON-NLS-2$
-            writer.addAttribute( "path", dir.getPath() ); //$NON-NLS-1$
+            writer.addAttribute( ATTR_KIND, "src" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( ATTR_PATH, dir.getPath() ); //$NON-NLS-1$
             if ( dir.getOutput() != null )
             {
-                writer.addAttribute( "output", dir.getOutput() ); //$NON-NLS-1$
+                writer.addAttribute( ATTR_OUTPUT, dir.getOutput() ); //$NON-NLS-1$
             }
 
             writer.endElement();
@@ -111,9 +151,9 @@
         // The default output
         // ----------------------------------------------------------------------
 
-        writer.startElement( "classpathentry" ); //$NON-NLS-1$
-        writer.addAttribute( "kind", "output" ); //$NON-NLS-1$ //$NON-NLS-2$
-        writer.addAttribute( "path", //$NON-NLS-1$ 
+        writer.startElement( ELT_CLASSPATHENTRY ); //$NON-NLS-1$
+        writer.addAttribute( ATTR_KIND, ATTR_OUTPUT ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( ATTR_PATH, //$NON-NLS-1$ 
                              EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, buildOutputDirectory, false ) );
         writer.endElement();
 
@@ -123,9 +163,9 @@
 
         for ( Iterator it = classpathContainers.iterator(); it.hasNext(); )
         {
-            writer.startElement( "classpathentry" ); //$NON-NLS-1$
-            writer.addAttribute( "kind", "con" ); //$NON-NLS-1$ //$NON-NLS-2$
-            writer.addAttribute( "path", (String) it.next() ); //$NON-NLS-1$
+            writer.startElement( ELT_CLASSPATHENTRY ); //$NON-NLS-1$
+            writer.addAttribute( ATTR_KIND, "con" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( ATTR_PATH, (String) it.next() ); //$NON-NLS-1$
             writer.endElement(); // name
         }
 
@@ -171,7 +211,7 @@
 
             if ( artifactPath == null )
             {
-                log.error( Messages.getString( "EclipsePlugin.artifactpathisnull", artifact.getId() ) ); //$NON-NLS-1$
+                getLog().error( Messages.getString( "EclipsePlugin.artifactpathisnull", artifact.getId() ) ); //$NON-NLS-1$
                 return;
             }
 
@@ -179,10 +219,10 @@
             {
                 path = EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, artifactPath, false );
 
-                if ( log.isDebugEnabled() )
+                if ( getLog().isDebugEnabled() )
                 {
-                    log.debug( Messages.getString( "EclipsePlugin.artifactissystemscoped", //$NON-NLS-1$
-                                                   new Object[] { artifact.getArtifactId(), path } ) );
+                    getLog().debug( Messages.getString( "EclipsePlugin.artifactissystemscoped", //$NON-NLS-1$
+                                                        new Object[] { artifact.getArtifactId(), path } ) );
                 }
 
                 kind = "lib"; //$NON-NLS-1$
@@ -197,7 +237,7 @@
                     + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, new File( fullPath ), false );
 
                 Artifact sourceArtifact = EclipseUtils.resolveLocalSourceArtifact( artifact, localRepository,
-                                                                              artifactResolver, artifactFactory );
+                                                                                   artifactResolver, artifactFactory );
 
                 if ( sourceArtifact.isResolved() )
                 {
@@ -208,7 +248,9 @@
                 {
 
                     // if a source artifact is not available, try with a plain javadoc jar
-                    Artifact javadocArtifact = EclipseUtils.resolveLocalJavadocArtifact( artifact, localRepository, artifactResolver, artifactFactory );
+                    Artifact javadocArtifact = EclipseUtils.resolveLocalJavadocArtifact( artifact, localRepository,
+                                                                                         artifactResolver,
+                                                                                         artifactFactory );
                     if ( javadocArtifact.isResolved() )
                     {
                         try

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseProjectWriter.java Wed Dec 28 02:51:19 2005
@@ -48,19 +48,24 @@
  * @version $Id$
  */
 public class EclipseProjectWriter
+    extends AbstractEclipseResourceWriter
 {
 
-    private Log log;
+    private static final String ELT_NAME = "name";
 
-    private File eclipseProjectDir;
+    private static final String ELT_BUILD_COMMAND = "buildCommand";
 
-    private MavenProject project;
+    private static final String ELT_BUILD_SPEC = "buildSpec";
+
+    private static final String ELT_NATURE = "nature";
+
+    private static final String ELT_NATURES = "natures";
+
+    private static final String FILE_DOT_PROJECT = ".project";
 
     public EclipseProjectWriter( Log log, File eclipseProjectDir, MavenProject project )
     {
-        this.log = log;
-        this.eclipseProjectDir = eclipseProjectDir;
-        this.project = project;
+        super( log, eclipseProjectDir, project );
     }
 
     public void write( File projectBaseDir, MavenProject executedProject, List reactorArtifacts,
@@ -71,12 +76,12 @@
         Set projectnatures = new LinkedHashSet();
         Set buildCommands = new LinkedHashSet();
 
-        File dotProject = new File( eclipseProjectDir, ".project" );
+        File dotProject = new File( getEclipseProjectDirectory(), FILE_DOT_PROJECT );
 
         if ( dotProject.exists() )
         {
 
-            log.info( Messages.getString( "EclipsePlugin.keepexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
+            getLog().info( Messages.getString( "EclipsePlugin.keepexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
 
             // parse existing file in order to keep manually-added entries
             FileReader reader = null;
@@ -85,10 +90,10 @@
                 reader = new FileReader( dotProject );
                 Xpp3Dom dom = Xpp3DomBuilder.build( reader );
 
-                Xpp3Dom naturesElement = dom.getChild( "natures" );
+                Xpp3Dom naturesElement = dom.getChild( ELT_NATURES );
                 if ( naturesElement != null )
                 {
-                    Xpp3Dom[] existingNatures = naturesElement.getChildren( "nature" );
+                    Xpp3Dom[] existingNatures = naturesElement.getChildren( ELT_NATURE );
                     for ( int j = 0; j < existingNatures.length; j++ )
                     {
                         // adds all the existing natures
@@ -96,13 +101,13 @@
                     }
                 }
 
-                Xpp3Dom buildSpec = dom.getChild( "buildSpec" );
+                Xpp3Dom buildSpec = dom.getChild( ELT_BUILD_SPEC );
                 if ( buildSpec != null )
                 {
-                    Xpp3Dom[] existingBuildCommands = buildSpec.getChildren( "buildCommand" );
+                    Xpp3Dom[] existingBuildCommands = buildSpec.getChildren( ELT_BUILD_COMMAND );
                     for ( int j = 0; j < existingBuildCommands.length; j++ )
                     {
-                        Xpp3Dom buildCommandName = existingBuildCommands[j].getChild( "name" );
+                        Xpp3Dom buildCommandName = existingBuildCommands[j].getChild( ELT_NAME );
                         if ( buildCommandName != null )
                         {
                             buildCommands.add( buildCommandName.getValue() );
@@ -112,11 +117,11 @@
             }
             catch ( XmlPullParserException e )
             {
-                log.warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
+                getLog().warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
             }
             catch ( IOException e )
             {
-                log.warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
+                getLog().warn( Messages.getString( "EclipsePlugin.cantparseexisting", dotProject.getAbsolutePath() ) ); //$NON-NLS-1$
             }
             finally
             {
@@ -149,18 +154,19 @@
 
         writer.startElement( "projectDescription" ); //$NON-NLS-1$
 
-        writer.startElement( "name" ); //$NON-NLS-1$
-        writer.writeText( project.getArtifactId() );
+        writer.startElement( ELT_NAME ); //$NON-NLS-1$
+        writer.writeText( getProject().getArtifactId() );
         writer.endElement();
 
         // TODO: this entire element might be dropped if the comment is null.
-        // but as the maven1 eclipse plugin does it, it's better to be safe than sorry
+        // but as the maven1 eclipse plugin does it, it's better to be safe than
+        // sorry
         // A eclipse developer might want to look at this.
         writer.startElement( "comment" ); //$NON-NLS-1$
 
-        if ( project.getDescription() != null )
+        if ( getProject().getDescription() != null )
         {
-            writer.writeText( project.getDescription() );
+            writer.writeText( getProject().getDescription() );
         }
 
         writer.endElement();
@@ -179,12 +185,12 @@
 
         writer.endElement(); // projects
 
-        writer.startElement( "buildSpec" ); //$NON-NLS-1$
+        writer.startElement( ELT_BUILD_SPEC ); //$NON-NLS-1$
 
         for ( Iterator it = buildCommands.iterator(); it.hasNext(); )
         {
-            writer.startElement( "buildCommand" ); //$NON-NLS-1$
-            writer.startElement( "name" ); //$NON-NLS-1$
+            writer.startElement( ELT_BUILD_COMMAND ); //$NON-NLS-1$
+            writer.startElement( ELT_NAME ); //$NON-NLS-1$
             writer.writeText( (String) it.next() );
             writer.endElement(); // name
             writer.startElement( "arguments" ); //$NON-NLS-1$
@@ -194,28 +200,32 @@
 
         writer.endElement(); // buildSpec
 
-        writer.startElement( "natures" ); //$NON-NLS-1$
+        writer.startElement( ELT_NATURES ); //$NON-NLS-1$
 
         for ( Iterator it = projectnatures.iterator(); it.hasNext(); )
         {
-            writer.startElement( "nature" ); //$NON-NLS-1$
+            writer.startElement( ELT_NATURE ); //$NON-NLS-1$
             writer.writeText( (String) it.next() );
             writer.endElement(); // name
         }
 
         writer.endElement(); // natures
 
-        if ( !projectBaseDir.equals( eclipseProjectDir ) )
+        if ( !projectBaseDir.equals( getEclipseProjectDirectory() ) )
         {
             writer.startElement( "linkedResources" ); //$NON-NLS-1$
 
-            addFileLink( writer, projectBaseDir, eclipseProjectDir, project.getFile() );
-
-            addSourceLinks( writer, projectBaseDir, eclipseProjectDir, executedProject.getCompileSourceRoots() );
-            addResourceLinks( writer, projectBaseDir, eclipseProjectDir, executedProject.getBuild().getResources() );
+            addFileLink( writer, projectBaseDir, getEclipseProjectDirectory(), getProject().getFile() );
 
-            addSourceLinks( writer, projectBaseDir, eclipseProjectDir, executedProject.getTestCompileSourceRoots() );
-            addResourceLinks( writer, projectBaseDir, eclipseProjectDir, executedProject.getBuild().getTestResources() );
+            addSourceLinks( writer, projectBaseDir, getEclipseProjectDirectory(), executedProject
+                .getCompileSourceRoots() );
+            addResourceLinks( writer, projectBaseDir, getEclipseProjectDirectory(), executedProject.getBuild()
+                .getResources() );
+
+            addSourceLinks( writer, projectBaseDir, getEclipseProjectDirectory(), executedProject
+                .getTestCompileSourceRoots() );
+            addResourceLinks( writer, projectBaseDir, getEclipseProjectDirectory(), executedProject.getBuild()
+                .getTestResources() );
 
             writer.endElement(); // linedResources
         }
@@ -232,7 +242,7 @@
         {
             writer.startElement( "link" ); //$NON-NLS-1$
 
-            writer.startElement( "name" ); //$NON-NLS-1$
+            writer.startElement( ELT_NAME ); //$NON-NLS-1$
             writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, file, true ) );
             writer.endElement(); // name
 
@@ -256,7 +266,7 @@
         }
         else
         {
-            log.warn( Messages.getString( "EclipseProjectWriter.notafile", file ) ); //$NON-NLS-1$
+            getLog().warn( Messages.getString( "EclipseProjectWriter.notafile", file ) ); //$NON-NLS-1$
         }
     }
 
@@ -272,7 +282,7 @@
             {
                 writer.startElement( "link" ); //$NON-NLS-1$
 
-                writer.startElement( "name" ); //$NON-NLS-1$
+                writer.startElement( ELT_NAME ); //$NON-NLS-1$
                 writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRoot, true ) );
                 writer.endElement(); // name
 
@@ -310,7 +320,7 @@
             {
                 writer.startElement( "link" ); //$NON-NLS-1$
 
-                writer.startElement( "name" ); //$NON-NLS-1$
+                writer.startElement( ELT_NAME ); //$NON-NLS-1$
                 writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, resourceDir, true ) );
                 writer.endElement(); // name
 

Modified: maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java
URL: http://svn.apache.org/viewcvs/maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java?rev=359477&r1=359476&r2=359477&view=diff
==============================================================================
--- maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java (original)
+++ maven/plugins/trunk/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseSettingsWriter.java Wed Dec 28 02:51:19 2005
@@ -36,19 +36,38 @@
  * @version $Id$
  */
 public class EclipseSettingsWriter
+    extends AbstractEclipseResourceWriter
 {
 
-    private Log log;
+    /**
+     * 'target' property for maven-compiler-plugin.
+     */
+    private static final String PROPERTY_TARGET = "target";
 
-    private File eclipseProjectDir;
+    /**
+     * 'source' property for maven-compiler-plugin.
+     */
+    private static final String PROPERTY_SOURCE = "source";
 
-    private MavenProject project;
+    private static final String JDK_1_2_SOURCES = "1.2";
+
+    private static final String JDK_1_3_SOURCES = "1.3";
+
+    private static final String FILE_ECLIPSE_JDT_CORE_PREFS = "org.eclipse.jdt.core.prefs";
+
+    private static final String PROP_ECLIPSE_PREFERENCES_VERSION = "eclipse.preferences.version";
+
+    private static final String DIR_DOT_SETTINGS = ".settings";
+
+    private static final String PROP_JDT_CORE_COMPILER_COMPLIANCE = "org.eclipse.jdt.core.compiler.compliance";
+
+    private static final String PROP_JDT_CORE_COMPILER_SOURCE = "org.eclipse.jdt.core.compiler.source";
+
+    private static final String ARTIFACT_MAVEN_COMPILER_PLUGIN = "maven-compiler-plugin";
 
     public EclipseSettingsWriter( Log log, File eclipseProjectDir, MavenProject project )
     {
-        this.log = log;
-        this.eclipseProjectDir = eclipseProjectDir;
-        this.project = project;
+        super( log, eclipseProjectDir, project );
     }
 
     public void write()
@@ -58,16 +77,18 @@
         // check if it's necessary to create project specific settings
         Properties coreSettings = new Properties();
 
-        String source = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "source", null ); //$NON-NLS-1$ //$NON-NLS-2$
-        String target = EclipseUtils.getPluginSetting( project, "maven-compiler-plugin", "target", null ); //$NON-NLS-1$ //$NON-NLS-2$
+        String source = EclipseUtils.getPluginSetting( getProject(), ARTIFACT_MAVEN_COMPILER_PLUGIN, PROPERTY_SOURCE,
+                                                       null ); //$NON-NLS-1$ //$NON-NLS-2$
+        String target = EclipseUtils.getPluginSetting( getProject(), ARTIFACT_MAVEN_COMPILER_PLUGIN, PROPERTY_TARGET,
+                                                       null ); //$NON-NLS-1$ //$NON-NLS-2$
 
-        if ( source != null && !"1.3".equals( source ) ) //$NON-NLS-1$
+        if ( source != null && !JDK_1_3_SOURCES.equals( source ) ) //$NON-NLS-1$
         {
-            coreSettings.put( "org.eclipse.jdt.core.compiler.source", source ); //$NON-NLS-1$
-            coreSettings.put( "org.eclipse.jdt.core.compiler.compliance", source ); //$NON-NLS-1$
+            coreSettings.put( PROP_JDT_CORE_COMPILER_SOURCE, source ); //$NON-NLS-1$
+            coreSettings.put( PROP_JDT_CORE_COMPILER_COMPLIANCE, source ); //$NON-NLS-1$
         }
 
-        if ( target != null && !"1.2".equals( target ) ) //$NON-NLS-1$
+        if ( target != null && !JDK_1_2_SOURCES.equals( target ) ) //$NON-NLS-1$
         {
             coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target ); //$NON-NLS-1$
         }
@@ -75,17 +96,17 @@
         // write the settings, if needed
         if ( !coreSettings.isEmpty() )
         {
-            File settingsDir = new File( eclipseProjectDir, "/.settings" ); //$NON-NLS-1$
+            File settingsDir = new File( getEclipseProjectDirectory(), "/" + DIR_DOT_SETTINGS ); //$NON-NLS-1$
 
             settingsDir.mkdirs();
 
-            coreSettings.put( "eclipse.preferences.version", "1" ); //$NON-NLS-1$ //$NON-NLS-2$
+            coreSettings.put( PROP_ECLIPSE_PREFERENCES_VERSION, "1" ); //$NON-NLS-1$ //$NON-NLS-2$
 
             try
             {
                 File oldCoreSettingsFile;
 
-                File coreSettingsFile = new File( settingsDir, "org.eclipse.jdt.core.prefs" ); //$NON-NLS-1$
+                File coreSettingsFile = new File( settingsDir, FILE_ECLIPSE_JDT_CORE_PREFS ); //$NON-NLS-1$
 
                 if ( coreSettingsFile.exists() )
                 {
@@ -106,8 +127,8 @@
                 {
                     coreSettings.store( new FileOutputStream( coreSettingsFile ), null );
 
-                    log.info( Messages.getString( "EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$
-                                                  coreSettingsFile.getCanonicalPath() ) );
+                    getLog().info( Messages.getString( "EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$
+                                                       coreSettingsFile.getCanonicalPath() ) );
                 }
             }
             catch ( FileNotFoundException e )
@@ -121,7 +142,7 @@
         }
         else
         {
-            log.info( Messages.getString( "EclipseSettingsWriter.usingdefaults" ) ); //$NON-NLS-1$
+            getLog().info( Messages.getString( "EclipseSettingsWriter.usingdefaults" ) ); //$NON-NLS-1$
         }
     }
 }



Mime
View raw message