Maven 1.x Eclipse Plugin

Two hacks to the eclipse plug-in in .classpath generation (see comments for details)

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Incomplete
  • Affects Version/s: None
  • Fix Version/s: 1.8
  • Component/s: None
  • Labels:
    None
  • Number of attachments :
    1

Description

The attached file contains two hacks to the generation of the classpath in the eclipse:generate-classpath plug-in:
1. Added the source directory for the integration unit tests.
(TODO: add cactus JARs to the classpath)
2. Add JARs only once (using a Set), this is useful when you have a junit in the dependencies (or may be in the future when you have the cactus libs)

Activity

Hide
Jens Andersen added a comment -

Thanks Diego, great stuff. I think we should "upgrade" the plugin to support the exclude and the "compile to different folders" feature which is introduced in Eclipse 2.1.

The "child" containing the source dir could look something like this:

<j:if test="${sourcesPresent}">
<classpathentry kind="src" excluding="**/Test" output="${outputDir}" path="${pom.build.sourceDirectory}"/>
</j:if>

And the "child" containing the unit test could look something like this:

<!-- Must be defined the same place as var="outputDir" etc. -->
<j:set var="outputDirTest" value="${maven.eclipse.outputtest.dir}"/>
<j:if test="${empty outputDirTest}">
<j:set var="outputDirTest" value="target/test-classes"/>
</j:if>


<j:if test="${unitTestSourcesPresent}">
<j:forEach var="exclude" items="${pom.build.unitTest.excludes}">
<j:set var="excluding" value="${excluding}|${exclude}"/>
</j:forEach>

<classpathentry kind="src" excluding="${excluding.substring(1)}" output="${outputDirTest}" path="${pom.build.unitTestSourceDirectory}"/>

//Damn - it's a bit hacked - bette look into Jelly.
//Here comes the rest of your patch
...
</j:if>

It might also be usefull to support the pom.build.resources - like creating another leaf to the goal - the code below could be a starting point - but it's not working correctly.

<j:if test="${!pom.build.resources.isEmpty()}">
<j:forEach var="dir" items="${pom.build.resources.dirs}">
<classpathentry kind="src" output="${outputDir}" path="${dir}"/>
</j:forEach>
</j:if>

And aging the "leaf" should support the exclude feature like the unittest "leaf" - look above. By the way is there a better way to get the name/location of each resource directory than shown above?

Best regards,

Jens Andersen

Show
Jens Andersen added a comment - Thanks Diego, great stuff. I think we should "upgrade" the plugin to support the exclude and the "compile to different folders" feature which is introduced in Eclipse 2.1. The "child" containing the source dir could look something like this: <j:if test="${sourcesPresent}"> <classpathentry kind="src" excluding="**/Test" output="${outputDir}" path="${pom.build.sourceDirectory}"/> </j:if> And the "child" containing the unit test could look something like this: <!-- Must be defined the same place as var="outputDir" etc. --> <j:set var="outputDirTest" value="${maven.eclipse.outputtest.dir}"/> <j:if test="${empty outputDirTest}"> <j:set var="outputDirTest" value="target/test-classes"/> </j:if> <j:if test="${unitTestSourcesPresent}"> <j:forEach var="exclude" items="${pom.build.unitTest.excludes}"> <j:set var="excluding" value="${excluding}|${exclude}"/> </j:forEach> <classpathentry kind="src" excluding="${excluding.substring(1)}" output="${outputDirTest}" path="${pom.build.unitTestSourceDirectory}"/> //Damn - it's a bit hacked - bette look into Jelly. //Here comes the rest of your patch ... </j:if> It might also be usefull to support the pom.build.resources - like creating another leaf to the goal - the code below could be a starting point - but it's not working correctly. <j:if test="${!pom.build.resources.isEmpty()}"> <j:forEach var="dir" items="${pom.build.resources.dirs}"> <classpathentry kind="src" output="${outputDir}" path="${dir}"/> </j:forEach> </j:if> And aging the "leaf" should support the exclude feature like the unittest "leaf" - look above. By the way is there a better way to get the name/location of each resource directory than shown above? Best regards, Jens Andersen
Hide
Pål Brattberg added a comment -

