ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From peter reilly <peter.rei...@corvil.com>
Subject Re: copy
Date Mon, 17 Nov 2003 12:39:48 GMT
On Monday 17 November 2003 12:16, Jan.Materne@rzf.fin-nrw.de wrote:
> Ok, big examples for all three.
> But I have NOT tested these ideas :-)
>
>
> a) using AntContrib´s <foreach>
>
> AntContrib is available at [1].
> If you have a list (like your String) you can use
>
> <foreach target="doCopy" param="todir" list="${list}"/>
>
> <target name="doCopy">
>     <copy file="${file}" todir="${todir}"/>
> </target>
>
>
> You can define the target directories using <dirset>s.
>
> <foreach target="doCopy" param="todir">
>     <path>
>         <dirset dir="c:\test\web" includes="**/chk/**"/>
>     </path>
> </foreach>
>
> <target name="doCopy">
>     <copy file="${file}" todir="${todir}"/>
> </target>
>
>
>
>
> b) using AntContrib´s <for>
>
> Simply the same as with <foreach> but without the need of a new target.
> The problem is that this task is not described in the manual (of
> AntContrib).

It is in the cvs manual:

http://cvs.sourceforge.net/viewcvs.py/ant-contrib/ant-contrib/manual/tasks/for.html?rev=1.2&view=markup

> So you have to look into the source (and understand the most of that)...
>
> <for param="todir" list="${list}">
>     <sequential>
>         <copy file="${file}" todir="${todir}"/>
>     </sequential>
> </for>
>
> or the way using <dirset>
>
>
> <for param="todir">
>     <path>
>         <dirset dir="c:\test\web" includes="**/chk/**"/>
>     </path>
>     <sequential>
>         <copy file="${file}" todir="${todir}"/>
>     </sequential>
> </for>
>
> But <for> requires the newest Ant version (not released yet), so sais the
> javadoc
> comment at the beginning of the For.java [2]:
>  * Task definition for the for task.  This is based on
>  * the foreach task but takes a sequential element
>  * instead of a target and only works for ant >= 1.6Beta3
>
> You can download the latest binary from [3].
>
>
> c) using <script>
>
> This example uses JavaScript, therefore you need the dependend libraries
> described
> in manual [4].
>
> If you use a list, you have to split that inside your loop. For that you
> can use the
> StringTokenizer class.
>
> <property name="file" value="the-copied-file"/>
> <property name="list" value="dir1,dir2"/>
> <script language="javascript"> <![CDATA[
>     list = project.getProperty("list");  // the name of the property as
> argument
>     file = project.getProperty("file");
>     tokenizer = new StringTokenizer(list);
>     copy = project.createTask("copy");
>     copy.setFile(new java.io.File(file));
>     while (tokenizer.hasMoreTokens()) {
>         todir = tokenizer.nextToken();
>         copy.setTodir(new java.io.File(todir));
>         copy.perform();
>     }
> ]]></script>
>
>
> If you uses <dirset> you can iterate over that
>
>
> <property name="file" value="the-copied-file"/>
> <dirset id="todirs" dir="c:\test\web" includes="**/chk/**"/>
> <script language="javascript"> <![CDATA[
>     file = project.getProperty("file");
>     copy = project.createTask("copy");
>     copy.setFile(new java.io.File(file));
>     ds = todirs.getDirectoryScanner(project);  // use the id for accessing
> the dirset
>     targetDirs = = ds.getIncludedFiles();
>     for (i=0; i<targetDirs.length; i++) {
>         todir = tokenizer.nextToken();
>         copy.setTodir(new java.io.File(todir));
>         copy.perform();
>     }
> ]]></script>
>
>
> Because you´re using Ant´s API, a look into their description [5] would be
> good.
> And the manual for <script> [6] has some hints, too.
>
>
>
>
> Like I said, these examples are not tested. So they may contain some
> errors. But you should be able
> to find them and correct them :-)
>
> Jan
>
>
> [1] http://sourceforge.net/projects/ant-contrib/
> [2]
> http://cvs.sourceforge.net/viewcvs.py/ant-contrib/ant-contrib/src/net/sf/an
>t contrib/logic/For.java?rev=1.5&view=markup
> [3] http://gump.covalent.net/jars/latest/ant/ (all files needed)
> [4] http://ant.apache.org/manual-1.6beta/install.html#librarydependencies
> [5] http://nagoya.apache.org/gump/javadoc/ant/build/javadocs/index.html
> [6] http://ant.apache.org/manual-1.6beta/OptionalTasks/script.html
>
> > -----Original Message-----
> > From: Parimala [mailto:parimala@medicomsoft.com]
> > Sent: Monday, November 17, 2003 12:45 PM
> > To: 'Ant Users List'
> > Subject: RE: copy
> >
> >
> > can u pls tell me how to do it.
> >
> > a) i have a property that has the following String
> > c:\test\web\chk\try\jsp,c:\test\web\chk\try1\jsp
> > b) i want to copy a file from c:\web\chk to try and try1
> >
> > How to write this???
> > Note: try and try1 folders are determined dynamically
> >
> >
> > Parimala
> >
> >
> >
> > -----Original Message-----
> > From: Jan.Materne@rzf.fin-nrw.de [mailto:Jan.Materne@rzf.fin-nrw.de]
> > Sent: Monday, November 17, 2003 4:03 PM
> > To: user@ant.apache.org
> > Subject: RE: copy
> >
> >
> > a) using AntContrib´s <foreach>
> > b) using AntContrib´s <for>
> > c) using <script>
> >
> > In all cases you´re looping over a <dirset> and do the copy.
> >
> >
> > Jan
> >
> > > -----Original Message-----
> > > From: Parimala [mailto:parimala@medicomsoft.com]
> > > Sent: Monday, November 17, 2003 11:34 AM
> > > To: user@ant.apache.org
> > > Subject: copy
> > >
> > >
> > > Rose StationeryHow to copy a file in all the underlying directories?
> >
> > ---------------------------------------------------------------------
> > 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


Mime
View raw message