From 786e2e2e1cf34805da69f13fa1d7dd06da1a1454 Mon Sep 17 00:00:00 2001 From: Magesh Umasankar Date: Sun, 3 Feb 2002 22:23:37 +0000 Subject: [PATCH] Prefix attirubte for tar task PR: 6054 Submitted by: mail@stefanheimann.net (Stefan Heimann) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271134 13f79535-47bb-0310-9956-ffa450edef68 --- docs/manual/CoreTasks/tar.html | 66 ++++++++++--------- src/etc/testcases/taskdefs/tar.xml | 16 +++++ .../org/apache/tools/ant/taskdefs/Tar.java | 19 +++++- .../apache/tools/ant/taskdefs/TarTest.java | 19 +++++- 4 files changed, 86 insertions(+), 34 deletions(-) diff --git a/docs/manual/CoreTasks/tar.html b/docs/manual/CoreTasks/tar.html index 49125f470..e8359f21a 100644 --- a/docs/manual/CoreTasks/tar.html +++ b/docs/manual/CoreTasks/tar.html @@ -12,36 +12,36 @@

Creates a tar archive.

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

This task is a directory based task -and, as such, forms an implicit Fileset. This +and, as such, forms an implicit Fileset. This defines which files, relative to the basedir, will be included in the archive. The tar task supports all the attributes of Fileset to refine the set of files to be included in the implicit fileset.

In addition to the implicit fileset, the tar task supports nested filesets. These -filesets are extended to allow control over the access mode, username and groupname -to be applied to the tar entries. This is useful, for example, when preparing archives for +filesets are extended to allow control over the access mode, username and groupname +to 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.

-

Early versions of tar did not support path lengths greater than 100 +

Early versions of tar did not support path lengths greater than 100 characters. Modern versions of tar do so, but in incompatible ways. -The behaviour of the tar task when it encounters such paths is -controlled by the longfile attribute. -If the longfile attribute is set to fail, any long paths will -cause the tar task to fail. If the longfile attribute is set to -truncate, any long paths will be truncated to the 100 character -maximum length prior to adding to the archive. If the value of the longfile -attribute is set to omit then files containing long paths will be -omitted from the archive. Either option ensures that the archive can be -untarred by any compliant version of tar. If the loss of path or file -information is not acceptable, and it rarely is, longfile may be set to the -value gnu. The tar task will then produce a GNU tar file which -can have arbitrary length paths. Note however, that the resulting archive will -only be able to be untarred with GNU tar. The default for the longfile -attribute is warn which behaves just like the gnu option except -that it produces a warning for each file path encountered that does not match +The behaviour of the tar task when it encounters such paths is +controlled by the longfile attribute. +If the longfile attribute is set to fail, any long paths will +cause the tar task to fail. If the longfile attribute is set to +truncate, any long paths will be truncated to the 100 character +maximum length prior to adding to the archive. If the value of the longfile +attribute is set to omit then files containing long paths will be +omitted from the archive. Either option ensures that the archive can be +untarred by any compliant version of tar. If the loss of path or file +information is not acceptable, and it rarely is, longfile may be set to the +value gnu. The tar task will then produce a GNU tar file which +can have arbitrary length paths. Note however, that the resulting archive will +only be able to be untarred with GNU tar. The default for the longfile +attribute is warn which behaves just like the gnu option except +that it produces a warning for each file path encountered that does not match the limit.

-

Note that this task does not perform compression. You might want to use the +

Note that this task does not perform compression. You might want to use the GZip task to prepare a .tar.gz package.

Parameters

@@ -63,9 +63,9 @@ the limit.

longfile - Determines how long files (>100 chars) are to be - handled. Allowable values are "truncate", "fail", - "warn", "omit" and "gnu". Default is + Determines how long files (>100 chars) are to be + handled. Allowable values are "truncate", "fail", + "warn", "omit" and "gnu". Default is "warn". No @@ -114,22 +114,28 @@ attributes mode - An 3 digit octal string, specify the user, group and other modes in + An 3 digit octal string, specify the user, group and other modes in the standard Unix fashion No username - The username for the tar entry. This is not the same as the UID, which is + The username for the tar entry. This is not the same as the UID, which is not currently set by the tar task. No group - The groupname for the tar entry. This is not the same as the GID, which is + The groupname for the tar entry. This is not the same as the GID, which is not currently set by the tar task. No + + prefix + If the prefix attribute is set, all files in the fileset + are prefixed with that path in the archive. + No +

Examples

@@ -151,8 +157,8 @@ or files with the name todo.html are excluded.

<tarfileset dir="${dist.name}/.." mode="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"> + </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"/> @@ -166,7 +172,7 @@ fileset selects just the executable files. The second fileset must exclude the executable files and include all others.

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

Note: The patterns in the include and exclude @@ -177,7 +183,7 @@ of a directory, so ${dist.name} is a valid path relative to ${dist.name}/...


-

Copyright © 2001 Apache Software Foundation. All rights +

Copyright © 2001-2002 Apache Software Foundation. All rights Reserved.

diff --git a/src/etc/testcases/taskdefs/tar.xml b/src/etc/testcases/taskdefs/tar.xml index ea31a9a85..ef8f0635c 100644 --- a/src/etc/testcases/taskdefs/tar.xml +++ b/src/etc/testcases/taskdefs/tar.xml @@ -31,11 +31,27 @@ + + + + + + + + + + + + + + + + diff --git a/src/main/org/apache/tools/ant/taskdefs/Tar.java b/src/main/org/apache/tools/ant/taskdefs/Tar.java index 15d35b492..4f80deff8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Tar.java +++ b/src/main/org/apache/tools/ant/taskdefs/Tar.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -320,7 +320,13 @@ public class Tar extends MatchingTask { } } - TarEntry te = new TarEntry(vPath); + String prefix = tarFileSet.getPrefix(); + // '/' is appended for compatibility with the zip task. + if(prefix.length() > 0 && !prefix.endsWith("/")) { + prefix = prefix + "/"; + } + + TarEntry te = new TarEntry(prefix + vPath); te.setModTime(file.lastModified()); if (!file.isDirectory()) { te.setSize(file.length()); @@ -364,7 +370,7 @@ public class Tar extends MatchingTask { private String userName = ""; private String groupName = ""; - + private String prefix = ""; public TarFileSet(FileSet fileset) { super(fileset); @@ -417,6 +423,13 @@ public class Tar extends MatchingTask { return groupName; } + public void setPrefix(String prefix) { + this.prefix = prefix; + } + + public String getPrefix() { + return prefix; + } } /** diff --git a/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java b/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java index d10041c8a..5ebcccae8 100644 --- a/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java +++ b/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java @@ -1,7 +1,7 @@ /* * The Apache Software License, Version 1.1 * - * Copyright (c) 2000-2001 The Apache Software Foundation. All rights + * Copyright (c) 2000-2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without @@ -98,6 +98,23 @@ public class TarTest extends BuildFileTest { expectBuildException("test6", "Invalid value specified for longfile attribute."); } + public void test7() { + executeTarget("test7"); + java.io.File f1 + = new java.io.File("src/etc/testcases/taskdefs/test7-prefix"); + + if (!(f1.exists() && f1.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + + java.io.File f2 + = new java.io.File("src/etc/testcases/taskdefs/test7dir"); + + if (!(f2.exists() && f2.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + } + public void tearDown() { executeTarget("cleanup"); }