Five minute tutorial
The Ant Timer is a plug-in that prints out diagnostic messages when ant targets and tasks take longer than the configured amount of time. You can use it with any ant build. Here is some sample output when I use it on my renamer program.
[javadoc] Generating Javadoc
[javadoc] Javadoc execution
[javadoc] Loading source files for package com.motlin.base...
[javadoc] Loading source files for package com.motlin.base.log4j...
[javadoc] Loading source files for package com.motlin.renamer...
[javadoc] Loading source files for package com.motlin.renamer.exceptions...
[javadoc] Constructing Javadoc information...
[javadoc] Standard Doclet version 1.6.0_06
[javadoc] Building tree for all the packages and classes...
[javadoc] C:\cygwin\home\Administrator\dev\renamer\trunk\src\com\motlin\base\log4j\StdOutErrAppender.java:318: warning - Tag @link: reference not found: org.apache.log4j.net.SocketAppender
[javadoc] Building index for all the packages and classes...
[javadoc] Building index for all classes...
[javadoc] Generating C:\cygwin\home\Administrator\dev\renamer\trunk\dist\api\stylesheet.css...
[javadoc] 1 warning
XXX task [renamer.javadocs.javadoc] took 2 seconds to run
XXX task [renamer.null.sequential] took 2 seconds to run
XXX task [renamer.javadocs.ac:outofdate] took 2 seconds to run
XXX target [renamer.javadocs] took 2 seconds to run
Total time: 2 seconds
Running ant with the custom listener is pretty simple. Here’s the command that produced the output above.
ant -listener com.motlin.ant.timer.TimerListener -lib ant-timer-1.0.jar -lib lib/joda-time-1.5.2.jar -Dtarget.timer=2 -Dtask.timer=1 -Dtimer.prefix="XXX" clean javadocs
Let’s break it down.
This is the class name of the custom task.
-lib ant-timer-1.0.jar -lib lib/joda-time-1.5.2.jar
Unfortunately, the Ant Timer depends on joda time. It didn’t have to but I like it better than using the built in classes for working with times. You’ll need to download the joda jar separately.
-Dtarget.timer=2 -Dtask.timer=1 -Dtimer.prefix="XXX"
You can configure the behavior through these properties. The first two are the timeouts in seconds for targets and tasks. If you leave them off they default to 10 seconds and 1 second respectively. The prefix makes it easy to find the output printed by the custom listener. If you leave it off it defaults to “!!!”