You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ah...@apache.org on 2007/11/02 03:17:02 UTC

svn commit: r591192 [1/4] - in /maven/plugins/branches/MECLIPSE-333/src: main/java/org/apache/maven/plugin/eclipse/ main/java/org/apache/maven/plugin/eclipse/writers/ main/java/org/apache/maven/plugin/eclipse/writers/rad/ main/java/org/apache/maven/plu...

Author: aheritier
Date: Thu Nov  1 19:16:57 2007
New Revision: 591192

URL: http://svn.apache.org/viewvc?rev=591192&view=rev
Log:
MECLIPSE-333 : WTP-2.0 support with howto apt, refactoring and contextroot handling
Applied :
maven-eclipse-plugin_only_new.tar.gz
maven-eclipse-plugin_only_new_2.tar.tgz
wtp-2.0-and-more-2.5-SNAPSHOT.patch

Added:
    maven/plugins/branches/MECLIPSE-333/src/site/apt/examples/multi-module-projects.apt   (with props)
    maven/plugins/branches/MECLIPSE-333/src/site/resources/
    maven/plugins/branches/MECLIPSE-333/src/site/resources/j2ee-simple.tar.gz   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/eclipsetest/multymodule-war/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/eclipsetest/multymodule-war/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/eclipsetest/multymodule-war/1.0/multymodule-war-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/eclipsetest/multymodule-war/1.0/multymodule-war-1.0.war   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/1.0/project-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/ejbs/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/ejbs/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/ejbs/1.0/ejbs-1.0.jar   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/ejbs/1.0/ejbs-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/primary-source/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/primary-source/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/primary-source/1.0/primary-source-1.0.jar   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/primary-source/1.0/primary-source-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/1.0/projects-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/logging/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/logging/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/logging/1.0/logging-1.0.jar   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/projects/logging/1.0/logging-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/1.0/servlets-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/servlet/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/servlet/1.0/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/servlet/1.0/servlet-1.0.pom   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/m2repo/root/project/servlets/servlet/1.0/servlet-1.0.war   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/.project   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ear/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ear/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/java/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/java/hello/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/resources/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/resources/META-INF/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/ejbs/src/main/resources/META-INF/ejb-jar.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/primary-source/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/primary-source/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/primary-source/src/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/primary-source/src/main/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/primary-source/src/main/java/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/projects/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/projects/logging/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/projects/logging/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/projects/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/main/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/main/webapp/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/main/webapp/WEB-INF/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/main/webapp/WEB-INF/web.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/servlets/servlet/src/main/webapp/index.jsp   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/src/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/src/main/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/j2ee-simple/src/main/resources/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-ear/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-ear/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/pom.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/src/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/src/main/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/src/main/webapp/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/src/main/webapp/WEB-INF/
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/multymodule-war/src/main/webapp/WEB-INF/web.xml   (with props)
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-35/pom.xml   (with props)
Modified:
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadManifestWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/AbstractWtpResourceWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpApplicationXMLWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponent15Writer.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpComponentWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpFacetsWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/wtp/EclipseWtpmodulesWriter.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/ide/AbstractIdeSupportMojo.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/ide/IdeUtils.java
    maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/ide/JeeUtils.java
    maven/plugins/branches/MECLIPSE-333/src/site/site.xml
    maven/plugins/branches/MECLIPSE-333/src/test/java/org/apache/maven/plugin/eclipse/AbstractEclipsePluginTestCase.java
    maven/plugins/branches/MECLIPSE-333/src/test/java/org/apache/maven/plugin/eclipse/EclipsePluginTest.java
    maven/plugins/branches/MECLIPSE-333/src/test/java/org/apache/maven/plugin/eclipse/RadPluginTest.java
    maven/plugins/branches/MECLIPSE-333/src/test/resources/projects/project-34/pom.xml

Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java Thu Nov  1 19:16:57 2007
@@ -49,21 +49,23 @@
 import org.apache.maven.plugin.ide.AbstractIdeSupportMojo;
 import org.apache.maven.plugin.ide.IdeDependency;
 import org.apache.maven.plugin.ide.IdeUtils;
+import org.apache.maven.plugin.ide.JeeUtils;
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
 
 /**
  * Generates the following eclipse configuration files:
  * <ul>
- *   <li><code>.project</code> and <code>.classpath</code> files</li>
- *   <li><code>.setting/org.eclipse.jdt.core.prefs</code> with project specific compiler settings</li>
- *   <li>various configuration files for WTP (Web Tools Project), if the parameter <code>wtpversion</code> is set to a
- *   valid version (WTP configuration is not generated by default)</li>
+ * <li><code>.project</code> and <code>.classpath</code> files</li>
+ * <li><code>.setting/org.eclipse.jdt.core.prefs</code> with project specific compiler settings</li>
+ * <li>various configuration files for WTP (Web Tools Project), if the parameter <code>wtpversion</code> is set to a
+ * valid version (WTP configuration is not generated by default)</li>
  * </ul>
  * If this goal is run on a multiproject root, dependencies between modules will be configured as direct project
  * dependencies in Eclipse (unless <code>useProjectReferences</code> is set to <code>false</code>).
- *
+ * 
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @author <a href="mailto:fgiust@apache.org">Fabrizio Giustina</a>
  * @version $Id$
@@ -76,13 +78,15 @@
 
     private static final String NATURE_WST_FACET_CORE_NATURE = "org.eclipse.wst.common.project.facet.core.nature"; //$NON-NLS-1$
 
-    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; //$NON-NLS-1$
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER =
+        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver"; //$NON-NLS-1$
 
     private static final String BUILDER_WST_VALIDATION = "org.eclipse.wst.validation.validationbuilder"; //$NON-NLS-1$
 
     private static final String BUILDER_JDT_CORE_JAVA = "org.eclipse.jdt.core.javabuilder"; //$NON-NLS-1$
 
-    private static final String BUILDER_WST_COMPONENT_STRUCTURAL = "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; //$NON-NLS-1$
+    private static final String BUILDER_WST_COMPONENT_STRUCTURAL =
+        "org.eclipse.wst.common.modulecore.ComponentStructuralBuilder"; //$NON-NLS-1$
 
     private static final String BUILDER_WST_FACET = "org.eclipse.wst.common.project.facet.core.builder"; //$NON-NLS-1$
 
@@ -102,8 +106,8 @@
 
     protected static final String REQUIRED_PLUGINS_CONTAINER = "org.eclipse.pde.core.requiredPlugins"; //$NON-NLS-1$
 
-    //  warning, order is important for binary search
-    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$  //$NON-NLS-3$
+    // warning, order is important for binary search
+    public static final String[] WTP_SUPPORTED_VERSIONS = new String[] { "1.0", "1.5", "2.0", "R7", "none" }; //$NON-NLS-1$ //$NON-NLS-2$  //$NON-NLS-3$
 
     /**
      * Constant for 'artifactId' element in POM.xml.
@@ -116,34 +120,33 @@
     private static final String POM_ELT_GROUP_ID = "groupId"; //$NON-NLS-1$
 
     /**
-     * List of eclipse project natures. By default the
-     * <code>org.eclipse.jdt.core.javanature</code> nature plus the needed WTP
-     * natures are added. Natures added using this property <strong>replace</strong> the default list.
-     *
+     * List of eclipse project natures. By default the <code>org.eclipse.jdt.core.javanature</code> nature plus the
+     * needed WTP natures are added. Natures added using this property <strong>replace</strong> the default list.
+     * 
      * <pre>
      * &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 project natures to be added to the default ones.
-     *
+     * 
      * <pre>
      * &lt;additionalProjectnatures&gt;
      *    &lt;projectnature&gt;org.springframework.ide.eclipse.core.springnature&lt;/projectnature&gt;
      * &lt;/additionalProjectnatures&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List additionalProjectnatures;
-    
+
     /**
      * List of eclipse project facets to be added to the default ones.
      * 
@@ -152,21 +155,17 @@
      *    &lt;jst.jsf&gt;1.1&lt;jst.jsf/&gt;
      * &lt;/additionalProjectFacets&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private Map additionalProjectFacets;
 
     /**
-     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the needed
-     * WTP builders are added.
-     *
-     * If you specify any configuration for this parameter, only those buildcommands specified will be used; the defaults
-     * won't be added. Use the <code>additionalBuildCommands</code> parameter for that.
-     *
-     * Configuration example:
-     *
-     * Old style:
+     * List of eclipse build commands. By default the <code>org.eclipse.jdt.core.javabuilder</code> builder plus the
+     * needed WTP builders are added. If you specify any configuration for this parameter, only those buildcommands
+     * specified will be used; the defaults won't be added. Use the <code>additionalBuildCommands</code> parameter for
+     * that. Configuration example: Old style:
+     * 
      * <pre>
      * &lt;buildcommands&gt;
      *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilder&lt;/buildcommand&gt;
@@ -174,24 +173,24 @@
      *    &lt;buildcommand&gt;org.eclipse.wst.common.modulecore.ComponentStructuralBuilderDependencyResolver&lt;/buildcommand&gt;
      * &lt;/buildcommands&gt;
      * </pre>
-     *
+     * 
      * For new style, see <code>additionalBuildCommands</code>.
-     *
+     * 
      * @parameter
      */
     private List buildcommands;
 
     /**
-     * List of eclipse build commands to be added to the default ones.
-     *
-     * Old style:
+     * List of eclipse build commands to be added to the default ones. Old style:
+     * 
      * <pre>
      * &lt;additionalBuildcommands&gt;
      *    &lt;buildcommand&gt;org.springframework.ide.eclipse.core.springbuilder&lt;/buildcommand&gt;
      * &lt;/additionalBuildcommands&gt;
      * </pre>
-     *
+     * 
      * New style:
+     * 
      * <pre>
      * &lt;additionalBuildcommands&gt;
      *    &lt;buildCommand&gt;
@@ -203,19 +202,18 @@
      *    &lt;/buildCommand&gt;
      * &lt;/additionalBuildcommands&gt;
      * </pre>
-     *
-     * Note the difference between <code>build<strong>c</strong>ommand</code>
-     * and <code>build<strong>C</strong>ommand</code>.
-     *
-     * You can mix and match old and new-style configuration entries.
-     *
+     * 
+     * Note the difference between <code>build<strong>c</strong>ommand</code> and
+     * <code>build<strong>C</strong>ommand</code>. You can mix and match old and new-style configuration entries.
+     * 
      * @parameter
      */
     private List additionalBuildcommands;
 
     /**
-     * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code> classpath
-     * container is added. Configuration example:
+     * List of container classpath entries. By default the <code>org.eclipse.jdt.launching.JRE_CONTAINER</code>
+     * classpath container is added. Configuration example:
+     * 
      * <pre>
      * &lt;classpathContainers&gt;
      *    &lt;classpathContainer&gt;org.eclipse.jdt.launching.JRE_CONTAINER&lt;/classpathContainer&gt;
@@ -223,14 +221,14 @@
      *    &lt;classpathContainer&gt;org.eclipse.jst.j2ee.internal.web.container/artifact&lt;/classpathContainer&gt;
      * &lt;/classpathContainers&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private List classpathContainers;
 
     /**
      * Enables/disables the downloading of source attachments. Defaults to false. DEPRECATED - use downloadSources
-     *
+     * 
      * @parameter expression="${eclipse.downloadSources}"
      * @deprecated use downloadSources
      */
