You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by br...@apache.org on 2005/09/12 07:28:13 UTC

svn commit: r280259 [1/2] - in /maven/components/trunk/maven-plugins/maven-eclipse-plugin/src: main/java/org/apache/maven/plugin/eclipse/ main/resources/ main/resources/org/ main/resources/org/apache/ main/resources/org/apache/maven/ main/resources/org...

Author: brett
Date: Sun Sep 11 22:27:40 2005
New Revision: 280259

URL: http://svn.apache.org/viewcvs?rev=280259&view=rev
Log:
PR: MNG-760
Submitted by: Fabrizio Giustina
Reviewed by:  Brett Porter
m2 eclipse plugin improvements (source download and attachment, customization of natures/builders/conclasspath, flexible project dupport) and refactoring
(applied with modifications)

Added:
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseProjectWriter.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSettingsWriter.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWtpmodulesWriter.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-2/settings
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-2/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-3/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/classpath
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/project
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/project.xml   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/settings
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/src/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/src/main/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/src/main/java/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/src/main/java/DummyClass.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-5/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/classpath
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/project
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/project.xml   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/src/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/src/main/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/src/main/java/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/src/main/java/DummyClass.java   (with props)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-6/wtpmodules
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/repository/maven/java-sources/
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/repository/maven/java-sources/maven-core-98.0-sources.jar
Removed:
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWriter.java
Modified:
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginException.java
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/   (props changed)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/   (props changed)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/classpath
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/project.xml
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-2/   (props changed)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-2/project.xml
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-3/   (props changed)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-3/project
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-3/project.xml
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/   (props changed)
    maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-4/project.xml

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseClasspathWriter.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,240 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolutionException;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Writes eclipse .classpath file.
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseClasspathWriter
+{
+
+    private Log log;
+
+    public EclipseClasspathWriter( Log log )
+    {
+        this.log = log;
+    }
+
+    /**
+     * @todo the list of needed parameters is really long, maybe this should become a Plexus component
+     */
+    protected void write( File projectBaseDir, File basedir, MavenProject project, List referencedReactorArtifacts,
+                         EclipseSourceDir[] sourceDirs, List classpathContainers, ArtifactRepository localRepository,
+                         ArtifactResolver artifactResolver, ArtifactFactory artifactFactory,
+                         List remoteArtifactRepositories )
+        throws EclipsePluginException
+    {
+
+        FileWriter w;
+
+        try
+        {
+            w = new FileWriter( new File( basedir, ".classpath" ) ); //$NON-NLS-1$
+        }
+        catch ( IOException ex )
+        {
+            throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
+        }
+
+        XMLWriter writer = new PrettyPrintXMLWriter( w );
+
+        writer.startElement( "classpath" ); //$NON-NLS-1$
+
+        // ----------------------------------------------------------------------
+        // Source roots and resources
+        // ----------------------------------------------------------------------
+
+        for ( int j = 0; j < sourceDirs.length; j++ )
+        {
+            EclipseSourceDir dir = sourceDirs[j];
+
+            writer.startElement( "classpathentry" ); //$NON-NLS-1$
+
+            writer.addAttribute( "kind", "src" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "path", dir.getPath() ); //$NON-NLS-1$
+            if ( dir.getOutput() != null )
+            {
+                writer.addAttribute( "output", dir.getOutput() ); //$NON-NLS-1$
+            }
+
+            writer.endElement();
+
+        }
+
+        // ----------------------------------------------------------------------
+        // The default output
+        // ----------------------------------------------------------------------
+
+        writer.startElement( "classpathentry" ); //$NON-NLS-1$
+        writer.addAttribute( "kind", "output" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "path", EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, project.getBuild() //$NON-NLS-1$
+            .getOutputDirectory(), false ) );
+        writer.endElement();
+
+        // ----------------------------------------------------------------------
+        // The JRE reference
+        // ----------------------------------------------------------------------
+
+        writer.startElement( "classpathentry" ); //$NON-NLS-1$
+        writer.addAttribute( "kind", "var" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "rootpath", "JRE_SRCROOT" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "path", "JRE_LIB" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "sourcepath", "JRE_SRC" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.endElement();
+
+        // ----------------------------------------------------------------------
+        // The dependencies
+        // ----------------------------------------------------------------------
+
+        Set artifacts = project.getArtifacts();
+
+        for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+            addDependency( writer, artifact, referencedReactorArtifacts, localRepository, artifactResolver,
+                           artifactFactory, remoteArtifactRepositories );
+        }
+
+        // ----------------------------------------------------------------------
+        // Additional container classpath entries
+        // ----------------------------------------------------------------------
+
+        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.endElement(); // name
+        }
+
+        writer.endElement();
+
+        IOUtil.close( w );
+    }
+
+    private void addDependency( XMLWriter writer, Artifact artifact, List referencedReactorArtifacts,
+                               ArtifactRepository localRepository, ArtifactResolver artifactResolver,
+                               ArtifactFactory artifactFactory, List remoteArtifactRepositories )
+    {
+
+        String path;
+        String kind;
+        String sourcepath = null;
+
+        if ( referencedReactorArtifacts.contains( artifact ) )
+        {
+            path = "/" + artifact.getArtifactId(); //$NON-NLS-1$
+            kind = "src"; //$NON-NLS-1$
+        }
+        else
+        {
+            File artifactPath = artifact.getFile();
+
+            if ( artifactPath == null )
+            {
+                log.error( Messages.getString( "EclipsePlugin.artifactpathisnull", artifact.getId() ) ); //$NON-NLS-1$
+                return;
+            }
+
+            String fullPath = artifactPath.getPath();
+            File localRepositoryFile = new File( localRepository.getBasedir() );
+
+            path = "M2_REPO/" //$NON-NLS-1$
+                + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, fullPath, false );
+
+            // source artifact: use the "sources" classifier added by the source plugin
+            Artifact sourceArtifact = artifactFactory.createArtifactWithClassifier( artifact.getGroupId(), artifact
+                .getArtifactId(), artifact.getVersion(), "java-source", "sources" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            try
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( Messages.getString( "EclipseClasspathWriter.lookingforsources", //$NON-NLS-1$
+                                                   sourceArtifact.getArtifactId() ) );
+                }
+                artifactResolver.resolve( sourceArtifact, remoteArtifactRepositories, localRepository );
+            }
+            catch ( ArtifactResolutionException e )
+            {
+                // ignore, the jar has not been found
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( e.getMessage(), e );
+                }
+            }
+
+            File sourceArtifactFile = sourceArtifact.getFile();
+
+            if ( !sourceArtifact.isResolved() )
+            {
+                log.info( Messages.getString( "EclipseClasspathWriter.sourcesnotavailable", //$NON-NLS-1$
+                                              sourceArtifact.getArtifactId() ) );
+            }
+            else
+            {
+                if ( log.isDebugEnabled() )
+                {
+                    log.debug( Messages.getString( "EclipseClasspathWriter.sourcesavailable", //$NON-NLS-1$
+                                                   new Object[] {
+                                                       sourceArtifact.getArtifactId(),
+                                                       sourceArtifactFile.getPath() } ) );
+                }
+                sourcepath = "M2_REPO/" //$NON-NLS-1$
+                    + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, sourceArtifactFile.getPath(), false );
+            }
+
+            kind = "var"; //$NON-NLS-1$
+        }
+
+        writer.startElement( "classpathentry" ); //$NON-NLS-1$
+        writer.addAttribute( "kind", kind ); //$NON-NLS-1$
+        writer.addAttribute( "path", path ); //$NON-NLS-1$
+
+        if ( sourcepath != null )
+        {
+            writer.addAttribute( "sourcepath", sourcepath ); //$NON-NLS-1$
+        }
+
+        writer.endElement();
+
+    }
+
+}
+

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

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

Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?rev=280259&r1=280258&r2=280259&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Sun Sep 11 22:27:40 2005
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,13 +16,22 @@
  * limitations under the License.
  */
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
+import org.apache.maven.model.Resource;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.project.MavenProject;
-
-import java.io.File;
-import java.util.List;
+import org.codehaus.plexus.util.StringUtils;
 
 /**
  * A Maven2 plugin which integrates the use of Maven2 with Eclipse.
@@ -37,22 +46,27 @@
 public class EclipsePlugin
     extends AbstractMojo
 {
-    protected EclipseWriter eclipseWriter;
+
+    /**
+     * Separator used for natures, builders, etc. (can't use space since conclasspath entries can contain spaces).
+     */
+    private static final String LIST_SEPARATOR = ","; //$NON-NLS-1$
 
     /**
      * The project whose project files to create.
-     *
      * @parameter expression="${project}"
      * @required
      */
     private MavenProject project;
 
     /**
+     * The currently executed project (can be a reactor project).
      * @parameter expression="${executedProject}"
      */
     private MavenProject executedProject;
 
     /**
+     * Local maven repository.
      * @parameter expression="${localRepository}"
      * @required
      * @readonly
@@ -60,6 +74,7 @@
     private ArtifactRepository localRepository;
 
     /**
+     * If the executed project is a reactor project, this will contains the full list of projects in the reactor.
      * @parameter expression="${reactorProjects}"
      * @required
      * @readonly
@@ -67,42 +82,197 @@
     private List reactorProjects;
 
     /**
+     * Artifact resolver, needed to download source jars for inclusion in classpath.
+     * @parameter expression="${component.org.apache.maven.artifact.resolver.ArtifactResolver}"
+     * @required
+     * @readonly
+     * @todo waiting for the component tag
+     */
+    private ArtifactResolver artifactResolver;
+
+    /**
+     * Artifact factory, needed to download source jars for inclusion in classpath.
+     * @parameter expression="${component.org.apache.maven.artifact.factory.ArtifactFactory}"
+     * @required
+     * @readonly
+     * @todo waiting for the component tag
+     */
+    private ArtifactFactory artifactFactory;
+
+    /**
+     * Remote repositories which will be searched for source attachments.
+     * @parameter expression="${project.remoteArtifactRepositories}"
+     * @required
+     * @readonly
+     */
+    private List remoteArtifactRepositories;
+
+    /**
+     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature is added.
+     * Configuration example:
+     * <pre>
+     *    &lt;projectnatures>
+     *      &lt;java.lang.String>org.eclipse.jdt.core.javanature&lt;/java.lang.String>
+     *      &lt;java.lang.String>org.eclipse.wst.common.modulecore.ModuleCoreNature&lt;/java.lang.String>
+     *    &lt;/projectnatures>
+     * </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.
+     * 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>
+     * </pre>
+     * @parameter
+     * @todo default-value="org.eclipse.jdt.core.javabuilder"
+     */
+    private List buildcommands;
+
+    /**
+     * List of container classpath entries. No classpath container is added by default.
+     * Configuration example:
+     * <pre>
+     *    &lt;classpathContainers>
+     *      &lt;java.lang.String>org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v5.5&lt;/java.lang.String>
+     *      &lt;java.lang.String>org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/java.lang.String>
+     *    &lt;/classpathContainers>
+     * </pre>
+     * @parameter
+     * @todo default-value=empty list
+     */
+    private List classpathContainers;
+
+    /**
+     * Eclipse workspace directory.
      * @parameter expression="${eclipse.workspace}"
      */
     private File outputDir;
 
