You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Rob Wilson <ne...@gmail.com> on 2008/03/05 18:08:17 UTC

Repeating a task for a list of directories

Hi,

I have not done too much with Ant, but I would like to find all
sub-directories below a given directory and then for each directory repeat a
task in the context of that directory, so for example

topdir
   subdir1
   subdir2

I would like to get ant to repeat a task for subdir1 and subdir2 and have
access to the directory name within the task - does anyone know how I can
achieve this?

Cheers,
Rob.

Re: Repeating a task for a list of directories

Posted by Peter Reilly <pe...@gmail.com>.
The first has a "/" in front of the lib.
-> this is an absolute path.

Peter

On Mon, Mar 10, 2008 at 11:56 AM, Rob Wilson <ne...@gmail.com> wrote:
> I thought I would give some feedback, it seems that I made two mistakes...
>
>  1) I typed the incorrect version number, so this was why it could not find
>  the explicitly named jar file.
>
>  2) even after fixing the jar name this syntax did not work...
>
>
>  <taskdef resource="net/sf/antcontrib/antlib.xml">
>   <classpath>
>     <pathelement location="/lib/ant/ant-contrib-1.0b3.jar"/>
>   </classpath>
>  </taskdef>
>
>  (yes I did correct the jar name by this point!)
>
>  but this did work...
>
>
>  <taskdef resource="net/sf/antcontrib/antlib.xml">
>   <classpath>
>     <fileset dir="lib/ant" includes="*.jar"/>
>   </classpath>
>  </taskdef>
>
>  Does anyone know what was wrong with the first one?
>
>  Cheers,
>  Rob.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Repeating a task for a list of directories

Posted by Rob Wilson <ne...@gmail.com>.
I thought I would give some feedback, it seems that I made two mistakes...

1) I typed the incorrect version number, so this was why it could not find
the explicitly named jar file.

2) even after fixing the jar name this syntax did not work...

<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <pathelement location="/lib/ant/ant-contrib-1.0b3.jar"/>
  </classpath>
</taskdef>

(yes I did correct the jar name by this point!)

but this did work...

<taskdef resource="net/sf/antcontrib/antlib.xml">
  <classpath>
    <fileset dir="lib/ant" includes="*.jar"/>
  </classpath>
</taskdef>

Does anyone know what was wrong with the first one?

Cheers,
Rob.

Re: Repeating a task for a list of directories

Posted by Peter Reilly <pe...@gmail.com>.
Yes,
normally I keep a lib/ant/-plugin-name-/(jars needed for the plugin)
directory structure and have a ant-contrib.xml importable file to
configure the plugin:

<project name="ant-contrib"
         xmlns:ac="antlib:net.sf.antcontrib">

  <typedef uri="antlib:net.sf.antcontrib"
           resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <fileset dir="lib/ant/ant-contrib" includes="*.jar"/>
    </classpath>
  </typedef>

  <presetdef name="bash" uri="antlib:net.sf.antcontrib">
    <ac:shellscript shell="bash"/>
  </presetdef>


</project>

(note that for ant 1.7.0 you do not need to specify resource when the
uri is an antlib:)

Peter

