The Buildfile Execution Process
We have the buildfile, but what happens when Ant runs? Understanding how Ant parses the buildfile and executes the targets is key to writing good, solid buildfiles.
Ant interprets the
buildfile’s XML, meaning that it processes the
elements as it parses them. The XML library that Ant uses represents
a hierarchal tree structure; Ant follows this tree’s
path during processing. At the project level,
the level of XML just inside the
element, Ant does a breadth-first traversal of the XML elements. This
means that it loads and processes all of the elements just below the
level of the
<project> element first, and
then moves on to the first target. Inside a target, Ant does a
depth-first traversal. This means that, starting with a
target’s first element, Ant processes each element
as deep as it can before it moves on to the next element.
Understanding this design is most important when trying to understand how Ant processes its own errors (as opposed to errors from bad compilation or failed file copies). At the project level, Ant does a kind of syntax check before it actually processes any elements. In general, when speaking of Ant processing an element, we mean that Ant goes through the full processing life cycle on that element. Assuming a syntactically correct element declaration, the processing appears to be atomic from the outside; you cannot insert any operations between the time Ant parses the element and when Ant performs the ...