2001-02-13 12:32:01 +00:00
|
|
|
<html>
|
|
|
|
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Language" content="en-us">
|
2002-02-03 22:11:39 +00:00
|
|
|
<title>Script Task</title>
|
2001-02-13 12:32:01 +00:00
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
|
|
|
|
<h2><a name="script">Script</a></h2>
|
|
|
|
<h3>Description</h3>
|
|
|
|
<p>Execute a script in a
|
2002-11-14 07:48:25 +00:00
|
|
|
<a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a> supported language.</p>
|
2001-08-30 13:23:14 +00:00
|
|
|
<p><b>Note:</b> This task depends on external libraries not included in the Ant distribution.
|
|
|
|
See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<p>All items (tasks, targets, etc) of the running project are
|
|
|
|
accessible from the script, using either their <code>name</code> or
|
2002-06-01 12:26:43 +00:00
|
|
|
<code>id</code> attributes (as long as their names are considered
|
|
|
|
valid Java identifiers, that is).
|
|
|
|
The name "project" is a pre-defined reference to the Project, which can be
|
|
|
|
used instead of the project name.</p>
|
2001-02-13 12:32:01 +00:00
|
|
|
<p>Scripts can do almost anything a task written in Java could do.</p>
|
|
|
|
<h3>Parameters</h3>
|
|
|
|
<table border="1" cellpadding="2" cellspacing="0">
|
|
|
|
<tr>
|
|
|
|
<td valign="top"><b>Attribute</b></td>
|
|
|
|
<td valign="top"><b>Description</b></td>
|
|
|
|
<td align="center" valign="top"><b>Required</b></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">language</td>
|
|
|
|
<td valign="top">The programming language the script is written in.
|
2002-11-14 07:48:25 +00:00
|
|
|
Must be a supported Apache BSF language</td>
|
2002-07-09 21:06:15 +00:00
|
|
|
<td valign="top" align="center">Yes</td>
|
2001-02-13 12:32:01 +00:00
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td valign="top">src</td>
|
|
|
|
<td valign="top">The location of the script as a file, if not inline</td>
|
|
|
|
<td valign="top" align="center">No</td>
|
|
|
|
</tr>
|
|
|
|
</table>
|
|
|
|
<h3>Examples</h3>
|
|
|
|
<blockquote><pre>
|
|
|
|
<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>
|
|
|
|
</pre></blockquote>
|
|
|
|
<p>generates</p>
|
|
|
|
<blockquote><pre>
|
|
|
|
setup:
|
|
|
|
|
|
|
|
main:
|
|
|
|
1
|
|
|
|
4
|
|
|
|
9
|
|
|
|
16
|
|
|
|
25
|
|
|
|
36
|
|
|
|
49
|
|
|
|
64
|
|
|
|
81
|
|
|
|
100
|
|
|
|
|
|
|
|
BUILD SUCCESSFUL
|
|
|
|
</pre></blockquote>
|
|
|
|
<p>Another example, using <a href="../using.html#references">references by id</a>
|
|
|
|
and two different scripting languages:</p>
|
|
|
|
<blockquote><pre>
|
|
|
|
<project name="testscript" default="main">
|
|
|
|
<target name="sub">
|
|
|
|
<echo id="theEcho"/>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<target name="sub1">
|
|
|
|
<script language="netrexx"><![CDATA[
|
|
|
|
theEcho.setMessage("In sub1")
|
|
|
|
sub.execute
|
|
|
|
]]></script>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<target name="sub2">
|
|
|
|
<script language="javascript"><![CDATA[
|
|
|
|
theEcho.setMessage("In sub2");
|
|
|
|
sub.execute();
|
|
|
|
]]></script>
|
|
|
|
</target>
|
|
|
|
|
|
|
|
<target name="main" depends="sub1,sub2"/>
|
|
|
|
</project>
|
|
|
|
</pre></blockquote>
|
|
|
|
<p>generates</p>
|
|
|
|
<blockquote><pre>
|
|
|
|
sub1:
|
|
|
|
In sub1
|
|
|
|
|
|
|
|
sub2:
|
|
|
|
In sub2
|
|
|
|
|
|
|
|
main:
|
|
|
|
|
|
|
|
BUILD SUCCESSFUL
|
|
|
|
</pre></blockquote>
|
|
|
|
|
|
|
|
<hr>
|
2002-06-01 12:26:43 +00:00
|
|
|
<p align="center">Copyright © 2000-2002 Apache Software Foundation. All rights
|
2001-02-13 12:32:01 +00:00
|
|
|
Reserved.</p>
|
|
|
|
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
|