Ant: copy the same set of files to multiple locations - continued

My question is to continue this topic: Ant: copy the same set of files to several places

I am new to mappers. Can anyone (care?) Kindly share an example of using mapper for this? Here is what I am trying to do:

  parent_folder
     | ---- child1_folder
     |  | ---- files
     |  | ---- config.file
     |  | ---- data.txt
     | ---- child2_folder
     | ---- child3_folder
     .
     .
     .
     | ---- childn_folder

I have no way to use ant -contrib (sorry ... the location of ant or any taskdesf is not under my control). Therefore, I do not know how to overlap an indefinite number of folders.

Limitations on me:

  • I only know the name of child1_folder (I don't know the names of other children)
  • The number of other children is not determined.
  • I expect to create a files folder under each child folder (through another task, if not copied).

Here is what I tried (currently trying to create one file, it will expand with additional cards as soon as it starts working):

 <copy todir="/tmp/parent_folder" verbose="true"> <fileset dir="/tmp/parent_folder"> <include name="*/files/config.file"/> </fileset> <mapper type="glob" from="*/files/config.file" to="*/files/config.file"/> </copy> 

He continues to say skipped - don't know how to handle it , followed by No sources found. .

Thanks in advance, Parag Doke

Another (maybe?) Question: Using mapper and a set of files to copy files to another subdirectory?

+6
source share
1 answer

Here is an example of one way. Key features are the use of enablemultiplemappings in the copy task and scriptmapper to handle iterations over the target directories. The mapping chain is used so that the source provided to the script mapper is just a file to be copied relative to the target directory.

 <property name="src.dir" value="child1_folder" /> <dirset dir="parent_folder" id="target.dirs"> <include name="*" /> <exclude name="${src.dir}" /> </dirset> <copy todir="parent_folder" enablemultiplemappings="yes"> <fileset dir="parent_folder"> <include name="${src.dir}/**"/> </fileset> <chainedmapper> <globmapper from="${src.dir}/*" to="*" /> <scriptmapper language="javascript"> <![CDATA[ // Obtain a reference to the dirset var dirSet = project.getReference( "target.dirs" ); // Now get matching dirs. var ds = dirSet.getDirectoryScanner( project ); var includes = ds.getIncludedDirectories( ); for ( var i = 0; i < includes.length; i++ ) { self.addMappedName( includes[i] + "/" + source ); } ]]> </scriptmapper> </chainedmapper> </copy> 

Malite mappings in the copy task have been in Ant since version 1.6.

+3
source

Source: https://habr.com/ru/post/888980/


All Articles