@@ -1,7 +1,7 @@
<html>
<html>
<head>
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Language" content="en-us"></meta>
<title>Script Task</title>
<title>Script Task</title>
</head>
</head>
@@ -19,7 +19,7 @@ accessible from the script, using either their <code>name</code> or
valid Java identifiers, that is).
valid Java identifiers, that is).
The name "project" is a pre-defined reference to the Project, which can be
The name "project" is a pre-defined reference to the Project, which can be
used instead of the project name. The name "self" is a pre-defined reference to the actual
used instead of the project name. The name "self" is a pre-defined reference to the actual
<script>-Task instance.<br>From these objects you have access to the Ant Java API, see the
<script>-Task instance.<br/ >From these objects you have access to the Ant Java API, see the
<a href="../api/index.html">JavaDoc</a> (especially for
<a href="../api/index.html">JavaDoc</a> (especially for
<a href="../api/org/apache/tools/ant/Project.html">Project</a> and
<a href="../api/org/apache/tools/ant/Project.html">Project</a> and
<a href="../api/org/apache/tools/ant/taskdefs/optional/Script.html">Script</a>) for more information.</p>
<a href="../api/org/apache/tools/ant/taskdefs/optional/Script.html">Script</a>) for more information.</p>
@@ -55,7 +55,7 @@ Groups@Google: "Rhino, enum.js, JavaAdapter?"</a> by Norris Boyd in the newsgrou
</tr>
</tr>
</table>
</table>
<h3>Examples</h3>
<h3>Examples</h3>
The following snippet shows use of four different languages:
The following snippet shows use of five different languages:
<blockquote><pre>
<blockquote><pre>
<property name="message" value="Hello world"/>
<property name="message" value="Hello world"/>
@@ -71,6 +71,10 @@ The following snippet shows use of four different languages:
println 'message is ', message
println 'message is ', message
</script>
</script>
<script language="ruby">
print 'message is ', $message, "\n"
</script>
<script language="jython">
<script language="jython">
print "message is %s" % message
print "message is %s" % message
</script>
</script>
@@ -80,6 +84,31 @@ print "message is %s" % message
Note that for the <i>jython</i> example, the script contents <b>must</b>
Note that for the <i>jython</i> example, the script contents <b>must</b>
start on the first column.
start on the first column.
</p>
</p>
<p>
The following script shows a little more complicted jruby example:
</p>
<blockquote><pre>
<script language="ruby">
xmlfiles = Dir.new(".").entries.delete_if { |i| ! (i =~ /\.xml$/) }
xmlfiles.sort.each { |i| $self.log(i) }
</script>
</pre>
</blockquote>
<p>
Note that due to a limitation in the current version of jruby (0.7.0),
$project.log("Hello World") does not work (most likely because there are
two log methods on Project), this is fixed in the current CVS version of jruby.
</p>
<p>
The same example in groovy is:
</p>
<blockquote><pre>
<script language="groovy">
xmlfiles = new java.io.File(".").listFiles().findAll{ it =~ "\.xml$"}
xmlfiles.sort().each { self.log(it.toString())}
</script>
</pre>
</blockquote>
<p>
<p>
The following script uses javascript to create a number of
The following script uses javascript to create a number of
echo tasks and execute them.
echo tasks and execute them.