Ant Tasks

I’ve written a few things to make my builds easier at home, and I finally figured I should share them with the community (and I finally had time to make a distribution jar and these web pages).

The jar file that contains some loggers and an ant task is anns-ant-dist.jar.

The ant task is called jnlpsize; it updates the sizes for items in JNLP files using the href address. Here is an example usage:

<taskdef name=”jnlpsize” classname=”net.alephnaught.ant.task.UpdateJNLPSizes” />
<target name=”test”>
<jnlpsize jnlpfilename=”/Users/roberthays/AlephNaught/WebStart/working.jnlp”/>
</target>

Note that it takes one argument, the location of the JNLP file to update. I find this really useful to put near the end of my build script that builds my JNLP-released software.

In addition, the distribution contains some logging tools I wrote. The most interesting item is net.alephnaught.ant.event.LoggerFactory; this logger reads a properties file and executes any loggers configured inside it. This was a hack to allow me to log to a text file while also logging to an RSS feed and an XML file. Here’s the build script I use to run ant:

#!/bin/bash

datemarker=`date ‘+%y%m%d%H%M%S’`
logfile=build_$datemarker.txt
txtlogfile=/Library/WebServer/Documents/Build/$logfile
rssfile=/Library/WebServer/Documents/Build/RSSLogger.xml

ant -logger net.alephnaught.ant.event.LoggerFactory -DRSSLogger.output_file=$rssfile -DRSSLogger.build_link=http://localhost/Build/$logfile $* | tee $txtlogfile

The properties file must be named LoggerFactory.properties and must be on the classpath. I use the following content for mine:

LoggerFactory.logger=org.apache.tools.ant.DefaultLogger,net.alephnaught.ant.event.RSSLogger,net.alephnaught.ant.event.AntPerformanceLogger
LoggerFactory.passthru=false

You can have multiple LoggerFactory.logger lines and each will be called. The passthru property tells the factory whether to eat exceptions internally or pass them to ant.

In addition there’s a class that converts the excellent net.sf.antcontrib.perf.AntPerformanceListener to a logger, an RSSLogger that creates an entry for each build indicating success or failure and a link to the text/XML file with the whole build log, and a JabberLogger that uses the JabberBeans library to output log information to subscribed Jabber listeners. The source code is included in the jar file, and its all covered under the Eclipse license (CPL). If you make changes, please pass them back to me for inclusion in the main tree.

Revisions:

There are no revisions for this post.