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 14 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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">spawn</td>
  48. <td valign="top">whether or not you want the commands to be spawned<br/>
  49. Default is false.<br>
  50. If you spawn a command, its output will not be logged by ant.<br/>
  51. The input, output, error, and result property settings are not active when spawning a process.<br>
  52. <em>since Ant 1.6</em>
  53. </td>
  54. <td align="center" valign="top">No</td>
  55. </tr>
  56. <tr>
  57. <td valign="top">dir</td>
  58. <td valign="top">the directory in which the command should be executed.</td>
  59. <td align="center" valign="top">No</td>
  60. </tr>
  61. <tr>
  62. <td valign="top">relative</td>
  63. <td valign="top">whether the filenames should be passed on the
  64. command line as absolute or relative pathnames (relative to the
  65. base directory of the corresponding fileset/list for source files or
  66. the <i>dest</i> attribute for target files).</td>
  67. <td align="center" valign="top">No, default is <i>false</i></td>
  68. </tr>
  69. <tr>
  70. <td valign="top">forwardslash</td>
  71. <td valign="top">whether the file names should be passed
  72. with forward slashes even if the operating system requires other
  73. file separator. The option is ignored if the system file separator
  74. is a forward slash.</td>
  75. <td align="center" valign="top">No, default is <i>false</i></td>
  76. </tr>
  77. <tr>
  78. <td valign="top">os</td>
  79. <td valign="top">list of Operating Systems on which the command may be
  80. executed.</td>
  81. <td align="center" valign="top">No</td>
  82. </tr>
  83. <tr>
  84. <td valign="top">output</td>
  85. <td valign="top">the file to which the output of the command
  86. should be redirected. If the error stream is not also redirected
  87. to a file or property, it will appear in this output.</td>
  88. <td align="center" valign="top">No</td>
  89. </tr>
  90. <tr>
  91. <td valign="top">error</td>
  92. <td valign="top">The file to which the standard error of the
  93. command should be redirected. <em>since Ant 1.6</em></td>
  94. <td align="center" valign="top">No</td>
  95. </tr>
  96. <tr>
  97. <td valign="top">logError</td>
  98. <td valign="top">This attribute is used when you wish to see error
  99. output in Ant's log and you are redirecting output to a
  100. file/property. The error output will not be included in the output
  101. file/property. If you redirect error with the &quot;error&quot; or
  102. &quot;errorProperty&quot; attributes, this will have no effect.
  103. <em>since Ant 1.6</em></td>
  104. <td align="center" valign="top">No</td>
  105. </tr>
  106. <tr>
  107. <td valign="top">append</td>
  108. <td valign="top">whether output should be appended to or overwrite
  109. an existing file. Defaults to false. If you set parallel to
  110. false, you will probably want to set this one to true.</td>
  111. <td align="center" valign="top">No</td>
  112. </tr>
  113. <tr>
  114. <td valign="top">outputproperty</td>
  115. <td valign="top">the name of a property in which the output of the
  116. command should be stored. Unless the error stream is redirected
  117. to a separate file or stream, this property will include the error
  118. output.</td>
  119. <td align="center" valign="top">No</td>
  120. </tr>
  121. <tr>
  122. <td valign="top">errorproperty</td>
  123. <td valign="top">The name of a property in which the standard error of the
  124. command should be stored. <em>since Ant 1.6</em></td>
  125. <td align="center" valign="top">No</td>
  126. </tr>
  127. <tr>
  128. <td valign="top">input</td>
  129. <td valign="top">A file from which the executed command's standard
  130. input is taken. This attribute is mutually exclusive with the
  131. inputstring attribute. <em>since Ant 1.6</em></td>
  132. <td align="center" valign="top">No</td>
  133. </tr>
  134. <tr>
  135. <td valign="top">inputstring</td>
  136. <td valign="top">A string which serves as the input stream for the
  137. executed command. This attribute is mutually exclusive with the
  138. input attribute. <em>since Ant 1.6</em></td>
  139. <td align="center" valign="top">No</td>
  140. </tr>
  141. <tr>
  142. <td valign="top">resultproperty</td>
  143. <td valign="top">the name of a property in which the return code
  144. of the command should be stored. Only of interest if
  145. failonerror=false. If you set parallel to false, only the result
  146. of the first execution will be stored.</td>
  147. <td align="center" valign="top">No</td>
  148. </tr>
  149. <tr>
  150. <td valign="top">timeout</td>
  151. <td valign="top">Stop the command if it doesn't finish within the
  152. specified time (given in milliseconds).</td>
  153. <td align="center" valign="top">No</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">failonerror</td>
  157. <td valign="top">Stop the buildprocess if the command exits with a
  158. returncode other than 0.</td>
  159. <td align="center" valign="top">No</td>
  160. </tr>
  161. <tr>
  162. <td valign="top">failifexecutionfails</td>
  163. <td valign="top">Stop the build if we can't start the program.
  164. Defaults to true. </td>
  165. <td align="center" valign="top">No</td>
  166. </tr>
  167. <tr>
  168. <td valign="top">skipemptyfilesets</td>
  169. <td valign="top">Don't run the command, if no source files have
  170. been found or are newer than their corresponding target
  171. files. Despite its name, this attribute applies to filelists as
  172. well.</td>
  173. <td align="center" valign="top">No, default is <i>false</i></td>
  174. </tr>
  175. <tr>
  176. <td valign="top">parallel</td>
  177. <td valign="top">Run the command only once, appending all files as
  178. arguments. If false, command will be executed once for every file.
  179. Defaults to false. </td>
  180. <td align="center" valign="top">No</td>
  181. </tr>
  182. <tr>
  183. <td valign="top">type</td>
  184. <td valign="top">One of <i>file</i>, <i>dir</i> or
  185. <i>both</i>. If set to <i>file</i>, only the names of plain
  186. files will be sent to the command. If set to <i>dir</i>, only
  187. the names of directories are considered.<br>
  188. <strong>Note:</strong> The type attribute does not apply to
  189. nested <i>dirset</i>s - <i>dirset</i>s always implicitly
  190. assume type to be <i>dir</i>.</td>
  191. <td align="center" valign="top">No, default is <i>file</i></td>
  192. </tr>
  193. <tr>
  194. <td valign="top">newenvironment</td>
  195. <td valign="top">Do not propagate old environment when new environment
  196. variables are specified.</td>
  197. <td align="center" valign="top">No, default is <i>false</i></td>
  198. </tr>
  199. <tr>
  200. <td valign="top">vmlauncher</td>
  201. <td valign="top">Run command using the Java VM's execution facilities
  202. where available. If set to false the underlying OS's shell,
  203. either directly or through the antRun scripts, will be used.
  204. Under some operating systems, this gives access to facilities
  205. not normally available through the VM including, under Windows,
  206. being able to execute scripts, rather than their associated
  207. interpreter. If you want to specify the name of the
  208. executable as a relative path to the directory given by the
  209. dir attribute, it may become necessary to set vmlauncher to
  210. false as well.</td>
  211. <td align="center" valign="top">No, default is <i>true</i></td>
  212. </tr>
  213. <tr>
  214. <td valign="top">resolveExecutable</td>
  215. <td valign="top">When this attribute is true, the name of the
  216. executable if resolved firstly against the project basedir and if
  217. that does not exist, against the execution directory if
  218. specified. On Unix systems, if you only want to allow execution of
  219. commands in the user's path, set this to false. <em>since Ant
  220. 1.6</em></td>
  221. <td align="center" valign="top">No, default is <i>false</i></td>
  222. </tr>
  223. <tr>
  224. <td valign="top">maxparallel</td>
  225. <td valign="top">Limit the amount of parallelism by passing at
  226. most this many sourcefiles at once. Set it to &lt;= 0 for
  227. unlimited. Defaults to unlimited. <em>Since Ant 1.6.</em></td>
  228. <td align="center" valign="top">No</td>
  229. </tr>
  230. <tr>
  231. <td valign="top">addsourcefile</td>
  232. <td valign="top">Whether source file names should be added to the
  233. command automatically. Defaults to <code>true</code>.
  234. <em>Since Ant 1.6.</em></td>
  235. <td align="center" valign="top">No</td>
  236. </tr>
  237. <tr>
  238. <td valign="top">verbose</td>
  239. <td valign="top">Whether to print a summary after execution or not.
  240. Defaults to <code>false</code>. <em>Since Ant 1.6.</em></td>
  241. <td align="center" valign="top">No</td>
  242. </tr>
  243. </table>
  244. <h3>Parameters specified as nested elements</h3>
  245. <h4>fileset</h4>
  246. <p>You can use any number of nested <code>&lt;fileset&gt;</code>
  247. elements to define the files for this task and refer to
  248. <code>&lt;fileset&gt;</code>s defined elsewhere.</p>
  249. <h4>filelist</h4>
  250. <p><em>Since Ant 1.6</em></p>
  251. <p>You can use any number of nested <code>&lt;filelist&gt;</code>
  252. elements to define the files for this task and refer to
  253. <code>&lt;filelist&gt;</code>s defined elsewhere.</p>
  254. <h4>dirset</h4>
  255. <p><em>Since Ant 1.6</em></p>
  256. <p>You can use any number of nested <code>&lt;dirset&gt;</code>
  257. elements to define the directories for this task and refer to
  258. <code>&lt;dirset&gt;</code>s defined elsewhere.</p>
  259. <h4>arg</h4>
  260. <p>Command line arguments should be specified as nested
  261. <code>&lt;arg&gt;</code> elements. See <a
  262. href="../using.html#arg">Command line arguments</a>.</p>
  263. <h4>srcfile</h4>
  264. <p>By default the file names of the source files will be added to the
  265. end of the command line (unless you set addsourcefile to
  266. <code>false</code>). If you need to place it somewhere different,
  267. use a nested <code>&lt;srcfile&gt;</code> element between your
  268. <code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
  269. <h4>targetfile</h4>
  270. <p><code>&lt;targetfile&gt;</code> is similar to
  271. <code>&lt;srcfile&gt;</code> and marks the position of the target
  272. filename on the command line. If omitted, the target filenames will
  273. not be added to the command line at all. This element can only be
  274. specified, if you also define a nested mapper and the <i>dest</i>
  275. attribute.</p>
  276. <h4>env</h4>
  277. <p>It is possible to specify environment variables to pass to the
  278. system command via nested <code>&lt;env&gt;</code> elements. See the
  279. description in the section about <a href="exec.html#env">exec</a></p>
  280. <h3>Examples</h3>
  281. <blockquote><pre>
  282. &lt;apply executable=&quot;ls&quot;&gt;
  283. &lt;arg value=&quot;-l&quot;/&gt;
  284. &lt;fileset dir=&quot;/tmp&quot;&gt;
  285. &lt;patternset&gt;
  286. &lt;exclude name=&quot;**/*.txt&quot;/&gt;
  287. &lt;/patternset&gt;
  288. &lt;/fileset&gt;
  289. &lt;fileset refid=&quot;other.files&quot;/&gt;
  290. &lt;/apply&gt;
  291. </pre></blockquote>
  292. <p>invokes <code>ls -l</code>, adding the absolute filenames of all
  293. files below <code>/tmp</code> not ending in <code>.txt</code> and all
  294. files of the FileSet with <code>id</code> <code>other.files</code> to
  295. the command line.</p>
  296. <blockquote><pre>
  297. &lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  298. &lt;arg value=&quot;arg1&quot;/&gt;
  299. &lt;srcfile/&gt;
  300. &lt;arg value=&quot;arg2&quot;/&gt;
  301. &lt;fileset dir=&quot;/tmp&quot;/&gt;
  302. &lt;/apply&gt;
  303. </pre></blockquote>
  304. <p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
  305. file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
  306. filename of each file in turn. If <code>parallel</code> had been set
  307. to true, SOURCEFILENAME would be replaced with the absolute filenames
  308. of all files separated by spaces.</p>
  309. <blockquote><pre>
  310. &lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  311. &lt;arg value=&quot;-c&quot;/&gt;
  312. &lt;arg value=&quot;-o&quot;/&gt;
  313. &lt;targetfile/&gt;
  314. &lt;srcfile/&gt;
  315. &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  316. &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
  317. &lt;/apply&gt;
  318. </pre></blockquote>
  319. <p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
  320. <code>.c</code> file that is newer than the corresponding
  321. <code>.o</code>, replacing TARGETFILE with the absolute filename of
  322. the <code>.o</code> and SOURCEFILE with the absolute name of the
  323. <code>.c</code> file.</p>
  324. <hr><p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
  325. Reserved.</p>
  326. </body>
  327. </html>