-    public EclipsePlugin()
+    /**
+     * Setter for <code>project</code>. Needed for tests.
+     * @param project The MavenProject to set.
+     */
+    protected void setProject( MavenProject project )
     {
-        eclipseWriter = new EclipseWriter();
+        this.project = project;
     }
 
-    public void setProject( MavenProject project )
+    /**
+     * Setter for <code>localRepository</code>. Needed for tests.
+     * @param localRepository The ArtifactRepository to set.
+     */
+    protected void setLocalRepository( ArtifactRepository localRepository )
     {
-        this.project = project;
+        this.localRepository = localRepository;
     }
 
-    public void setLocalRepository( ArtifactRepository localRepository )
+    /**
+     * Setter for <code>artifactFactory</code>. Needed for tests.
+     * @param artifactFactory The artifactFactory to set.
+     */
+    protected void setArtifactFactory( ArtifactFactory artifactFactory )
     {
-        this.localRepository = localRepository;
+        this.artifactFactory = artifactFactory;
+    }
+
+    /**
+     * Setter for <code>artifactResolver</code>. Needed for tests.
+     * @param artifactResolver The artifactResolver to set.
+     */
+    protected void setArtifactResolver( ArtifactResolver artifactResolver )
+    {
+        this.artifactResolver = artifactResolver;
+    }
+
+    /**
+     * Setter for <code>remoteArtifactRepositories</code>. Needed for tests.
+     * @param remoteArtifactRepositories The remoteArtifactRepositories to set.
+     */
+    protected void setRemoteArtifactRepositories( List remoteArtifactRepositories )
+    {
+        this.remoteArtifactRepositories = remoteArtifactRepositories;
+    }
+
+    /**
+     * Setter for <code>buildcommands</code>. Needed for tests.
+     * @param buildcommands The buildcommands to set.
+     */
+    protected void setBuildcommands( List buildcommands )
+    {
+        this.buildcommands = buildcommands;
+    }
+
+    /**
+     * Setter for <code>classpathContainers</code>. Needed for tests.
+     * @param classpathContainers The classpathContainers to set.
+     */
+    protected void setClasspathContainers( List classpathContainers )
+    {
+        this.classpathContainers = classpathContainers;
     }
 
