I put a lot of power into the scripting task, a lot more than I think
people realize. I wasn't going to discuss it until the time was right, but
now it does appear that there is enough genuine interest (trust me, it was
*very* controversial at the time). I present it here to seed discussion -
if there are things that there is consensus on needing to be changed, then
I'm OK with change as I doubt that anybody is seriously using it.
The first thing worth mentioning is that scripts have access to everything
a Java task would have access to. Below is an example of a simple loop
which actually modifies the build script. Note the use of the name
"squares" and "main".
<project name="squares" default="main" basedir=".">
<target name="setup">
<script language="javascript"> <![CDATA[
for (i=1; i<=10; i++) {
echo = squares.createTask("echo");
main.addTask(echo);
echo.setMessage(i*i);
}
]]> </script>
</target>
<target name="main" depends="setup" />
</project>
And here is the output I get when I run this script on my machine:
Buildfile: build.xml
Project base dir set to: C:\tmp
Executing Target: setup
Executing Target: main
1
4
9
16
25
36
49
64
81
100
Completed in 4 seconds
- Sam Ruby