ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject Re: Validating task attributes
Date Fri, 02 Jun 2000 13:15:31 GMT

Actaully, execute isn't your only choice.  Using the init() method is a
perfectly viable alternative.

During the parsing of the build file, the attribute values are reflected
into the Task object.  Once that's complete, the init method is called -
during parse time.  As an example, the Property task uses init() to make
use of the attributes to either set a property to a particular value, read
properties from a file, or check to see if a resource exists.  That
property information is then available to the next task being parsed.  The
Property.init() method has a "catch all" try/catch Exception block to
wrapper any potential problems with a BuildException.

What you get is parse time validation of your attributes, but you leave the
setters clean and simple.

Glenn McAllister
TID - Software Developer - VisualAge for Java
IBM Toronto Lab, (416) 448-3805
"An approximate answer to the right question is better than the
right answer to the wrong question." - John W. Tukey

>>>>> "CC" == Craig Cottingham <> writes:

 CC> When is the appropriate time to validate the values of the
CC> attributes for a task: when the attribute is set (I assume this
CC> happens at parse time), or when the attribute would be used (for
CC> instance, in execute())?

First, yes you are right, attributes are set at parse time right now.

If you want to throw a BuildException on malformed attributes execute
is your only clean choice - as the setters shouldn't throw any
Exceptions at all. If you just want to print a warning you can do it
in the setter method.

In some cases execute is your only choice anyway - when two attributes
depend on each other for example.


View raw message