<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<title>Apply Task</title>
</head>

<body>

<h2><a name="apply">Apply/<i>ExecOn</i></a></h2>
<p><i>The name <code>execon</code> is deprecated and only kept for backwards
compatibility.</i></p>
<h3>Description</h3>
<p>Executes a system command. When the <i>os</i> attribute is specified, then
the command is only executed when Ant is run on one of the specified operating
systems.</p>
<p>The files and/or directories of a number of <a
href="../CoreTypes/fileset.html">FileSet</a>s, <a
href="../CoreTypes/dirset.html">DirSet</a>s (<em>since Ant 1.6</em>)
or <a href="../CoreTypes/filelist.html">FileList</a>s (<em>since Ant
1.6</em>) are passed as arguments to the system command.</p>
<p>If you specify a nested <a
href="../CoreTypes/mapper.html">mapper</a> and the <i>dest</i> attribute,
the timestamp of each source file is compared to the timestamp of a
target file which is defined by the nested mapper element and searched
for in the given dest.</p>
<p>At least one fileset or filelist is required, and you must not specify more than
one mapper.</p>
<h3>Parameters</h3>
<table border="1" cellpadding="2" cellspacing="0">
  <tr>
    <td valign="top"><b>Attribute</b></td>
    <td valign="top"><b>Description</b></td>
    <td align="center" valign="top"><b>Required</b></td>
  </tr>
  <tr>
    <td valign="top">executable</td>
    <td valign="top">the command to execute without any command line
      arguments.</td>
    <td align="center" valign="top">Yes</td>
  </tr>
  <tr>
    <td valign="top">dest</td>
    <td valign="top">the directory where the &lt;apply&gt; expects the target files will be placed by the 
                     command, when it is executed. 
    </td>
    <td align="center" valign="top">Yes, if you specify a nested mapper</td>
  </tr>
  <tr>
    <td valign="top">dir</td>
    <td valign="top">the directory in which the command should be executed.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">relative</td>
    <td valign="top">whether the filenames should be passed on the
      command line as absolute or relative pathnames (relative to the
      base directory of the corresponding fileset/list for source files or
      the <i>dest</i> attribute for target files).</td>
    <td align="center" valign="top">No, default is <i>false</i></td>
  </tr>
  <tr>
    <td valign="top">forwardslash</td>
    <td valign="top">whether the file names should be passed
      with forward slashes even if the operating system requires other
      file separator. The option is ignored if the system file separator
      is a forward slash.</td>
    <td align="center" valign="top">No, default is <i>false</i></td>
  </tr>
  <tr>
    <td valign="top">os</td>
    <td valign="top">list of Operating Systems on which the command may be
      executed.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">output</td>
    <td valign="top">the file to which the output of the command should be
      redirected.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">append</td>
    <td valign="top">whether output should be appended to or overwrite
      an existing file.  Defaults to false.  If you set parallel to
      false, you will probably want to set this one to true.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">outputproperty</td>
    <td valign="top">the name of a property in which the output of the 
      command should be stored.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">resultproperty</td>
    <td valign="top">the name of a property in which the return code
      of the command should be stored. Only of interest if
      failonerror=false. If you set parallel to false, only the result
      of the first execution will be stored.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">timeout</td>
    <td valign="top">Stop the command if it doesn't finish within the
      specified time (given in milliseconds).</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">failonerror</td>
    <td valign="top">Stop the buildprocess if the command exits with a
      returncode other than 0.</td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">failifexecutionfails</td>
    <td valign="top">Stop the build if we can't start the program.
      Defaults to true. </td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">skipemptyfilesets</td>
    <td valign="top">Don't run the command, if no source files have
      been found or are newer than their corresponding target
      files.  Despite its name, this attribute applies to filelists as
      well.</td>
    <td align="center" valign="top">No, default is <i>false</i></td>
  </tr>
  <tr>
    <td valign="top">parallel</td>
    <td valign="top">Run the command only once, appending all files as
      arguments. If false, command will be executed once for every file. 
      Defaults to false. </td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">type</td>
    <td valign="top">One of <i>file</i>, <i>dir</i> or
      <i>both</i>. If set to <i>file</i>, only the names of plain
      files will be sent to the command. If set to <i>dir</i>, only
      the names of directories are considered.<br>
      <strong>Note:</strong> The type attribute does not apply to
      nested <i>dirset</i>s - <i>dirset</i>s always implicitly
      assume type to be <i>dir</i>.</td>
    <td align="center" valign="top">No, default is <i>file</i></td>
  </tr>
  <tr>
    <td valign="top">newenvironment</td>
    <td valign="top">Do not propagate old environment when new environment
      variables are specified.</td>
    <td align="center" valign="top">No, default is <i>false</i></td>
  </tr>
  <tr>
    <td valign="top">vmlauncher</td>
    <td valign="top">Run command using the Java VM's execution facilities
        where available. If set to false the underlying OS's shell,
        either directly or through the antRun scripts, will be used.
        Under some operating systems, this gives access to facilities
        not normally available through the VM including, under Windows,
        being able to execute scripts, rather than their associated
        interpreter.  If you want to specify the name of the
        executable as a relative path to the directory given by the
        dir attribute, it may become necessary to set vmlauncher to
        false as well.</td>
    <td align="center" valign="top">No, default is <i>true</i></td>
  </tr>
  <tr>
    <td valign="top">maxparallel</td>
    <td valign="top">Limit the amount of parallelism by passing at
      most this many sourcefiles at once.  Set it to &lt;= 0 for
      unlimited.  Defaults to unlimited.  <em>Since Ant 1.6.</em></td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">addsourcefile</td>
    <td valign="top">Whether source file names should be added to the
      command automatically.  Defaults to <code>true</code>.  
      <em>Since Ant 1.6.</em></td>
    <td align="center" valign="top">No</td>
  </tr>
  <tr>
    <td valign="top">verbose</td>
    <td valign="top">Whether to print a summary after execution or not.
      Defaults to <code>false</code>.  <em>Since Ant 1.6.</em></td>
    <td align="center" valign="top">No</td>
  </tr>
