source: release-kits/lirk3/bin/ant-installer/web/manual1.7.0/manual/CoreTasks/apply.html@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

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