@@ -238,16 +236,15 @@
 
     /**
      * 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
-     *
+     * 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
      */
@@ -255,41 +252,41 @@
 
     /**
      * The default output directory
-     *
-     * @parameter expression="${outputDirectory}" alias="outputDirectory" default-value="${project.build.outputDirectory}"
+     * 
+     * @parameter expression="${outputDirectory}" alias="outputDirectory"
+     *            default-value="${project.build.outputDirectory}"
      * @required
      */
     private File buildOutputDirectory;
 
     /**
-     * The version of WTP for which configuration files will be generated.
-     * The default value is "none" (don't generate WTP configuration), supported versions are "R7", "1.0", and "1.5"
-     *
+     * The version of WTP for which configuration files will be generated. The default value is "none" (don't generate
+     * WTP configuration), supported versions are "R7", "1.0", and "1.5"
+     * 
      * @parameter expression="${wtpversion}" default-value="none"
      */
     private String wtpversion;
-    
+
     /**
-    * JEE context name of the WTP module. ( ex. WEB context name ).
-    *
-    * @parameter expression="${wtpContextName}" default-value="${project.artifactId}"
-    */
+     * JEE context name of the WTP module. ( ex. WEB context name ).
+     * 
+     * @parameter expression="${wtpContextName}"
+     */
     private String wtpContextName;
-    
 
     /**
-     * Is it an PDE project? If yes, the plugin adds the necessary natures and build commands to
-     * the .project file. Additionally it copies all libraries to a project local directory and
-     * references them instead of referencing the files in the local Maven repository. It also
-     * ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is synchronized.
-     *
+     * Is it an PDE project? If yes, the plugin adds the necessary natures and build commands to the .project file.
+     * Additionally it copies all libraries to a project local directory and references them instead of referencing the
+     * files in the local Maven repository. It also ensured that the "Bundle-Classpath" in META-INF/MANIFEST.MF is
+     * synchronized.
+     * 
      * @parameter expression="${eclipse.pde}" default-value="false"
      */
     private boolean pde;
 
     /**
      * The relative path of the manifest file
-     *
+     * 
      * @parameter expression="${eclipse.manifest}" default-value="${basedir}/META-INF/MANIFEST.MF"
      */
     private File manifest;
@@ -297,55 +294,51 @@
     /**
      * Allow to configure additional generic configuration files for eclipse that will be written out to disk when
      * running eclipse:eclipse. FOr each file you can specify the name and the text content.
-     *
+     * 
      * <pre>
      * &lt;additionalConfig&gt;
      *    &lt;file&gt;
      *      &lt;name&gt;.checkstyle&lt;/name&gt;
      *      &lt;content&gt;
-     *        &lt;![CDATA[&lt;fileset-config file-format-version="1.2.0" simple-config="true"&gt;
-     *          &lt;fileset name="all" enabled="true" check-config-name="acme corporate style" local="false"&gt;
-     *              &lt;file-match-pattern match-pattern="." include-pattern="true"/&gt;
+     *        &lt;![CDATA[&lt;fileset-config file-format-version=&quot;1.2.0&quot; simple-config=&quot;true&quot;&gt;
+     *          &lt;fileset name=&quot;all&quot; enabled=&quot;true&quot; check-config-name=&quot;acme corporate style&quot; local=&quot;false&quot;&gt;
+     *              &lt;file-match-pattern match-pattern=&quot;.&quot; include-pattern=&quot;true&quot;/&gt;
      *          &lt;/fileset&gt;
-     *          &lt;filter name="NonSrcDirs" enabled="true"/&gt;
+     *          &lt;filter name=&quot;NonSrcDirs&quot; enabled=&quot;true&quot;/&gt;
      *        &lt;/fileset-config&gt;]]&gt;
      *      &lt;/content&gt;
      *    &lt;/file&gt;
      * &lt;/additionalConfig&gt;
      * </pre>
-     *
+     * 
      * @parameter
      */
     private EclipseConfigFile[] additionalConfig;
-    
+
     /**
-     * If set to <code>true</code>, the version number of the artifact is appended
-     * to the name of the generated Eclipse project. See projectNameTemplate for other options.
+     * If set to <code>true</code>, the version number of the artifact is appended to the name of the generated
+     * Eclipse project. See projectNameTemplate for other options.
      * 
      * @parameter expression="${eclipse.addVersionToProjectName}" default-value="false"
      */
     private boolean addVersionToProjectName;
 
     /**
-     * If set to <code>true</code>, the groupId of the artifact is appended
-     * to the name of the generated Eclipse project. See projectNameTemplate for other options.
+     * If set to <code>true</code>, the groupId of the artifact is appended to the name of the generated Eclipse
+     * project. See projectNameTemplate for other options.
      * 
      * @parameter expression="${eclipse.addGroupIdToProjectName}" default-value="false"
      */
     private boolean addGroupIdToProjectName;
 
     /**
-     * Allows configuring the name of the eclipse projects. This property if set wins over
-     * addVersionToProjectName and addGroupIdToProjectName
-     * 
-     * You can use <code>[groupId]</code>, <code>[artifactId]</code> and <code>[version]</code>
-     * variables.
-     * 
-     * eg. <code>[groupId].[artifactId]-[version]</code>
+     * Allows configuring the name of the eclipse projects. This property if set wins over addVersionToProjectName and
+     * addGroupIdToProjectName You can use <code>[groupId]</code>, <code>[artifactId]</code> and
+     * <code>[version]</code> variables. eg. <code>[groupId].[artifactId]-[version]</code>
      * 
      * @parameter expression="${eclipse.projectNameTemplate}"
      */
-    private String projectNameTemplate; 
+    private String projectNameTemplate;
 
     /**
      * Parsed wtp version.
@@ -363,19 +356,19 @@
      * @parameter expression="${eclipse.wtpmanifest}" default-value="false"
      */
     private boolean wtpmanifest;
