Author: bodewig
Date: Fri Sep 27 19:40:11 2013
New Revision: 1527046

URL: http://svn.apache.org/r1527046
Log:
un7z task

Added:
    
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Un7z.java
      - copied, changed from r1527026, 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java
    
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java
      - copied, changed from r1527026, 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
    ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml
      - copied, changed from r1527026, 
ant/antlibs/compress/trunk/src/tests/antunit/unar-test.xml
    ant/antlibs/compress/trunk/src/tests/resources/asf-logo.gif.7z   (with 
props)
Modified:
    ant/antlibs/compress/trunk/NOTICE
    ant/antlibs/compress/trunk/docs/expand.html
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml

Modified: ant/antlibs/compress/trunk/NOTICE
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/NOTICE?rev=1527046&r1=1527045&r2=1527046&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/NOTICE (original)
+++ ant/antlibs/compress/trunk/NOTICE Fri Sep 27 19:40:11 2013
@@ -1,5 +1,5 @@
    Apache Compress Ant Library
-   Copyright 2009-2012 The Apache Software Foundation
+   Copyright 2009-2013 The Apache Software Foundation
 
    This product includes software developed by
    The Apache Software Foundation (http://www.apache.org/).

Modified: ant/antlibs/compress/trunk/docs/expand.html
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/expand.html?rev=1527046&r1=1527045&r2=1527046&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/expand.html (original)
+++ ant/antlibs/compress/trunk/docs/expand.html Fri Sep 27 19:40:11 2013
@@ -101,6 +101,15 @@ mapper</a>.</p>
   </tr>
 </table>
 
+<h3><a name="un7z">Un7z</a></h3>
+
+<p><em>Since Apache Compress Antlib 1.3</em>.</p>
+
+<p>An <a href="#expand">unarchiving task</a> for 7z archives.</p>
+
+<p>As of version 1.3 of the Compress Antlib this task can only work on
+  file based resources.</p>
+
 <h3><a name="unar">UnAr</a></h3>
 
 <p>An <a href="#expand">unarchiving task</a> for AR archives.</p>

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=1527046&r1=1527045&r2=1527046&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml 
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Fri 
Sep 27 19:40:11 2013
@@ -17,6 +17,10 @@
   -->
 <antlib>
   <taskdef
+     name="un7z"
+     classname="org.apache.ant.compress.taskdefs.Un7z"
+     />
+  <taskdef
      name="unar"
      classname="org.apache.ant.compress.taskdefs.Unar"
      />

Copied: 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Un7z.java 
(from r1527026, 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java)
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Un7z.java?p2=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Un7z.java&p1=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java&r1=1527026&r2=1527046&rev=1527046&view=diff
==============================================================================
--- 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Unzip.java 
(original)
+++ 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Un7z.java 
Fri Sep 27 19:40:11 2013
@@ -21,14 +21,12 @@ package org.apache.ant.compress.taskdefs
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Date;
-import java.util.Enumeration;
 
 import org.apache.ant.compress.util.Messages;
-import org.apache.ant.compress.util.ZipStreamFactory;
+import org.apache.ant.compress.util.SevenZStreamFactory;
 
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipFile;
+import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
+import org.apache.commons.compress.archivers.sevenz.SevenZFile;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
@@ -36,49 +34,55 @@ import org.apache.tools.ant.util.FileNam
 import org.apache.tools.ant.util.FileUtils;
 
 /**
- * Unzip a file.
+ * Un7z a file.
+ * @since Apache Compress Antlib 1.3
  */
-public class Unzip extends ExpandBase {
+public class Un7z extends ExpandBase {
 
-    public Unzip() {
-        super(new ZipStreamFactory());
+    public Un7z() {
+        super(new SevenZStreamFactory());
     }
 
-    public void setEncoding(String encoding) {
-        internalSetEncoding(encoding);
-    }
-
-    // overridden in order to take advantage of ZipFile
+    // overridden in order to take advantage of SevenzFile
     protected void expandFile(FileUtils fileUtils, File srcF, File dir) {
-        log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
-        ZipFile zf = null;
-        FileNameMapper mapper = getMapper();
         if (!srcF.exists()) {
             throw new BuildException("Unable to expand " + srcF
                                      + " as the file does not exist",
                                      getLocation());
         }
+        log("Expanding: " + srcF + " into " + dir, Project.MSG_INFO);
+        FileNameMapper mapper = getMapper();
+        SevenZFile outer = null;
         try {
-            zf = new ZipFile(srcF, getEncoding(), true);
+            final SevenZFile zf = outer = new SevenZFile(srcF);
             boolean empty = true;
-            Enumeration e = zf.getEntries();
-            while (e.hasMoreElements()) {
+            SevenZArchiveEntry ze = zf.getNextEntry();
+            while (ze != null) {
                 empty = false;
-                ZipArchiveEntry ze = (ZipArchiveEntry) e.nextElement();
+                /* TODO implement canReadEntryData in CC
                 if (getSkipUnreadableEntries() && !zf.canReadEntryData(ze)) {
                     log(Messages.skippedIsUnreadable(ze));
                     continue;
                 }
+                */
                 log("extracting " + ze.getName(), Project.MSG_DEBUG);
                 InputStream is = null;
                 try {
                     extractFile(fileUtils, srcF, dir,
-                                is = zf.getInputStream(ze),
-                                ze.getName(), new Date(ze.getTime()),
+                                is = new InputStream() {
+                                        public int read() throws IOException {
+                                            return zf.read();
+                                        }
+                                        public int read(byte[] b) throws 
IOException {
+                                            return zf.read(b);
+                                        }
+                                    },
+                                ze.getName(), ze.getLastModifiedDate(),
                                 ze.isDirectory(), mapper);
                 } finally {
                     FileUtils.close(is);
                 }
+                ze = zf.getNextEntry();
             }
             if (empty && getFailOnEmptyArchive()) {
                 throw new BuildException("archive '" + srcF + "' is empty");
@@ -90,7 +94,9 @@ public class Unzip extends ExpandBase {
                 + "\n" + ioe.toString(),
                 ioe);
         } finally {
-            ZipFile.closeQuietly(zf);
+            if (outer != null) {
+                outer.close();
+            }
         }
     }
 

Copied: 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java
 (from r1527026, 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java)
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java?p2=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java&p1=ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java&r1=1527026&r2=1527046&rev=1527046&view=diff
==============================================================================
--- 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/ZipStreamFactory.java
 (original)
+++ 
ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java
 Fri Sep 27 19:40:11 2013
@@ -18,19 +18,20 @@
 
 package org.apache.ant.compress.util;
 
-import java.io.BufferedInputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
-import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
-import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
+import org.apache.commons.compress.archivers.sevenz.SevenZFile;
 
-public class ZipStreamFactory implements FileAwareArchiveStreamFactory {
+/**
+ * @since Apache Compress Antlib 1.3
+ */
+public class SevenZStreamFactory implements FileAwareArchiveStreamFactory {
 
     /**
      * @param stream the stream to read from, should be buffered
@@ -39,7 +40,7 @@ public class ZipStreamFactory implements
     public ArchiveInputStream getArchiveStream(InputStream stream,
                                                String encoding)
         throws IOException {
-        return new ZipArchiveInputStream(stream, encoding, true);
+        throw new UnsupportedOperationException("only file-based archives can 
be read");
     }
 
     /**
@@ -49,9 +50,7 @@ public class ZipStreamFactory implements
     public ArchiveOutputStream getArchiveStream(OutputStream stream,
                                                 String encoding)
         throws IOException {
-        ZipArchiveOutputStream o = new ZipArchiveOutputStream(stream);
-        o.setEncoding(encoding);
-        return o;
+        throw new UnsupportedOperationException("only file-based archives can 
be written");
     }
 
     /**
@@ -61,9 +60,7 @@ public class ZipStreamFactory implements
     public ArchiveInputStream getArchiveInputStream(File file,
                                                     String encoding)
         throws IOException {
-        return
-            getArchiveStream(new BufferedInputStream(new 
FileInputStream(file)),
-                             encoding);
+        return new SevenZArchiveInputStream(file);
     }
 
     /**
@@ -73,8 +70,32 @@ public class ZipStreamFactory implements
     public ArchiveOutputStream getArchiveOutputStream(File file,
                                                       String encoding)
         throws IOException {
-        ZipArchiveOutputStream o = new ZipArchiveOutputStream(file);
-        o.setEncoding(encoding);
-        return o;
+        throw new UnsupportedOperationException();
     }
-}
\ No newline at end of file
+
+    /**
+     * Not really a stream but provides an ArchiveInputStream
+     * compatible interface over SevenZFile.
+     */
+    private static class SevenZArchiveInputStream extends ArchiveInputStream {
+
+        private final SevenZFile zipFile;
+
+        public SevenZArchiveInputStream(File file) throws IOException {
+            zipFile = new SevenZFile(file);
+        }
+
+        public ArchiveEntry getNextEntry() throws IOException {
+            return zipFile.getNextEntry();
+        }
+
+        public int read(byte[] b, int off, int len) throws IOException {
+            return zipFile.read(b, off, len);
+        }
+
+        public void close() throws IOException {
+            zipFile.close();
+        }
+    }
+
+}

Copied: ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml (from 
r1527026, ant/antlibs/compress/trunk/src/tests/antunit/unar-test.xml)
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml?p2=ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml&p1=ant/antlibs/compress/trunk/src/tests/antunit/unar-test.xml&r1=1527026&r2=1527046&rev=1527046&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/unar-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml Fri Sep 27 
19:40:11 2013
@@ -26,36 +26,22 @@
     <mkdir dir="${input}"/>
   </target>
 
-  <target name="testAgainstAntlibArTask" depends="setUp">
-    <cmp:ar destfile="${input}/test.ar">
-      <fileset dir="." includes="unar-test.xml"/>
-    </cmp:ar>
-    <cmp:unar src="${input}/test.ar" dest="${output}"/>
-    <au:assertFileExists file="${output}/unar-test.xml"/>
+  <!--
+  <target name="testAgainstAntlib7zTask" depends="setUp">
+    <cmp:7z destfile="${input}/test.7z">
+      <fileset dir="." includes="un7z-test.xml"/>
+    </cmp:7z>
+    <cmp:un7z src="${input}/test.7z" dest="${output}"/>
+    <au:assertFileExists file="${output}/un7z-test.xml"/>
     <au:assertFilesMatch
-       actual="${output}/unar-test.xml"
-       expected="unar-test.xml"
+       actual="${output}/un7z-test.xml"
+       expected="un7z-test.xml"
        />
   </target>
+  -->
 
-  <target name="testAgainstNativeAr" depends="setUp">
-    <cmp:unar src="../resources/asf-logo.gif.ar" dest="${output}" />
-    <au:assertFileExists file="${output}/asf-logo.gif"/>
-    <au:assertFilesMatch
-       actual="${output}/asf-logo.gif"
-       expected="../resources/asf-logo.gif"
-       />
-  </target>
-
-  <target name="fails-testResourceCollection" depends="setUp">
-    <zip destfile="${input}/test.zip">
-      <fileset dir="../resources" includes="*.ar"/>
-    </zip>
-    <cmp:unar dest="${output}">
-      <zipfileset src="${input}/test.zip">
-        <include name="*.ar"/>
-      </zipfileset>
-    </cmp:unar>
+  <target name="testAgainstNative7z" depends="setUp">
+    <cmp:un7z src="../resources/asf-logo.gif.7z" dest="${output}" />
     <au:assertFileExists file="${output}/asf-logo.gif"/>
     <au:assertFilesMatch
        actual="${output}/asf-logo.gif"

Added: ant/antlibs/compress/trunk/src/tests/resources/asf-logo.gif.7z
URL: 
http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/resources/asf-logo.gif.7z?rev=1527046&view=auto
==============================================================================
Binary file - no diff available.

Propchange: ant/antlibs/compress/trunk/src/tests/resources/asf-logo.gif.7z
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream


Reply via email to