Friday, July 24, 2009

Ant refid resolution 1.5, 1.6, 1.7

I noticed some behaviour changes in Ant related to refids. In Ant 1.5.x a fileset refid has to be defined before being used. So for example if I define a fileset in target "a" and then call target "b" which uses the refid, the build will fail because target "a" was never run and never set up the refid.

This behaviour changed in Ant 1.6.x, so that Ant tries to be more intelligent and automatically searches for refids that are defined in the build, but not necessarily run. So in the above example, Ant silently succeeds and the refid is found in target "a" even though that target was never actually called. This seems like strange behaviour to me, because it's not well documented and seems like it could produce some tricky bugs. I guess the Ant developers also thought this behaviour was not ideal because in Ant 1.7 the same automatic refid resolution works but now produces a warning. I briefly tried to track down some discussion related to this in the ant developer mailing list archives, but I was unsuccessful in finding anything.

Tuesday, July 14, 2009

Recursive Grepping

I recently had some need to search for certain text within files in a directory. This works with eclipse, but sometimes it can be slow and a bit limited in options. So I turned to good old grep. I wanted to exclude certain directory patterns from the search, but the problem I ran into was that the version of grep packaged with Fedora 10 and available in the yum repository is an older version (2.5.1) and does not include the "--exclude-dir" option. So I had to grab a recent copy of the source. I then did a ./configure, make, make install and I was good to go with version 2.5.4. The last tricky part for me was how to match multiple filename patterns using GLOB. Here is an example of the final command:

grep -R "apache.commons." . --include={*.xml,*.ent} --exclude-dir="output"