-    
+
     /**
      * Must the application files be written for ear projects in a separate directory.
      * 
      * @parameter expression="${eclipse.wtpapplicationxml}" default-value="false"
      */
     private boolean wtpapplicationxml;
-    
+
     protected boolean isJavaProject()
     {
         return isJavaProject;
     }
-    
+
     protected boolean isPdeProject()
     {
         return pde;
@@ -383,6 +376,7 @@
 
     /**
      * Getter for <code>buildcommands</code>.
+     * 
      * @return Returns the buildcommands.
      */
     public List getBuildcommands()
@@ -392,6 +386,7 @@
 
     /**
      * Setter for <code>buildcommands</code>.
+     * 
      * @param buildcommands The buildcommands to set.
      */
     public void setBuildcommands( List buildcommands )
@@ -401,6 +396,7 @@
 
     /**
      * Getter for <code>buildOutputDirectory</code>.
+     * 
      * @return Returns the buildOutputDirectory.
      */
     public File getBuildOutputDirectory()
@@ -410,6 +406,7 @@
 
     /**
      * Setter for <code>buildOutputDirectory</code>.
+     * 
      * @param buildOutputDirectory The buildOutputDirectory to set.
      */
     public void setBuildOutputDirectory( File buildOutputDirectory )
@@ -419,6 +416,7 @@
 
     /**
      * Getter for <code>classpathContainers</code>.
+     * 
      * @return Returns the classpathContainers.
      */
     public List getClasspathContainers()
@@ -428,6 +426,7 @@
 
     /**
      * Setter for <code>classpathContainers</code>.
+     * 
      * @param classpathContainers The classpathContainers to set.
      */
     public void setClasspathContainers( List classpathContainers )
@@ -437,6 +436,7 @@
 
     /**
      * Getter for <code>eclipseProjectDir</code>.
+     * 
      * @return Returns the eclipseProjectDir.
      */
     public File getEclipseProjectDir()
@@ -446,6 +446,7 @@
 
     /**
      * Setter for <code>eclipseProjectDir</code>.
+     * 
      * @param eclipseProjectDir The eclipseProjectDir to set.
      */
     public void setEclipseProjectDir( File eclipseProjectDir )
@@ -455,6 +456,7 @@
 
     /**
      * Getter for <code>projectnatures</code>.
+     * 
      * @return Returns the projectnatures.
      */
     public List getProjectnatures()
@@ -464,6 +466,7 @@
 
     /**
      * Setter for <code>projectnatures</code>.
+     * 
      * @param projectnatures The projectnatures to set.
      */
     public void setProjectnatures( List projectnatures )
@@ -473,6 +476,7 @@
 
     /**
      * Getter for <code>useProjectReferences</code>.
+     * 
      * @return Returns the useProjectReferences.
      */
     public boolean getUseProjectReferences()
@@ -482,6 +486,7 @@
 
     /**
      * Setter for <code>useProjectReferences</code>.
+     * 
      * @param useProjectReferences The useProjectReferences to set.
      */
     public void setUseProjectReferences( boolean useProjectReferences )
@@ -491,6 +496,7 @@
 
     /**
      * Getter for <code>wtpversion</code>.
+     * 
      * @return Returns the wtpversion.
      */
     public String getWtpversion()
@@ -500,6 +506,7 @@
 
     /**
      * Setter for <code>wtpversion</code>.
+     * 
      * @param wtpversion The wtpversion to set.
      */
     public void setWtpversion( String wtpversion )
@@ -509,6 +516,7 @@
 
     /**
      * Getter for <code>additionalBuildcommands</code>.
+     * 
      * @return Returns the additionalBuildcommands.
      */
     public List getAdditionalBuildcommands()
@@ -518,6 +526,7 @@
 
     /**
      * Setter for <code>additionalBuildcommands</code>.
+     * 
      * @param additionalBuildcommands The additionalBuildcommands to set.
      */
     public void setAdditionalBuildcommands( List additionalBuildcommands )
@@ -527,6 +536,7 @@
 
     /**
      * Getter for <code>additionalProjectnatures</code>.
+     * 
      * @return Returns the additionalProjectnatures.
      */
     public List getAdditionalProjectnatures()
@@ -536,13 +546,14 @@
 
     /**
      * Setter for <code>additionalProjectnatures</code>.
+     * 
      * @param additionalProjectnatures The additionalProjectnatures to set.
      */
     public void setAdditionalProjectnatures( List additionalProjectnatures )
     {
         this.additionalProjectnatures = additionalProjectnatures;
     }
-    
+
     /**
      * Getter for <code>addVersionToProjectName</code>.
      */
@@ -550,7 +561,7 @@
     {
         return addVersionToProjectName;
     }
-    
+
     /**
      * Setter for <code>addVersionToProjectName</code>.
      */
@@ -566,7 +577,7 @@
     {
         return addGroupIdToProjectName;
     }
-    
+
     /**
      * Setter for <code>addGroupIdToProjectName</code>.
      */
@@ -602,9 +613,9 @@
 
         // ear projects don't contain java sources
         // pde projects are always java projects
-        isJavaProject = pde
-            || ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR
-                .equals( packaging ) );
+        isJavaProject =
+            pde ||
+                ( Constants.LANGUAGE_JAVA.equals( artifactHandler.getLanguage() ) && !Constants.PROJECT_PACKAGING_EAR.equals( packaging ) );
 
         setupExtras();
 
@@ -680,6 +691,10 @@
         {
             wtpVersionFloat = 1.5f;
         }
