Return-Path: Delivered-To: apmail-ant-notifications-archive@minotaur.apache.org Received: (qmail 57787 invoked from network); 16 Aug 2009 05:34:21 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 16 Aug 2009 05:34:21 -0000 Received: (qmail 40078 invoked by uid 500); 16 Aug 2009 05:34:28 -0000 Delivered-To: apmail-ant-notifications-archive@ant.apache.org Received: (qmail 40006 invoked by uid 500); 16 Aug 2009 05:34:28 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 39996 invoked by uid 99); 16 Aug 2009 05:34:28 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Aug 2009 05:34:28 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 16 Aug 2009 05:34:24 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B6E9B238889D; Sun, 16 Aug 2009 05:34:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r804624 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/ main/org/apache/ant/compress/taskdefs/ tests/antunit/ Date: Sun, 16 Aug 2009 05:34:02 -0000 To: notifications@ant.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090816053402.B6E9B238889D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Sun Aug 16 05:34:02 2009 New Revision: 804624 URL: http://svn.apache.org/viewvc?rev=804624&view=rev Log: tiny refactoring plus ar task Added: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java (contents, props changed) - copied, changed from r804622, ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=804624&r1=804623&r2=804624&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml (original) +++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Sun Aug 16 05:34:02 2009 @@ -33,6 +33,10 @@ classname="org.apache.ant.compress.taskdefs.Unzip" /> + Copied: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java (from r804622, ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java) URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java&p1=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java&r1=804622&r2=804624&rev=804624&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java (original) +++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java Sun Aug 16 05:34:02 2009 @@ -18,63 +18,59 @@ package org.apache.ant.compress.taskdefs; -import org.apache.ant.compress.util.TarStreamFactory; +import org.apache.ant.compress.util.ArStreamFactory; import org.apache.commons.compress.archivers.ArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarArchiveEntry; -import org.apache.commons.compress.archivers.tar.TarConstants; +import org.apache.commons.compress.archivers.ar.ArArchiveEntry; +import org.apache.tools.ant.BuildException; /** * Creates tar archives. */ -public class Tar extends ArchiveBase { - public Tar() { - super(new TarStreamFactory(), +public class Ar extends ArchiveBase { + /** stolen from ArEntry */ + private static final int DEFAULT_MODE = 33188; + + public Ar() { + super(new ArStreamFactory(), new ArchiveBase.EntryBuilder() { - public ArchiveEntry buildEntry(String name, - ArchiveBase.ResourceWithFlags r) { + public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) { boolean isDir = r.getResource().isDirectory(); - TarArchiveEntry ent = - new TarArchiveEntry(name, - isDir ? TarConstants.LF_DIR - : TarConstants.LF_NORMAL); - ent.setModTime(r.getResource().getLastModified()); - ent.setSize(isDir ? 0 : r.getResource().getSize()); + if (isDir) { + // REVISIT + throw new BuildException("ar archives cannot store" + + " directory entries"); + } + int mode = DEFAULT_MODE; if (r.getResourceFlags().hasModeBeenSet()) { - ent.setMode(r.getResourceFlags().getMode()); + mode = r.getResourceFlags().getMode(); } else if (!isDir && r.getCollectionFlags().hasModeBeenSet()) { - ent.setMode(r.getCollectionFlags().getMode()); + mode = r.getCollectionFlags().getMode(); } else if (isDir && r.getCollectionFlags().hasDirModeBeenSet()) { - ent.setMode(r.getCollectionFlags().getDirMode()); + mode = r.getCollectionFlags().getDirMode(); } + int uid = 0; if (r.getResourceFlags().hasUserIdBeenSet()) { - ent.setUserId(r.getResourceFlags().getUserId()); + uid = r.getResourceFlags().getUserId(); } else if (r.getCollectionFlags().hasUserIdBeenSet()) { - ent.setUserId(r.getCollectionFlags().getUserId()); + uid = r.getCollectionFlags().getUserId(); } + int gid = 0; if (r.getResourceFlags().hasGroupIdBeenSet()) { - ent.setGroupId(r.getResourceFlags().getGroupId()); + gid = r.getResourceFlags().getGroupId(); } else if (r.getCollectionFlags().hasGroupIdBeenSet()) { - ent.setGroupId(r.getCollectionFlags().getGroupId()); - } - - if (r.getResourceFlags().hasUserNameBeenSet()) { - ent.setUserName(r.getResourceFlags().getUserName()); - } else if (r.getCollectionFlags().hasUserNameBeenSet()) { - ent.setUserName(r.getCollectionFlags().getUserName()); + gid = r.getCollectionFlags().getGroupId(); } - if (r.getResourceFlags().hasGroupNameBeenSet()) { - ent.setGroupName(r.getResourceFlags().getGroupName()); - } else if (r.getCollectionFlags().hasGroupNameBeenSet()) { - ent.setGroupName(r.getCollectionFlags().getGroupName()); - } - - return ent; + return new ArArchiveEntry(r.getName(), + r.getResource().getSize(), + uid, gid, mode, + r.getResource().getLastModified() + / 1000); } }); } Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java ------------------------------------------------------------------------------ svn:mergeinfo = Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=804624&r1=804623&r2=804624&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java (original) +++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java Sun Aug 16 05:34:02 2009 @@ -127,7 +127,7 @@ log("No sources, nothing to do", Project.MSG_WARN); } else { try { - writeArchive(dest, toAdd); + writeArchive(toAdd); } catch (IOException ioex) { throw new BuildException("Failed to write archive", ioex); } @@ -163,7 +163,10 @@ return (ResourceWithFlags[]) l.toArray(new ResourceWithFlags[l.size()]); } - protected void writeArchive(Resource dest, ResourceWithFlags[] src) + /** + * Creates the archive archiving the given resources. + */ + protected void writeArchive(ResourceWithFlags[] src) throws IOException { FileUtils fu = FileUtils.getFileUtils(); ArchiveOutputStream out = null; @@ -174,18 +177,8 @@ Expand.NATIVE_ENCODING.equals(encoding) ? null : encoding); for (int i = 0; i < src.length; i++) { - String name = src[i].getResource().getName(); - if (src[i].getCollectionFlags().hasFullpath()) { - name = src[i].getCollectionFlags().getFullpath(); - } else if (src[i].getCollectionFlags().hasPrefix()) { - String prefix = src[i].getCollectionFlags().getPrefix(); - if (!prefix.endsWith("/")) { - prefix = prefix + "/"; - } - name = prefix + name; - } - ArchiveEntry ent = builder.buildEntry(name, src[i]); + ArchiveEntry ent = builder.buildEntry(src[i]); out.putArchiveEntry(ent); if (!src[i].getResource().isDirectory()) { InputStream in = null; @@ -533,9 +526,39 @@ public Resource getResource() { return r; } public ResourceCollectionFlags getCollectionFlags() { return rcFlags; } public ResourceFlags getResourceFlags() { return rFlags; } + + /** + * The name the target entry will have. + * + *

