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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Language" content="en-us">
  4. <link rel="stylesheet" type="text/css" href="../stylesheets/style.css">
  5. <title>Apply Task</title>
  6. <link rel="stylesheet" type="text/css" href="../stylesheets/antmanual.css">
  7. </head>
  8. <body>
  9. <h2><a name="apply">Apply/<i>ExecOn</i></a></h2>
  10. <p><i>The name <code>execon</code> is deprecated and only kept for backwards
  11. compatibility.</i></p>
  12. <h3>Description</h3>
  13. <p>Executes a system command. When the <i>os</i> attribute is specified, then
  14. the command is only executed when Ant is run on one of the specified operating
  15. systems.</p>
  16. <p>The files and/or directories of a number of <a
  17. href="../CoreTypes/resources.html#collection">Resource Collection</a>s
  18. &ndash; including but not restricted to
  19. <a href="../CoreTypes/fileset.html">FileSet</a>s,
  20. <a href="../CoreTypes/dirset.html">DirSet</a>s
  21. (<em>since&nbsp;Ant&nbsp;1.6</em>) or
  22. <a href="../CoreTypes/filelist.html">FileList</a>s
  23. (<em>since&nbsp;Ant&nbsp;1.6</em>)
  24. &ndash;
  25. are passed as arguments to the system command.</p>
  26. <p>If you specify a nested <a href="../CoreTypes/mapper.html">mapper</a>,
  27. the timestamp of each source file is compared to the timestamp of a
  28. target file which is defined by the nested mapper element and searched
  29. for in the given <i>dest</i>, if specified.</p>
  30. <p>At least one fileset or filelist is required,
  31. and you must not specify more than one mapper.</p>
  32. <p>Note that you cannot interact with the forked program, the only way
  33. to send input to it is via the input and inputstring attributes.</p>
  34. <h3>Parameters</h3>
  35. <table border="1" cellpadding="2" cellspacing="0">
  36. <tr>
  37. <td valign="top"><b>Attribute</b></td>
  38. <td valign="top"><b>Description</b></td>
  39. <td align="center" valign="top"><b>Required</b></td>
  40. </tr>
  41. <tr>
  42. <td valign="top">executable</td>
  43. <td valign="top">the command to execute without any command line
  44. arguments.</td>
  45. <td align="center" valign="top">Yes</td>
  46. </tr>
  47. <tr>
  48. <td valign="top">dest</td>
  49. <td valign="top">the directory where the command is expected to place
  50. target files when it is executed. This attribute is valid only when used
  51. in conjunction with a nested mapper; if omitted, the target filenames
  52. returned by the mapper will be interpreted as absolute paths.</td>
  53. <td align="center" valign="top">No</td>
  54. </tr>
  55. <tr>
  56. <td valign="top">spawn</td>
  57. <td valign="top">whether or not you want the commands to be spawned.<br>
  58. If you spawn a command, its output will not be logged by ant.<br>
  59. The input, output, error, and result property settings are not active when spawning a process.<br>
  60. <em>since&nbsp;Ant&nbsp;1.6</em>
  61. </td>
  62. <td align="center" valign="top">No, default is <i>false</i></td>
  63. </tr>
  64. <tr>
  65. <td valign="top">dir</td>
  66. <td valign="top">the directory in which the command should be executed.</td>
  67. <td align="center" valign="top">No</td>
  68. </tr>
  69. <tr>
  70. <td valign="top">relative</td>
  71. <td valign="top">whether the filenames should be passed on the
  72. command line as relative pathnames (relative to the base directory
  73. of the corresponding fileset/list for source files or the
  74. <i>dest</i> attribute for target files).</td>
  75. <td align="center" valign="top">No, default is <i>false</i></td>
  76. </tr>
  77. <tr>
  78. <td valign="top">forwardslash</td>
  79. <td valign="top">whether the file names should be passed
  80. with forward slashes even if the operating system requires other
  81. file separator. The option is ignored if the system file separator
  82. is a forward slash.</td>
  83. <td align="center" valign="top">No, default is <i>false</i></td>
  84. </tr>
  85. <tr>
  86. <td valign="top">os</td>
  87. <td valign="top">list of Operating Systems on which the command may be
  88. executed.</td>
  89. <td align="center" valign="top">No</td>
  90. </tr>
  91. <tr>
  92. <td valign="top">osfamily</td>
  93. <td valign="top">OS family as used in the &lt;os&gt; condition.
  94. <em>since Ant 1.7</em></td>
  95. <td align="center" valign="top">No</td>
  96. </tr>
  97. <tr>
  98. <td valign="top">output</td>
  99. <td valign="top">the file to which the output of the command
  100. should be redirected. If the error stream is not also redirected
  101. to a file or property, it will appear in this output.</td>
  102. <td align="center" valign="top">No</td>
  103. </tr>
  104. <tr>
  105. <td valign="top">error</td>
  106. <td valign="top">The file to which the standard error of the
  107. command should be redirected. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  108. <td align="center" valign="top">No</td>
  109. </tr>
  110. <tr>
  111. <td valign="top">logError</td>
  112. <td valign="top">This attribute is used when you wish to see error
  113. output in Ant's log and you are redirecting output to a
  114. file/property. The error output will not be included in the output
  115. file/property. If you redirect error with the &quot;error&quot; or
  116. &quot;errorProperty&quot; attributes, this will have no effect.
  117. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  118. <td align="center" valign="top">No</td>
  119. </tr>
  120. <tr>
  121. <td valign="top">append</td>
  122. <td valign="top">whether output should be appended to or overwrite
  123. an existing file. If you set parallel to false, you will probably
  124. want to set this one to true.</td>
  125. <td align="center" valign="top">No, default is <i>false</i></td>
  126. </tr>
  127. <tr>
  128. <td valign="top">outputproperty</td>
  129. <td valign="top">the name of a property in which the output of the
  130. command should be stored. Unless the error stream is redirected
  131. to a separate file or stream, this property will include the error
  132. output.</td>
  133. <td align="center" valign="top">No</td>
  134. </tr>
  135. <tr>
  136. <td valign="top">errorproperty</td>
  137. <td valign="top">The name of a property in which the standard error of the
  138. command should be stored. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  139. <td align="center" valign="top">No</td>
  140. </tr>
  141. <tr>
  142. <td valign="top">input</td>
  143. <td valign="top">A file from which the executed command's standard
  144. input is taken. This attribute is mutually exclusive with the
  145. inputstring attribute. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  146. <td align="center" valign="top">No</td>
  147. </tr>
  148. <tr>
  149. <td valign="top">inputstring</td>
  150. <td valign="top">A string which serves as the input stream for the
  151. executed command. This attribute is mutually exclusive with the
  152. input attribute. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  153. <td align="center" valign="top">No</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">resultproperty</td>
  157. <td valign="top">the name of a property in which the return code
  158. of the command should be stored. Only of interest if
  159. failonerror=false. If you set parallel to false, only the result
  160. of the first execution will be stored.</td>
  161. <td align="center" valign="top">No</td>
  162. </tr>
  163. <tr>
  164. <td valign="top">timeout</td>
  165. <td valign="top">Stop the command if it doesn't finish within the
  166. specified time (given in milliseconds).</td>
  167. <td align="center" valign="top">No</td>
  168. </tr>
  169. <tr>
  170. <td valign="top">failonerror</td>
  171. <td valign="top">Stop the buildprocess if the command exits with a
  172. returncode other than 0.</td>
  173. <td align="center" valign="top">No</td>
  174. </tr>
  175. <tr>
  176. <td valign="top">failifexecutionfails</td>
  177. <td valign="top">Stop the build if we can't start the program.
  178. Defaults to true. </td>
  179. <td align="center" valign="top">No</td>
  180. </tr>
  181. <tr>
  182. <td valign="top">skipemptyfilesets</td>
  183. <td valign="top">Don't run the command, if no source files have
  184. been found or are newer than their corresponding target
  185. files. Despite its name, this attribute applies to filelists as
  186. well.</td>
  187. <td align="center" valign="top">No, default is <i>false</i></td>
  188. </tr>
  189. <tr>
  190. <td valign="top">parallel</td>
  191. <td valign="top">Run the command only once, appending all files as
  192. arguments. If false, command will be executed once for every file.</td>
  193. <td align="center" valign="top">No, default is <i>false</i></td>
  194. </tr>
  195. <tr>
  196. <td valign="top">type</td>
  197. <td valign="top">One of <i>file</i>, <i>dir</i> or
  198. <i>both</i>. If set to <i>file</i>, only the names of plain
  199. files will be sent to the command. If set to <i>dir</i>, only
  200. the names of directories are considered.<br>
  201. <strong>Note:</strong> The type attribute does not apply to
  202. nested <i>dirset</i>s - <i>dirset</i>s always implicitly
  203. assume type to be <i>dir</i>.</td>
  204. <td align="center" valign="top">No, default is <i>file</i></td>
  205. </tr>
  206. <tr>
  207. <td valign="top">newenvironment</td>
  208. <td valign="top">Do not propagate old environment when new environment
  209. variables are specified.</td>
  210. <td align="center" valign="top">No, default is <i>false</i></td>
  211. </tr>
  212. <tr>
  213. <td valign="top">vmlauncher</td>
  214. <td valign="top">Run command using the Java VM's execution facilities
  215. where available. If set to false the underlying OS's shell,
  216. either directly or through the antRun scripts, will be used.
  217. Under some operating systems, this gives access to facilities
  218. not normally available through the VM including, under Windows,
  219. being able to execute scripts, rather than their associated
  220. interpreter. If you want to specify the name of the
  221. executable as a relative path to the directory given by the
  222. dir attribute, it may become necessary to set vmlauncher to
  223. false as well.</td>
  224. <td align="center" valign="top">No, default is <i>true</i></td>
  225. </tr>
  226. <tr>
  227. <td valign="top">resolveExecutable</td>
  228. <td valign="top">When this attribute is true, the name of the
  229. executable if resolved firstly against the project basedir and if
  230. that does not exist, against the execution directory if
  231. specified. On Unix systems, if you only want to allow execution of
  232. commands in the user's path, set this to false.
  233. <em>since&nbsp;Ant&nbsp;1.6</em></td>
  234. <td align="center" valign="top">No, default is <i>false</i></td>
  235. </tr>
  236. <tr>
  237. <td valign="top">maxparallel</td>
  238. <td valign="top">Limit the amount of parallelism by passing at
  239. most this many sourcefiles at once. Set it to &lt;= 0 for
  240. unlimited. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  241. <td align="center" valign="top">No, unlimited by default</td>
  242. </tr>
  243. <tr>
  244. <td valign="top">addsourcefile</td>
  245. <td valign="top">Whether source file names should be added to the
  246. command automatically. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  247. <td align="center" valign="top">No, default is <i>true</i></td>
  248. </tr>
  249. <tr>
  250. <td valign="top">verbose</td>
  251. <td valign="top">Whether to print a summary after execution or not.
  252. <em>Since&nbsp;Ant&nbsp;1.6.</em></td>
  253. <td align="center" valign="top">No, default <i>false</i></td>
  254. </tr>
  255. <tr>
  256. <td valign="top">ignoremissing</td>
  257. <td valign="top">Whether to ignore nonexistent files specified
  258. via filelists. <em>Since&nbsp;Ant&nbsp;1.6.2.</em></td>
  259. <td align="center" valign="top">No, default is <i>true</i></td>
  260. </tr>
  261. <tr>
  262. <td valign="top">force</td>
  263. <td valign="top">Whether to bypass timestamp comparisons
  264. for target files. <em>Since&nbsp;Ant&nbsp;1.6.3.</em></td>
  265. <td align="center" valign="top">No, default is <i>false</i></td>
  266. </tr>
  267. </table>
  268. <h3>Parameters specified as nested elements</h3>
  269. <h4>fileset</h4>
  270. <p>You can use any number of nested <code>&lt;fileset&gt;</code>
  271. elements to define the files for this task and refer to
  272. <code>&lt;fileset&gt;</code>s defined elsewhere.</p>
  273. <h4>filelist</h4>
  274. <p><em>Since&nbsp;Ant&nbsp;1.6</em></p>
  275. <p>You can use any number of nested <code>&lt;filelist&gt;</code>
  276. elements to define the files for this task and refer to
  277. <code>&lt;filelist&gt;</code>s defined elsewhere.</p>
  278. <h4>dirset</h4>
  279. <p><em>Since&nbsp;Ant&nbsp;1.6</em></p>
  280. <p>You can use any number of nested <code>&lt;dirset&gt;</code>
  281. elements to define the directories for this task and refer to
  282. <code>&lt;dirset&gt;</code>s defined elsewhere.</p>
  283. <h4>Any other <a href="../CoreTypes/resources.html#collection">Resource
  284. Collection</a></h4>
  285. <p><em>since Ant 1.7</em></p>
  286. <p>You can use any number of nested resource collections.</p>
  287. <h4>mapper</h4>
  288. <p>A single <code>&lt;mapper&gt;</code> specifies the target files relative
  289. to the <code>dest</code> attribute for dependency checking. If the
  290. <code>dest</code> attribute is specified it will be used as a base directory
  291. for resolving relative pathnames returned by the mapper. At least one
  292. <code>&lt;fileset&gt;</code> or <code>&lt;filelist&gt;</code> is required.</p>
  293. <h4>arg</h4>
  294. <p>Command line arguments should be specified as nested
  295. <code>&lt;arg&gt;</code> elements. See <a
  296. href="../using.html#arg">Command line arguments</a>.</p>
  297. <h4>srcfile</h4>
  298. <p>By default the file names of the source files will be added to the
  299. end of the command line (unless you set addsourcefile to
  300. <code>false</code>). If you need to place it somewhere different,
  301. use a nested <code>&lt;srcfile&gt;</code> element between your
  302. <code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
  303. <h4>targetfile</h4>
  304. <p><code>&lt;targetfile&gt;</code> is similar to
  305. <code>&lt;srcfile&gt;</code> and marks the position of the target
  306. filename on the command line. If omitted, the target filenames will
  307. not be added to the command line at all. This element can only be
  308. specified if you also define a nested mapper.</p>
  309. <h4>env</h4>
  310. <p>It is possible to specify environment variables to pass to the
  311. system command via nested <code>&lt;env&gt;</code> elements. See the
  312. description in the section about <a href="exec.html#env">exec</a></p>
  313. <h4>redirector</h4>
  314. <i><b>Since&nbsp;Ant&nbsp;1.6.2</b></i>
  315. <p>A nested <a href="../CoreTypes/redirector.html">I/O Redirector</a>
  316. can be specified. &lt;apply&gt;'s behavior is like that of
  317. <a href="exec.html#redirector">exec</a> with regard to
  318. redirectors, with the exception that, in non-<i>parallel</i> mode,
  319. file mapping will take place with each iteration. This grants the
  320. user the capacity to receive input from, and send output to, different
  321. files for each sourcefile.
  322. </p>
  323. <h3>Examples</h3>
  324. <blockquote><pre>
  325. &lt;apply executable=&quot;ls&quot;&gt;
  326. &lt;arg value=&quot;-l&quot;/&gt;
  327. &lt;fileset dir=&quot;/tmp&quot;&gt;
  328. &lt;patternset&gt;
  329. &lt;exclude name=&quot;**/*.txt&quot;/&gt;
  330. &lt;/patternset&gt;
  331. &lt;/fileset&gt;
  332. &lt;fileset refid=&quot;other.files&quot;/&gt;
  333. &lt;/apply&gt;
  334. </pre></blockquote>
  335. <p>invokes <code>ls -l</code>, adding the absolute filenames of all
  336. files below <code>/tmp</code> not ending in <code>.txt</code> and all
  337. files of the FileSet with <code>id</code> <code>other.files</code> to
  338. the command line.</p>
  339. <blockquote><pre>
  340. &lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  341. &lt;arg value=&quot;arg1&quot;/&gt;
  342. &lt;srcfile/&gt;
  343. &lt;arg value=&quot;arg2&quot;/&gt;
  344. &lt;fileset dir=&quot;/tmp&quot;/&gt;
  345. &lt;/apply&gt;
  346. </pre></blockquote>
  347. <p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
  348. file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
  349. filename of each file in turn. If <code>parallel</code> had been set
  350. to true, SOURCEFILENAME would be replaced with the absolute filenames
  351. of all files separated by spaces.</p>
  352. <blockquote><pre>
  353. &lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  354. &lt;arg value=&quot;-c&quot;/&gt;
  355. &lt;arg value=&quot;-o&quot;/&gt;
  356. &lt;targetfile/&gt;
  357. &lt;srcfile/&gt;
  358. &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  359. &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
  360. &lt;/apply&gt;
  361. </pre></blockquote>
  362. <p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
  363. <code>.c</code> file that is newer than the corresponding
  364. <code>.o</code>, replacing TARGETFILE with the absolute filename of
  365. the <code>.o</code> and SOURCEFILE with the absolute name of the
  366. <code>.c</code> file.</p>
  367. <blockquote><pre>
  368. &lt;mapper id=&quot;out&quot; type=&quot;glob&quot;
  369. from=&quot;src${file.separator}*.file&quot;
  370. to=&quot;dest${file.separator}*.out&quot;/&gt;
  371. &lt;apply executable=&quot;processfile&quot; dest=&quot;dest&quot;&gt;
  372. &lt;fileset dir=&quot;src&quot; includes=&quot;*.file&quot;/&gt;
  373. &lt;mapper refid=&quot;out&quot;/&gt;
  374. &lt;redirector&gt;
  375. &lt;outputmapper refid=&quot;out&quot;/&gt;
  376. &lt;/redirector&gt;
  377. &lt;/apply&gt;
  378. </pre></blockquote>
  379. Applies the fictitious &quot;processfile&quot; executable to all
  380. files matching <code>*.file</code> in the <code>src</code> directory.
  381. The <code>out</code> <code>&lt;mapper&gt;</code> has been set up to map
  382. <code>*.file</code> to <code>*.out</code>, then this <code>&lt;mapper&gt;</code>
  383. is used to specify <code>targetfile</code>s for this &lt;apply&gt;
  384. task. A reference to <code>out</code> is then used as an
  385. <code>&lt;outputmapper&gt;</code> nested in a <code>&lt;redirector&gt;</code>, which in turn is
  386. nested beneath this <code>&lt;apply&gt;</code> instance. This allows us to perform
  387. dependency checking against output files--the target files in this case.
  388. <blockquote><pre>
  389. &lt;apply executable="ls" parallel="true"
  390. force="true" dest="${basedir}" append="true" type="both"&gt;
  391. &lt;path&gt;
  392. &lt;pathelement path="${env.PATH}"/&gt;
  393. &lt;/path&gt;
  394. &lt;identitymapper/&gt;
  395. &lt;/apply&gt;
  396. </pre></blockquote>
  397. Applies the "ls" executable to all directories in the PATH, effectively
  398. listing all executables that are available on the PATH.
  399. <blockquote><pre>
  400. &lt;apply executable="jsmin" addsourcefile="false"&gt;
  401. &lt;!-- Collect the JS-files --&gt;
  402. &lt;fileset dir="src" includes="*.js"/&gt;
  403. &lt;redirector&gt;
  404. &lt;!-- redirect STDIN; fileset collects relative to its dir, but we need --&gt;
  405. &lt;!-- relative to basedir --&gt;
  406. &lt;inputmapper type="glob" from="*" to="src/*"/&gt;
  407. &lt;!-- redirect STDOUT to file in dest-dir --&gt;
  408. &lt;outputmapper id="out" type="glob" from="*.js" to="dest/*.js"/&gt;
  409. &lt;/redirector&gt;
  410. &lt;/apply&gt;
  411. </pre></blockquote>
  412. Conversion of the command <code>jsmin &lt; src/a.js &gt; dest/a.js</code> but for
  413. all files in the src-directory. Because the filename itself should not be passed
  414. to the <code>jsmin</code> program, the <code>addsourcefile</code> is set to
  415. <code>false</code>.
  416. <hr><p align="center">Copyright &copy; 2000-2005 The Apache Software Foundation. All rights
  417. Reserved.</p>
  418. </body>
  419. </html>