+        else if ( "2.0".equalsIgnoreCase( wtpversion ) ) //$NON-NLS-1$
+        {
+            wtpVersionFloat = 2.0f;
+        }
         if ( !"none".equalsIgnoreCase( wtpversion ) )
         {
             getLog().info( Messages.getString( "EclipsePlugin.wtpversion", wtpversion ) );
@@ -708,9 +723,10 @@
         // validate sanity of the current m2 project
         if ( Arrays.binarySearch( WTP_SUPPORTED_VERSIONS, wtpversion ) < 0 )
         {
-            throw new MojoExecutionException( Messages
-                .getString( "EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$
-                            wtpversion, StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); //$NON-NLS-1$
+            throw new MojoExecutionException(
+                                              Messages.getString( "EclipsePlugin.unsupportedwtp", new Object[] { //$NON-NLS-1$
+                                                                  wtpversion,
+                                                                      StringUtils.join( WTP_SUPPORTED_VERSIONS, " " ) } ) ); //$NON-NLS-1$
         }
 
         assertNotEmpty( executedProject.getGroupId(), POM_ELT_GROUP_ID ); //$NON-NLS-1$
@@ -789,9 +805,9 @@
     {
         EclipseWriterConfig config = createEclipseWriterConfig( deps );
 
-        if (wtpmanifest && isJavaProject())
+        if ( wtpmanifest && isJavaProject() )
         {
-            EclipseManifestWriter.addManifestResource(getLog(), config);
+            EclipseManifestWriter.addManifestResource( getLog(), config );
         }
         // NOTE: This could change the config!
         writeExtraConfiguration( config );
@@ -809,7 +825,7 @@
         {
             new EclipseWtpComponentWriter().init( getLog(), config ).write();
         }
-        if ( wtpVersionFloat >= 1.5 )
+        if ( wtpVersionFloat == 1.5f || wtpVersionFloat == 2.0f )
         {
             new EclipseWtpComponent15Writer().init( getLog(), config ).write();
         }
@@ -820,12 +836,12 @@
         {
             new EclipseClasspathWriter().init( getLog(), config ).write();
         }
-        
-        if (wtpapplicationxml)
+
+        if ( wtpapplicationxml )
         {
-            new EclipseWtpApplicationXMLWriter().init(getLog(), config).write();
+            new EclipseWtpApplicationXMLWriter().init( getLog(), config ).write();
         }
-        
+
         if ( pde )
         {
             this.getLog().info( "The Maven Eclipse plugin runs in 'pde'-mode." );
@@ -884,8 +900,10 @@
         String projectName = IdeUtils.getProjectName( config.getProjectNameTemplate(), project );
 
         config.setEclipseProjectName( projectName );
-        
-        config.setWtpapplicationxml(wtpapplicationxml);
+
+        config.setWtpapplicationxml( wtpapplicationxml );
+
+        config.setWtpVersion( this.wtpVersionFloat );
 
         Set convertedBuildCommands = new LinkedHashSet();
 
@@ -921,20 +939,79 @@
         config.setProjectFacets( additionalProjectFacets );
         config.setSourceDirs( sourceDirs );
         config.setAddVersionToProjectName( isAddVersionToProjectName() );
-        config.setContextName( this.wtpContextName );
-        config.setPackaging(this.packaging);
+        config.setPackaging( this.packaging );
+
+        collectWarContextRootsFromReactorEarConfiguration( config );
 
         return config;
     }
 
     /**
-     * Write any extra configuration information for the Eclipse project. This is an extension
-     * point, called before the main configurations are written.
-     * <br/>
-     * <b>
-     * NOTE: This could change the config!
-     * </b>
-     *
+     * If this is a war module peek into the reactor an search for an ear module that defines the context root of this
+     * module.
+     * 
+     * @param config config to save the context root.
+     */
+    private void collectWarContextRootsFromReactorEarConfiguration( EclipseWriterConfig config )
+    {
+        if ( reactorProjects != null && this.wtpContextName == null &&
+            Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) )
+        {
+            for ( Iterator iter = reactorProjects.iterator(); iter.hasNext(); )
+            {
+                MavenProject reactorProject = (MavenProject) iter.next();
+
+                if ( Constants.PROJECT_PACKAGING_EAR.equals( reactorProject.getPackaging() ) )
+                {
+                    Xpp3Dom[] warDefinitions =
+                        IdeUtils.getPluginConfigurationDom( reactorProject, JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+                                                            new String[] { "modules", "webModule" } );
+                    for ( int index = 0; index < warDefinitions.length; index++ )
+                    {
+                        Xpp3Dom groupId = warDefinitions[index].getChild( "groupId" );
+                        Xpp3Dom artifactId = warDefinitions[index].getChild( "artifactId" );
+                        Xpp3Dom contextRoot = warDefinitions[index].getChild( "contextRoot" );
+                        if ( groupId != null && artifactId != null && contextRoot != null &&
+                            groupId.getValue() != null && artifactId.getValue() != null &&
+                            contextRoot.getValue() != null )
+                        {
+                            getLog().info(
+                                           "Found context root definition for " + groupId.getValue() + ":" +
+                                               artifactId.getValue() + " " + contextRoot.getValue() );
+                            if ( this.project.getArtifactId().equals( artifactId.getValue() ) &&
+                                this.project.getGroupId().equals( groupId.getValue() ) )
+                            {
+                                config.setContextName( contextRoot.getValue() );
+                            }
+                        }
+                        else
+                        {
+                            getLog().info(
+                                           "Found incomplete ear configuration in " + reactorProject.getGroupId() +
+                                               ":" + reactorProject.getGroupId() + " found " +
+                                               warDefinitions[index].toString() );
+                        }
+                    }
+                }
+            }
+        }
+        if ( config.getContextName() == null && Constants.PROJECT_PACKAGING_WAR.equals( this.project.getPackaging() ) )
+        {
+            if ( this.wtpContextName == null )
+            {
+                config.setContextName( this.project.getArtifactId() );
+            }
+            else
+            {
+                config.setContextName( this.wtpContextName );
+            }
+        }
+    }
+
+    /**
+     * Write any extra configuration information for the Eclipse project. This is an extension point, called before the
+     * main configurations are written. <br/> <b> NOTE: This could change the config! </b>
+     * 
      * @param config
      * @throws MojoExecutionException
      */
@@ -1021,7 +1098,8 @@
 
         if ( wtpVersionFloat == 0.7f )
         {
-            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) ); // WTP 0.7 builder
+            buildcommands.add( new BuildCommand( BUILDER_WST_COMPONENT_STRUCTURAL_DEPENDENCY_RESOLVER ) ); // WTP 0.7
+            // builder
         }
 
         if ( pde )
@@ -1048,15 +1126,17 @@
 
         // If using the standard output location, don't mix the test output into it.
         String testOutput = null;
-        boolean useStandardOutputDir = buildOutputDirectory
-            .equals( new File( project.getBuild().getOutputDirectory() ) );
+        boolean useStandardOutputDir =
+            buildOutputDirectory.equals( new File( project.getBuild().getOutputDirectory() ) );
         if ( useStandardOutputDir )
         {
-            getLog().debug("testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " + project.getBuild()
-                    .getTestOutputDirectory());
-            testOutput = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, new File( project.getBuild()
-                .getTestOutputDirectory() ), false );
-            getLog().debug("testOutput after toRelative : " + testOutput);
+            getLog().debug(
+                            "testOutput toRelativeAndFixSeparator " + projectBaseDir + " , " +
+                                project.getBuild().getTestOutputDirectory() );
+            testOutput =
+                IdeUtils.toRelativeAndFixSeparator( projectBaseDir,
+                                                    new File( project.getBuild().getTestOutputDirectory() ), false );
+            getLog().debug( "testOutput after toRelative : " + testOutput );
         }
 
         extractSourceDirs( directories, project.getTestCompileSourceRoots(), basedir, projectBaseDir, true, testOutput );
@@ -1078,8 +1158,9 @@
 
             if ( sourceRootFile.isDirectory() )
             {
-                String sourceRoot = IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile, !projectBaseDir
-                    .equals( basedir ) );
+                String sourceRoot =
+                    IdeUtils.toRelativeAndFixSeparator( projectBaseDir, sourceRootFile,
+                                                        !projectBaseDir.equals( basedir ) );
 
                 directories.add( new EclipseSourceDir( sourceRoot, output, false, test, null, null, false ) );
             }
@@ -1112,7 +1193,7 @@
             // TODO: figure out how to merge if the same dir is specified twice
             // with different in/exclude patterns.
 
-            File resourceDirectory = new File( /*basedir,*/resource.getDirectory() );
+            File resourceDirectory = new File( /* basedir, */resource.getDirectory() );
 
             if ( !resourceDirectory.exists() || !resourceDirectory.isDirectory() )
             {
@@ -1120,14 +1201,16 @@
                 continue;
             }
 
-            String resourceDir = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
-                                                                     !workspaceProjectBaseDir.equals( basedir ) );
+            String resourceDir =
+                IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, resourceDirectory,
+                                                    !workspaceProjectBaseDir.equals( basedir ) );
             String thisOutput = output;
             if ( thisOutput != null )
             {
                 // sometimes thisOutput is already an absolute path
                 File outputFile = new File( thisOutput );
-                if(!outputFile.isAbsolute()){
+                if ( !outputFile.isAbsolute() )
+                {
                     outputFile = new File( workspaceProjectBaseDir, thisOutput );
                 }
                 // create output dir if it doesn't exist
@@ -1141,13 +1224,14 @@
                 }
 
                 getLog().debug(
-                        "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " +  outputFile + ", false }." );
+                                "Making relative and fixing separator: { " + workspaceProjectBaseDir + ", " +
+                                    outputFile + ", false }." );
                 thisOutput = IdeUtils.toRelativeAndFixSeparator( workspaceProjectBaseDir, outputFile, false );
             }
 
             getLog().debug(
-                            "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test + ", "
-                                + includePattern + ", " + excludePattern + " }." );
+                            "Adding eclipse source dir: { " + resourceDir + ", " + thisOutput + ", true, " + test +
+                                ", " + includePattern + ", " + excludePattern + " }." );
 
             directories.add( new EclipseSourceDir( resourceDir, thisOutput, true, test, includePattern, excludePattern,
                                                    resource.isFiltering() ) );
