ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r807472 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ tests/antunit/
Date Tue, 25 Aug 2009 04:20:51 GMT
Author: bodewig
Date: Tue Aug 25 04:20:50 2009
New Revision: 807472

URL: http://svn.apache.org/viewvc?rev=807472&view=rev
Log:
port level from core <zip>

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
    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/Cpio.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Tar.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java?rev=807472&r1=807471&r2=807472&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java (original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Ar.java Tue
Aug 25 04:20:50 2009
@@ -33,7 +33,7 @@
         + " directory entries";
 
     public Ar() {
-        super(new ArStreamFactory());
+        setFactory(new ArStreamFactory());
         setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {

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=807472&r1=807471&r2=807472&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
Tue Aug 25 04:20:50 2009
@@ -65,7 +65,7 @@
  * Base implementation of tasks creating archives.
  */
 public abstract class ArchiveBase extends Task {
-    private final StreamFactory factory;
+    private StreamFactory factory;
     private EntryBuilder builder;
 
     private Resource dest;
@@ -77,7 +77,9 @@
     private boolean roundUp = true;
     private boolean preserveLeadingSlashes = false;
 
-    protected ArchiveBase(StreamFactory factory) {
+    protected ArchiveBase() {}
+
+    protected final void setFactory(StreamFactory factory) {
         this.factory = factory;
     }
 
@@ -196,6 +198,10 @@
      * Argument validation.
      */
     protected void validate() throws BuildException {
+        if (factory == null) {
+            throw new BuildException("subclass didn't provide a factory"
+                                     + " instance");
+        }
         if (builder == null) {
             throw new BuildException("subclass didn't provide a builder"
                                      + " instance");

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java?rev=807472&r1=807471&r2=807472&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Cpio.java
Tue Aug 25 04:20:50 2009
@@ -28,7 +28,7 @@
  */
 public class Cpio extends ArchiveBase {
     public Cpio() {
-        super(new CpioStreamFactory());
+        setFactory(new CpioStreamFactory());
         setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {

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=807472&r1=807471&r2=807472&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
Tue Aug 25 04:20:50 2009
@@ -29,7 +29,7 @@
  */
 public class Tar extends ArchiveBase {
     public Tar() {
-        super(new TarStreamFactory());
+        setFactory(new TarStreamFactory());
         setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java?rev=807472&r1=807471&r2=807472&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Zip.java
Tue Aug 25 04:20:50 2009
@@ -18,17 +18,35 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.zip.Deflater;
+
 import org.apache.ant.compress.util.ZipStreamFactory;
 import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
 import org.apache.tools.ant.types.ArchiveFileSet;
 
 /**
  * Creates zip archives.
  */
 public class Zip extends ArchiveBase {
+    private int level = Deflater.DEFAULT_COMPRESSION;
+
     public Zip() {
-        super(new ZipStreamFactory());
+        setFactory(new ZipStreamFactory() {
+                public ArchiveOutputStream getArchiveStream(OutputStream stream,
+                                                            String encoding)
+        throws IOException {
+                    ZipArchiveOutputStream o =
+                        (ZipArchiveOutputStream) super.getArchiveStream(stream,
+                                                                        encoding);
+                    o.setLevel(level);
+                    return o;
+                }
+            });
         setBuilder(
               new ArchiveBase.EntryBuilder() {
                 public ArchiveEntry buildEntry(ArchiveBase.ResourceWithFlags r) {
@@ -60,4 +78,12 @@
             });
     }
 
+    /**
+     * Set the compression level to use.  Default is
+     * Deflater.DEFAULT_COMPRESSION.
+     * @param level compression level.
+     */
+    public void setLevel(int level) {
+        this.level = level;
+    }
 }
\ No newline at end of file

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml?rev=807472&r1=807471&r2=807472&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml Tue Aug 25 04:20:50
2009
@@ -354,4 +354,26 @@
       </cmp:zipentry>
     </assertResourceDoesntExist>
   </target>
+
+  <target name="testLevel" depends="setUp">
+    <cmp:zip destfile="${output}/compressed.zip">
+      <file file="${ant.file}"/>
+    </cmp:zip>
+    <cmp:zip destfile="${output}/uncompressed.zip" level="0">
+      <file file="${ant.file}"/>
+    </cmp:zip>
+    <au:assertTrue>
+      <resourcecount count="2">
+        <fileset dir="${output}"/>
+      </resourcecount>
+    </au:assertTrue>
+    <au:assertTrue>
+      <resourcecount count="1">
+        <fileset dir="${output}">
+          <size value="5" units="Ki" when="less"/>
+        </fileset>
+      </resourcecount>
+    </au:assertTrue>
+  </target>
+
 </project>



Mime
View raw message