Fixing the output of mvn eclipse:eclipse for Sling

xslt

I tend to use Eclipse only for editing/navigating code and for remote debugging, leaving the heavy lifting of building and executing stuff to the old trusted command line.

In this context, the mvn eclipse:eclipse plugin often generates too much magic for me. When working with Sling, especially, I don't want any maven or java builders in my Eclipse projects, and for some reason the plugin generates an extra resource path based on the LICENSE, NOTICE and similar files.

If you like to work in the same way (I know many people like go further with their IDEs), here are two scripts that I use to post-process the Eclipse project files after mvn eclipse:eclipse.

This scripts "fixes" all .project and .classpath files under the current directory (uses xsltproc):

#!/bin/bash
XSLT=$(dirname $0)/fix-eclipse-maven.xsl
TMPF=/tmp/$$.tmp

find . -name .project | while read p
do
echo "Running $(basename $XSLT) on $p..."
xsltproc $XSLT $p > $TMPF
rm -f $p
mv $TMPF $p
done

EXPR="LICENSE.\*DISCLAIMER"
find . -name .classpath | while read c
do
echo "Removing lines containing $EXPR from $c)"
grep -v $EXPR $c > $TMPF
rm -f $c
mv $TMPF $c
done

And uses this XSLT transform to get rid of the build commands in .project files:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>


<xsl:template match="\*">
<xsl:copy>
<xsl:copy-of select="@\*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

<!-- remove all Eclipse buildCommands -->
<xsl:template match="buildCommand"/>
</xsl:stylesheet>