@@ -1158,8 +1242,7 @@
      * Calculate the project name template from the fields {@link #projectNameTemplate},
      * {@link #addVersionToProjectName} and {@link #addGroupIdToProjectName}
      * 
-     * @return the project name template that should be used after considering the plugin
-     *         configuration
+     * @return the project name template that should be used after considering the plugin configuration
      */
     private String calculateProjectNameTemplate()
     {
@@ -1191,7 +1274,8 @@
     /**
      * {@inheritDoc}
      */
-    public String getProjectNameForArifact(Artifact artifact) {
-        return IdeUtils.getProjectName(calculateProjectNameTemplate(), artifact);
+    public String getProjectNameForArifact( Artifact artifact )
+    {
+        return IdeUtils.getProjectName( calculateProjectNameTemplate(), artifact );
     }
 }

Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/EclipseToMavenMojo.java Thu Nov  1 19:16:57 2007
@@ -31,6 +31,8 @@
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
+import aQute.lib.osgi.Analyzer;
+
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.deployer.ArtifactDeployer;
 import org.apache.maven.artifact.deployer.ArtifactDeploymentException;
@@ -62,16 +64,11 @@
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 
-import aQute.lib.osgi.Analyzer;
-
 /**
  * Add eclipse artifacts from an eclipse installation to the local repo. This mojo automatically analize the eclipse
- * directory, copy plugins jars to the local maven repo, and generates appropriate poms.
- * 
- * This is the official central repository builder for Eclipse plugins, so it has the necessary default values.
- * For customized repositories see {@link MakeArtifactsMojo}
- * 
- * Typical usage:
+ * directory, copy plugins jars to the local maven repo, and generates appropriate poms. This is the official central
+ * repository builder for Eclipse plugins, so it has the necessary default values. For customized repositories see
+ * {@link MakeArtifactsMojo} Typical usage:
  * <code>mvn eclipse:to-maven -DdeployTo=maven.org::default::scpexe://repo1.maven.org/home/maven/repository-staging/to-ibiblio/eclipse -DeclipseDir=.</code>
  * 
  * @author Fabrizio Giustina
@@ -111,18 +108,21 @@
 
     /**
      * ArtifactFactory component.
+     * 
      * @component
      */
     private ArtifactFactory artifactFactory;
 
     /**
      * ArtifactInstaller component.
+     * 
      * @component
      */
     protected ArtifactInstaller installer;
 
     /**
      * ArtifactDeployer component.
+     * 
      * @component
      */
     private ArtifactDeployer deployer;
@@ -136,14 +136,14 @@
 
     /**
      * Input handler, needed for comand line handling.
+     * 
      * @component
      */
     protected InputHandler inputHandler;
 
     /**
      * Specifies a remote repository to which generated artifacts should be deployed to. If this property is specified,
-     * artifacts are also deployed to the remote repo.
-     * The format for this parameter is <code>id::layout::url</code>
+     * artifacts are also deployed to the remote repo. The format for this parameter is <code>id::layout::url</code>
      * 
      * @parameter expression="${deployTo}"
      */
@@ -218,8 +218,9 @@
 
             if ( plugins.containsKey( getKey( model ) ) )
             {
-                throw new MojoFailureException( "There are two versions of the same plugin, can not resolve versions: "
-                    + getKey( model ) );
+                throw new MojoFailureException(
+                                                "There are two versions of the same plugin, can not resolve versions: " +
+                                                    getKey( model ) );
             }
 
             plugins.put( getKey( model ), plugin );
@@ -238,21 +239,19 @@
         }
     }
 
-    private String getKey(Model model)
+    private String getKey( Model model )
     {
         return model.getGroupId() + "." + model.getArtifactId();
     }
 
-    private String getKey(Dependency dependency)
+    private String getKey( Dependency dependency )
     {
         return dependency.getGroupId() + "." + dependency.getArtifactId();
     }
 
     /**
-     * Resolve version ranges in the model provided, overriding version ranges with versions from
-     * the dependency in the provided map of models.
-     * 
-     * TODO doesn't check if the version is in range, it just overwrites it
+     * Resolve version ranges in the model provided, overriding version ranges with versions from the dependency in the
+     * provided map of models. TODO doesn't check if the version is in range, it just overwrites it
      * 
      * @param model
      * @param models
@@ -274,8 +273,8 @@
                 }
                 else
                 {
-                    throw new MojoFailureException( "Unable to resolve version range for dependency " + dep
-                        + " in project " + key );
+                    throw new MojoFailureException( "Unable to resolve version range for dependency " + dep +
+                        " in project " + key );
                 }
             }
         }
@@ -331,8 +330,8 @@
 
             Analyzer analyzer = new Analyzer();
 
-            Map bundleSymbolicNameHeader = analyzer.parseHeader( plugin
-                .getManifestAttribute( Analyzer.BUNDLE_SYMBOLICNAME ) );
+            Map bundleSymbolicNameHeader =
+                analyzer.parseHeader( plugin.getManifestAttribute( Analyzer.BUNDLE_SYMBOLICNAME ) );
             bundleName = (String) bundleSymbolicNameHeader.keySet().iterator().next();
             version = plugin.getManifestAttribute( Analyzer.BUNDLE_VERSION );
 
@@ -397,7 +396,7 @@
 
         return model;
     }
-    
+
     /**
      * Writes the artifact to the repo
      * 
@@ -411,10 +410,11 @@
         Writer fw = null;
         ArtifactMetadata metadata = null;
         File pomFile = null;
-        Artifact pomArtifact = artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model
-            .getVersion(), null, "pom" );
-        Artifact artifact = artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model
-            .getVersion(), null, "jar" );
+        Artifact pomArtifact =
+            artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), null, "pom" );
+        Artifact artifact =
+            artifactFactory.createArtifact( model.getGroupId(), model.getArtifactId(), model.getVersion(), null,
+                                            Constants.PROJECT_PACKAGING_JAR );
         try
         {
             pomFile = File.createTempFile( "pom-", ".xml" );
@@ -478,6 +478,7 @@
     /**
      * The 4th (build) token MUST be separed with "-" and not with "." in maven. A version with 4 dots is not parsed,
      * and the whole string is considered a qualifier. See tests in DefaultArtifactVersion for reference.
+     * 
      * @param version initial version
      * @param forcedQualifier build number
      * @param stripQualifier always remove 4th token in version
@@ -498,8 +499,9 @@
             }
             else
             {
-                version = StringUtils.substring( version, 0, lastDot ) + "-"
-                    + StringUtils.substring( version, lastDot + 1, version.length() );
+                version =
+                    StringUtils.substring( version, 0, lastDot ) + "-" +
+                        StringUtils.substring( version, lastDot + 1, version.length() );
             }
         }
         return version;
@@ -556,8 +558,8 @@
     }
 
     /**
-     * Get the group id as the tokens until last dot
-     * e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse</code>
+     * Get the group id as the tokens until last dot e.g. <code>org.eclipse.jdt</code> -> <code>org.eclipse</code>
+     * 
      * @param bundleName bundle name
      * @return group id
      */
@@ -573,8 +575,8 @@
     }
 
     /**
-     * Get the artifact id as the tokens after last dot
-     * e.g. <code>org.eclipse.jdt</code> -> <code>jdt</code>
+     * Get the artifact id as the tokens after last dot e.g. <code>org.eclipse.jdt</code> -> <code>jdt</code>
+     * 
      * @param bundleName bundle name
      * @return artifact id
      */
@@ -591,6 +593,7 @@
 
     /**
      * Parses the "Require-Bundle" and convert it to a list of dependencies.
+     * 
      * @param requireBundle "Require-Bundle" entry
      * @return an array of <code>Dependency</code>
      */
@@ -641,6 +644,7 @@
 
     /**
      * Fix the separator for the 4th token in a versions. In maven this must be "-", in OSGI it's "."
+     * 
      * @param versionRange input range
      * @return modified version range
      */
