ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1577923 - in /ant/antlibs/compress/trunk: changes.xml docs/pack.html src/main/org/apache/ant/compress/taskdefs/GZip.java src/tests/antunit/gunzip-test.xml
Date Sat, 15 Mar 2014 19:43:02 GMT
Author: bodewig
Date: Sat Mar 15 19:43:02 2014
New Revision: 1577923

URL: http://svn.apache.org/r1577923
Log:
Add level attribute to gzip task.  PR 52414

Modified:
    ant/antlibs/compress/trunk/changes.xml
    ant/antlibs/compress/trunk/docs/pack.html
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
    ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml

Modified: ant/antlibs/compress/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/changes.xml?rev=1577923&r1=1577922&r2=1577923&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/changes.xml (original)
+++ ant/antlibs/compress/trunk/changes.xml Sat Mar 15 19:43:02 2014
@@ -51,6 +51,10 @@
         Multiple content compression/encryption/filter methods can now
         be specified via nested elements of the sevenz task.
       </action>
+      <action type="add" issue="52414">
+        The gzip task has a new attribute that controls the level of
+        compression.
+      </action>
     </release>
 
     <release version="1.4" date="2014-01-29">

Modified: ant/antlibs/compress/trunk/docs/pack.html
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/pack.html?rev=1577923&r1=1577922&r2=1577923&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/pack.html (original)
+++ ant/antlibs/compress/trunk/docs/pack.html Sat Mar 15 19:43:02 2014
@@ -103,6 +103,24 @@
   <p>Is a <a href="#pack">compressing task</a> that uses the GZIP
     compression algorithm.</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">level</td>
+      <td valign="top">Non-default level at which file compression
+        should be performed. Valid values range from 0 (no
+        compression/fastest) to 9 (maximum
+        compression/slowest).  <em>Since Compress Antlib 1.5</em></td>
+      <td valign="top" align="center">No</td>
+    </tr>
+  </table>
+
   <h3><a name="pack200">Pack200</a></h3>
 
   <p>Is a <a href="#pack">compressing task</a> that uses

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java?rev=1577923&r1=1577922&r2=1577923&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java Sat Mar
15 19:43:02 2014
@@ -18,23 +18,48 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.Deflater;
+
 import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
 import org.apache.ant.compress.resources.GZipResource;
 import org.apache.ant.compress.util.GZipStreamFactory;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream;
+import org.apache.commons.compress.compressors.gzip.GzipParameters;
 import org.apache.tools.ant.types.Resource;
 
 /**
  * Compresses using gzip.
  */
 public final class GZip extends PackBase {
+    private int level = Deflater.DEFAULT_COMPRESSION;
 
     public GZip() {
-        super(new GZipStreamFactory(),
-              new PackBase.ResourceWrapper() {
+        super(new PackBase.ResourceWrapper() {
                 public CommonsCompressCompressorResource wrap(Resource dest) {
                     return new GZipResource(dest);
                 }
             });
+        setFactory(new GZipStreamFactory() {
+                public CompressorOutputStream getCompressorStream(OutputStream stream)
+                    throws IOException {
+                    GzipParameters params = new GzipParameters();
+                    params.setCompressionLevel(level);
+                    return new GzipCompressorOutputStream(stream, params);
+                }
+            });
+    }
+
+    /**
+     * Set the compression level to use.  Default is
+     * Deflater.DEFAULT_COMPRESSION.
+     * @param level compression level.
+     * @since 1.5
+     */
+    public void setLevel(int level) {
+        this.level = level;
     }
 
-}
\ No newline at end of file
+}

Modified: ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml?rev=1577923&r1=1577922&r2=1577923&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/gunzip-test.xml Sat Mar 15 19:43:02 2014
@@ -54,6 +54,14 @@
                          actual="${output}/asf-logo.gif"/>
   </target>
 
+  <target name="testAntlibGzipTaskWithLevel" depends="setUp">
+    <cmp:gzip src="../resources/asf-logo.gif" level="9"
+              destfile="${output}/asf-logo.gif.gz"/>
+    <cmp:gunzip src="${output}/asf-logo.gif.gz" dest="${output}/asf-logo.gif" />
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
   <target name="testNativeGzip" depends="setUp">
     <cmp:gunzip src="../resources/asf-logo.gif.gz"
                 dest="${output}/asf-logo.gif" />



Mime
View raw message