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

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