Jens, I too needed what you was asking for, and here is my attempt.

Notice that support for exclusion patterns in not on by default in Eclipse, at least not in IBM WSAD (which in turn is derived from Eclipse). So, if you do not have exclusion support on, and you have exclude patterns in your project.xml file, Eclipse will complain about your new .classpath file. Either comment the piece in my addition that adds exclusions, or tell Eclipse to support exclusion.

This code should go in MAVEN_HOME/plugins/maven-eclipse-plugin-1.7/plugin-resources/templates/classpath.jelly. I added it right after the first <classpath> entry.

<j:if test="${!pom.build.resources.isEmpty()}">
<j:forEach var="res" items="${pom.build.resources}">
<maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${res.directory}"/>
<!-- Comment this if you do not wish to use exclusions for resources.
Note that includes do not yet work in Eclipse (AFAIK), so beware of that
if things seem to crash. Also make sure your project is prepared for exclusions,
this can be set as a property for the compiler. -->
<j:set var="excluding" value=""/>
<j:forEach var="exclude" items="${res.excludes}">
<j:choose>
<j:when test="${excluding.length() == 0}">
<j:set var="excluding" value="${exclude}"/>
</j:when>
<j:otherwise>
<j:set var="excluding" value="${excluding},${exclude}"/>
</j:otherwise>
</j:choose>
</j:forEach>
<!-- End exclusion patterns -->
<classpathentry kind="src" path="${srcDir}" excluding="${excluding}" />
</j:forEach>
</j:if>

Show
Pål Brattberg added a comment - Jens, I too needed what you was asking for, and here is my attempt. Notice that support for exclusion patterns in not on by default in Eclipse, at least not in IBM WSAD (which in turn is derived from Eclipse). So, if you do not have exclusion support on, and you have exclude patterns in your project.xml file, Eclipse will complain about your new .classpath file. Either comment the piece in my addition that adds exclusions, or tell Eclipse to support exclusion. This code should go in MAVEN_HOME/plugins/maven-eclipse-plugin-1.7/plugin-resources/templates/classpath.jelly. I added it right after the first <classpath> entry. <j:if test="${!pom.build.resources.isEmpty()}"> <j:forEach var="res" items="${pom.build.resources}"> <maven:makeRelativePath var="srcDir" basedir="${basedir}" path="${res.directory}"/> <!-- Comment this if you do not wish to use exclusions for resources. Note that includes do not yet work in Eclipse (AFAIK), so beware of that if things seem to crash. Also make sure your project is prepared for exclusions, this can be set as a property for the compiler. --> <j:set var="excluding" value=""/> <j:forEach var="exclude" items="${res.excludes}"> <j:choose> <j:when test="${excluding.length() == 0}"> <j:set var="excluding" value="${exclude}"/> </j:when> <j:otherwise> <j:set var="excluding" value="${excluding},${exclude}"/> </j:otherwise> </j:choose> </j:forEach> <!-- End exclusion patterns --> <classpathentry kind="src" path="${srcDir}" excluding="${excluding}" /> </j:forEach> </j:if>
Hide
David Eric Pugh added a comment -

Hi, I am marking this as incomplete as the first part has been added for the integration tests. The second part I am not convinced is a good idea. If, for some reason, I add a jar twice to my POM, I expect that should show up everywhere as an error, versus masking it with a Set.. It seems that maven maybe in some sort of pom:validate goal should flag it as an error.

Show
David Eric Pugh added a comment - Hi, I am marking this as incomplete as the first part has been added for the integration tests. The second part I am not convinced is a good idea. If, for some reason, I add a jar twice to my POM, I expect that should show up everywhere as an error, versus masking it with a Set.. It seems that maven maybe in some sort of pom:validate goal should flag it as an error.

People

Vote (1)
Watch (3)

Dates

  • Created:
    Updated:
    Resolved: