Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I pretty sure there isn't a way to generically call a task for each file without either creating your own <a href="http://ant.apache.org/manual/develop.html" rel="nofollow">custom task</a> or using <a href="http://ant-contrib.sourceforge.net/" rel="nofollow">ant-contrib</a>. However there are ways to get ant to automatically retrieve ant-contrib (or a custom jar) so you can achieve the desired result. This is the approach used by <a href="https://windyroad.assembla.com/spaces/tibant/trac_mercurial_tool" rel="nofollow">TIBant</a>, which has a similar requirement (so that it's easy for anyone to contribute to the development),</p> <p><strong>Step 1: Download Apache Ivy</strong></p> <p>Apache Ivy can be used to retrieve dependencies such as ant-contrib. I use the following ant properties and target to download and load Ivy</p> <pre><code>&lt;property name="ivy.install.version" value="2.2.0" /&gt; &lt;property name="ivy.jar.dir" location="${user.home}/.ivy2/jars" /&gt; &lt;property name="ivy.jar.file" location="${ivy.jar.dir}/ivy-${ivy.install.version}.jar" /&gt; &lt;target name="-download-ivy" unless="ivy.downloaded"&gt; &lt;mkdir dir="${ivy.jar.dir}" /&gt; &lt;!-- download Ivy from web site so that it can be used even without any special installation --&gt; &lt;echo message="installing ivy..." /&gt; &lt;get src="http://repo1.maven.org/maven2/org/apache/ivy/ivy/${ivy.install.version}/ivy-${ivy.install.version}.jar" dest="${ivy.jar.file}" usetimestamp="true" verbose="true" /&gt; &lt;/target&gt; &lt;target name="-check-ivy-downloaded"&gt; &lt;condition property="ivy.downloaded"&gt; &lt;and&gt; &lt;available file="${ivy.jar.file}" /&gt; &lt;available file="${ivy.jar.dir}/jsch-0.1.44-1.jar" /&gt; &lt;/and&gt; &lt;/condition&gt; &lt;/target&gt; &lt;target name="-load-ivy" depends="-check-ivy-downloaded,-download-ivy" unless="ivy.loaded"&gt; &lt;path id="ivy.lib.path"&gt; &lt;fileset dir="${ivy.jar.dir}" includes="*.jar" /&gt; &lt;/path&gt; &lt;taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path" /&gt; &lt;property name="ivy.loaded" value="true" /&gt; &lt;/target&gt; </code></pre> <p><strong>Step 2: Add ant-contrib dependency</strong></p> <p>Ivy uses an "ivy file" for specifying dependencies. You can add ant-contrib as follows</p> <pre><code> &lt;dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" transitive="false"/&gt; </code></pre> <p>a full ivy file might look like</p> <pre><code>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt; &lt;ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd"&gt; &lt;info organisation="org.my" module="mymodule" status="release"/&gt; &lt;dependencies&gt; &lt;dependency org="ant-contrib" name="ant-contrib" rev="1.0b3" transitive="false"/&gt; &lt;/dependencies&gt; &lt;/ivy-module&gt; </code></pre> <p>You could also output this file dynamically from your ant script using <a href="http://file://localhost/Users/tomhoward/Documents/apache-ant-1.8.1/CoreTasks/echoxml.html" rel="nofollow">echoxml</a></p> <p><strong>Step 3: Retrieve the dependencies</strong></p> <p>Use Ivy to download <code>ant-contrib</code> (or whatever dependencies you have specified)</p> <pre><code>&lt;target name="retrieve" description="retrieve dependancies with ivy" depends="-load-ivy"&gt; &lt;ivy:retrieve /&gt; &lt;ivy:artifactproperty name="[module].[artifact]" value="lib/[artifact]-[revision].[ext]" /&gt; &lt;/target&gt; </code></pre> <p><strong>Step 4: Load <code>ant-contrib</code></strong></p> <pre><code>&lt;target name="-load-ant-contrib" depends="retrieve" unless="ant.contrib.loaded"&gt; &lt;taskdef resource="net/sf/antcontrib/antlib.xml"&gt; &lt;classpath&gt; &lt;pathelement location="${ant-contrib.ant-contrib}" /&gt; &lt;/classpath&gt; &lt;/taskdef&gt; &lt;property name="ant.contrib.loaded" value="true" /&gt; &lt;/target&gt; </code></pre> <p><strong>Step 5: Create your target that iterates over the files using <code>for</code></strong></p> <pre><code>&lt;target name="mytarget" depends="-load-ant-contrib"&gt; &lt;for param="file"&gt; &lt;fileset dir="somedir" includes="..." /&gt; &lt;sequential&gt; &lt;!-- do stuff with @{file} --&gt; &lt;/sequential&gt; &lt;/for&gt; &lt;/target&gt; </code></pre> <p>If you only need to download ant-contrib and don't want to use Ivy to manage other dependencies, then you can skip most of the above and just use a <a href="http://file://localhost/Users/tomhoward/Documents/apache-ant-1.8.1/CoreTasks/get.html" rel="nofollow">get</a> to download <code>ant-contrib</code> in the same way the above downloads Ivy.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload