Return-Path: Delivered-To: apmail-jakarta-ant-dev-archive@apache.org Received: (qmail 68515 invoked from network); 4 Feb 2002 20:44:23 -0000 Received: from unknown (HELO nagoya.betaversion.org) (192.18.49.131) by daedalus.apache.org with SMTP; 4 Feb 2002 20:44:23 -0000 Received: (qmail 23524 invoked by uid 97); 4 Feb 2002 20:44:23 -0000 Delivered-To: qmlist-jakarta-archive-ant-dev@jakarta.apache.org Received: (qmail 23469 invoked by uid 97); 4 Feb 2002 20:44:22 -0000 Mailing-List: contact ant-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list ant-dev@jakarta.apache.org Received: (qmail 23458 invoked by uid 97); 4 Feb 2002 20:44:22 -0000 Date: 4 Feb 2002 20:44:17 -0000 Message-ID: <20020204204417.29897.qmail@icarus.apache.org> From: umagesh@apache.org To: jakarta-ant-cvs@apache.org Subject: cvs commit: jakarta-ant/src/testcases/org/apache/tools/ant/taskdefs TarTest.java X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N umagesh 02/02/04 12:44:17 Modified: . WHATSNEW 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: New attributes to tarfileset to allow equivalent of tar -P option PR: 5874 Submitted by: Stefan Heimann (mail@stefanheimann.net) Revision Changes Path 1.204 +3 -0 jakarta-ant/WHATSNEW Index: WHATSNEW =================================================================== RCS file: /home/cvs/jakarta-ant/WHATSNEW,v retrieving revision 1.203 retrieving revision 1.204 diff -u -r1.203 -r1.204 --- WHATSNEW 3 Feb 2002 01:53:34 -0000 1.203 +++ WHATSNEW 4 Feb 2002 20:44:16 -0000 1.204 @@ -70,6 +70,9 @@ Other changes: -------------- +* TarFileset takes in three new attributes - fullpath, prefix + and preserveLeadingSlashes. + * attempts to rename the directory, if everything inside it is included, before performing file-by-file moves. This attempt will be done only if filtering is off and if mappers are not used. This 1.9 +11 -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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- tar.xml 3 Feb 2002 22:23:37 -0000 1.8 +++ tar.xml 4 Feb 2002 20:44:16 -0000 1.9 @@ -44,6 +44,15 @@ + + + + + + + + + @@ -52,6 +61,8 @@ + + 1.24 +50 -13 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.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- Tar.java 3 Feb 2002 22:23:37 -0000 1.23 +++ Tar.java 4 Feb 2002 20:44:16 -0000 1.24 @@ -265,6 +265,10 @@ for (Enumeration e = filesets.elements(); e.hasMoreElements();) { TarFileSet fs = (TarFileSet)e.nextElement(); String[] files = fs.getFiles(project); + if (files.length > 1 && fs.getFullpath().length() > 0) { + throw new BuildException("fullpath attribute may only be specified for " + + "filesets that specify a single file."); + } for (int i = 0; i < files.length; i++) { File f = new File(fs.getDir(project), files[i]); String name = files[i].replace(File.separatorChar,'/'); @@ -291,13 +295,34 @@ { FileInputStream fIn = null; - // don't add "" to the archive - if (vPath.length() <= 0) { - return; + String fullpath = tarFileSet.getFullpath(); + if (fullpath.length() > 0) { + vPath = fullpath; + } else { + // don't add "" to the archive + if (vPath.length() <= 0) { + return; + } + + if (file.isDirectory() && !vPath.endsWith("/")) { + vPath += "/"; + } + + String prefix = tarFileSet.getPrefix(); + // '/' is appended for compatibility with the zip task. + if (prefix.length() > 0 && !prefix.endsWith("/")) { + prefix = prefix + "/"; + } + vPath = prefix + vPath; } - if (file.isDirectory() && !vPath.endsWith("/")) { - vPath += "/"; + if (vPath.startsWith("/") && !tarFileSet.getPreserveLeadingSlashes()) { + int l = vPath.length(); + if (l <= 1) { + // we would end up adding "" to the archive + return; + } + vPath = vPath.substring(1, l); } try { @@ -320,13 +345,7 @@ } } - 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); + TarEntry te = new TarEntry(vPath); te.setModTime(file.lastModified()); if (!file.isDirectory()) { te.setSize(file.length()); @@ -371,7 +390,9 @@ private String userName = ""; private String groupName = ""; private String prefix = ""; - + private String fullpath = ""; + private boolean preserveLeadingSlashes = false; + public TarFileSet(FileSet fileset) { super(fileset); } @@ -429,6 +450,22 @@ public String getPrefix() { return prefix; + } + + public void setFullpath(String fullpath) { + this.fullpath = fullpath; + } + + public String getFullpath() { + return fullpath; + } + + public void setPreserveLeadingSlashes(boolean b) { + this.preserveLeadingSlashes = b; + } + + public boolean getPreserveLeadingSlashes() { + return preserveLeadingSlashes; } } 1.9 +9 -0 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.8 retrieving revision 1.9 diff -u -r1.8 -r1.9 --- TarTest.java 3 Feb 2002 22:23:37 -0000 1.8 +++ TarTest.java 4 Feb 2002 20:44:16 -0000 1.9 @@ -115,6 +115,15 @@ } } + public void test8() { + executeTarget("test8"); + java.io.File f1 + = new java.io.File("src/etc/testcases/taskdefs/test8.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + public void tearDown() { executeTarget("cleanup"); } -- To unsubscribe, e-mail: For additional commands, e-mail: