source: other-projects/trunk/gs3-release-maker/apache-ant-1.6.5/docs/manual/CoreTasks/apply.html@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

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