You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by um...@apache.org on 2002/02/03 23:23:37 UTC
cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TarTest.java
umagesh 02/02/03 14:23:37
Modified: docs/manual/CoreTasks tar.html
src/etc/testcases/taskdefs tar.xml
src/main/org/apache/tools/ant/taskdefs Tar.java
src/testcases/org/apache/tools/ant/taskdefs TarTest.java
Log:
Prefix attirubte for tar task
PR: 6054
Submitted by: mail@stefanheimann.net (Stefan Heimann)
Revision Changes Path
1.14 +36 -30 jakarta-ant/docs/manual/CoreTasks/tar.html
Index: tar.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/tar.html,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- tar.html 3 Feb 2002 22:00:42 -0000 1.13
+++ tar.html 3 Feb 2002 22:23:37 -0000 1.14
@@ -12,36 +12,36 @@
<p>Creates a tar archive.</p>
<p>The <i>basedir</i> attribute is the reference directory from where to tar.</p>
<p>This task is a <a href="../dirtasks.html#directorybasedtasks">directory based task</a>
-and, as such, forms an implicit <a href="../CoreTypes/fileset.html">Fileset</a>. This
+and, as such, forms an implicit <a href="../CoreTypes/fileset.html">Fileset</a>. This
defines which files, relative to the <i>basedir</i>, 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.</p>
<p>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.</p>
-<p>Early versions of tar did not support path lengths greater than 100
+<p>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 <i>longfile</i> attribute.
-If the longfile attribute is set to <code>fail</code>, any long paths will
-cause the tar task to fail. If the longfile attribute is set to
-<code>truncate</code>, 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 <code>omit</code> 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 <code>gnu</code>. 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 <code>warn</code> 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 <i>longfile</i> attribute.
+If the longfile attribute is set to <code>fail</code>, any long paths will
+cause the tar task to fail. If the longfile attribute is set to
+<code>truncate</code>, 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 <code>omit</code> 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 <code>gnu</code>. 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 <code>warn</code> which behaves just like the gnu option except
+that it produces a warning for each file path encountered that does not match
the limit.</p>
-<p>Note that this task does not perform compression. You might want to use the
+<p>Note that this task does not perform compression. You might want to use the
<a href="gzip.html">GZip</a> task to prepare a .tar.gz package.</p>
<h3>Parameters</h3>
@@ -63,9 +63,9 @@
</tr>
<tr>
<td valign="top">longfile</td>
- <td valign="top">Determines how long files (>100 chars) are to be
- handled. Allowable values are "truncate", "fail",
- "warn", "omit" and "gnu". Default is
+ <td valign="top">Determines how long files (>100 chars) are to be
+ handled. Allowable values are "truncate", "fail",
+ "warn", "omit" and "gnu". Default is
"warn".</td>
<td valign="top" align="center">No</td>
</tr>
@@ -114,22 +114,28 @@
</tr>
<tr>
<td valign="top">mode</td>
- <td valign="top">An 3 digit octal string, specify the user, group and other modes in
+ <td valign="top">An 3 digit octal string, specify the user, group and other modes in
the standard Unix fashion</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">username</td>
- <td valign="top">The username for the tar entry. This is not the same as the UID, which is
+ <td valign="top">The username for the tar entry. This is not the same as the UID, which is
not currently set by the tar task.</td>
<td align="center" valign="top">No</td>
</tr>
<tr>
<td valign="top">group</td>
- <td valign="top">The groupname for the tar entry. This is not the same as the GID, which is
+ <td valign="top">The groupname for the tar entry. This is not the same as the GID, which is
not currently set by the tar task.</td>
<td align="center" valign="top">No</td>
</tr>
+ <tr>
+ <td valign="top">prefix</td>
+ <td valign="top">If the prefix attribute is set, all files in the fileset
+ are prefixed with that path in the archive.</td>
+ <td align="center" valign="top">No</td>
+ </tr>
</table>
<h3>Examples</h3>
@@ -151,8 +157,8 @@
<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 @@
the executable files and include all others. </p>
<p><strong>Note: </strong> 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.</p>
<p><strong>Note:</strong> The patterns in the include and exclude
@@ -177,7 +183,7 @@
to <code>${dist.name}/..</code>.</p>
<hr>
-<p align="center">Copyright © 2001 Apache Software Foundation. All rights
+<p align="center">Copyright © 2001-2002 Apache Software Foundation. All rights
Reserved.</p>
</body>
1.8 +16 -0 jakarta-ant/src/etc/testcases/taskdefs/tar.xml
Index: tar.xml
===================================================================
RCS file: /home/cvs/jakarta-ant/src/etc/testcases/taskdefs/tar.xml,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- tar.xml 1 Feb 2002 07:34:34 -0000 1.7
+++ tar.xml 3 Feb 2002 22:23:37 -0000 1.8
@@ -31,11 +31,27 @@
<tar destfile="blah" longfile="Foo"/>
</target>
+ <target name="test7">
+ <mkdir dir="test7dir"/>
+ <tar destfile="test7.tar">
+ <tarfileset dir="." prefix="test7-prefix/">
+ <include name="test7dir"/>
+ </tarfileset>
+ <tarfileset dir="." prefix="">
+ <include name="test7dir"/>
+ </tarfileset>
+ </tar>
+ <untar src="test7.tar" dest="."/>
+ </target>
+
<target name="cleanup">
<delete file="test4.tar"/>
<delete file="test5.tar"/>
<delete file="asf-logo.gif.tar"/>
<delete dir="test5dir"/>
+ <delete dir="test7dir"/>
+ <delete dir="test7-prefix"/>
+ <delete file="test7.tar"/>
</target>
<target name="feather">
1.23 +16 -3 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java
Index: Tar.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Tar.java,v
retrieving revision 1.22
retrieving revision 1.23
diff -u -r1.22 -r1.23
--- Tar.java 1 Feb 2002 07:34:34 -0000 1.22
+++ Tar.java 3 Feb 2002 22:23:37 -0000 1.23
@@ -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 @@
}
}
- 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 @@
private String userName = "";
private String groupName = "";
-
+ private String prefix = "";
public TarFileSet(FileSet fileset) {
super(fileset);
@@ -417,6 +423,13 @@
return groupName;
}
+ public void setPrefix(String prefix) {
+ this.prefix = prefix;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
}
/**
1.8 +18 -1 jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java
Index: TarTest.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs/TarTest.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- TarTest.java 10 Jan 2002 10:13:12 -0000 1.7
+++ TarTest.java 3 Feb 2002 22:23:37 -0000 1.8
@@ -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
@@ -96,6 +96,23 @@
public void test6() {
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() {
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>