</table>
<h3>Parameters specified as nested elements</h3>
<h4>fileset</h4>
<p>You can use any number of nested <code>&lt;fileset&gt;</code>
elements to define the files for this task and refer to
<code>&lt;fileset&gt;</code>s defined elsewhere.</p>
<h4>filelist</h4>
<p><em>Since Ant 1.6</em></p>
<p>You can use any number of nested <code>&lt;filelist&gt;</code>
elements to define the files for this task and refer to
<code>&lt;filelist&gt;</code>s defined elsewhere.</p>
<h4>dirset</h4>
<p><em>Since Ant 1.6</em></p>
<p>You can use any number of nested <code>&lt;dirset&gt;</code>
elements to define the directories for this task and refer to
<code>&lt;dirset&gt;</code>s defined elsewhere.</p>
<h4>arg</h4>
<p>Command line arguments should be specified as nested
<code>&lt;arg&gt;</code> elements. See <a
href="../using.html#arg">Command line arguments</a>.</p>
<h4>srcfile</h4>
<p>By default the file names of the source files will be added to the
end of the command line (unless you set addsourcefile to
<code>false</code>). If you need to place it somewhere different,
use a nested <code>&lt;srcfile&gt;</code> element between your
<code>&lt;arg&gt;</code> elements to mark the insertion point.</p>
<h4>targetfile</h4>
<p><code>&lt;targetfile&gt;</code> is similar to
<code>&lt;srcfile&gt;</code> and marks the position of the target
filename on the command line. If omitted, the target filenames will
not be added to the command line at all. This element can only be
specified, if you also define a nested mapper and the <i>dest</i>
attribute.</p>
<h4>env</h4>
<p>It is possible to specify environment variables to pass to the
system command via nested <code>&lt;env&gt;</code> elements. See the
description in the section about <a href="exec.html#env">exec</a></p>
<h3>Examples</h3>
<blockquote><pre>
&lt;apply executable=&quot;ls&quot;&gt;
  &lt;arg value=&quot;-l&quot;/&gt;
  &lt;fileset dir=&quot;/tmp&quot;&gt;
    &lt;patternset&gt;
      &lt;exclude name=&quot;**/*.txt&quot;/&gt;
    &lt;/patternset&gt;
  &lt;/fileset&gt;
  &lt;fileset refid=&quot;other.files&quot;/&gt;
&lt;/apply&gt;
</pre></blockquote>
<p>invokes <code>ls -l</code>, adding the absolute filenames of all
files below <code>/tmp</code> not ending in <code>.txt</code> and all
files of the FileSet with <code>id</code> <code>other.files</code> to
the command line.</p>
<blockquote><pre>
&lt;apply executable=&quot;somecommand&quot; parallel=&quot;false&quot;&gt;
  &lt;arg value=&quot;arg1&quot;/&gt;
  &lt;srcfile/&gt;
  &lt;arg value=&quot;arg2&quot;/&gt;
  &lt;fileset dir=&quot;/tmp&quot;/&gt;
&lt;/apply&gt;
</pre></blockquote>
<p>invokes <code>somecommand arg1 SOURCEFILENAME arg2</code> for each
file in <code>/tmp</code> replacing SOURCEFILENAME with the absolute
filename of each file in turn. If <code>parallel</code> had been set
to true, SOURCEFILENAME would be replaced with the absolute filenames
of all files separated by spaces.</p>
<blockquote><pre>
&lt;apply executable=&quot;cc&quot; dest=&quot;src/C&quot; parallel=&quot;false&quot;&gt;
  &lt;arg value=&quot;-c&quot;/&gt;
  &lt;arg value=&quot;-o&quot;/&gt;
  &lt;targetfile/&gt;
  &lt;srcfile/&gt;
  &lt;fileset dir=&quot;src/C&quot; includes=&quot;*.c&quot;/&gt;
  &lt;mapper type=&quot;glob&quot; from=&quot;*.c&quot; to=&quot;*.o&quot;/&gt;
&lt;/apply&gt;
</pre></blockquote>
<p>invokes <code>cc -c -o TARGETFILE SOURCEFILE</code> for each
<code>.c</code> file that is newer than the corresponding
<code>.o</code>, replacing TARGETFILE with the absolute filename of
the <code>.o</code> and SOURCEFILE with the absolute name of the
<code>.c</code> file.</p>
<hr><p align="center">Copyright &copy; 2000-2003 Apache Software Foundation. All rights
Reserved.</p>

</body>
</html>