First of all I hope this is the right place to send my patch to.
At my company we're used to check out an entire project from subversion.
So we'll get all the modules of a project in one eclipse project. The
eclipse plugin will create .project and .classpath files in each module
directory. For easy checkout and maintainability I've made a patch for
the eclipse plugin. With the config '<multiModule>true</multiModule>'
the plugin now creates a .project and .classpath file in the root of the
multi module project. This classpath has all the source and output
directories setup so eclipse put's it's outputs in the same directories
(in the modules target directories) where maven places them.
I'm sending this patch to this mailinglist because I suspect more people
would like to be able to check out their multi module projects in this
manner instead of the circumvent way that is described on
http://maven.apache.org/plugins/maven-eclipse-plugin/reactor.html .
Perhaps it'll even make it into the next release who knows :)
Syte Beimin
Better.be
Index:
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
===================================================================
---
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
(revision 556880)
+++
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePlugin.java
(working copy)
@@ -272,6 +272,15 @@
* @parameter expression="${wtpContextName}"
default-value="${project.artifactId}"
*/
private String wtpContextName;
+
+ /**
+ * Is it a multi module project? If yes only 1 .classpath and .project
file will be created.
+ * These will be created in the root dir of the project. No .classpath or
.project files will
+ * be created in the submodules.
+ *
+ * @parameter expression="${multiModule}" default-value="false"
+ */
+ private String multiModule;
/**
@@ -350,6 +359,11 @@
private float wtpVersionFloat;
/**
+ * Is this a multi module project?
+ */
+ private boolean isMultiModule;
+
+ /**
* Not a plugin parameter. Is this a java project?
*/
private boolean isJavaProject;
@@ -491,6 +505,22 @@
}
/**
+ * Getter for <code>multiModule</code>.
+ * @return Returns the multiModule.
+ */
+ public String getMultiModule() {
+ return multiModule;
+ }
+
+ /**
+ * Setter for <code>multiModule</code>.
+ * @param multiModule The multiModule to set.
+ */
+ public void setMultiModule(String multiModule) {
+ this.multiModule = multiModule;
+ }
+
+ /**
* Getter for <code>additionalBuildcommands</code>.
* @return Returns the additionalBuildcommands.
*/
@@ -669,6 +699,16 @@
{
getLog().info( Messages.getString( "EclipsePlugin.wtpversion",
wtpversion ) );
}
+ if( "true".equals( multiModule ) )
+ {
+ isMultiModule = true;
+ getLog().info("multiModule configured as true. Building 1
eclipse config for all modules togetherin the root project .");
+ }
+ else
+ {
+ isMultiModule = false;
+ getLog().info("multiModule configured as false or not
configures. Building config for each module in the module dir.");
+ }
}
protected void setupExtras()
@@ -708,11 +748,11 @@
throw new MojoExecutionException( Messages.getString(
"EclipsePlugin.missingpom" ) ); //$NON-NLS-1$
}
- if ( "pom".equals( packaging ) && eclipseProjectDir == null )
//$NON-NLS-1$
- {
- getLog().info( Messages.getString( "EclipsePlugin.pompackaging" )
); //$NON-NLS-1$
- return false;
- }
+// if ( "pom".equals( packaging ) && eclipseProjectDir == null )
//$NON-NLS-1$
+// {
+// getLog().info( Messages.getString( "EclipsePlugin.pompackaging"
) ); //$NON-NLS-1$
+// return false;
+// }
if ( "eclipse-plugin".equals( packaging ) )
{
@@ -778,7 +818,34 @@
// NOTE: This could change the config!
writeExtraConfiguration( config );
-
+
+ if(isMultiModule && config.getProject().getModules().size()>0)
+ {
+ Set sourceDirCollection = new TreeSet();
+ // add module info to EclipseWriterConfig
+ for (Iterator iter = reactorProjects.iterator();
iter.hasNext();) {
+ MavenProject module = (MavenProject) iter.next();
+ String moduleArtifactId =
module.getArtifactId();
+
if(config.getProject().getModules().contains(moduleArtifactId)){
+ EclipseSourceDir[] sourceDirs =
buildDirectoryList( module, module.getBasedir(), new
File(module.getBuild().getOutputDirectory()) );
+ for (int i = 0; i < sourceDirs.length;
i++) {
+ EclipseSourceDir dir =
sourceDirs[i];
+
dir.setPath(moduleArtifactId+"/"+ dir.getPath());
+ String output = dir.getOutput();
+ if(output==null)
+ output =
IdeUtils.toRelativeAndFixSeparator( project.getFile().getParentFile(), new
File( project.getBuild().getOutputDirectory() ), false );
+
dir.setOutput(moduleArtifactId+"/"+ output);
+ sourceDirCollection.add(dir);
+ }
+ }
+ }
+ config.setSourceDirs((EclipseSourceDir[])
sourceDirCollection.toArray( new EclipseSourceDir[sourceDirCollection.size()]
));
+ new EclipseClasspathWriter().init( getLog(), config ).write();
+ }
+ if(isMultiModule && config.getProject().getModules().size()==0) {
+ return;
+ }
+
if ( wtpVersionFloat == 0.7f )
{
new EclipseWtpmodulesWriter().init( getLog(), config ).write();
Index:
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginMultiModuleProjectTest.java
===================================================================
---
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginMultiModuleProjectTest.java
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/main/java/org/apache/maven/plugin/eclipse/EclipsePluginMultiModuleProjectTest.java
(revision 0)
@@ -0,0 +1,71 @@
+package org.apache.maven.plugin.eclipse;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+
+import org.codehaus.plexus.util.IOUtil;
+
+public class EclipsePluginMultiModuleProjectTest extends
AbstractEclipsePluginTestCase {
+
+ protected File basedir;
+
+ /**
+ * @see
org.apache.maven.plugin.eclipse.AbstractEclipsePluginTestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ basedir =
getTestFile("target/test-classes/projects/multi-module-test");
+ super.setUp();
+ }
+
+ protected void executeMaven2() throws Exception {
+ File pom = new File(basedir, "pom.xml");
+
+ Properties properties = new Properties();
+ properties.setProperty("multiModule", "true");
+
+ String pluginSpec = getPluginCLISpecification();
+
+ List goals = new ArrayList();
+
+ goals.add(pluginSpec + "clean");
+ goals.add(pluginSpec + "eclipse");
+
+ executeMaven(pom, properties, goals);
+
+ }
+
+ public void testModuleProject() throws Exception {
+ executeMaven2();
+ assertFileEquals(null, new File(basedir, "expected/.project"),
//
+ new File(basedir, ".project"));
+ }
+
+ public void testModuleClasspath() throws Exception {
+ executeMaven2();
+ InputStream fis = new FileInputStream(new File(basedir,
".classpath"));
+ String classpath = IOUtil.toString(fis);
+ IOUtil.close(fis);
+ System.out.println(classpath);
+ // direct dependencies, include all
+ assertContains("Invalid classpath", classpath,
"/refproject-test");
+ assertContains("Invalid classpath", classpath,
"/refproject-optional");
+ assertContains("Invalid classpath", classpath,
"/refproject-provided");
+ assertContains("Invalid classpath", classpath, "/direct-compile" );
+ assertContains("Invalid classpath", classpath, "/direct-test" );
+ assertContains("Invalid classpath", classpath, "/direct-optional" );
+
+ // transitive dependencies
+ assertContains("Invalid classpath", classpath, "/deps-direct-compile"
);
+
+ // source dirs
+ assertContains("Invalid classpath", classpath,
"module-1/src/main/java");
+ assertContains("Invalid classpath", classpath,
"module-1/target/classes");
+ assertContains("Invalid classpath", classpath,
"module-2/src/test/java");
+ assertContains("Invalid classpath", classpath,
"module-2/target/test-classes");
+ assertContains("Invalid classpath", classpath,
"module-2/src/test/resources");
+ }
+}
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/expected/.project
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/expected/.project
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/expected/.project
(revision 0)
@@ -0,0 +1,7 @@
+<projectDescription>
+ <name>multi-module-test</name>
+ <comment/>
+ <projects/>
+ <buildSpec/>
+ <natures/>
+</projectDescription>
\ No newline at end of file
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/pom.xml
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/pom.xml
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/pom.xml
(revision 0)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>eclipsetest</groupId>
+ <artifactId>multi-module-test</artifactId>
+ <version>1.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+ <groupId>eclipsetest</groupId>
+ <artifactId>module-1</artifactId>
+ <version>1.0</version>
+ <name>module 1</name>
+</project>
\ No newline at end of file
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/src/main/java/DummyClass.txt
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/src/main/java/DummyClass.txt
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-1/src/main/java/DummyClass.txt
(revision 0)
@@ -0,0 +1,7 @@
+/**
+ * @author <a href="mailto:[EMAIL PROTECTED]">Trygve Laugstøl</a>
+ * @version $Id: DummyClass.txt 359507 2005-12-28 13:14:19 +0000 (Wed, 28 Dec
2005) fgiust $
+ */
+public class DummyClass
+{
+}
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/pom.xml
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/pom.xml
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/pom.xml
(revision 0)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <groupId>eclipsetest</groupId>
+ <artifactId>multi-module-test</artifactId>
+ <version>1.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>jar</packaging>
+ <groupId>eclipsetest</groupId>
+ <artifactId>module-2</artifactId>
+ <version>1.0</version>
+ <name>module 2</name>
+</project>
\ No newline at end of file
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/java/DummyClass.txt
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/java/DummyClass.txt
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/java/DummyClass.txt
(revision 0)
@@ -0,0 +1,3 @@
+public class DummyClass
+{
+}
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/resources/placeholder.txt
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/resources/placeholder.txt
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/module-2/src/test/resources/placeholder.txt
(revision 0)
@@ -0,0 +1 @@
+this file is a placeholder
\ No newline at end of file
Index:
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/pom.xml
===================================================================
---
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/pom.xml
(revision 0)
+++
/maven-eclipse-plugin-2.4/src/test/resources/projects/multi-module-test/pom.xml
(revision 0)
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <packaging>pom</packaging>
+ <groupId>eclipsetest</groupId>
+ <artifactId>multi-module-test</artifactId>
+ <version>1.0</version>
+ <name>multi-module</name>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <workspace>${basedir}</workspace>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+ <modules>
+ <module>module-1</module>
+ <module>module-2</module>
+ </modules>
+ <dependencies>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>refproject-test</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>refproject-provided</artifactId>
+ <version>1.0</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>refproject-optional</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>direct-compile</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>direct-test</artifactId>
+ <version>1.0</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>eclipsetest</groupId>
+ <artifactId>direct-optional</artifactId>
+ <version>1.0</version>
+ <optional>true</optional>
+ </dependency>
+ </dependencies>
+</project>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]