Already takes fullpath and prefix into account.

+ * + *

Ensures directory names end in slashes while file names + * never will.

+ */ + public String getName() { + String name = r.getName(); + if (rcFlags.hasFullpath()) { + name = rcFlags.getFullpath(); + } else if (rcFlags.hasPrefix()) { + String prefix = rcFlags.getPrefix(); + if (!prefix.endsWith("/")) { + prefix = prefix + "/"; + } + name = prefix + name; + } + if (r.isDirectory() && !name.endsWith("/")) { + name += "/"; + } else if (r.isDirectory() && name.endsWith("/")) { + name = name.substring(0, name.length() - 1); + } + return name; + } } + /** + * Creates an archive entry for the concrete format. + */ public static interface EntryBuilder { - ArchiveEntry buildEntry(String name, ResourceWithFlags resource); + ArchiveEntry buildEntry(ResourceWithFlags resource); } } Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java?rev=804624&r1=804623&r2=804624&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java (original) +++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java Sun Aug 16 05:34:02 2009 @@ -30,11 +30,10 @@ public Tar() { super(new TarStreamFactory(), new ArchiveBase.EntryBuilder() { - public ArchiveEntry buildEntry(String name, - ArchiveBase.ResourceWithFlags r) { + public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) { boolean isDir = r.getResource().isDirectory(); TarArchiveEntry ent = - new TarArchiveEntry(name, + new TarArchiveEntry(r.getName(), isDir ? TarConstants.LF_DIR : TarConstants.LF_NORMAL); ent.setModTime(r.getResource().getLastModified()); Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml?rev=804624&r1=804623&r2=804624&view=diff ============================================================================== --- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml (original) +++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/unar-test.xml Sun Aug 16 05:34:02 2009 @@ -26,6 +26,18 @@ + + + + + + + + +