@@ -664,8 +668,9 @@
             {
                 // build number found, fix it
                 int lastDot = group.lastIndexOf( "." );
-                group = StringUtils.substring( group, 0, lastDot ) + "-"
-                    + StringUtils.substring( group, lastDot + 1, group.length() );
+                group =
+                    StringUtils.substring( group, 0, lastDot ) + "-" +
+                        StringUtils.substring( group, lastDot + 1, group.length() );
             }
             matcher.appendReplacement( newVersionRange, group );
         }

Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseClasspathWriter.java Thu Nov  1 19:16:57 2007
@@ -44,7 +44,7 @@
 
 /**
  * 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@apache.org">Fabrizio Giustina</a>
@@ -130,7 +130,9 @@
 
         try
         {
-            w = new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(), FILE_DOT_CLASSPATH ) ), "UTF-8" );
+            w =
+                new OutputStreamWriter( new FileOutputStream( new File( config.getEclipseProjectDirectory(),
+                                                                        FILE_DOT_CLASSPATH ) ), "UTF-8" );
         }
         catch ( IOException ex )
         {
@@ -141,8 +143,8 @@
 
         writer.startElement( ELT_CLASSPATH );
 
-        String defaultOutput = IdeUtils.toRelativeAndFixSeparator( config.getProjectBaseDir(), config
-            .getBuildOutputDirectory(), false );
+        String defaultOutput =
+            IdeUtils.toRelativeAndFixSeparator( config.getProjectBaseDir(), config.getBuildOutputDirectory(), false );
 
         // ----------------------------------------------------------------------
         // Source roots and resources
@@ -163,8 +165,8 @@
             if ( byOutputDirs == null )
             {
                 // ArrayList<EclipseSourceDir>
-                byOutputDir.put( dir.getOutput() == null ? defaultOutput : dir.getOutput(),
-                                 byOutputDirs = new ArrayList() );
+                byOutputDir.put( dir.getOutput() == null ? defaultOutput : dir.getOutput(), byOutputDirs =
+                    new ArrayList() );
             }
             byOutputDirs.add( dir );
         }
@@ -173,8 +175,8 @@
         {
             EclipseSourceDir dir = config.getSourceDirs()[j];
 
-            log.debug( "Processing " + ( dir.isResource() ? "re" : "" ) + "source " + dir.getPath() + ": output="
-                + dir.getOutput() + "; default output=" + defaultOutput );
+            log.debug( "Processing " + ( dir.isResource() ? "re" : "" ) + "source " + dir.getPath() + ": output=" +
+                dir.getOutput() + "; default output=" + defaultOutput );
 
             boolean isSpecial = false;
 
@@ -185,7 +187,8 @@
                 // and if the default output has any sources that copy there.
 
                 if ( dir.getOutput() != null // resource output dir is set
-                    && !dir.getOutput().equals( defaultOutput ) // output dir is not default target/classes
+                    &&
+                    !dir.getOutput().equals( defaultOutput ) // output dir is not default target/classes
                     && dir.getOutput().startsWith( defaultOutput ) // ... but is nested
                     && byOutputDir.get( defaultOutput ) != null // ???
                     && !( (List) byOutputDir.get( defaultOutput ) ).isEmpty() // ???
@@ -194,8 +197,8 @@
                     // do not specify as source since the output will be nested. Instead, mark
                     // it as a todo, and handle it with a custom build.xml file later.
 
-                    log.debug( "Marking as special to prevent output folder nesting: " + dir.getPath() + " (output="
-                        + dir.getOutput() + ")" );
+                    log.debug( "Marking as special to prevent output folder nesting: " + dir.getPath() + " (output=" +
+                        dir.getOutput() + ")" );
 
                     isSpecial = true;
                     specialSources.add( dir );
@@ -291,8 +294,8 @@
             }
             catch ( IOException e )
             {
-                throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory()
-                    + "/maven-eclipse.xml", e );
+                throw new MojoExecutionException( "Cannot create " + config.getEclipseProjectDirectory() +
+                    "/maven-eclipse.xml", e );
             }
 
             log.info( "Creating external launcher file" );
@@ -302,11 +305,13 @@
 
             // finally add it to the project writer.
 
-            config.getBuildCommands()
-                .add(
-                      new BuildCommand( "org.eclipse.ui.externaltools.ExternalToolBuilder", "LaunchConfigHandle",
-                                        "<project>/" + EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS
-                                            + "Maven_Ant_Builder.launch" ) );
+            config.getBuildCommands().add(
+                                           new BuildCommand(
+                                                             "org.eclipse.ui.externaltools.ExternalToolBuilder",
+                                                             "LaunchConfigHandle",
+                                                             "<project>/" +
+                                                                 EclipseLaunchConfigurationWriter.FILE_DOT_EXTERNAL_TOOL_BUILDERS +
+                                                                 "Maven_Ant_Builder.launch" ) );
         }
 
         // ----------------------------------------------------------------------
@@ -340,8 +345,8 @@
 
             if ( dep.isAddedToClasspath() )
             {
-                String depId = dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":"
-						+ dep.getVersion();
+                String depId =
+                    dep.getGroupId() + ":" + dep.getArtifactId() + ":" + dep.getClassifier() + ":" + dep.getVersion();
                 /* avoid duplicates in the classpath for artifacts with different types (like ejbs) */
                 if ( !addedDependencies.contains( depId ) )
                 {
@@ -366,6 +371,8 @@
         String sourcepath = null;
         String javadocpath = null;
 
+        boolean attributeElemOpen = false;
+
         if ( dep.isReferencedProject() && !config.isPde() )
         {
             path = "/" + IdeUtils.getProjectName( config.getProjectNameTemplate(), dep ); //$NON-NLS-1$
@@ -431,10 +438,12 @@
                 {
                     if ( ATTR_VAR.equals( kind ) )
                     {
-                        sourcepath = M2_REPO
-                            + "/" //$NON-NLS-1$
-                            + IdeUtils
-                                .toRelativeAndFixSeparator( localRepositoryFile, dep.getSourceAttachment(), false );
+                        sourcepath =
+                            M2_REPO +
+                                "/" //$NON-NLS-1$
+                                +
+                                IdeUtils.toRelativeAndFixSeparator( localRepositoryFile, dep.getSourceAttachment(),
+                                                                    false );
                     }
                     else
                     {
@@ -447,8 +456,8 @@
                 {
                     // NB eclipse (3.1) doesn't support variables in javadoc paths, so we need to add the
                     // full path for the maven repo
-                    javadocpath = StringUtils.replace( IdeUtils.getCanonicalPath( dep.getJavadocAttachment() ),
-                                                       "\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
+                    javadocpath =
+                        StringUtils.replace( IdeUtils.getCanonicalPath( dep.getJavadocAttachment() ), "\\", "/" ); //$NON-NLS-1$ //$NON-NLS-2$
                 }
 
             }
@@ -466,16 +475,39 @@
 
         if ( javadocpath != null )
         {
-            writer.startElement( "attributes" ); //$NON-NLS-1$
+            if ( !attributeElemOpen )
+            {
+                writer.startElement( "attributes" ); //$NON-NLS-1$
+                attributeElemOpen = true;
+            }
 
             writer.startElement( "attribute" ); //$NON-NLS-1$
             writer.addAttribute( "value", "jar:file:/" + javadocpath + "!/" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
             writer.addAttribute( "name", "javadoc_location" ); //$NON-NLS-1$ //$NON-NLS-2$
             writer.endElement();
 
+        }
+
+        if ( config.getWtpapplicationxml() && kind.equals( ATTR_VAR ) && !dep.isTestDependency() && !dep.isProvided() &&
+            !dep.isSystemScoped() )
+        {
+            if ( !attributeElemOpen )
+            {
+                writer.startElement( "attributes" ); //$NON-NLS-1$
+                attributeElemOpen = true;
+            }
+
+            writer.startElement( "attribute" ); //$NON-NLS-1$
+            writer.addAttribute( "value", "/WEB-INF/lib" ); //$NON-NLS-1$ //$NON-NLS-2$
+            writer.addAttribute( "name", "org.eclipse.jst.component.dependency" ); //$NON-NLS-1$ //$NON-NLS-2$
             writer.endElement();
+
         }
 
+        if ( attributeElemOpen )
+        {
+            writer.endElement();
+        }
         writer.endElement();
 
     }

Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/EclipseWriterConfig.java Thu Nov  1 19:16:57 2007
@@ -38,7 +38,7 @@
      * The maven project.
      */
     private MavenProject project;
-    
+
     /**
      * The maven project packaging.
      */
@@ -93,16 +93,14 @@
      * Project natures.
      */
     private List projectnatures;
-    
+
     /**
      * Project facets.
      */
     private Map projectFacets;
 
     /**
-     * Build commands.
-     *
-     * List&lt;BuildCommand&gt;
+     * Build commands. List&lt;BuildCommand&gt;
      */
     private List buildCommands;
 
@@ -110,9 +108,10 @@
      * Classpath containers.
      */
     private List classpathContainers;
-    
+
     /**
      * Appends the version number to the project name if <tt>true</tt>.
+     * 
      * @deprecated use {@link #projectNameTemplate}
      */
     private boolean addVersionToProjectName;
@@ -125,25 +124,32 @@
     /**
      * @see EclipsePlugin#deployName()
      */
-    
+
     private String contextName;
-    
+
     /**
      * @see EclipsePlugin#wtpapplicationxml()
      */
     private boolean wtpapplicationxml;
-    
+
+    /**
+     * @see EclipsePlugin#getWtpversion()
+     */
+    private float wtpVersion;
+
     /**
      * Getter for <code>deps</code>.
+     * 
      * @return Returns the deps.
      */
     public IdeDependency[] getDeps()
     {
         return this.deps;
     }
-    
+
     /**
      * Setter for <code>deps</code>.
+     * 
      * @param deps The deps to set.
      */
     public void setDeps( IdeDependency[] deps )
@@ -153,6 +159,7 @@
 
     /**
      * Getter for <code>eclipseProjectDir</code>.
+     * 
      * @return Returns the eclipseProjectDir.
      */
     public File getEclipseProjectDirectory()
@@ -162,6 +169,7 @@
 
     /**
      * Setter for <code>eclipseProjectDir</code>.
+     * 
      * @param eclipseProjectDir The eclipseProjectDir to set.
      */
     public void setEclipseProjectDirectory( File eclipseProjectDir )
@@ -171,6 +179,7 @@
 
     /**
      * Getter for <code>eclipseProjectName</code>.
+     * 
      * @return Returns the project name used in eclipse.
      */
     public String getEclipseProjectName()
@@ -180,6 +189,7 @@
 
     /**
      * Setter for <code>eclipseProjectName</code>.
+     * 
      * @param eclipseProjectName the project name used in eclipse.
      */
     public void setEclipseProjectName( String eclipseProjectName )
@@ -189,6 +199,7 @@
 
     /**
      * Getter for <code>project</code>.
+     * 
      * @return Returns the project.
      */
     public MavenProject getProject()
@@ -198,6 +209,7 @@
 
     /**
      * Setter for <code>project</code>.
+     * 
      * @param project The project to set.
      */
     public void setProject( MavenProject project )
@@ -207,6 +219,7 @@
 
     /**
      * Getter for <code>sourceDirs</code>.
+     * 
      * @return Returns the sourceDirs.
      */
     public EclipseSourceDir[] getSourceDirs()
@@ -216,6 +229,7 @@
 
     /**
      * Setter for <code>sourceDirs</code>.
+     * 
      * @param sourceDirs The sourceDirs to set.
      */
     public void setSourceDirs( EclipseSourceDir[] sourceDirs )
@@ -225,6 +239,7 @@
 
     /**
      * Getter for <code>buildOutputDirectory</code>.
+     * 
      * @return Returns the buildOutputDirectory.
      */
     public File getBuildOutputDirectory()
@@ -234,6 +249,7 @@
 
     /**
      * Setter for <code>buildOutputDirectory</code>.
+     * 
      * @param buildOutputDirectory The buildOutputDirectory to set.
      */
     public void setBuildOutputDirectory( File buildOutputDirectory )
@@ -243,6 +259,7 @@
 
     /**
      * Getter for <code>localRepository</code>.
+     * 
      * @return Returns the localRepository.
      */
     public ArtifactRepository getLocalRepository()
@@ -252,6 +269,7 @@
 
     /**
      * Setter for <code>localRepository</code>.
+     * 
      * @param localRepository The localRepository to set.
      */
     public void setLocalRepository( ArtifactRepository localRepository )
@@ -261,6 +279,7 @@
 
     /**
      * Getter for <code>manifestFile</code>.
+     * 
      * @return Returns the manifestFile.
      */
     public File getManifestFile()
@@ -270,6 +289,7 @@
 
     /**
      * Setter for <code>manifestFile</code>.
+     * 
      * @param manifestFile The manifestFile to set.
      */
     public void setManifestFile( File manifestFile )
@@ -279,6 +299,7 @@
 
     /**
      * Getter for <code>classpathContainers</code>.
+     * 
      * @return Returns the classpathContainers.
      */
     public List getClasspathContainers()
@@ -288,6 +309,7 @@
 
     /**
      * Setter for <code>classpathContainers</code>.
+     * 
      * @param classpathContainers The classpathContainers to set.
      */
     public void setClasspathContainers( List classpathContainers )
@@ -297,6 +319,7 @@
 
     /**
      * Getter for <code>pde</code>.
+     * 
      * @return Returns the pde.
      */
     public boolean isPde()
@@ -306,6 +329,7 @@
 
     /**
      * Setter for <code>pde</code>.
+     * 
      * @param pde The pde to set.
      */
     public void setPde( boolean pde )
@@ -315,6 +339,7 @@
 
     /**
      * Getter for <code>buildCommands</code>.
+     * 
      * @return Returns the buildCommands.
      */
     public List getBuildCommands()
@@ -324,6 +349,7 @@
 
     /**
      * Setter for <code>buildCommands</code>.
+     * 
      * @param buildCommands The buildCommands to set.
      */
     public void setBuildCommands( List buildCommands )
@@ -333,6 +359,7 @@
 
     /**
      * Getter for <code>projectnatures</code>.
+     * 
      * @return Returns the projectnatures.
      */
     public List getProjectnatures()
@@ -342,6 +369,7 @@
 
     /**
      * Setter for <code>projectnatures</code>.
+     * 
      * @param projectnatures The projectnatures to set.
      */
     public void setProjectnatures( List projectnatures )
@@ -351,6 +379,7 @@
 
     /**
      * Getter for <code>projectFacets</code>.
+     * 
      * @return Returns the projectFacets
      */
     public Map getProjectFacets()
@@ -360,6 +389,7 @@
 
     /**
      * Setter for <code>projectFacets</code>
+     * 
      * @param projectFacets The projectFacets to set.
      */
     public void setProjectFacets( Map projectFacets )
@@ -369,6 +399,7 @@
 
     /**
      * Getter for <code>projectBaseDir</code>.
+     * 
      * @return Returns the projectBaseDir.
      */
     public File getProjectBaseDir()
@@ -378,6 +409,7 @@
 
     /**
      * Setter for <code>projectBaseDir</code>.
+     * 
      * @param projectBaseDir The projectBaseDir to set.
      */
     public void setProjectBaseDir( File projectBaseDir )
@@ -414,12 +446,12 @@
     {
         return projectNameTemplate;
     }
-    
+
     public String getContextName()
     {
-         return this.contextName;
+        return this.contextName;
     }
-    
+
     public void setContextName( String deployName )
     {
         this.contextName = deployName;
@@ -428,24 +460,57 @@
     /**
      * @return the packaging
      */
-    public String getPackaging() {
+    public String getPackaging()
+    {
         return this.packaging;
     }
 
     /**
      * @param packaging the packaging to set
      */
-    public void setPackaging(String packaging) {
+    public void setPackaging( String packaging )
+    {
         this.packaging = packaging;
     }
-    
+
+    /**
+     * Getter for <code>wtpapplicationxml</code>.
+     * 
+     * @return Returns the wtpapplicationxml.
+     */
     public boolean getWtpapplicationxml()
     {
-         return this.wtpapplicationxml;
+        return this.wtpapplicationxml;
     }
-    
+
+    /**
+     * Setter for <code>buildCommands</code>.
+     * 
+     * @param buildCommands The buildCommands to set.
+     */
     public void setWtpapplicationxml( boolean wtpapplicationxml )
     {
         this.wtpapplicationxml = wtpapplicationxml;
-    }    
+    }
+
+    /**
+     * Getter for <code>wtpVersion</code>.
+     * 
+     * @return Returns the wtpVersion.
+     */
+    public float getWtpVersion()
+    {
+        return wtpVersion;
+    }
+
+    /**
+     * Setter for <code>wtpVersion</code>.
+     * 
+     * @param wtpVersion The wtpVersion to set.
+     */
+    public void setWtpVersion( float wtpVersion )
+    {
+        this.wtpVersion = wtpVersion;
+    }
+
 }

Modified: maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java
URL: http://svn.apache.org/viewvc/maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java?rev=591192&r1=591191&r2=591192&view=diff
==============================================================================
--- maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java (original)
+++ maven/plugins/branches/MECLIPSE-333/src/main/java/org/apache/maven/plugin/eclipse/writers/rad/RadApplicationXMLWriter.java Thu Nov  1 19:16:57 2007
@@ -36,6 +36,7 @@
 import org.apache.maven.plugin.eclipse.writers.AbstractEclipseWriter;
 import org.apache.maven.plugin.eclipse.writers.wtp.AbstractWtpResourceWriter;
 import org.apache.maven.plugin.ide.IdeDependency;
+import org.apache.maven.plugin.ide.IdeUtils;
 import org.apache.maven.plugin.ide.JeeUtils;
 import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.xml.PrettyPrintXMLWriter;
@@ -51,7 +52,8 @@
  * 
  * @author <a href="mailto:nir@cfc.at">Richard van Nieuwenhoven </a>
  */
-public class RadApplicationXMLWriter extends AbstractEclipseWriter
+public class RadApplicationXMLWriter
+    extends AbstractEclipseWriter
 {
 
     private static final String APPLICATION_XML_APPLICATION = "application";
@@ -122,16 +124,13 @@
      * write the application.xml and the .modulemaps file to the META-INF directory.
      * 
      * @see AbstractWtpResourceWriter#write(EclipseSourceDir[], ArtifactRepository, File)
-     * @param sourceDirs
-     *            all eclipse source directorys
-     * @param localRepository
-     *            the local reposetory
-     * @param buildOutputDirectory
-     *            build output directory (target)
-     * @throws MojoExecutionException
-     *             when writing the config files was not possible
+     * @param sourceDirs all eclipse source directorys
+     * @param localRepository the local reposetory
+     * @param buildOutputDirectory build output directory (target)
+     * @throws MojoExecutionException when writing the config files was not possible
      */
-    public void write() throws MojoExecutionException
+    public void write()
+        throws MojoExecutionException
     {
         String packaging = config.getPackaging();
         if ( Constants.PROJECT_PACKAGING_EAR.equalsIgnoreCase( packaging ) )
@@ -154,18 +153,9 @@
             }
             this.modulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
 
-            try
-            {
-                this.webModulesFromPoms =
-                    ( (Xpp3Dom) ( (org.apache.maven.model.Plugin) config.getProject().getBuild().getPluginsAsMap().get(
-                                                                                                                        "org.apache.maven.plugins:maven-ear-plugin" ) ).getConfiguration() ).getChild(
-                                                                                                                                                                                                       "modules" ).getChildren(
-                                                                                                                                                                                                                                "webModule" );
-            }
-            catch ( java.lang.NullPointerException ex )
-            {
-                this.webModulesFromPoms = new Xpp3Dom[0];
-            }
+            this.webModulesFromPoms =
+                IdeUtils.getPluginConfigurationDom( config.getProject(), JeeUtils.ARTIFACT_MAVEN_EAR_PLUGIN,
+                                                    new String[] { "modules", "webModule" } );
 
             IdeDependency[] deps = config.getDeps();
             for ( int index = 0; index < deps.length; index++ )
@@ -196,8 +186,8 @@
         result.setAttribute( XMLNS, "http://java.sun.com/xml/ns/j2ee" );
         result.setAttribute( XMLNS_XSI, "http://www.w3.org/2001/XMLSchema-instance" );
         result.setAttribute( XMLNS_SCHEMA_LOCATION,
-                             "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_"
-                                             + j2eeVersion.charAt( 0 ) + "_" + j2eeVersion.charAt( 2 ) + ".xsd" );
+                             "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/application_" +
+                                 j2eeVersion.charAt( 0 ) + "_" + j2eeVersion.charAt( 2 ) + ".xsd" );
         result.addChild( new Xpp3Dom( APPLICATION_XML_DESCRIPTION ) );
         Xpp3Dom name = new Xpp3Dom( APPLICATION_XML_DISPLAY_NAME );
         name.setValue( config.getProject().getArtifactId() );
@@ -225,10 +215,8 @@
      * find an existing module entry in the application.xml file by looking up the id in the modulemaps file and then
      * using that to locate the entry in the application.xml file.
      * 
-     * @param applicationXmlDom
-     *            application.xml dom tree
-     * @param mapping
-     *            .modulemaps dom tree
+     * @param applicationXmlDom application.xml dom tree
+     * @param mapping .modulemaps dom tree
      * @return dom tree representing the module
      */
     private Xpp3Dom findModuleInApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom mapping )
@@ -249,10 +237,8 @@
     /**
      * find an artifact in the modulemaps dom tree, if it is missing create a new entry in the modulemaps dom tree.
      * 
-     * @param dependency
-     *            dependency to find
-     * @param modulemapXmlDom
-     *            dom-tree of modulemaps
+     * @param dependency dependency to find
+     * @param modulemapXmlDom dom-tree of modulemaps
      * @return dom-tree representing the artifact
      */
     private Xpp3Dom findOrCreateArtifact( IdeDependency dependency, Xpp3Dom modulemapXmlDom )
@@ -263,22 +249,22 @@
         {
             if ( children[index].getAttribute( MODULEMAPS_PROJECT_NAME ).equals( dependency.getArtifactId() ) )
             {
-                if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB )
-                                && children[index].getName().equals( MODULEMAPS_MAPPINGS )
-                                && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
-                                                                                                                       MODULEMAPS_APPLICATION_EJB_MODULE ) )
+                if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_EJB ) &&
+                    children[index].getName().equals( MODULEMAPS_MAPPINGS ) &&
+                    children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
+                                                                                                        MODULEMAPS_APPLICATION_EJB_MODULE ) )
                 {
                     return children[index];
                 }
