Ant: copy the same fileset to multiple places - continued

My question is in continuation of this thread: Ant: copy the same fileset to multiple places

I am new to mappers. Can someone (carej?) kindly share an example of using the mapper to do this ? Here is what I am trying for:

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

I don't have the option to use ant-contrib (sorry ... the ant location or any taskdesf isn't under my control). So I don't know how to loop over the uncertain number of folders.

Restrictions on me:

  1. I only know the name of child1_folder (don't know names of the other children)
  2. Number of other children is uncertain
  3. I am expected to create the files folder under each child folder (via another task, if not copy).

Here is what I was trying for (currently trying for a single file, will extend with additional mappers once this starts to work):

<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>

It keeps saying skipped - don't know how to handle it followed by No sources found..

Thanks in advance, Parag Doke

Another (possibly?) related question: Using mapper & fileset to copy files into a different subdirectory ?

Answers


Here's an example of one way. The key features are the use of enablemultiplemappings in the copy task, and a scriptmapper to deal with iterating over the target directories. A mapper chain is used to make the source that is provided to the scriptmapper be just the path of the 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>

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


Need Your Help

Handling the key collision in Hashmap

java collections hashtable

The code I found for Hashmap's put(K key, V value). This method replaces the value if collision occured, it doesn't add the Entry to the LinkedList of the bucket.

How do I use ng-filter without changing $index on ng-repeat?

angularjs angularjs-ng-repeat angularjs-filter

Currently if I filter, the $index also updates. So if there are 500 results, and I filter the ranking, also updates. How do I have an index column that doesn't update?

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.