Cari di Apache Ant 
    Apache Ant User Manual
Daftar Isi
(Sebelumnya) SyncTaskdef (Berikutnya)
Apache Ant Tasks

Tar

Tar

Description

Creates a tar archive.

The basedir attribute is the reference directory from where to tar.

This task is a directory based taskand, as such, forms an implicit Fileset. Thisdefines which files, relative to the basedir, will be included in thearchive. The tar task supports all the attributes of Fileset to refine theset of files to be included in the implicit fileset.

In addition to the implicit fileset, the tar task supports nested resource collections and a special form of filesets. Thesefilesets are extended to allow control over the access mode, username and groupnameto be applied to the tar entries. This is useful, for example, when preparing archives for Unix systems where some files need to have execute permission. By default this task will use Unix permissions of 644 for files and 755 for directories.

Early versions of tar did not support path lengths greater than 100characters. Modern versions of tar do so, but in incompatible ways.The behaviour of the tar task when it encounters such paths iscontrolled by the longfile attribute.If the longfile attribute is set to fail, any long paths willcause the tar task to fail. If the longfile attribute is set totruncate, any long paths will be truncated to the 100 charactermaximum length prior to adding to the archive. If the value of the longfileattribute is set to omit then files containing long paths will beomitted from the archive. Either option ensures that the archive can beuntarred by any compliant version of tar. If the loss of path or fileinformation is not acceptable, and it rarely is, longfile may be set to thevalue gnu. The tar task will then produce a GNU tar file whichcan have arbitrary length paths. Note however, that the resulting archive willonly be able to be untarred with GNU tar. The default for the longfileattribute is warn which behaves just like the gnu option exceptthat it produces a warning for each file path encountered that does not matchthe limit.

This task can perform compression by setting the compression attribute to "gzip"or "bzip2".

Parameters

Attribute Description Required
destfile the tar-file to create. Yes
basedir the directory from which to tar the files. No
longfile Determines how long files (>100 chars) are to be handled. Allowable values are "truncate", "fail", "warn", "omit" and "gnu". Default is "warn". No
includes comma- or space-separated list of patterns of files that must be included. All files are included when omitted. No
includesfile the name of a file. Each line of this file is taken to be an include pattern No
excludes comma- or space-separated list of patterns of files that must be excluded. No files (except default excludes) are excluded when omitted. No
excludesfile the name of a file. Each line of this file is taken to be an exclude pattern No
defaultexcludes indicates whether default excludes should be used or not ("yes"/"no"). Default excludes are used when omitted. No
compression compression method. Allowable values are "none", "gzip" and "bzip2". Default is "none". No

Nested Elements

The tar task supports nested tarfileset elements. These areextended FileSets which,in addition to the standard elements, support one additionalattributes
Attribute Description Required
preserveLeadingSlashes Indicates whether leading `/'s should be preserved in the file names. Default is false. No

any other resource collection

ResourceCollections are used to select groups of files to archive.

Prior to Apache Ant 1.7 only <fileset> has beensupported as a nested element.

Examples

<tar destfile="${dist}/manual.tar" basedir="htdocs/manual"/><gzip destfile="${dist}/manual.tar.gz" src="${dist}/manual.tar"/>

tars all files in the htdocs/manual directory into a file called manual.tarin the ${dist} directory, then applies the gzip task to compressit.

<tar destfile="${dist}/manual.tar" basedir="htdocs/manual" excludes="mydocs/**, **/todo.html"/>

tars all files in the htdocs/manual directory into a file called manual.tarin the ${dist} directory. Files in the directory mydocs,or files with the name todo.html are excluded.

<tar destfile="${basedir}/docs.tar">  <tarfileset dir="${dir.src}/docs"  fullpath="/usr/doc/ant/README"  preserveLeadingSlashes="true"> <include name="readme.txt"/>  </tarfileset>  <tarfileset dir="${dir.src}/docs"  prefix="/usr/doc/ant"  preserveLeadingSlashes="true"> <include name="*.html"/>  </tarfileset></tar>

Writes the file docs/readme.txt as /usr/doc/ant/README into the archive. All *.html files in the docs directory are prefixed by /usr/doc/ant, so for example docs/index.html is written as /usr/doc/ant/index.html to the archive.

<tar longfile="gnu" destfile="${dist.base}/${dist.name}-src.tar">  <tarfileset dir="${dist.name}/.." filemode="755" username="ant" group="ant"> <include name="${dist.name}/bootstrap.sh"/> <include name="${dist.name}/build.sh"/>  </tarfileset>  <tarfileset dir="${dist.name}/.." username="ant" group="ant"> <include name="${dist.name}/**"/> <exclude name="${dist.name}/bootstrap.sh"/> <exclude name="${dist.name}/build.sh"/>  </tarfileset></tar>

This example shows building a tar which uses the GNU extensions for long paths andwhere some files need to be marked as executable (mode 755)and the rest are use the default mode (read-write by owner). The firstfileset selects just the executable files. The second fileset must excludethe executable files and include all others.

Note: The tar task does not ensure that a file is only selectedby one resource collection. If the same file is selected by more than one collection, it will be included in thetar file twice, with the same path.

Note: The patterns in the include and excludeelements are considered to be relative to the corresponding dirattribute as with all other filesets. In the example above,${dist.name} is not an absolute path, but a simple nameof a directory, so ${dist.name} is a valid path relativeto ${dist.name}/...

<tar destfile="release.tar.gz" compression="gzip">  <zipfileset src="release.zip"/></tar>

Re-packages a ZIP archive as a GZip compressed tar archive. IfUnix file permissions have been stored as part of the ZIP file, theywill be retained in the resulting tar archive.

Note: Please note the tar task creates a tar file, it does not append to an existing tar file. The existing tar file is replaced instead. As with most tasks in Ant, the task only takes action if the output file (the tar file in this case) is older than the input files, or if the output file does not exist.

(Sebelumnya) SyncTaskdef (Berikutnya)