You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

script.html 3.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Script Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="script">Script</a></h2>
  8. <h3>Description</h3>
  9. <p>Execute a script in a
  10. <a href="http://jakarta.apache.org/bsf" target="_top">Apache BSF</a> supported language.</p>
  11. <p><b>Note:</b> This task depends on external libraries not included in the Ant distribution.
  12. See <a href="../install.html#librarydependencies">Library Dependencies</a> for more information.</p>
  13. <p>All items (tasks, targets, etc) of the running project are
  14. accessible from the script, using either their <code>name</code> or
  15. <code>id</code> attributes (as long as their names are considered
  16. valid Java identifiers, that is).
  17. The name "project" is a pre-defined reference to the Project, which can be
  18. used instead of the project name.</p>
  19. <p>Scripts can do almost anything a task written in Java could do.</p>
  20. <h3>Parameters</h3>
  21. <table border="1" cellpadding="2" cellspacing="0">
  22. <tr>
  23. <td valign="top"><b>Attribute</b></td>
  24. <td valign="top"><b>Description</b></td>
  25. <td align="center" valign="top"><b>Required</b></td>
  26. </tr>
  27. <tr>
  28. <td valign="top">language</td>
  29. <td valign="top">The programming language the script is written in.
  30. Must be a supported Apache BSF language</td>
  31. <td valign="top" align="center">Yes</td>
  32. </tr>
  33. <tr>
  34. <td valign="top">src</td>
  35. <td valign="top">The location of the script as a file, if not inline</td>
  36. <td valign="top" align="center">No</td>
  37. </tr>
  38. </table>
  39. <h3>Examples</h3>
  40. <blockquote><pre>
  41. &lt;project name=&quot;squares&quot; default=&quot;main&quot; basedir=&quot;.&quot;&gt;
  42. &lt;target name=&quot;setup&quot;&gt;
  43. &lt;script language=&quot;javascript&quot;&gt; &lt;![CDATA[
  44. for (i=1; i&lt;=10; i++) {
  45. echo = squares.createTask(&quot;echo&quot;);
  46. main.addTask(echo);
  47. echo.setMessage(i*i);
  48. }
  49. ]]&gt; &lt;/script&gt;
  50. &lt;/target&gt;
  51. &lt;target name=&quot;main&quot; depends=&quot;setup&quot;/&gt;
  52. &lt;/project&gt;
  53. </pre></blockquote>
  54. <p>generates</p>
  55. <blockquote><pre>
  56. setup:
  57. main:
  58. 1
  59. 4
  60. 9
  61. 16
  62. 25
  63. 36
  64. 49
  65. 64
  66. 81
  67. 100
  68. BUILD SUCCESSFUL
  69. </pre></blockquote>
  70. <p>Another example, using <a href="../using.html#references">references by id</a>
  71. and two different scripting languages:</p>
  72. <blockquote><pre>
  73. &lt;project name=&quot;testscript&quot; default=&quot;main&quot;&gt;
  74. &lt;target name=&quot;sub&quot;&gt;
  75. &lt;echo id=&quot;theEcho&quot;/&gt;
  76. &lt;/target&gt;
  77. &lt;target name=&quot;sub1&quot;&gt;
  78. &lt;script language=&quot;netrexx&quot;&gt;&lt;![CDATA[
  79. theEcho.setMessage(&quot;In sub1&quot;)
  80. sub.execute
  81. ]]&gt;&lt;/script&gt;
  82. &lt;/target&gt;
  83. &lt;target name=&quot;sub2&quot;&gt;
  84. &lt;script language=&quot;javascript&quot;&gt;&lt;![CDATA[
  85. theEcho.setMessage(&quot;In sub2&quot;);
  86. sub.execute();
  87. ]]&gt;&lt;/script&gt;
  88. &lt;/target&gt;
  89. &lt;target name=&quot;main&quot; depends=&quot;sub1,sub2&quot;/&gt;
  90. &lt;/project&gt;
  91. </pre></blockquote>
  92. <p>generates</p>
  93. <blockquote><pre>
  94. sub1:
  95. In sub1
  96. sub2:
  97. In sub2
  98. main:
  99. BUILD SUCCESSFUL
  100. </pre></blockquote>
  101. <hr>
  102. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  103. Reserved.</p>
  104. </body>
  105. </html>