+    /**
+     * Setter for <code>projectnatures</code>. Needed for tests.
+     * @param projectnatures The projectnatures to set.
+     */
+    protected void setProjectnatures( List projectnatures )
+    {
+        this.projectnatures = projectnatures;
+    }
+
+    /**
+     * Setter for <code>outputDir</code>. Needed for tests.
+     * @param outputDir The outputDir to set.
+     */
     public void setOutputDir( File outputDir )
     {
         this.outputDir = outputDir;
     }
 
+    /**
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
     public void execute()
         throws MojoExecutionException
     {
-        if ( project.getFile() == null || !project.getFile().exists() )
+
+        assertNotEmpty( project.getGroupId(), "groupId" ); //$NON-NLS-1$
+        assertNotEmpty( project.getArtifactId(), "artifactId" ); //$NON-NLS-1$
+
+        // defaults
+        // @todo how set List values in @default-value??
+        if ( projectnatures == null )
+        {
+            projectnatures = new ArrayList();
+            projectnatures.add( "org.eclipse.jdt.core.javanature" );
+        }
+        if ( buildcommands == null )
+        {
+            buildcommands = new ArrayList();
+            buildcommands.add( "org.eclipse.jdt.core.javabuilder" );
+        }
+        if ( classpathContainers == null )
         {
-            throw new MojoExecutionException( "There must be a POM in the current working directory for the Eclipse plugin to work." );
+            classpathContainers = new ArrayList();
         }
+        // end defaults
 
-        if ( "pom".equals( project.getPackaging() ) )
+        if ( project.getFile() == null || !project.getFile().exists() )
         {
-            getLog().info( "Don't generate Eclipse project for pom project" );
+            throw new MojoExecutionException( Messages.getString( "EclipsePlugin.missingpom" ) ); //$NON-NLS-1$
+        }
 
+        if ( "pom".equals( project.getPackaging() ) ) //$NON-NLS-1$
+        {
+            getLog().info( Messages.getString( "EclipsePlugin.pompackaging" ) ); //$NON-NLS-1$
             return;
         }
 
@@ -114,34 +284,224 @@
         {
             if ( !outputDir.isDirectory() )
             {
-                throw new MojoExecutionException( "Not a directory: '" + outputDir + "'" );
+                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.notadir", outputDir ) ); //$NON-NLS-1$
             }
 
             outputDir = new File( outputDir, project.getArtifactId() );
 
             if ( !outputDir.isDirectory() && !outputDir.mkdir() )
             {
-                throw new MojoExecutionException( "Can't create directory '" + outputDir + "'" );
+                throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantcreatedir", outputDir ) ); //$NON-NLS-1$
             }
         }
 
-        try
+        if ( executedProject == null )
+        {
+            // backwards compat with alpha-2 only
+            executedProject = project;
+        }
+
+        // ready to start
+        write();
+
+    }
+
+    public void write()
+        throws EclipsePluginException
+    {
+
+        File projectBaseDir = project.getFile().getParentFile();
+
+        // build the list of referenced ARTIFACTS produced by reactor projects
+        List reactorArtifacts = resolveReactorArtifacts();
+
+        // build a list of UNIQUE source dirs (both src and resources) to be used in classpath and wtpmodules
+        EclipseSourceDir[] sourceDirs = buildDirectoryList( project, outputDir );
+
+        new EclipseClasspathWriter( getLog() ).write( projectBaseDir, outputDir, project, reactorArtifacts, sourceDirs,
+                                                      classpathContainers, localRepository, artifactResolver,
+                                                      artifactFactory, remoteArtifactRepositories );
+
+        new EclipseProjectWriter( getLog() ).write( projectBaseDir, outputDir, project, executedProject,
+                                                    reactorArtifacts, projectnatures, buildcommands );
+
+        new EclipseSettingsWriter( getLog() ).write( projectBaseDir, outputDir, project, executedProject );
+
+        new EclipseWtpmodulesWriter( getLog() ).write( outputDir, project, reactorArtifacts, sourceDirs,
+                                                       localRepository );
+
+        getLog().info( Messages.getString( "EclipsePlugin.wrote", //$NON-NLS-1$
+                                           new Object[] { project.getArtifactId(), outputDir.getAbsolutePath() } ) );
+    }
+
+    private void assertNotEmpty( String string, String elementName )
+        throws EclipsePluginException
+    {
+        if ( string == null )
         {
-            eclipseWriter.setLocalRepositoryFile( new File ( localRepository.getBasedir() ) );
+            throw new EclipsePluginException( Messages.getString( "EclipsePlugin.missingelement", elementName ) ); //$NON-NLS-1$
+        }
+    }
 
-            eclipseWriter.setLog( getLog() );
+    private EclipseSourceDir[] buildDirectoryList( MavenProject project, File basedir )
+    {
+        File projectBaseDir = project.getFile().getParentFile();
 
-            if ( executedProject == null )
+        // avoid duplicated entries
+        Set directories = new TreeSet();
+
+        extractSourceDirs( directories, executedProject.getCompileSourceRoots(), basedir, projectBaseDir, false, null );
+
+        extractResourceDirs( directories, project.getBuild().getResources(), project, basedir, projectBaseDir, false,
+                             null );
+
+        extractSourceDirs( directories, executedProject.getTestCompileSourceRoots(), basedir, projectBaseDir, true,
+                           EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, project.getBuild()
+                               .getTestOutputDirectory(), false ) );
+
+        extractResourceDirs( directories, project.getBuild().getTestResources(), project, basedir, projectBaseDir,
+                             true, EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, project.getBuild()
+                                 .getTestOutputDirectory(), false ) );
+
+        return (EclipseSourceDir[]) directories.toArray( new EclipseSourceDir[directories.size()] );
+    }
+
+    private void extractSourceDirs( Set directories, List sourceRoots, File basedir, File projectBaseDir, boolean test,
+                                   String output )
+    {
+        for ( Iterator it = sourceRoots.iterator(); it.hasNext(); )
+        {
+            String sourceRoot = (String) it.next();
+
+            if ( new File( sourceRoot ).isDirectory() )
             {
-                // backwards compat with alpha-2 only
-                executedProject = project;
+                sourceRoot = EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRoot, !projectBaseDir
+                    .equals( basedir ) );
+
+                directories.add( new EclipseSourceDir( sourceRoot, output, test, null, null ) );
             }
+        }
+    }
+
+    private void extractResourceDirs( Set directories, List resources, MavenProject project, File basedir,
+                                     File projectBaseDir, boolean test, String output )
+    {
+        for ( Iterator it = resources.iterator(); it.hasNext(); )
+        {
 
-            eclipseWriter.write( outputDir, project, executedProject, reactorProjects );
+            Resource resource = (Resource) it.next();
+            String includePattern = null;
+            String excludePattern = null;
+
+            if ( resource.getIncludes().size() != 0 )
+            {
+                // @todo includePattern = ?
+                getLog().warn( Messages.getString( "EclipsePlugin.includenotsupported" ) ); //$NON-NLS-1$
+            }
+
+            if ( resource.getExcludes().size() != 0 )
+            {
+                // @todo excludePattern = ?
+                getLog().warn( Messages.getString( "EclipsePlugin.excludenotsupported" ) ); //$NON-NLS-1$
+            }
+
+            //          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.
+            //
+            //          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 ( !StringUtils.isEmpty( resource.getTargetPath() ) )
+            {
+                output = resource.getTargetPath();
+            }
+
+            File resourceDirectory = new File( resource.getDirectory() );
+
+            if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() )
+            {
+                continue;
+            }
+
+            String resourceDir = resource.getDirectory();
+            resourceDir = EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, resourceDir, !projectBaseDir
+                .equals( basedir ) );
+
+            if ( output != null )
+            {
+                output = EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, output, false );
+            }
+
+            directories.add( new EclipseSourceDir( resourceDir, output, test, includePattern, excludePattern ) );
+        }
+    }
+
+    /**
+     * Returns the list of referenced artifacts produced by reactor projects.
+     * @return List of Artifacts
+     */
+    private List resolveReactorArtifacts()
+    {
+        List referencedProjects = new ArrayList();
+
+        Set artifacts = project.getArtifacts();
+
+        for ( Iterator it = artifacts.iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+
+            MavenProject refProject = findReactorProject( reactorProjects, artifact );
+
+            if ( refProject != null )
+            {
+                referencedProjects.add( artifact );
+            }
         }
-        catch ( EclipsePluginException e )
+
+        return referencedProjects;
+    }
+
+    /**
+     * 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.
+     * @return null or the first project found producing the artifact.
+     */
+    private static MavenProject findReactorProject( List reactorProjects, Artifact artifact )
+    {
+        if ( reactorProjects == null )
+        {
+            return null; // we're a single project
+        }
+
+        for ( Iterator it = reactorProjects.iterator(); it.hasNext(); )
         {
-            throw new MojoExecutionException( "Error writing eclipse files.", e );
+            MavenProject project = (MavenProject) it.next();
+
+            if ( project.getGroupId().equals( artifact.getGroupId() )
+                && project.getArtifactId().equals( artifact.getArtifactId() )
+                && project.getVersion().equals( artifact.getVersion() ) )
+            {
+                return project;
+            }
         }
+
+        return null;
     }
