Thursday, July 14, 2005

Ant Crash Course

Posted by Phil Aaronson at 12:45 PM

I guess I've been living under a rock for the past couple of years. I hadn't played with Ant. Ant is billed as a Java build tool, but its more flexible, and is easily extended. Forgive me, I'm not a Java guy.

One of my coworkers (thanks Paul!) clued me in recently. Everything I wanted a component I had just finished spec'ing to do, Ant could do better. So a few days last week turned into an Ant crash course. I plowed through the online manual, and then Ant: The Definitive Guide one right after each other. Which made for some interesting reading. Its sort of funny to put the two side by side, here's a bit from the exec core task ...

Quote from the online manual:
By default the return code of a <exec> is ignored; when you set failonerror="true" then any return code signaling failure (OS specific) causes the build to fail. Alternatively, you can set resultproperty to the name of a property and have it assigned to the result code (barring immutability, of course).
Quote from Ant: The Definitive Guide (from the second Edition):
By default the return code of an exec is ignored. However, if you set failonerror to true, then any OS-specific return code that indicates failure means the build will fail. ... You can set the resultproperty to the name of a property that will be assigned the return code for testing.
So anyway, while Ant: The Definitive Guide didn't make my most favorite technical book list, it does have some nice examples. But like the above sort of indicates, it doesn't cover too much territory beyond where the online (free) manual goes. And both leave a lot left unsaid.

Our project is pulling together a series of web service calls, parsing the resulting XML and so on. Nothing too shocking, but we wanted to be robust about it. To make an HTTP request in Ant, there's a really nice core task called "get" (don't fall out of your chair now). But I couldn't find documention on when exactly this task tosses a build exception (signals an error which might stop the script). Is it when it gets a 404 (file not found) error? When it can't connect? When? Digging around in the source code, it turns out it only tosses an error when the web server returns a 403 (authorization failed) code. But you had to dig in the source. Which isn't so bad, I suppose, at least I had access.

[Update: July 22] Interestingly Slashdot posted a mostly positive review of Ant: The Definitive Guide. Shows you what I know.

0 Comments:

Post a Comment

<< Home