20041112 Friday November 12, 2004

Ant Hacks by Erik Hatcher The first session I attended was Erik Hatcher's Ant Hacks talk. The first half of his talk was about Ant in general and was most of the stuff covered in Java Development with Ant. The good stuff was the 2nd half when he covered all the new stuff in Ant 1.6. Steve is working on an update to Java Development with Ant - shoujld will be a lot thinner. Below are some notes I took on what's new in 1.6.

  • <image> task. Requires Java Advanced Imaging API
    • Performs image manipulation
  • <import> task
    • No more entity ref includes needed - can use Ant properties for file reference now.
    • OO Nature
      • mix in imported build files - call super on imported file by specifying depends="${ant.project.name}.target" where the project.name is specified in the imported build file. Only targets that are overridden will get prefixed with namespace.
      • target overriding - main build file takes precedence
      • "abstract" targets - requires main build file implementation
  • <subant> task - Recurses tree
    • Two modes: 1) same build file in each sub directory 2) crawl a tree and run same build file on all subdirectories
  • Can have targetless build files. Everything outside a target gets executed before any targets
  • <presetdef> - Use the same task and optionally repeat. Define the options once, give it a name and refer to it later. Can override attributes later in the build.xml file. Only works for one task at a time.
  • <macrodef> - bye bye antcall. Much faster than antcall - does all the same things
    • You can specify attributes and elements as part of the definition. Tasks are wrapped in a <sequential> tag.
      • attributes are referred to in tasks using @{attribute}
      • elements are simple placeholders using XML <element/>
    • I could really use this stuff in AppFuse to replace the compile-module and test-module targets
    • "spawn" a new attribute on <java> - allows process to live past when Ant dies
  • <scriptdef> - allows you to use all kinds of scripting languages - i.e. Groovy, JavaScript, etc.
    • the project, attributes and elements are given to you - so you can easily grab them in the scripts
    • helpful to know Ant's API when writing
  • <antlib> - componentizes definition of types and tasks
    • anything that defines stuff - put in antlib.xml (i.e. <taskdef>)
    • mostly designed for Ant task distributors because they can package an antlib.xml with a namespace
    • has root element of <antlib> instead of XML
      • xmlns:antcontrib="antlib:net.sf.antcontrib" - brings in all tasks into your project

I really liked Erik's talk because AppFuse was inspired by his Java Development with Ant book. Its build.xml file was intially based on Erik's sample app and therefore, the first half of his talk pretty much pointed out tips and tricks that I'm currently using. The 2nd half of his talk was highlighting the new features of 1.6 - which he's suggested I adopt in the past. I've never had much desire (or time) to dig in and update AppFuse's build.xml file to 1.6. However, after attending his talk - it seems like it should be pretty easy to do. Good bye <antcall>, hello <macrodef>.

Later: One of the coolest things I saw in Erik's talk was how his Ant logging was color coded. I asked him about it and all your need to do is specify "-logger org.apache.tools.ant.listener.AnsiColorLogger" in an ANT_ARGS environment variable. Good stuff! Posted in NFJS at Nov 12 2004, 05:12:12 PM MST 1 Comment

Comments:

You can place an .antrc file in your home directory with the following options to turn that on: ANT_OPTS="$ANT_OPTS -Dant.logger.defaults=/home/ehauser/.ant.colors.properties" ANT_ARGS="$ANT_ARGS -logger org.apache.tools.ant.listener.AnsiColorLogger" If you don't like the default colors, then you need the colors defined in a property file. Here's my .ant.colors.properties file: AnsiColorLogger.ERROR_COLOR=1;31 AnsiColorLogger.WARNING_COLOR=1;35 AnsiColorLogger.INFO_COLOR=1;36 AnsiColorLogger.VERBOSE_COLOR=1;34 AnsiColorLogger.DEBUG_COLOR=1;36

Posted by Eric Hauser on November 18, 2004 at 11:58 AM MST #

Post a Comment:
Comments are closed for this entry.
Click me to subscribe
Matt Raible is a Web Architecture Consultant specializing in open source frameworks.
« May 2012
SunMonTueWedThuFriSat
  
1
2
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
23
24
25
26
27
28
29
30
31
  
       
Today

Recent Entries

Tag Cloud