+
 }

Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginException.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginException.java?rev=280259&r1=280258&r2=280259&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginException.java (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginException.java Sun Sep 11 22:27:40 2005
@@ -2,13 +2,13 @@
 
 /*
  * Copyright 2001-2005 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -16,11 +16,14 @@
  * limitations under the License.
  */
 
+import org.apache.maven.plugin.MojoExecutionException;
+
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
  */
-public class EclipsePluginException extends Exception
+public class EclipsePluginException
+    extends MojoExecutionException
 {
     public EclipsePluginException( String msg )
     {

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseProjectWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseProjectWriter.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseProjectWriter.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseProjectWriter.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,222 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.model.Resource;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Writes eclipse .project file.
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseProjectWriter
+{
+
+    private Log log;
+
+    public EclipseProjectWriter( Log log )
+    {
+        this.log = log;
+    }
+
+    protected void write( File projectBaseDir, File basedir, MavenProject project, MavenProject executedProject,
+                         List reactorArtifacts, List projectnatures, List buildCommands )
+        throws EclipsePluginException
+    {
+        FileWriter w;
+
+        try
+        {
+            w = new FileWriter( new File( basedir, ".project" ) ); //$NON-NLS-1$
+        }
+        catch ( IOException ex )
+        {
+            throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
+        }
+
+        XMLWriter writer = new PrettyPrintXMLWriter( w );
+
+        writer.startElement( "projectDescription" ); //$NON-NLS-1$
+
+        writer.startElement( "name" ); //$NON-NLS-1$
+        writer.writeText( project.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
+        // A eclipse developer might want to look at this.
+        writer.startElement( "comment" ); //$NON-NLS-1$
+
+        if ( project.getDescription() != null )
+        {
+            writer.writeText( project.getDescription() );
+        }
+
+        writer.endElement();
+
+        writer.startElement( "projects" ); //$NON-NLS-1$
+
+        for ( Iterator it = reactorArtifacts.iterator(); it.hasNext(); )
+        {
+            writer.startElement( "project" ); //$NON-NLS-1$
+            writer.writeText( ( (Artifact) it.next() ).getArtifactId() );
+            writer.endElement();
+        }
+
+        writer.endElement(); // projects
+
+        writer.startElement( "buildSpec" ); //$NON-NLS-1$
+
+        for ( Iterator it = buildCommands.iterator(); it.hasNext(); )
+        {
+            writer.startElement( "buildCommand" ); //$NON-NLS-1$
+            writer.startElement( "name" ); //$NON-NLS-1$
+            writer.writeText( (String) it.next() );
+            writer.endElement(); // name
+            writer.startElement( "arguments" ); //$NON-NLS-1$
+            writer.endElement(); // arguments
+            writer.endElement(); // buildCommand
+        }
+
+        writer.endElement(); // buildSpec
+
+        writer.startElement( "natures" ); //$NON-NLS-1$
+
+        for ( Iterator it = projectnatures.iterator(); it.hasNext(); )
+        {
+            writer.startElement( "nature" ); //$NON-NLS-1$
+            writer.writeText( (String) it.next() );
+            writer.endElement(); // name
+        }
+
+        writer.endElement(); // natures
+
+        if ( !projectBaseDir.equals( basedir ) )
+        {
+            writer.startElement( "linkedResources" ); //$NON-NLS-1$
+
+            addFileLink( writer, projectBaseDir, basedir, project.getFile() );
+
+            addSourceLinks( writer, projectBaseDir, basedir, executedProject.getCompileSourceRoots() );
+            addResourceLinks( writer, projectBaseDir, basedir, executedProject.getBuild().getResources() );
+
+            addSourceLinks( writer, projectBaseDir, basedir, executedProject.getTestCompileSourceRoots() );
+            addResourceLinks( writer, projectBaseDir, basedir, executedProject.getBuild().getTestResources() );
+
+            writer.endElement(); // linedResources
+        }
+
+        writer.endElement(); // projectDescription
+
+        IOUtil.close( w );
+    }
+
+    private void addFileLink( XMLWriter writer, File projectBaseDir, File basedir, File file )
+    {
+        if ( file.isFile() )
+        {
+            writer.startElement( "link" ); //$NON-NLS-1$
+
+            writer.startElement( "name" ); //$NON-NLS-1$
+            writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, file.toString(), true ) );
+            writer.endElement(); // name
+
+            writer.startElement( "type" ); //$NON-NLS-1$
+            writer.writeText( "1" ); //$NON-NLS-1$
+            writer.endElement(); // type
+
+            writer.startElement( "location" ); //$NON-NLS-1$
+            writer.writeText( file.toString().replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.endElement(); // location
+
+            writer.endElement(); // link
+        }
+        else
+        {
+            log.warn( Messages.getString( "EclipseProjectWriter.notafile", file ) ); //$NON-NLS-1$
+        }
+    }
+
+    private void addSourceLinks( XMLWriter writer, File projectBaseDir, File basedir, List sourceRoots )
+    {
+        for ( Iterator it = sourceRoots.iterator(); it.hasNext(); )
+        {
+            String sourceRoot = (String) it.next();
+
+            if ( new File( sourceRoot ).isDirectory() )
+            {
+                writer.startElement( "link" ); //$NON-NLS-1$
+
+                writer.startElement( "name" ); //$NON-NLS-1$
+                writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRoot, true ) );
+                writer.endElement(); // name
+
+                writer.startElement( "type" ); //$NON-NLS-1$
+                writer.writeText( "2" ); //$NON-NLS-1$
+                writer.endElement(); // type
+
+                writer.startElement( "location" ); //$NON-NLS-1$
+                writer.writeText( sourceRoot.replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                writer.endElement(); // location
+
+                writer.endElement(); // link
+            }
+        }
+    }
+
+    private void addResourceLinks( XMLWriter writer, File projectBaseDir, File basedir, List sourceRoots )
+    {
+        for ( Iterator it = sourceRoots.iterator(); it.hasNext(); )
+        {
+            String resourceDir = ( (Resource) it.next() ).getDirectory();
+
+            if ( new File( resourceDir ).isDirectory() )
+            {
+                writer.startElement( "link" ); //$NON-NLS-1$
+
+                writer.startElement( "name" ); //$NON-NLS-1$
+                writer.writeText( EclipseUtils.toRelativeAndFixSeparator( projectBaseDir, resourceDir, true ) );
+                writer.endElement(); // name
+
+                writer.startElement( "type" ); //$NON-NLS-1$
+                writer.writeText( "2" ); //$NON-NLS-1$
+                writer.endElement(); // type
+
+                writer.startElement( "location" ); //$NON-NLS-1$
+                writer.writeText( resourceDir.replaceAll( "\\\\", "/" ) ); //$NON-NLS-1$ //$NON-NLS-2$
+                writer.endElement(); // location
+
+                writer.endElement(); // link
+            }
+        }
+    }
+
+}

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSettingsWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSettingsWriter.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSettingsWriter.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSettingsWriter.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,96 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:kenney@neonics.com">Kenney Westerhof</a>
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseSettingsWriter
+{
+
+    private Log log;
+
+    public EclipseSettingsWriter( Log log )
+    {
+        this.log = log;
+    }
+
+    protected void write( File projectBaseDir, File outputDir, MavenProject project, MavenProject executedProject )
+        throws EclipsePluginException
+    {
+
+        // 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$
+
+        if ( source != null && !source.equals( "1.3" ) ) //$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$
+        }
+
+        if ( target != null && !target.equals( "1.2" ) ) //$NON-NLS-1$
+        {
+            coreSettings.put( "org.eclipse.jdt.core.compiler.codegen.targetPlatform", target ); //$NON-NLS-1$
+        }
+
+        // write the settings, if needed
+        if ( !coreSettings.isEmpty() )
+        {
+            File settingsDir = new File( outputDir, "/.settings" ); //$NON-NLS-1$
+
+            settingsDir.mkdirs();
+
+            coreSettings.put( "eclipse.preferences.version", "1" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            try
+            {
+                File coreSettingsFile = new File( settingsDir, "org.eclipse.jdt.core.prefs" ); //$NON-NLS-1$
+                coreSettings.store( new FileOutputStream( coreSettingsFile ), null );
+
+                log.info( Messages.getString( "EclipseSettingsWriter.wrotesettings", //$NON-NLS-1$
+                                              coreSettingsFile.getAbsolutePath() ) );
+            }
+            catch ( FileNotFoundException e )
+            {
+                throw new EclipsePluginException( Messages.getString( "EclipseSettingsWriter.cannotcreatesettings" ), e ); //$NON-NLS-1$
+            }
+            catch ( IOException e )
+            {
+                throw new EclipsePluginException( Messages.getString( "EclipseSettingsWriter.errorwritingsettings" ), e ); //$NON-NLS-1$
+            }
+        }
+        else
+        {
+            log.info( Messages.getString( "EclipseSettingsWriter.usingdefaults" ) ); //$NON-NLS-1$
+        }
+    }
+}

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseSourceDir.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,162 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Represent an eclipse source dir. Eclipse has no "main", "test" or "resource" concepts, so two source dirs with the
+ * same path are equal.
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseSourceDir
+    implements Comparable
+{
+
+    private String path;
+
+    private String output;
+
+    private String include;
+
+    private String exclude;
+
+    private boolean test;
+
+    public EclipseSourceDir( String path, String output, boolean test, String include, String exclude )
+    {
+        this.path = path;
+        this.output = output;
+        this.test = test;
+        this.include = include;
+        this.exclude = exclude;
+    }
+
+    /**
+     * Getter for <code>exclude</code>.
+     * @return Returns the exclude.
+     */
+    public String getExclude()
+    {
+        return this.exclude;
+    }
+
+    /**
+     * Setter for <code>exclude</code>.
+     * @param exclude The exclude to set.
+     */
+    public void setExclude( String exclude )
+    {
+        this.exclude = exclude;
+    }
+
+    /**
+     * Getter for <code>include</code>.
+     * @return Returns the include.
+     */
+    public String getInclude()
+    {
+        return this.include;
+    }
+
+    /**
+     * Setter for <code>include</code>.
+     * @param include The include to set.
+     */
+    public void setInclude( String include )
+    {
+        this.include = include;
+    }
+
+    /**
+     * Getter for <code>output</code>.
+     * @return Returns the output.
+     */
+    public String getOutput()
+    {
+        return this.output;
+    }
+
+    /**
+     * Setter for <code>output</code>.
+     * @param output The output to set.
+     */
+    public void setOutput( String output )
+    {
+        this.output = output;
+    }
+
+    /**
+     * Getter for <code>path</code>.
+     * @return Returns the path.
+     */
+    public String getPath()
+    {
+        return this.path;
+    }
+
+    /**
+     * Setter for <code>path</code>.
+     * @param path The path to set.
+     */
+    public void setPath( String path )
+    {
+        this.path = path;
+    }
+
+    /**
+     * Getter for <code>test</code>.
+     * @return Returns the test.
+     */
+    public boolean isTest()
+    {
+        return this.test;
+    }
+
+    /**
+     * Setter for <code>test</code>.
+     * @param test The test to set.
+     */
+    public void setTest( boolean test )
+    {
+        this.test = test;
+    }
+
+    /**
+     * @see java.lang.Object#equals(java.lang.Object)
+     */
+    public boolean equals( Object obj )
+    {
+        return this.path.equals( ( (EclipseSourceDir) obj ).path );
+    }
+
+    /**
+     * @see java.lang.Object#hashCode()
+     */
+    public int hashCode()
+    {
+        return this.path.hashCode();
+    }
+
+    /**
+     * @see java.lang.Comparable#compareTo(java.lang.Object)
+     */
+    public int compareTo( Object obj )
+    {
+        return this.path.compareTo( ( (EclipseSourceDir) obj ).path );
+    }
+
+}
\ No newline at end of file

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseUtils.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,90 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.util.Iterator;
+
+import org.apache.maven.model.Plugin;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
+
+/**
+ * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseUtils
+{
+
+    private EclipseUtils()
+    {
+        // don't instantiate
+    }
+
+    public static String toRelativeAndFixSeparator( File basedir, String absolutePath, boolean replaceSlashes )
+    {
+        String relative;
+
+        if ( absolutePath.equals( basedir.getAbsolutePath() ) )
+        {
+            relative = ".";
+        }
+        else if ( absolutePath.startsWith( basedir.getAbsolutePath() ) )
+        {
+            relative = absolutePath.substring( basedir.getAbsolutePath().length() + 1 );
+        }
+        else
+        {
+            relative = absolutePath;
+        }
+
+        relative = StringUtils.replace( relative, "\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        if ( replaceSlashes )
+        {
+            relative = StringUtils.replace( relative, "/", "-" ); //$NON-NLS-1$ //$NON-NLS-2$
+        }
+
+        return relative;
+    }
+
+    /**
+     * @todo there should be a better way to do this
+     */
+    public static String getPluginSetting( MavenProject project, String artifactId, String optionName,
+                                          String defaultValue )
+    {
+        for ( Iterator it = project.getModel().getBuild().getPlugins().iterator(); it.hasNext(); )
+        {
+            Plugin plugin = (Plugin) it.next();
+
+            if ( plugin.getArtifactId().equals( artifactId ) )
+            {
+                Xpp3Dom o = (Xpp3Dom) plugin.getConfiguration();
+
+                if ( o != null && o.getChild( optionName ) != null )
+                {
+                    return o.getChild( optionName ).getValue();
+                }
+            }
+        }
+
+        return defaultValue;
+    }
+}

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWtpmodulesWriter.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWtpmodulesWriter.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWtpmodulesWriter.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/EclipseWtpmodulesWriter.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,243 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+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.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
+import org.codehaus.plexus.util.xml.XMLWriter;
+
+/**
+ * Writes eclipse .wtpmodules file.
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+public class EclipseWtpmodulesWriter
+{
+
+    private Log log;
+
+    public EclipseWtpmodulesWriter( Log log )
+    {
+        this.log = log;
+    }
+
+    protected void write( File basedir, MavenProject project, List referencedReactorArtifacts,
+                         EclipseSourceDir[] sourceDirs, ArtifactRepository localRepository )
+        throws EclipsePluginException
+    {
+        FileWriter w;
+
+        try
+        {
+            w = new FileWriter( new File( basedir, ".wtpmodules" ) ); //$NON-NLS-1$
+        }
+        catch ( IOException ex )
+        {
+            throw new EclipsePluginException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$
+        }
+
+        XMLWriter writer = new PrettyPrintXMLWriter( w );
+
+        writer.startElement( "project-modules" ); //$NON-NLS-1$
+        writer.addAttribute( "id", "moduleCoreId" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+        writer.startElement( "wb-module" ); //$NON-NLS-1$
+        writer.addAttribute( "deploy-name", project.getArtifactId() ); //$NON-NLS-1$
+
+        writer.startElement( "module-type" ); //$NON-NLS-1$
+        if ( "war".equals( project.getPackaging() ) ) //$NON-NLS-1$
+        {
+            // <module-type module-type-id="jst.web">
+            //   <version>2.4</version>
+            //   <property name="context-root" value="magnolia">
+            //   </property>
+            // </module-type>
+
+            writer.addAttribute( "module-type-id", "jst.web" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( "version" ); //$NON-NLS-1$
+
+            // defaults to 2.4, try to detect real version from dependencies
+            String servletVersion = "2.4"; //$NON-NLS-1$
+
+            for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
+            {
+                Artifact artifact = (Artifact) it.next();
+                if ( "servletapi".equals( artifact.getArtifactId() ) //$NON-NLS-1$
+                    || "geronimo-spec-servlet".equals( artifact.getArtifactId() ) ) //$NON-NLS-1$
+                {
+                    servletVersion = StringUtils.substring( artifact.getVersion(), 0, 3 );
+                }
+            }
+
+            writer.writeText( servletVersion );
+            writer.endElement();
+
+            writer.startElement( "property" ); //$NON-NLS-1$
+            writer.addAttribute( "name", "context-root" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "value", project.getArtifactId() ); //$NON-NLS-1$
+            writer.endElement();
+        }
+        else if ( "ejb".equals( project.getPackaging() ) ) //$NON-NLS-1$
+        {
+            //  <module-type module-type-id="jst.ejb">
+            //    <version>2.1</version>
+            //    <property name="java-output-path" value="/bin/"/>
+            //  </module-type>
+
+            writer.addAttribute( "module-type-id", "jst.ejb" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( "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( "property" ); //$NON-NLS-1$
+            writer.addAttribute( "name", "java-output-path" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "value", "/" + //$NON-NLS-1$ //$NON-NLS-2$
+                EclipseUtils.toRelativeAndFixSeparator( project.getBasedir(), project.getBuild().getOutputDirectory(),
+                                                        false ) );
+            writer.endElement();
+        }
+        else
+        {
+            //  <module-type module-type-id="jst.utility">
+            //    <property name="java-output-path" value="/bin/"/>
+            //  </module-type>
+
+            writer.addAttribute( "module-type-id", "jst.utility" ); //$NON-NLS-1$ //$NON-NLS-2$
+
+            writer.startElement( "property" ); //$NON-NLS-1$
+            writer.addAttribute( "name", "java-output-path" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "value", "/" + //$NON-NLS-1$ //$NON-NLS-2$
+                EclipseUtils.toRelativeAndFixSeparator( project.getBasedir(), project.getBuild().getOutputDirectory(),
+                                                        false ) );
+            writer.endElement();
+        }
+        writer.endElement(); // module-type
+
+        // source and resource paths.
+        // deploy-path is "/" for utility and ejb projects, "/WEB-INF/classes" for webapps
+
+        String target = "/"; //$NON-NLS-1$
+        if ( "war".equals( project.getPackaging() ) ) //$NON-NLS-1$
+        {
+            writeWarSpecificResources( writer, basedir, project, referencedReactorArtifacts, localRepository );
+
+            target = "/WEB-INF/classes"; //$NON-NLS-1$
+        }
+
+        for ( int j = 0; j < sourceDirs.length; j++ )
+        {
+            EclipseSourceDir dir = sourceDirs[j];
+            // test src/resources are not added to wtpmodules
+            if ( !dir.isTest() )
+            {
+                //  <wb-resource deploy-path="/" source-path="/src/java" />
+                writer.startElement( "wb-resource" ); //$NON-NLS-1$
+                writer.addAttribute( "deploy-path", target ); //$NON-NLS-1$
+                writer.addAttribute( "source-path", dir.getPath() ); //$NON-NLS-1$
+                writer.endElement();
+            }
+        }
+
+        writer.endElement(); // wb-module
+        writer.endElement(); // project-modules
+
+        IOUtil.close( w );
+    }
+
+    private void writeWarSpecificResources( XMLWriter writer, File basedir, MavenProject project,
+                                           List referencedReactorArtifacts, ArtifactRepository localRepository )
+    {
+
+        String warSourceDirectory = EclipseUtils.getPluginSetting( project, "maven-war-plugin", //$NON-NLS-1$
+                                                                   "warSourceDirectory", //$NON-NLS-1$
+                                                                   "/src/main/webapp" ); //$NON-NLS-1$
+
+        writer.startElement( "wb-resource" ); //$NON-NLS-1$
+        writer.addAttribute( "deploy-path", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "source-path", //$NON-NLS-1$
+                             EclipseUtils.toRelativeAndFixSeparator( basedir, warSourceDirectory, false ) );
+        writer.endElement();
+
+        // dependencies
+        for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
+        {
+            Artifact artifact = (Artifact) it.next();
+            addDependency( writer, artifact, referencedReactorArtifacts, localRepository );
+        }
+    }
+
+    private void addDependency( XMLWriter writer, Artifact artifact, List referencedReactorProjects,
+                               ArtifactRepository localRepository )
+    {
+        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 )
+            {
+                log.error( Messages.getString( "EclipsePlugin.artifactpathisnull", artifact.getId() ) ); //$NON-NLS-1$
+                return;
+            }
+
+            String fullPath = artifactPath.getPath();
+            File localRepositoryFile = new File( localRepository.getBasedir() );
+
+            handle = "module:/classpath/var/M2_REPO/" //$NON-NLS-1$
+                + EclipseUtils.toRelativeAndFixSeparator( localRepositoryFile, fullPath, false );
+        }
+
+        writer.startElement( "dependent-module" ); //$NON-NLS-1$
+
+        writer.addAttribute( "deploy-path", "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$
+        writer.addAttribute( "handle", handle ); //$NON-NLS-1$
+
+        writer.startElement( "dependency-type" ); //$NON-NLS-1$
+        writer.writeText( "uses" ); //$NON-NLS-1$
+        writer.endElement();
+
+        writer.endElement();
+    }
+
+}

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/java/org/apache/maven/plugin/eclipse/Messages.java Sun Sep 11 22:27:40 2005
@@ -0,0 +1,65 @@
+package org.apache.maven.plugin.eclipse;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import java.text.MessageFormat;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * @author <a href="mailto:fgiust@users.sourceforge.net">Fabrizio Giustina</a>
+ * @version $Id$
+ */
+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 );
+
+    private Messages()
+    {
+    }
+
+    public static String getString( String key )
+    {
+        try
+        {
+            return RESOURCE_BUNDLE.getString( key );
+        }
+        catch ( MissingResourceException e )
+        {
+            return '!' + key + '!';
+        }
+    }
+
+    public static String getString( String key, Object[] params )
+    {
+        try
+        {
+            return MessageFormat.format( RESOURCE_BUNDLE.getString( key ), params );
+        }
+        catch ( MissingResourceException e )
+        {
+            return '!' + key + '!';
+        }
+    }
+
+    public static String getString( String key, Object param )
+    {
+        return getString( key, new Object[] { param } );
+    }
+}

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

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

