From 07f24b0382b895e07944e43bdcec6f41f6f54876 Mon Sep 17 00:00:00 2001 From: Peter Reilly Date: Wed, 15 Sep 2004 13:17:12 +0000 Subject: [PATCH] script doc: Add groovy, beanshell and jython examples Modify echo example so that it does not modify ant's task structure (This is not a usecase we want for script). git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@276863 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/OptionalTasks/script.html | 37 +++++++++++++++++++++------ 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/docs/manual/OptionalTasks/script.html b/docs/manual/OptionalTasks/script.html index 84060be34..257d0d268 100644 --- a/docs/manual/OptionalTasks/script.html +++ b/docs/manual/OptionalTasks/script.html @@ -26,7 +26,7 @@ used instead of the project name. The name "self" is a pre-defined reference to

If you are using JavaScript a good resource is http://www.mozilla.org/rhino/doc.html as we are using their JavaScript interpreter.

Scripts can do almost anything a task written in Java could do.

-

Rhino provides a special construct - the JavaAdapter. Whith that you can +

Rhino provides a special construct - the JavaAdapter. With that you can create an object which implements several interfaces, extends classes and for which you can overwrite methods. Because this is an undocumented feature (yet), here is the link to an explanation: @@ -55,31 +55,52 @@ Groups@Google: "Rhino, enum.js, JavaAdapter?" by Norris Boyd in the newsgrou

Examples

+The following snipnet shows use of three different languages: +
+    <property name="message" value="Hello world"/>
+
+    <script language="groovy">
+      println("message is " + message)
+    </script>
+
+    <script language="beanshell">
+      System.out.println("message is " + message);
+    </script>
+
+    <script language="jython">
+print "message is %s" % message
+    </script>
+
+
+

+ Note that for the jython example, the script contents must + start on the first column. +

+

+ The following script uses javascript to create a number of + echo tasks and execute them. +

 <project name="squares" default="main" basedir=".">
 
-  <target name="setup">
+  <target name="main">
 
     <script language="javascript"> <![CDATA[
 
       for (i=1; i<=10; i++) {
         echo = squares.createTask("echo");
-        main.addTask(echo);
         echo.setMessage(i*i);
+        echo.perform();
       }
 
     ]]> </script>
 
   </target>
 
-  <target name="main" depends="setup"/>
-
 </project>
 

generates

-setup:
-
 main:
 1
 4
@@ -211,4 +232,4 @@ apropriate logging before and after invoking execute().
 Reserved.

- \ No newline at end of file +