Frank Caputo’s Blog

Just another WordPress.com weblog

Update for Peter Thomas’ maven-antprops-plugin March 5, 2009

Filed under: netbeans — Frank Caputo @ 5:12 pm
Tags: , , , , , ,

When I found Peter’s maven-antprops-plugin, I was really happy about the the goal antprops:nbjavaee. I used it to evaluate some web-frameworks, for which maven-archetypes were available. I was less happy, when I had to code some EJBs based on POMs, and saw the plugin only works for WARs. So I decided to improve it and add the following features to the goal antprops:nbjavaee:

  • differentiate between test-libs and other libs
  • work with ejb- and ear-projects
  • attach sources and javadocs if available in local maven repository

We call this plugin in every clean in NetBeans’s build.xml:

    <target name="-post-clean">
        <exec executable="mvn.bat" dir="${basedir}" osfamily="windows">
            <arg value="clean"/>
            <arg value="eclipse:eclipse"/>
            <arg value="eclipse:clean"/>
            <arg value="antprops:nbjavaee"/>
            <arg value="-DdownloadSources=true"/>
            <arg value="-DdownloadJavadocs=true"/>
        </exec>
        <exec executable="mvn" dir="${basedir}" osfamily="mac">
            <arg value="clean"/>
            <arg value="eclipse:eclipse"/>
            <arg value="eclipse:clean"/>
            <arg value="antprops:nbjavaee"/>
            <arg value="-DdownloadSources=true"/>
            <arg value="-DdownloadJavadocs=true"/>
        </exec>
    </target>

We abuse the maven-eclipse-plugin to download the sources and javadocs for all our dependencies 😉 All sources and javadocs found in the local maven repository are automatically attached to the libraries in NetBeans. This is really helpfull for debugging and code-completion.

Another improvement is the ability to do glassfish-dirctory-deployment of EARs out of NetBeans. For this you need to add an additional target to the build.xml:

    <target name="pre-run-deploy">
        <unzip dest="${build.dir}" src="${dist.jar}">
            <patternset includes="${ee.archives}"/>
        </unzip>
        <mkdir dir="${build.generated.dir}/tmp"/>
        <!--touch file="${build.generated.dir}/unzipee.txt"/-->
        <echo file="${build.generated.dir}/tmp/UnzipEE.java"><![CDATA[
            package tmp;

            import java.io.File;
            import java.util.Iterator;
            import org.apache.tools.ant.BuildException;
            import org.apache.tools.ant.Task;
            import org.apache.tools.ant.taskdefs.Expand;
            import org.apache.tools.ant.types.FileSet;
            import org.apache.tools.ant.types.Resource;
            import org.apache.tools.ant.types.resources.FileResource;

            public class UnzipEE extends Task {

                private FileSet fileSet;

                public void add(FileSet fileSet) {
                    this.fileSet = fileSet;
                }

                public void execute() throws BuildException {
                    for(Iterator it = fileSet.iterator(); it.hasNext();) {
                        Resource resource = (Resource) it.next();
                        if(resource.isExists() && (resource instanceof FileResource)) {
                            File file = ((FileResource) resource).getFile();
                            String name = file.getName();
                            String dest = name.replaceAll("\\.jar", "_jar").replaceAll("\\.war", "_war");
                            Expand expand = new Expand();
                            expand.setProject(getProject());
                            expand.setSrc(file);
                            expand.setDest(new File(file.getParentFile(), dest));
                            expand.execute();
                        }
                    }
                }

            }
        ]]>
        </echo>
        <javac debug="true" srcdir="${build.generated.dir}" destdir="${build.generated.dir}"/>
        <taskdef name="unzipee" classname="tmp.UnzipEE" classpath="${build.generated.dir}"/>
        <unzipee>
            <fileset dir="${build.dir}" includes="${ee.archives}"/>
        </unzipee>
        <delete dir="${build.dir}" includes="${ee.archives}"/>
        <delete includeemptydirs="true">
            <fileset dir="${build.dir}" includes="**/.svn" defaultexcludes="false"/>
        </delete>
        <delete dir="${build.generated.dir}/tmp"/>
    </target>

This looks really weird, but is necessary if you want to reference some projects directly and use compile on save. You have to extract all ejb-jars and wars manually into the folder dist/gfdeploy. For this reason the updated plugin generates the property “ee.archives”, which is a space separated list of all dependencies of type “ejb” or “war”. If you want to reference a web-project directly, instead of a war, you have to remove the war-dependency and add the project instead.

The patch for Peter’s plugin can be found here: SourceForge.net: JTrac: Detail: 2667507

Advertisements
 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s