Added: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties?rev=280259&view=auto
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties (added)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties Sun Sep 11 22:27:40 2005
@@ -0,0 +1,21 @@
+EclipsePlugin.missingpom=There must be a POM in the current working directory for the Eclipse plugin to work.
+EclipsePlugin.pompackaging=Don't generate Eclipse project for pom project
+EclipsePlugin.notadir=Not a directory: "{0}"
+EclipsePlugin.cantcreatedir=Can''t create directory "{0}"
+EclipsePlugin.erroropeningfile=Exception while opening file.
+EclipsePlugin.wrote=Wrote Eclipse project for "{0}" to {1}.
+EclipsePlugin.missingelement=Missing element from the project descriptor: "{0}"
+EclipsePlugin.includenotsupported=This plugin currently doesn't support include patterns for resources. Adding the entire directory.
+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}
+
+EclipseSettingsWriter.wrotesettings=Wrote settings to {0}
+EclipseSettingsWriter.cannotcreatesettings=Cannot create settings file
+EclipseSettingsWriter.errorwritingsettings=Error writing settings file
+EclipseSettingsWriter.usingdefaults=Not writing settings - defaults suffice
+
+EclipseClasspathWriter.lookingforsources=Looking for source archive for artifact {0}
+EclipseClasspathWriter.sourcesnotavailable=Sources for artifact {0} are not available
+EclipseClasspathWriter.sourcesavailable=Sources attachment for artifact {0} set to {1}
+
+EclipseProjectWriter.notafile=Not adding a file link to {0}; it is not a file
\ No newline at end of file

