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.

apply.html 11 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <title>Apply Task</title>
  5. </head>
  6. <body>
  7. <h2><a name="apply">Apply/<i>ExecOn</i></a></h2>
  8. <p><i>The name <code>execon</code> is deprecated and only kept for backwards
  9. compatibility.</i></p>
  10. <h3>Description</h3>
  11. <p>Executes a system command. When the <i>os</i> attribute is specified, then
  12. the command is only executed when Ant is run on one of the specified operating
  13. systems.</p>
  14. <p>The files and/or directories of a number of <a
  15. href="../CoreTypes/fileset.html">FileSet</a>s, <a
  16. href="../CoreTypes/dirset.html">DirSet</a>s (<em>since Ant 1.6</em>)
  17. or <a href="../CoreTypes/filelist.html">FileList</a>s (<em>since Ant
  18. 1.6</em>) are passed as arguments to the system command.</p>
  19. <p>If you specify a nested <a
  20. href="../CoreTypes/mapper.html">mapper</a> and the <i>dest</i> attribute,
  21. the timestamp of each source file is compared to the timestamp of a
  22. target file which is defined by the nested mapper element and searched
  23. for in the given dest.</p>
  24. <p>At least one fileset or filelist is required, and you must not specify more than
  25. one mapper.</p>
  26. <h3>Parameters</h3>
  27. <table border="1" cellpadding="2" cellspacing="0">
  28. <tr>
  29. <td valign="top"><b>Attribute</b></td>
  30. <td valign="top"><b>Description</b></td>
  31. <td align="center" valign="top"><b>Required</b></td>
  32. </tr>
  33. <tr>
  34. <td valign="top">executable</td>
  35. <td valign="top">the command to execute without any command line
  36. arguments.</td>
  37. <td align="center" valign="top">Yes</td>
  38. </tr>
  39. <tr>
  40. <td valign="top">dest</td>
  41. <td valign="top">the directory where the &lt;apply&gt; expects the target files will be placed by the
  42. command, when it is executed.
  43. </td>
  44. <td align="center" valign="top">Yes, if you specify a nested mapper</td>
  45. </tr>
  46. <tr>
  47. <td valign="top">dir</td>
  48. <td valign="top">the directory in which the command should be executed.</td>
  49. <td align="center" valign="top">No</td>
  50. </tr>
  51. <tr>
  52. <td valign="top">relative</td>
  53. <td valign="top">whether the filenames should be passed on the
  54. command line as absolute or relative pathnames (relative to the
  55. base directory of the corresponding fileset/list for source files or
  56. the <i>dest</i> attribute for target files).</td>
  57. <td align="center" valign="top">No, default is <i>false</i></td>
  58. </tr>
  59. <tr>
  60. <td valign="top">forwardslash</td>
  61. <td valign="top">whether the file names should be passed
  62. with forward slashes even if the operating system requires other
  63. file separator. The option is ignored if the system file separator
  64. is a forward slash.</td>
  65. <td align="center" valign="top">No, default is <i>false</i></td>
  66. </tr>
  67. <tr>
  68. <td valign="top">os</td>
  69. <td valign="top">list of Operating Systems on which the command may be
  70. executed.</td>
  71. <td align="center" valign="top">No</td>
  72. </tr>
  73. <tr>
  74. <td valign="top">output</td>
  75. <td valign="top">the file to which the output of the command should be
  76. redirected.</td>
  77. <td align="center" valign="top">No</td>
  78. </tr>
  79. <tr>
  80. <td valign="top">append</td>
  81. <td valign="top">whether output should be appended to or overwrite
  82. an existing file. Defaults to false. If you set parallel to
  83. false, you will probably want to set this one to true.</td>
  84. <td align="center" valign="top">No</td>
  85. </tr>
  86. <tr>
  87. <td valign="top">outputproperty</td>
  88. <td valign="top">the name of a property in which the output of the
  89. command should be stored.</td>
  90. <td align="center" valign="top">No</td>
  91. </tr>
  92. <tr>
  93. <td valign="top">resultproperty</td>
  94. <td valign="top">the name of a property in which the return code
  95. of the command should be stored. Only of interest if
  96. failonerror=false. If you set parallel to false, only the result
  97. of the first execution will be stored.</td>
  98. <td align="center" valign="top">No</td>
  99. </tr>
  100. <tr>
  101. <td valign="top">timeout</td>
  102. <td valign="top">Stop the command if it doesn't finish within the
  103. specified time (given in milliseconds).</td>
  104. <td align="center" valign="top">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">failonerror</td>
  108. <td valign="top">Stop the buildprocess if the command exits with a
  109. returncode other than 0.</td>
  110. <td align="center" valign="top">No</td>
  111. </tr>
  112. <tr>
  113. <td valign="top">failifexecutionfails</td>
  114. <td valign="top">Stop the build if we can't start the program.
  115. Defaults to true. </td>
  116. <td align="center" valign="top">No</td>
  117. </tr>
  118. <tr>
  119. <td valign="top">skipemptyfilesets</td>
  120. <td valign="top">Don't run the command, if no source files have
  121. been found or are newer than their corresponding target
  122. files. Despite its name, this attribute applies to filelists as
  123. well.</td>
  124. <td align="center" valign="top">No, default is <i>false</i></td>
  125. </tr>
  126. <tr>
  127. <td valign="top">parallel</td>
  128. <td valign="top">Run the command only once, appending all files as
  129. arguments. If false, command will be executed once for every file.
  130. Defaults to false. </td>
  131. <td align="center" valign="top">No</td>
  132. </tr>
  133. <tr>
  134. <td valign="top">type</td>
  135. <td valign="top">One of <i>file</i>, <i>dir</i> or
  136. <i>both</i>. If set to <i>file</i>, only the names of plain
  137. files will be sent to the command. If set to <i>dir</i>, only
  138. the names of directories are considered.<br>
  139. <strong>Note:</strong> The type attribute does not apply to
  140. nested <i>dirset</i>s - <i>dirset</i>s always implicitly
  141. assume type to be <i>dir</i>.</td>
  142. <td align="center" valign="top">No, default is <i>file</i></td>
  143. </tr>
  144. <tr>
  145. <td valign="top">newenvironment</td>
  146. <td valign="top">Do not propagate old environment when new environment
  147. variables are specified.</td>
  148. <td align="center" valign="top">No, default is <i>false</i></td>
  149. </tr>
  150. <tr>
  151. <td valign="top">vmlauncher</td>
  152. <td valign="top">Run command using the Java VM's execution facilities
  153. where available. If set to false the underlying OS's shell,
  154. either directly or through the antRun scripts, will be used.
  155. Under some operating systems, this gives access to facilities
  156. not normally available through the VM including, under Windows,
  157. being able to execute scripts, rather than their associated
  158. interpreter. If you want to specify the name of the
  159. executable as a relative path to the directory given by the
  160. dir attribute, it may become necessary to set vmlauncher to
  161. false as well.</td>
  162. <td align="center" valign="top">No, default is <i>true</i></td>
  163. </tr>
  164. <tr>
  165. <td valign="top">maxparallel</td>
  166. <td valign="top">Limit the amount of parallelism by passing at
  167. most this many sourcefiles at once. Set it to &lt;= 0 for
  168. unlimited. Defaults to unlimited. <em>Since Ant 1.6.</em></td>
  169. <td align="center" valign="top">No</td>
  170. </tr>
  171. <tr>
  172. <td valign="top">addsourcefile</td>
  173. <td valign="top">Whether source file names should be added to the
  174. command automatically. Defaults to <code>true</code>.
  175. <em>Since Ant 1.6.</em></td>
  176. <td align="center" valign="top">No</td>
  177. </tr>
  178. <tr>
  179. <td valign="top">verbose</td>
  180. <td valign="top">Whether to print a summary after execution or not.
  181. Defaults to <code>false</code>. <em>Since Ant 1.6.</em></td>
  182. <td align="center" valign="top">No</td>
  183. </tr>
  184. </table>
  185. <h3>Parameters specified as nested elements</h3>
  186. <h4>fileset</h4>
  187. <p>You can use any number of nested <code>&lt;fileset&gt;</code>
  188. elements to define the files for this task and refer to
  189. <code>&lt;fileset&gt;</code>s defined elsewhere.</p>
  190. <h4>filelist</h4>
  191. <p><em>Since Ant 1.6</em></p>
  192. <p>You can use any number of nested <code>&lt;filelist&gt;</code>
  193. elements to define the files for this task and refer to
  194. <code>&lt;filelist&gt;</code>s defined elsewhere.</p>
  195. <h4>dirset</h4>
  196. <p><em>Since Ant 1.6</em></p>
  197. <p>You can use any number of nested <code>&lt;dirset&gt;</code>
  198. elements to define the directories for this task and refer to
  199. <code>&lt;dirset&gt;</code>s defined elsewhere.</p>
  200. <h4>arg</h4>
  201. <p>Command line arguments should be specified as nested
  202. <code>&lt;arg&gt;</code> elements. See <a
  203. href="../using.html#arg">Command line arguments</a>.</p>
  204. <h4>srcfile</h4>
  205. <p>By default the file names of the source files will be added to the
  206. end of the command line (unless you set addsourcefile to
  207. <code>false</code>). If you need to place it somewhere different,
  208. use a nested <code>&lt;srcfile&gt;</code> element between your
  209. <code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
  210. <h4>targetfile</h4>
  211. <p><code>&lt;targetfile&gt;</code> is similar to
  212. <code>&lt;srcfile&gt;</code> and marks the position of the target
  213. filename on the command line. If omitted, the target filenames will
  214. not be added to the command line at all. This element can only be
  215. specified, if you also define a nested mapper and the <i>dest</i>
  216. attribute.</p>
  217. <h4>env</h4>
  218. <p>It is possible to specify environment variables to pass to the
  219. system command via nested <code>&lt;env&gt;</code> elements. See the
  220. description in the section about <a href="exec.html#env">exec</a></p>
  221. <h3>Examples</h3>
  222. <blockquote><pre>
  223. &lt;apply executable=&quot;ls&quot;&gt;
  224. &lt;arg value=&quot;-l&quot;/&gt;
  225. &lt;fileset dir=&quot;/tmp&quot;&gt;
  226. &lt;patternset&gt;
  227. &lt;exclude name=&quot;**/*.txt&quot;/&gt;
  228. &lt;/patternset&gt;
  229. &lt;/fileset&gt;
  230. &lt;fileset refid=&quot;other.files&quot;/&gt;
  231. &lt;/apply&gt;
  232. </pre></blockquote>
  233. <p>invokes <code>ls -l</code>, adding the absolute filenames of all
  234. files below <code>/tmp</code> not ending in <code>.txt</code> and all
  235. files of the FileSet with <code>id</code> <code>other.files</code> to
  236. the command line.</p>
  237. <blockquote><pre>
  238. &lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  239. &lt;arg value=&quot;arg1&quot;/&gt;
  240. &lt;srcfile/&gt;
  241. &lt;arg value=&quot;arg2&quot;/&gt;
  242. &lt;fileset dir=&quot;/tmp&quot;/&gt;
  243. &lt;/apply&gt;
  244. </pre></blockquote>
  245. <p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
  246. file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
  247. filename of each file in turn. If <code>parallel</code> had been set
  248. to true, SOURCEFILENAME would be replaced with the absolute filenames
  249. of all files separated by spaces.</p>
  250. <blockquote><pre>
  251. &lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  252. &lt;arg value=&quot;-c&quot;/&gt;
  253. &lt;arg value=&quot;-o&quot;/&gt;
  254. &lt;targetfile/&gt;
  255. &lt;srcfile/&gt;
  256. &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  257. &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
  258. &lt;/apply&gt;
  259. </pre></blockquote>
  260. <p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
  261. <code>.c</code> file that is newer than the corresponding
  262. <code>.o</code>, replacing TARGETFILE with the absolute filename of
  263. the <code>.o</code> and SOURCEFILE with the absolute name of the
  264. <code>.c</code> file.</p>
  265. <hr><p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  266. Reserved.</p>
  267. </body>
  268. </html>