ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r827954 - in /ant/antlibs/compress/trunk: docs/archive.html docs/index.html src/main/org/apache/ant/compress/taskdefs/Tar.java src/tests/antunit/tar-test.xml
Date Wed, 21 Oct 2009 10:34:55 GMT
Author: bodewig
Date: Wed Oct 21 10:34:54 2009
New Revision: 827954

URL: http://svn.apache.org/viewvc?rev=827954&view=rev
Log:
Add support for long file names to tar

Modified:
    ant/antlibs/compress/trunk/docs/archive.html
    ant/antlibs/compress/trunk/docs/index.html
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
    ant/antlibs/compress/trunk/src/tests/antunit/tar-test.xml

Modified: ant/antlibs/compress/trunk/docs/archive.html
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/archive.html?rev=827954&r1=827953&r2=827954&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/archive.html (original)
+++ ant/antlibs/compress/trunk/docs/archive.html Wed Oct 21 10:34:54 2009
@@ -244,6 +244,24 @@
     task</a> with a <code>tar</code> task as nested element
     instead.</p>
 
+  <p>This task supports the following additional attributes:</p>
+
+  <table border="1" cellpadding="2" cellspacing="0">
+    <tr>
+      <td valign="top"><b>Attribute</b></td>
+      <td valign="top"><b>Description</b></td>
+      <td align="center" valign="top"><b>Required</b></td>
+    </tr>
+    <tr>
+      <td valign="top">format</td>
+      <td valign="top">Tar format for entries with names longer than
+        100 characters.  Supported values are "ustar" which doesn't
+        support entries of that length and results in a build failure
+        and "oldgnu".</td>
+      <td valign="top" align="center">No, default is "ustar"</td>
+    </tr>
+  </table>
+
   <h4>Examples</h4>
 
 <pre>
@@ -293,8 +311,8 @@
     <code>docs/index.html</code> is written as
     <code>/usr/doc/ant/index.html</code> to the archive.</p>
 
-<!--pre>
-&lt;tar longfile=&quot;gnu&quot;
+<pre>
+&lt;cmp:tar format=&quot;oldgnu&quot;
      destfile=&quot;${dist.base}/${dist.name}-src.tar&quot;&gt;
   &lt;tarfileset dir=&quot;${dist.name}/..&quot; filemode=&quot;755&quot;
username=&quot;ant&quot; group=&quot;ant&quot;&gt;
     &lt;include name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
@@ -305,13 +323,13 @@
     &lt;exclude name=&quot;${dist.name}/bootstrap.sh&quot;/&gt;
     &lt;exclude name=&quot;${dist.name}/build.sh&quot;/&gt;
   &lt;/tarfileset&gt;
-&lt;/tar&gt;
+&lt;/cmp:tar&gt;
 </pre>
 <p>This example shows building a tar which uses the GNU extensions for long paths and
 where some files need to be marked as executable (mode 755)
 and the rest are use the default mode (read-write by owner). The first
 fileset selects just the executable files. The second fileset must exclude
-the executable files and include all others. </p-->
+the executable files and include all others. </p>
 
 <pre>
 &lt;cmp:gzip destfile="release.tar.gz" xmlns:cmp="antlib:org.apache.ant.compress"&gt;

Modified: ant/antlibs/compress/trunk/docs/index.html
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/index.html?rev=827954&r1=827953&r2=827954&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/index.html (original)
+++ ant/antlibs/compress/trunk/docs/index.html Wed Oct 21 10:34:54 2009
@@ -34,12 +34,6 @@
 
     <h3>Known Limitations</h3>
 
-    <p>The <code>tar</code> task currently doesn't support the
-      equivalent of the core task's <code>longfile</code> attribute -
-      the <code>untar</code> task and the resources support this
-      format transparently, though - this is expected to be fixed
-      before the first release of the Antlib.</p>
-
     <p>Using Apache Commons Compress 1.0 the AR and CPIO formats don't
       read or write timestamps, permissions, userids and groupids
       properly - this has been fixed in the svn trunk of Apache

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java?rev=827954&r1=827953&r2=827954&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java Wed Oct
21 10:34:54 2009
@@ -18,20 +18,39 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.IOException;
+import java.io.OutputStream;
 import org.apache.ant.compress.util.TarStreamFactory;
 import org.apache.ant.compress.resources.TarFileSet;
 import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
 import org.apache.commons.compress.archivers.tar.TarConstants;
 import org.apache.tools.ant.types.ArchiveFileSet;
+import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.Resource;
 
 /**
  * Creates tar archives.
  */
 public class Tar extends ArchiveBase {
+    private Format format = Format.USTAR;
+
     public Tar() {
-        setFactory(new TarStreamFactory());
+        setFactory(new TarStreamFactory(){
+                public ArchiveOutputStream getArchiveStream(OutputStream stream,
+                                                            String encoding)
+                    throws IOException {
+                    TarArchiveOutputStream o =
+                        (TarArchiveOutputStream) super.getArchiveStream(stream,
+                                                                        encoding);
+                    if (format.equals(Format.OLDGNU)) {
+                        o.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
+                    }
+                    return o;
+                }
+            });
         setEntryBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
@@ -93,4 +112,39 @@
             });
     }
 
+    /**
+     * The format for entries with filenames longer than 100
+     * characters - any other entry will always use "ustar".
+     */
+    public void setFormat(Format f) {
+        format = f;
+    }
+
+    /**
+     * The supported tar formats for entries with long file names.
+     */
+    public final static class Format extends EnumeratedAttribute {
+        private static final String USTAR_NAME = "ustar";
+        private static final String OLDGNU_NAME = "oldgnu";
+
+        public static final Format USTAR = new Format(USTAR_NAME);
+        public static final Format OLDGNU = new Format(OLDGNU_NAME);
+
+        public Format(String v) {
+            setValue(v);
+        }
+
+        public Format() {
+            setValue(USTAR_NAME);
+        }
+
+        public String[] getValues() {
+            return new String[] {USTAR_NAME, OLDGNU_NAME};
+        }
+
+        public boolean equals(Object other) {
+            return other instanceof Format
+                && ((Format) other).getValue().equals(getValue());
+        }
+    }
 }
\ No newline at end of file

Modified: ant/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/tar-test.xml?rev=827954&r1=827953&r2=827954&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/tar-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/tar-test.xml Wed Oct 21 10:34:54 2009
@@ -592,4 +592,37 @@
       </cond:islastmodified>
     </au:assertFalse>
   </target>
+
+  <target name="-longFileSetUp" depends="setUp">
+    <property name="long" value="0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789/0123456789.txt"/>
+    <touch file="${input}/${long}"
+           mkdirs="true"/>
+  </target>
+
+  <target name="testImplicitUstarLongFile" depends="-longFileSetUp">
+    <au:expectfailure>
+      <cmp:tar destfile="${dest}">
+        <fileset dir="${input}"/>
+      </cmp:tar>
+    </au:expectfailure>
+  </target>
+
+  <target name="testExplicitUstarLongFile" depends="-longFileSetUp">
+    <au:expectfailure>
+      <cmp:tar destfile="${dest}" format="ustar">
+        <fileset dir="${input}"/>
+      </cmp:tar>
+    </au:expectfailure>
+  </target>
+
+  <target name="testOldgnuLongFile" depends="-longFileSetUp">
+    <cmp:tar destfile="${dest}" format="oldgnu">
+      <fileset dir="${input}"/>
+    </cmp:tar>
+    <assertResourceExists>
+      <cmp:tarentry name="${long}">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceExists>
+  </target>
 </project>



Mime
View raw message