1
votes

Is there any way to mark required and optional attributes/nested elements for custom ANT tasks and types?

I'm thinking of something like the @Required annotation in Spring IOC. At least for tasks it should be fairly easy to validate that all required attributes have been set before actually executing the task.

Thanks in advance.

EDIT: I know about the possibility to manually validate properties in execute() and throw BuildExceptions, but I'd think it would be more convenient to have automatic validation based on annotations.

2
No. You need to check them manually. - coolcfan
Seems like that is the simple but correct answer... you might want to add it as an answer so that I can accept it? - Florian Patzl

2 Answers

1
votes

Currently Ant doesn't provide a way to "mark" a property for validation. You need to check them manually.

At least for tasks it should be fairly easy to validate that all required attributes have been set before actually executing the task.

No. In Ant, many properties could be generated during the run -- one task outputs a property and another task use it. The <condition> tasks works in this way -- you set the name of the output property, and the task will set the value.

Although some tools/IDEs could staticly parse the build file and warn you if there is any property not set yet, they can't know if a task will output a property just by checking the XML.

0
votes

In the body of execute() method of your custom task, you can validate the attributes you need. You can throw exception to report validation failures. This post shows a complete example.