Propchange: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/main/resources/org/apache/maven/plugin/eclipse/messages.properties
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java?rev=280259&r1=280258&r2=280259&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java Sun Sep 11 22:27:40 2005
@@ -16,23 +16,25 @@
  * limitations under the License.
  */
 
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
 import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.repository.DefaultArtifactRepository;
 import org.apache.maven.artifact.repository.layout.ArtifactRepositoryLayout;
+import org.apache.maven.artifact.resolver.ArtifactResolver;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -61,12 +63,20 @@
     public void testProject4()
         throws Exception
     {
-        testProject( "project-4",  getTestFile( "target/project-4-test/" ) );
+        testProject( "project-4", getTestFile( "target/project-4-test/" ) );
+    }
+
+    public void testProject5()
+        throws Exception
+    {
+        testProject( "project-5", null );
     }
 
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
+    public void testProject6()
+        throws Exception
+    {
+        testProject( "project-6", null );
+    }
 
     private void testProject( String projectName, File outputDir )
         throws Exception
@@ -79,12 +89,16 @@
 
         File repo = getTestFile( "src/test/repository" );
 
-        ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup( ArtifactRepositoryLayout.ROLE, "legacy" );
+        ArtifactRepositoryLayout localRepositoryLayout = (ArtifactRepositoryLayout) lookup(
+                                                                                            ArtifactRepositoryLayout.ROLE,
+                                                                                            "legacy" );
 
