Scriptdef can be used to define an Ant task using a scripting language. Ant scripting languages supported by Apache BSF may be used to define the script. Scriptdef provides a mechanism to encapsulate control logic from a build within an Ant task minimizing the need for providing control style tasks in Ant itself. Complex logic can be made available while retaining the simple structure of an Ant build file. Scriptdef is also useful for prototyping new custom tasks. Certainly as the complexity of the script increases it would be better to migrate the task definition into a Java based custom task.
Note: This task depends on external libraries not included in the Ant distribution. See Library Dependencies for more information.
The attributes and nested elements supported by the task may be defined using
<element> nested elements. These are available to the script that implements the task as two collection style script variables
elements. The elements in the
attributes collection may be accessed by the attribute name. The
elements collection is accessed by the nested element name. This will return a list of all instances of the nested element. The instances in this list may be accessed by an integer index.
Note: Ant will turn all attribute and element names into all lowercase names, so even if you use name="SomeAttribute", you'll have to use "someattribute" to retrieve the attribute's value from the
The name "project" is a pre-defined reference to the Ant Project. For more information on writing scripts, please refer to the
|name||the name of the task to be created using the script||Yes|
|language||The programming language the script is written in. Must be a supported Apache BSF language||Yes|
|src||The location of the script as a file, if not inline||No|
|uri||The XML namespace uri that this definition should live in.||No|
|name||the name of the attribute||Yes|
|name||the name of the nested element to be supported by the task defined by the script||Yes|
|classname||the classname of the class to be used for the nested element. This specifies the class directly and is an alternative to specifying the Ant type name.||No|
|type||This is the name of an Ant task or type which is to be used when this element is to be created. This is an alternative to specifying the class name directly||No|
The following definition creates a task which supports an attribute called attr and two nested elements, one being a fileset and the other a path. When executed, the resulting task logs the value of the attribute and the basedir of the first fileset.
When a script has a syntax error, the scriptdef name will be listed in the error. For example in the above script, removing the closing curly bracket would result in this error
build.xml:15: SyntaxError: missing } in compound statement (scriptdef
<scripttest2>; line 10)
Script errors are only detected when a script task is actually executed.
Source: Apache Ant