On Thu, Mar 6, 2008 at 10:47 AM,  <Ja...@rzf.fin-nrw.de> wrote:
> You should put ant-contrib.jar into your project svn and let the buildfile refer to that (local) location.
>
>  PROJECT
>   | build.xml
>   +-- lib/ant
>         +-- ant-contrib.jar
>
>
>  build.xml
>  ---------
>  <project xmlns:ac="antlib:net.sf.antcontrib">
>     <taskdef uri="antlib:net.sf.antcontrib"
>
>              resource="net/sf/antcontrib/antlib.xml"
>              classpath="lib/ant/ant-contrib.jar"/>
>
>     <ac:for param="i" begin="1" end="3">
>         <sequential>
>             <echo>i: ${i}</echo>
>         </sequential>
>     </ac:for>
>  </project>
>
>
>  Jan
>
>  > -----Ursprüngliche Nachricht-----
>  > Von: Rob Wilson [mailto:netplay@gmail.com]
>  > Gesendet: Donnerstag, 6. März 2008 11:34
>  > An: Ant Users List
>  > Betreff: Re: Repeating a task for a list of directories
>
>
> >
>  > Thanks for the information, I believe I need ant-contribs
>  > foreach such that
>  > I can do some processing for each subdirectory.  I've
>  > downloaded the jar
>  > file and would prefer not to copy it directly into Ant libs
>  > folder, such
>  > that the next person to do a svn update can run with it
>  > without having to
>  > think about it.
>  >
>  > However, the documentation on sourceforge is not explaining
>  > how to do this
>  > (the homepage version http://ant-contrib.sourceforge.net/
>  > contains less
>  > information than the other tasks section (
>  > http://ant-contrib.sourceforge.net/tasks/index.html).
>  >
>  > Basically, trying to work out whether I need to reference the .xml or
>  > .properties reference, and where it exists - it complains it
>  > can't find it,
>  > but it's not in the .zip file downloaded... Am I meant to
>  > create it? What's
>  > in it? Help! ;-)
>  >
>  > It states....
>  >
>  > Keep ant-contrib-version.jar in a separate location. You now
>  > have to tell
>  > Ant explicitly where to find it (say in /usr/share/java/lib):
>  >
>  > <taskdef *resource="net/sf/antcontrib/antlib.xml*">
>  >   <classpath>
>  >     <pathelement
>  > location="/usr/share/java/lib/ant-contrib-version.jar"/>
>  >   </classpath>
>  > </taskdef>
>  >
>  > If you would like to use run with Ant Version 1.5 you must use the the
>  > .properties file instead. Keep in mind that some tasks will
>  > not be available
>  > to you , such as the <for> task:
>  >
>  > <taskdef resource="net/sf/antcontrib/antcontrib.properties">
>  >   <classpath>
>  >     <pathelement
>  > location="/usr/share/java/lib/ant-contrib-version.jar"/>
>  >   </classpath>
>  > </taskdef>
>  >
>
>
>
> ---------------------------------------------------------------------
>  To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>  For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


AW: Repeating a task for a list of directories

Posted by Ja...@rzf.fin-nrw.de.
You should put ant-contrib.jar into your project svn and let the buildfile refer to that (local) location.

PROJECT
  | build.xml
  +-- lib/ant
        +-- ant-contrib.jar


build.xml
---------
<project xmlns:ac="antlib:net.sf.antcontrib">
    <taskdef uri="antlib:net.sf.antcontrib"
             resource="net/sf/antcontrib/antlib.xml"
             classpath="lib/ant/ant-contrib.jar"/>

    <ac:for param="i" begin="1" end="3">
        <sequential>
            <echo>i: ${i}</echo>
        </sequential>
    </ac:for>
</project>


Jan

> -----Ursprüngliche Nachricht-----
> Von: Rob Wilson [mailto:netplay@gmail.com] 
> Gesendet: Donnerstag, 6. März 2008 11:34
> An: Ant Users List
> Betreff: Re: Repeating a task for a list of directories
> 
> Thanks for the information, I believe I need ant-contribs 
> foreach such that
> I can do some processing for each subdirectory.  I've 
> downloaded the jar
> file and would prefer not to copy it directly into Ant libs 
> folder, such
> that the next person to do a svn update can run with it 
> without having to
> think about it.
> 
> However, the documentation on sourceforge is not explaining 
> how to do this
> (the homepage version http://ant-contrib.sourceforge.net/ 
> contains less
> information than the other tasks section (
> http://ant-contrib.sourceforge.net/tasks/index.html).
> 
> Basically, trying to work out whether I need to reference the .xml or
> .properties reference, and where it exists - it complains it 
> can't find it,
> but it's not in the .zip file downloaded... Am I meant to 
> create it? What's
> in it? Help! ;-)
> 
> It states....
> 
> Keep ant-contrib-version.jar in a separate location. You now 
> have to tell
> Ant explicitly where to find it (say in /usr/share/java/lib):
> 
> <taskdef *resource="net/sf/antcontrib/antlib.xml*">
>   <classpath>
>     <pathelement 
> location="/usr/share/java/lib/ant-contrib-version.jar"/>
>   </classpath>
> </taskdef>
> 
> If you would like to use run with Ant Version 1.5 you must use the the
> .properties file instead. Keep in mind that some tasks will 
> not be available
> to you , such as the <for> task:
> 
> <taskdef resource="net/sf/antcontrib/antcontrib.properties">
>   <classpath>
>     <pathelement 
> location="/usr/share/java/lib/ant-contrib-version.jar"/>
>   </classpath>
> </taskdef>
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Repeating a task for a list of directories

Posted by Rob Wilson <ne...@gmail.com>.
Thanks for the information, I believe I need ant-contribs foreach such that
I can do some processing for each subdirectory.  I've downloaded the jar
file and would prefer not to copy it directly into Ant libs folder, such
that the next person to do a svn update can run with it without having to
think about it.

However, the documentation on sourceforge is not explaining how to do this
(the homepage version http://ant-contrib.sourceforge.net/ contains less
information than the other tasks section (
http://ant-contrib.sourceforge.net/tasks/index.html).

Basically, trying to work out whether I need to reference the .xml or
.properties reference, and where it exists - it complains it can't find it,
but it's not in the .zip file downloaded... Am I meant to create it? What's
in it? Help! ;-)

It states....

Keep ant-contrib-version.jar in a separate location. You now have to tell
Ant explicitly where to find it (say in /usr/share/java/lib):

<taskdef *resource="net/sf/antcontrib/antlib.xml*">
  <classpath>
    <pathelement location="/usr/share/java/lib/ant-contrib-version.jar"/>
  </classpath>
</taskdef>

If you would like to use run with Ant Version 1.5 you must use the the
.properties file instead. Keep in mind that some tasks will not be available
to you , such as the <for> task:

<taskdef resource="net/sf/antcontrib/antcontrib.properties">
  <classpath>
    <pathelement location="/usr/share/java/lib/ant-contrib-version.jar"/>
  </classpath>
</taskdef>

Re: Repeating a task for a list of directories

Posted by Vijay Aravamudhan <av...@gmail.com>.
hi,
if all you are doing is calling a different ant file within each 
subdirectory - you can look at subant 
(http://ant.apache.org/manual/CoreTasks/subant.html)

If your main build file has a target which you want to repeat for each 
subdirectory, use ant-contrib's for or foreach tasks 
(http://ant-contrib.sourceforge.net/tasks/tasks/index.html)
With the ant-contrib option, you will have access to a property that you 
can define which contains the directory name.

hth,
Vijay

Rob Wilson wrote:
> Hi,
>
> I have not done too much with Ant, but I would like to find all
> sub-directories below a given directory and then for each directory repeat a
> task in the context of that directory, so for example
>
> topdir
>    subdir1
>    subdir2
>
> I would like to get ant to repeat a task for subdir1 and subdir2 and have
> access to the directory name within the task - does anyone know how I can
> achieve this?
>
> Cheers,
> Rob.
>
>   

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org