开发者

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" ve开发者_如何学运维rbose="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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