antcopyexecutecpfileset

ANT - How to copy a group of files maintaining the Linux permissions


I need to copy a group of files with ant. Unfortunately I can't use the target "copy" because it loses the Linux file permissions. So must use the target "execute" "cp" . How can I pass a group of file to the execute cp target? I know that I have to use a fileset but in which manner I can pass a fileset as argument of the execute cp target?


Solution

  • You can't pass filesets to operating system commands. The best you can do is use the apply task to invoke the "cp" command on each file as follows:

      <apply executable="cp">
         <srcfile/>
         <targetfile/>
         <fileset dir="src" includes="*.txt"/>
         <globmapper from="*.txt" to="output/*.txt"/>
      </apply>
    

    But, I don't really understand why you couldn't combine the copy task with chmod, it would be most efficient:

    <copy todir="output">
      <fileset dir="src" includes="*.txt"/>
    </copy>
    
    <chmod perm="700">
      <fileset dir="output" includes="*.txt"/>
    </chmod>