ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1204501 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/resources/ tests/antunit/
Date Mon, 21 Nov 2011 14:00:28 GMT
Author: bodewig
Date: Mon Nov 21 14:00:27 2011
New Revision: 1204501

URL: http://svn.apache.org/viewvc?rev=1204501&view=rev
Log:
support for concatenated streams in resources

Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressCompressorResource.java
    ant/antlibs/compress/trunk/src/tests/antunit/bzip2resource-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/gzipresource-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/pack200resource-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/xzresource-test.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressCompressorResource.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressCompressorResource.java?rev=1204501&r1=1204500&r2=1204501&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressCompressorResource.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressCompressorResource.java
Mon Nov 21 14:00:27 2011
@@ -24,6 +24,8 @@ import java.io.InputStream;
 import java.io.OutputStream;
 
 import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.ant.compress.util.CompressorWithConcatenatedStreamsFactory;
+import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.ResourceCollection;
 import org.apache.tools.ant.types.resources.ContentTransformingResource;
 
@@ -38,6 +40,7 @@ public abstract class CommonsCompressCom
 
     private final String name;
     private final CompressorStreamFactory factory;
+    private boolean decompressConcatenated = false;
 
     /** A no-arg constructor */
     protected CommonsCompressCompressorResource(String name,
@@ -59,13 +62,37 @@ public abstract class CommonsCompressCom
     }
 
     /**
+     * Whether to extract the whole resource if it contains multiple
+     * concatenated streams.
+     *
+     * <p>Defaults to false for backwards compatibility.</p>
+     *
+     * @since Apache Compress Antlib 1.2
+     */
+    public void setDecompressConcatenated(boolean b) {
+        if (!b || factory instanceof CompressorWithConcatenatedStreamsFactory) {
+            decompressConcatenated = b;
+        } else {
+            throw new BuildException("concatenated streams are not supported"
+                                     + "by this compression format.");
+        }
+    }
+
+    /**
      * Decompress on the fly.
      * @param in the stream to wrap.
      * @return the wrapped stream.
      * @throws IOException if there is a problem.
      */
     protected final InputStream wrapStream(InputStream in) throws IOException {
+        if (factory instanceof CompressorWithConcatenatedStreamsFactory) {
+            CompressorWithConcatenatedStreamsFactory f
+                = (CompressorWithConcatenatedStreamsFactory) factory;
+            return f.getCompressorStream(new BufferedInputStream(in),
+                                         decompressConcatenated);
+        } else {
         return factory.getCompressorStream(new BufferedInputStream(in));
+        }
     }
 
     /**

Modified: ant/antlibs/compress/trunk/src/tests/antunit/bzip2resource-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/bzip2resource-test.xml?rev=1204501&r1=1204500&r2=1204501&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/bzip2resource-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/bzip2resource-test.xml Mon Nov 21 14:00:27
2011
@@ -37,4 +37,43 @@
     <au:assertFilesMatch expected="../resources/asf-logo.gif"
                          actual="${output}/asf-logo.gif"/>
   </target>
+
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:bzip2resource>
+        <file file="../resources/multiple.bz2"/>
+      </cmp:bzip2resource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:bzip2resource decompressconcatenated="false">
+        <file file="../resources/multiple.bz2"/>
+      </cmp:bzip2resource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <copy todir="${output}">
+      <cmp:bzip2resource decompressconcatenated="true">
+        <file file="../resources/multiple.bz2"/>
+      </cmp:bzip2resource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/gzipresource-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/gzipresource-test.xml?rev=1204501&r1=1204500&r2=1204501&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/gzipresource-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/gzipresource-test.xml Mon Nov 21 14:00:27
2011
@@ -37,4 +37,44 @@
     <au:assertFilesMatch expected="../resources/asf-logo.gif"
                          actual="${output}/asf-logo.gif"/>
   </target>
+
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:gzipresource>
+        <file file="../resources/multiple.gz"/>
+      </cmp:gzipresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:gzipresource decompressconcatenated="false">
+        <file file="../resources/multiple.gz"/>
+      </cmp:gzipresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <copy todir="${output}">
+      <cmp:gzipresource decompressconcatenated="true">
+        <file file="../resources/multiple.gz"/>
+      </cmp:gzipresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/pack200resource-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/pack200resource-test.xml?rev=1204501&r1=1204500&r2=1204501&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/pack200resource-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/pack200resource-test.xml Mon Nov 21 14:00:27
2011
@@ -38,4 +38,17 @@
     <au:assertFilesMatch expected="../resources/asf-logo.gif"
                          actual="${output}/asf-logo.gif"/>
   </target>
+
+  <target name="testDoesntSupportConcatenatedStreams">
+    <au:expectfailure>
+      <copy todir="${output}">
+        <cmp:zipfileset>
+          <cmp:pack200resource decompressconcatenated="true">
+            <file file="../resources/asf-logo.gif.pack"/>
+          </cmp:pack200resource>
+        </cmp:zipfileset>
+      </copy>
+    </au:expectfailure>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/xzresource-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/xzresource-test.xml?rev=1204501&r1=1204500&r2=1204501&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/xzresource-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/xzresource-test.xml Mon Nov 21 14:00:27 2011
@@ -37,4 +37,43 @@
     <au:assertFilesMatch expected="../resources/asf-logo.gif"
                          actual="${output}/asf-logo.gif"/>
   </target>
+
+  <target name="testConcatenatedStreamsDefault"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:xzresource>
+        <file file="../resources/multiple.xz"/>
+      </cmp:xzresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsOnlyFirstStream"
+          depends="setUp">
+    <echo file="${output}/expected">a</echo>
+    <copy todir="${output}">
+      <cmp:xzresource decompressconcatenated="false">
+        <file file="../resources/multiple.xz"/>
+      </cmp:xzresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
+
+  <target name="testConcatenatedStreamsAllStreams"
+          depends="setUp">
+    <echo file="${output}/expected">ab</echo>
+    <copy todir="${output}">
+      <cmp:xzresource decompressconcatenated="true">
+        <file file="../resources/multiple.xz"/>
+      </cmp:xzresource>
+      <mergemapper to="actual"/>
+    </copy>
+    <au:assertFilesMatch expected="${output}/expected"
+                         actual="${output}/actual"/>
+  </target>
 </project>



Mime
View raw message