Of course it can be done using exec task, but my question is: Is it possible to do it with tar task?
I don't think there is a way to retain existing permissions, per this note from the copy task:
Unix Note: File permissions are not retained when files are copied; they end up with the default UMASK permissions instead. This is caused by the lack of any means to query or set file permissions in the current Java runtimes. If you need a permission-preserving copy function, use
<exec executable="cp" ... >
instead.
However the tar task can take one or more tarfileset
elements. The tarfileset
can be defined with a filemode
and/or dirmode
attribute to specify the unix permissions. If you specify multiple includes matching only those files to get each set of required permissions, the files in that set will be included with those permissions.
This lack of permission makes ant tar task almost useless for me. My solution is to execute the operating system tar with the exec task:
<exec executable="tar" output="/dev/null" os="Linux">
<arg value="--exclude-from=files_to_exclude.txt"/>
<arg value="-cvz"/>
<arg value="--file=${file.tar}"/>
<arg value="."/>
</exec>