In Ant script we could write Javascript code using the <script> task. In the following example, i will pass 2 Ant properties to Javascript and print the square value to the console. Also at the end, i will assign the greeting to a new Ant property.
<project name="AntLoopExample" default="run" basedir="."> <target name="run"> <property name="loop.start" value="4"/> <property name="loop.end" value="7"/> <script language="javascript"> <![CDATA[ // Print the square value of the number within the range var start = AntLoopExample.getProperty("loop.start"); var end = AntLoopExample.getProperty("loop.end"); for (i = start; i <= end; i++) { echo = AntLoopExample.createTask("echo"); echo.setMessage(i*i); echo.perform(); } // Set a new property which could be retrieved by the ant script AntLoopExample.setProperty("greeting", "Hello World!") ]]> </script> <echo message="From Javascript: ${greeting}"/> </target> </project>
Done =)
Reference:
Reblogged this on Sutoprise Avenue, A SutoCom Source.
LikeLike
any guess if you can do the same with variables?
LikeLike
Hi do you know if it’s possible to do the same with Variables instead of Properties?
LikeLike