-        ArtifactRepository localRepository = new DefaultArtifactRepository( "local", "file://" + repo.getAbsolutePath(),
+        ArtifactRepository localRepository = new DefaultArtifactRepository( "local",
+                                                                            "file://" + repo.getAbsolutePath(),
                                                                             localRepositoryLayout );
 
-        MavenProject project = builder.buildWithDependencies( new File( basedir, "project.xml" ), localRepository, null );
+        MavenProject project = builder
+            .buildWithDependencies( new File( basedir, "project.xml" ), localRepository, null );
 
         File projectOutputDir = basedir;
 
@@ -99,26 +113,56 @@
             projectOutputDir = new File( outputDir, project.getArtifactId() );
         }
 
-        System.err.println("basedir: " + basedir+"\noutputdir: " + outputDir+"\nprojectOutputDir: " + projectOutputDir );
+        // Shouldn't PlexusTestCase at least offer a predefined log instance?
+        //  if ( log.isDebugEnabled() )
+        //  {
+        //    log.debug( "basedir: " + basedir + "\noutputdir: " + outputDir + "\nprojectOutputDir: " + projectOutputDir );
+        //  }
 
         plugin.setOutputDir( outputDir );
 
-
         for ( Iterator it = project.getArtifacts().iterator(); it.hasNext(); )
         {
             Artifact artifact = (Artifact) it.next();
-            artifact.setFile(new File(localRepository.getBasedir(), localRepository.pathOf(artifact)));
+            artifact.setFile( new File( localRepository.getBasedir(), localRepository.pathOf( artifact ) ) );
         }
 
         plugin.setProject( project );
 
         plugin.setLocalRepository( localRepository );
 
