Ant: copy the same fileset to multiple places

前端 未结 3 1556
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-29 21:49

I need an Ant script that will copy one folder to several other places. As a good obedient programmer, I want not to repeat myself. Is there any way of taking a fileset like

相关标签:
3条回答
  • 2020-12-29 22:19

    Rich's answer is probably better for your specific problem, but the generic way of reusing code in Ant is a <macrodef>.

    <macrodef name="copythings">
      <attribute name="todir"/>
      <sequential>
        <copy todir="@{todir}">
          <fileset dir="${src}">
            <exclude name='**/*svn' />
          </fileset>
        </copy>
      </sequential>
    </macrodef>
    
    <copythings todir="/path/to/target1"/>
    <copythings todir="/path/to/target2"/>
    
    0 讨论(0)
  • 2020-12-29 22:34

    Upvoted first answer already, but you can also use a mapper to copy to multiple destinations.

    0 讨论(0)
  • 2020-12-29 22:43

    Declare an id attribute on the fileset and then reference it in each copy task.

    For example:

    <project name="foo">
      <fileset id="myFileSet" dir="${src}">
        <exclude name='**/*svn' />
      </fileset>
      ...
      <target name="copy1">
        <copy todir="${target}/path/to/target/1">
          <fileset refid="myFileSet"/>
        </copy>
      </target>
      <target name="copy2">
        <copy todir="${target}/path/to/target/2">
          <fileset refid="myFileSet"/>
        </copy>
      </target>
    </project>
    
    0 讨论(0)
提交回复
热议问题