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.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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://www-124.ibm.com/developerworks/projects/bsf" target="_top">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><b>BeanShell users:</b> This task now natively supports the BeanShell
  20. scripting language, using language="beanshell". The BeanShell engine is
  21. still required.
  22. </p>
  23. <p>Scripts can do almost anything a task written in Java could do.</p>
  24. <h3>Parameters</h3>
  25. <table border="1" cellpadding="2" cellspacing="0">
  26. <tr>
  27. <td valign="top"><b>Attribute</b></td>
  28. <td valign="top"><b>Description</b></td>
  29. <td align="center" valign="top"><b>Required</b></td>
  30. </tr>
  31. <tr>
  32. <td valign="top">language</td>
  33. <td valign="top">The programming language the script is written in.
  34. Must be a supported BSF language</td>
  35. <td valign="top" align="center">Yes</td>
  36. </tr>
  37. <tr>
  38. <td valign="top">src</td>
  39. <td valign="top">The location of the script as a file, if not inline</td>
  40. <td valign="top" align="center">No</td>
  41. </tr>
  42. </table>
  43. <h3>Examples</h3>
  44. <blockquote><pre>
  45. &lt;project name=&quot;squares&quot; default=&quot;main&quot; basedir=&quot;.&quot;&gt;
  46. &lt;target name=&quot;setup&quot;&gt;
  47. &lt;script language=&quot;javascript&quot;&gt; &lt;![CDATA[
  48. for (i=1; i&lt;=10; i++) {
  49. echo = squares.createTask(&quot;echo&quot;);
  50. main.addTask(echo);
  51. echo.setMessage(i*i);
  52. }
  53. ]]&gt; &lt;/script&gt;
  54. &lt;/target&gt;
  55. &lt;target name=&quot;main&quot; depends=&quot;setup&quot;/&gt;
  56. &lt;/project&gt;
  57. </pre></blockquote>
  58. <p>generates</p>
  59. <blockquote><pre>
  60. setup:
  61. main:
  62. 1
  63. 4
  64. 9
  65. 16
  66. 25
  67. 36
  68. 49
  69. 64
  70. 81
  71. 100
  72. BUILD SUCCESSFUL
  73. </pre></blockquote>
  74. <p>Another example, using <a href="../using.html#references">references by id</a>
  75. and two different scripting languages:</p>
  76. <blockquote><pre>
  77. &lt;project name=&quot;testscript&quot; default=&quot;main&quot;&gt;
  78. &lt;target name=&quot;sub&quot;&gt;
  79. &lt;echo id=&quot;theEcho&quot;/&gt;
  80. &lt;/target&gt;
  81. &lt;target name=&quot;sub1&quot;&gt;
  82. &lt;script language=&quot;netrexx&quot;&gt;&lt;![CDATA[
  83. theEcho.setMessage(&quot;In sub1&quot;)
  84. sub.execute
  85. ]]&gt;&lt;/script&gt;
  86. &lt;/target&gt;
  87. &lt;target name=&quot;sub2&quot;&gt;
  88. &lt;script language=&quot;javascript&quot;&gt;&lt;![CDATA[
  89. theEcho.setMessage(&quot;In sub2&quot;);
  90. sub.execute();
  91. ]]&gt;&lt;/script&gt;
  92. &lt;/target&gt;
  93. &lt;target name=&quot;main&quot; depends=&quot;sub1,sub2&quot;/&gt;
  94. &lt;/project&gt;
  95. </pre></blockquote>
  96. <p>generates</p>
  97. <blockquote><pre>
  98. sub1:
  99. In sub1
  100. sub2:
  101. In sub2
  102. main:
  103. BUILD SUCCESSFUL
  104. </pre></blockquote>
  105. <hr>
  106. <p align="center">Copyright &copy; 2000-2002 Apache Software Foundation. All rights
  107. Reserved.</p>
  108. </body>
  109. </html>