-                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR )
-                                && children[index].getName().equals( MODULEMAPS_MAPPINGS )
-                                && children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
-                                                                                                                       MODULEMAPS_APPLICATION_WEB_MODULE ) )
+                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_WAR ) &&
+                    children[index].getName().equals( MODULEMAPS_MAPPINGS ) &&
+                    children[index].getChild( APPLICATION_XML_MODULE ).getAttribute( XMI_TYPE ).equals(
+                                                                                                        MODULEMAPS_APPLICATION_WEB_MODULE ) )
                 {
                     return children[index];
                 }
-                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR )
-                                && children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) )
+                else if ( dependency.getType().equals( Constants.PROJECT_PACKAGING_JAR ) &&
+                    children[index].getName().equals( MODULEMAPS_UTILITY_JARMAPPINGS ) )
                 {
                     return children[index];
                 }
@@ -330,8 +316,7 @@
     /**
      * get the id from the href of a modulemap.
      * 
-     * @param mapping
-     *            the dom-tree of modulemaps
+     * @param mapping the dom-tree of modulemaps
      * @return module identifier
      */
     private String getIdFromMapping( Xpp3Dom mapping )
@@ -348,8 +333,7 @@
     /**
      * mark the domtree entry as handled (all not handled ones will be deleted).
      * 
-     * @param xpp3Dom
-     *            dom element to mark handled
+     * @param xpp3Dom dom element to mark handled
      */
     private void handled( Xpp3Dom xpp3Dom )
     {
@@ -372,8 +356,7 @@
     /**
      * read an xml file (application.xml or .modulemaps).
      * 
-     * @param xmlFile
-     *            an xmlfile
+     * @param xmlFile an xmlfile
      * @return dom-tree representing the file contents
      */
     private Xpp3Dom readXMLFile( File xmlFile )
@@ -399,10 +382,8 @@
     /**
      * delete all unused entries from the dom-trees.
      * 
-     * @param applicationXmlDom
-     *            dom-tree of application.xml
-     * @param modulemapsXmlDom
-     *            dom-tree of modulemaps
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapsXmlDom dom-tree of modulemaps
      */
     private void removeUnusedEntries( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapsXmlDom )
     {
@@ -413,8 +394,8 @@
                 Xpp3Dom[] newModulemapsXmlDomChildren = modulemapsXmlDom.getChildren();
                 for ( int newIndex = 0; newIndex < newModulemapsXmlDomChildren.length; newIndex++ )
                 {
-                    if ( ( newModulemapsXmlDomChildren[newIndex] != null )
-                                    && ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) )
+                    if ( ( newModulemapsXmlDomChildren[newIndex] != null ) &&
+                        ( newModulemapsXmlDomChildren[newIndex] == this.modulemapsXmlDomChildren[index] ) )
                     {
                         modulemapsXmlDom.removeChild( newIndex );
                         break;
@@ -444,12 +425,9 @@
      * go in both files all others only in the modulemaps files. Webapplications contextroots are corrected to the
      * contextRoot specified in the pom.
      * 
-     * @param applicationXmlDom
-     *            dom-tree of application.xml
-     * @param modulemapXmlDom
-     *            dom-tree of modulemaps
-     * @param dependency
-     *            the eclipse dependency to handle
+     * @param applicationXmlDom dom-tree of application.xml
+     * @param modulemapXmlDom dom-tree of modulemaps
+     * @param dependency the eclipse dependency to handle
      */
     private void updateApplicationXml( Xpp3Dom applicationXmlDom, Xpp3Dom modulemapXmlDom, IdeDependency dependency )
     {
@@ -500,8 +478,8 @@
                 {
                     handled( module );
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_WEB_URI ).setValue(
-                                                                                                         dependency.getArtifactId()
-                                                                                                                         + ".war" );
+                                                                                                         dependency.getArtifactId() +
+                                                                                                             ".war" );
                     module.getChild( APPLICATION_XML_WEB ).getChild( APPLICATION_XML_CONTEXT_ROOT ).setValue(
                                                                                                               contextRootInPom );
                 }
@@ -512,8 +490,7 @@
     /**
      * Find the contextRoot specified in the pom and convert it into contextroot for the application.xml.
      * 
-     * @param artifactId
-     *            the artifactid to search
+     * @param artifactId the artifactid to search
      * @return string with the context root
      */
     private String getContextRootFor( String artifactId )
@@ -529,14 +506,12 @@
     /**
      * write back a domtree to a xmlfile and use the pretty print for it so that it is human readable.
      * 
-     * @param xmlFile
-     *            file to write to
-     * @param xmlDomTree
-     *            dom-tree to write
-     * @throws MojoExecutionException
-     *             if the file could not be written
+     * @param xmlFile file to write to
+     * @param xmlDomTree dom-tree to write
+     * @throws MojoExecutionException if the file could not be written
      */
-    private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree ) throws MojoExecutionException
+    private void writePrettyXmlFile( File xmlFile, Xpp3Dom xmlDomTree )
+        throws MojoExecutionException
     {
         Xpp3Dom original = readXMLFile( xmlFile );
         if ( original != null && original.equals( xmlDomTree ) )