I think there is a way to do what he is looking for with the built in copy
operation and the mappers. I haven't figured it out exactly but he should be
able to do something like:
<target name="CopyOneFileToManyDirectories">
<mkdir dir="./a/org/simple" />
<mkdir dir="./b/org/simple" />
<mkdir dir="./b/org/simple" />
<mkdir dir="./c/org/simple" />
<copy todir="." enablemultiplemappings="true">
<fileset dir="." includes="build.xml" />
<mapper>
<mapper type="glob" from="build.xml"
to="./a/org/simple/build.xml" />
<mapper type="glob" from="build.xml"
to="./b/org/simple/build.xml" />
<mapper type="glob" from="build.xml"
to="./c/org/simple/build.xml" />
<mapper type="glob" from="build.xml"
to="./d/org/simple/build.xml" />
</mapper>
</copy>
</target>
This I think is what he trying to do in general. If the target directories are
changing he could create his own task that extends mapper and have that take a
directory set. Something like:
<macrodef name="CopyOneFileToDirSet">
<attribute name="destDirIncludes" />
<attribute name="destBaseDir" />
<element name="files" />
<sequential>
<typedef name="ManyDirMapper"
classname="com.company.ant.ManyDirMapper"
classpath="${system.home}/classes"
adaptto="org.apache.tools.ant.types.Mapper"
/>
<ManyDirMapper id="multiMappings">
<dirset dir="@{destBaseDir}"
includes="@{destDirIncludes}" />
</ManyDirMapper>
<copy todir="@{destBaseDir}" enablemultiplemappings="true">
<files />
<mapper refid="multiMappings" />
</copy>
</sequential>
</macrodef>
<CopyOneFileToDirSet destdirincludes="*/org/simple/" destbasedir=".">
<files>
<fileset dir="." includes="build2.xml" />
</files>
</CopyOneFileToDirSet>
Where ManyDirMapper.java is:
package com.company.ant;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.DirSet;
import org.apache.tools.ant.types.Mapper;
import org.apache.tools.ant.util.FileNameMapper;
public class ManyDirMapper extends Mapper {
public ManyDirMapper(Project arg0) {
super(arg0);
}
public DirSet dirset;
public void addDirset(DirSet dirset) {
this.dirset = dirset;
}
@Override
public FileNameMapper getImplementation() throws BuildException {
String[] names =
dirset.getDirectoryScanner().getIncludedDirectories();
if(names != null && names.length > 0){
MapperType mt = new MapperType();
mt.setValue("glob");
for(int i=0; i < names.length; i++){
String name = names[i];
log(name);
if(name.length() == 0)continue;
Mapper m = new Mapper(getProject());
m.setType(mt);
m.setTo(names[i]+"/*");
m.setFrom("*");
addConfiguredMapper(m);
}
}
return super.getImplementation();
}
}
I have been hacking together a lot of these types of mappers and filter chains
to work with lists so I don't have to use "for" as it seemed to destroy the
performance of my previous build system. Normally I wouldn't give someone this
level of help but I realized that I might need something similar soon so enjoy!
Sam
-----Original Message-----
From: Peter Reilly [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 13, 2007 1:09 PM
To: Ant Users List
Subject: Re: AW: AW: Copy a single file to directories
An example:
<project default="dirs" xmlns:ac="antlib:net.sf.antcontrib">
<typedef uri="antlib:net.sf.antcontrib">
<classpath>
<fileset dir="${user.home}/apps/ant-contrib" includes="*.jar"/>
</classpath>
</typedef>
<target name="dirs">
<ac:shellscript shell="bash">
rm -rf dirs
mkdir -p dirs/a/org/simple
mkdir -p dirs/b/org/simple
mkdir -p dirs/d/org/simple
mkdir -p dirs/c/org/simple
</ac:shellscript>
<ac:for param="dir">
<dirset dir="dirs" includes="*"/>
<ac:sequential>
<copy todir="@{dir}">
<fileset dir="." includes="build.xml"/>
</copy>
</ac:sequential>
</ac:for>
</target>
</project>
Peter
On 2/13/07, Camer38 <[EMAIL PROTECTED]> wrote:
>
> Ok, let me take a deep look...
>
>
> Jan.Materne wrote:
> >
> >>Thanks for a quick answer.
> >>Could you be more elaborative and deliver more complex example, please.
> >>At this moment I have a very brief idea how to use antcontrib
> >
> >
> > Not without more information. Have you played with that code?
> >
> >
> > Jan
> >
> >
> >>
> >>Thanks in advance - I relay appreciate you help.
> >>
> >>Marcin
> >>
> >>
> >>Jan.Materne wrote:
> >>>
> >>> Quickshot ...
> >>>
> >>> <antcontrib:for param="todir">
> >>> <!-- specify the target directories -->
> >>> <dirset/>
> >>> <sequential>
> >>> <copy todir="@{todir}">
> >>> <!-- specify the files to copy -->
> >>> <fileset/>
> >>> </copy>
> >>> </sequential>
> >>> </antcontrib:for>
> >>>
> >>>
> >>> AFAIK there is no build-in way, so you have to iterate for your own.
> >>>
> >>>
> >>> Jan
> >>>
> >>>
> >>>
> >>>>-----Ursprüngliche Nachricht-----
> >>>>Von: Camer38 [mailto:[EMAIL PROTECTED]
> >>>>Gesendet: Dienstag, 13. Februar 2007 17:30
> >>>>An: [email protected]
> >>>>Betreff: Copy a single file to directories
> >>>>
> >>>>
> >>>>Hi,
> >>>>
> >>>>I would like to copy a single file to multiply directories.
> >>>>Every time the structure of folders may vary.
> >>>>One file has to be copy into every catalog under ./test/components
> >>>>
> >>>>Any idea?
> >>>>
> >>>>Thanks in advance
> >>>>Marcin
> >>>>--
> >>>>View this message in context:
> >>>>http://www.nabble.com/Copy-a-single-file-to-directories-tf32216
> >>>>51.html#a8947606
> >>>>Sent from the Ant - Users mailing list archive at Nabble.com.
> >>>>
> >>>>
> >>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>>>For additional commands, e-mail: [EMAIL PROTECTED]
> >>>>
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>> For additional commands, e-mail: [EMAIL PROTECTED]
> >>>
> >>>
> >>>
> >>
> >>--
> >>View this message in context:
> >>http://www.nabble.com/Copy-a-single-file-to-directories-tf32216
> >>51.html#a8948408
> >>Sent from the Ant - Users mailing list archive at Nabble.com.
> >>
> >>
> >>---------------------------------------------------------------------
> >>To unsubscribe, e-mail: [EMAIL PROTECTED]
> >>For additional commands, e-mail: [EMAIL PROTECTED]
> >>
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Copy-a-single-file-to-directories-tf3221651.html#a8948784
> Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]