+        plugin.setArtifactFactory( (ArtifactFactory) lookup( ArtifactFactory.ROLE ) );
+        plugin.setArtifactResolver( (ArtifactResolver) lookup( ArtifactResolver.ROLE ) );
+        plugin.setRemoteArtifactRepositories( new ArrayList( 0 ) );
+
+        List projectNatures = new ArrayList();
+        projectNatures.add( "org.eclipse.jdt.core.javanature" );
+        plugin.setProjectnatures( projectNatures );
+
+        List buildcommands = new ArrayList();
+        buildcommands.add( "org.eclipse.jdt.core.javabuilder" );
+        plugin.setBuildcommands( buildcommands );
+
+        plugin.setClasspathContainers( new ArrayList() );
+
+        // @todo how to test injected parameters?
+
         plugin.execute();
 
-        assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ), new File( projectOutputDir, ".project" ) );
+        assertFileEquals( localRepository.getBasedir(), new File( basedir, "project" ), new File( projectOutputDir,
+                                                                                                  ".project" ) );
+
+        assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ), new File( projectOutputDir,
+                                                                                                    ".classpath" ) );
 
-        assertFileEquals( localRepository.getBasedir(), new File( basedir, "classpath" ), new File( projectOutputDir, ".classpath" ) );
+        assertFileEquals( localRepository.getBasedir(), new File( basedir, "wtpmodules" ), new File( projectOutputDir,
+                                                                                                     ".wtpmodules" ) );
+
+        if ( new File( basedir, "settings" ).exists() )
+        {
+            assertFileEquals( localRepository.getBasedir(), new File( basedir, "settings" ),
+                              new File( basedir, ".settings/org.eclipse.jdt.core.prefs" ) );
+        }
     }
 
     private void assertFileEquals( String mavenRepo, File expectedFile, File actualFile )
@@ -137,14 +181,21 @@
 
             expected = StringUtils.replace( expected, "${basedir}", basedir.replace( '\\', '/' ) );
 
-            if ( actualLines.size() < i )
+            if ( actualLines.size() <= i )
             {
-                fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: " + expectedLines.size() );
+                fail( "Too few lines in the actual file. Was " + actualLines.size() + ", expected: "
+                    + expectedLines.size() );
             }
 
             String actual = actualLines.get( i ).toString();
 
-            assertEquals( "Checking line #" + (i + 1), expected, actual );
+            if ( expected.startsWith( "#" ) && actual.startsWith( "#" ) )
+            {
+                //ignore comments, for settings file
+                continue;
+            }
+
+            assertEquals( "Checking line #" + ( i + 1 ), expected, actual );
         }
 
         assertTrue( "Unequal number of lines.", expectedLines.size() == actualLines.size() );
@@ -159,7 +210,7 @@
 
         String line;
 
-        while ( (line = reader.readLine()) != null )
+        while ( ( line = reader.readLine() ) != null )
         {
             lines.add( line );//StringUtils.replace( line, "#ArtifactRepositoryPath#", mavenRepo.replace( '\\', '/' ) ) );
         }

Propchange: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Sun Sep 11 22:27:40 2005
@@ -0,0 +1,4 @@
+.classpath
+.settings
+.wtpmodules
+.project

Propchange: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Sun Sep 11 22:27:40 2005
@@ -1,2 +1,4 @@
 .classpath
+.settings
+.wtpmodules
 .project

Modified: maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/classpath
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/classpath?rev=280259&r1=280258&r2=280259&view=diff
==============================================================================
--- maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/classpath (original)
+++ maven/components/trunk/maven-plugins/maven-eclipse-plugin/src/test/projects/project-1/classpath Sun Sep 11 22:27:40 2005
@@ -2,5 +2,5 @@
   <classpathentry kind="src" path="src/main/java"/>
   <classpathentry kind="output" path="target/classes"/>
   <classpathentry kind="var" rootpath="JRE_SRCROOT" path="JRE_LIB" sourcepath="JRE_SRC"/>
-  <classpathentry kind="var" path="M2_REPO/maven/jars/maven-core-98.0.jar"/>
+  <classpathentry kind="var" path="M2_REPO/maven/jars/maven-core-98.0.jar" sourcepath="M2_REPO/maven/java-sources/maven-core-98.0-sources.jar"/>
 </classpath>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org