ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject [1/5] ant-antlibs-compress git commit: support DEFLATE
Date Sun, 07 May 2017 16:15:28 GMT
Repository: ant-antlibs-compress
Updated Branches:
  refs/heads/master 46b9c73b4 -> 3472e109d


support DEFLATE


Project: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/commit/85a1f823
Tree: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/tree/85a1f823
Diff: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/diff/85a1f823

Branch: refs/heads/master
Commit: 85a1f823bf6287fe3bc8616e394d24ecda803426
Parents: 46b9c73
Author: Stefan Bodewig <bodewig@apache.org>
Authored: Sun May 7 18:08:54 2017 +0200
Committer: Stefan Bodewig <bodewig@apache.org>
Committed: Sun May 7 18:08:54 2017 +0200

----------------------------------------------------------------------
 changes.xml                                     |   8 +-
 docs/compresource.html                          |  24 ++++
 docs/index.html                                 |   9 +-
 docs/pack.html                                  |  30 +++++
 docs/unpack.html                                |  24 ++++
 src/main/org/apache/ant/compress/antlib.xml     |  12 ++
 .../ant/compress/resources/DeflateResource.java |  78 +++++++++++++
 .../apache/ant/compress/taskdefs/Deflate.java   |  78 +++++++++++++
 .../apache/ant/compress/taskdefs/Undeflate.java |  59 ++++++++++
 .../ant/compress/util/DeflateStreamFactory.java |  53 +++++++++
 src/tests/antunit/deflate-test.xml              | 110 +++++++++++++++++++
 src/tests/antunit/deflateresource-test.xml      |  53 +++++++++
 src/tests/antunit/undeflate-test.xml            |  74 +++++++++++++
 src/tests/resources/asf-logo.gif.dfl            | Bin 0 -> 6965 bytes
 14 files changed, 607 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/changes.xml
----------------------------------------------------------------------
diff --git a/changes.xml b/changes.xml
index 75e20ec..0927c18 100644
--- a/changes.xml
+++ b/changes.xml
@@ -40,8 +40,9 @@
     <release version="1.5" date="unreleased">
       <action type="update" breaks-bwc="true">
         The Apache Compress Antlib now requires Apache Commons
-        Compress 1.13 or later for 7z and write support for LZMA, XZ
-        for Java 1.6 is required for write support for LZMA.
+        Compress 1.13 or later for 7z, DEFLATE and write support
+        for LZMA.
+        XZ for Java 1.6 is required for write support for LZMA.
       </action>
       <action type="add">
         A new keepCompression flag can be used to keep the content
@@ -59,6 +60,9 @@
       <action type="add">
         Added write support for the LZMA format.
       </action>
+      <action type="add">
+        Added support for the DEFLATE format with and without ZLIB headers.
+      </action>
     </release>
 
     <release version="1.4" date="2014-01-29">

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/docs/compresource.html
----------------------------------------------------------------------
diff --git a/docs/compresource.html b/docs/compresource.html
index 09d77b4..50dc979 100644
--- a/docs/compresource.html
+++ b/docs/compresource.html
@@ -63,6 +63,30 @@
   some-archive.tar.bz2 where the <code>bzip2resource</code> provides
   the decompression of the archive.</p>
 
+<h2><a name="deflateresource">deflateresource</a></h2>
+
+<p><em>Since Apache Compress Antlib 1.5</em>.</p>
+
+<p>This is a <a href="#compresource">compressed resource</a> using the
+  DEFLATE compression.</p>
+
+  <p>This resource 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">zlibheader</td>
+      <td valign="top">Whether to write or expect ZLIB headers. Unfortunately
+      it is currently not possible to detect whether zlib headers have
+      been used when reading.</td>
+      <td valign="top" align="center">No, defaults to <code>true</code></td>
+    </tr>
+  </table>
+
 <h2><a name="gzipresource">gzipresource</a></h2>
 
 <p>This is a <a href="#compresource">compressed resource</a> using the

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/docs/index.html
----------------------------------------------------------------------
diff --git a/docs/index.html b/docs/index.html
index f32107f..4be8fc0 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -28,8 +28,8 @@
     <p>This Antlib contains tasks and resources that provide
       compression/uncompression and archival/unarchival capabilities
       based on <a href="http://commons.apache.org/compress/">Apache
-      Commons Compress</a>.  Using Apache Commons Compress 1.6 this
-      Antlib supports gzip, bzip2, lzma standalone, xz, .Z, Snappy and
+      Commons Compress</a>.  Using Apache Commons Compress 1.13 this
+      Antlib supports gzip, bzip2, lzma standalone, xz, .Z, DEFLATE, Snappy and
       pack200 compression and ar, arj, cpio, 7z, Unix dump, tar and
       zip archives.  Support for lzma, arj, .Z, Snappy and dump is
       read-only.  7z can only be used on filesystem resources.</p>
@@ -49,6 +49,7 @@
       <li><a href="unpack.html#bunzip2">bunzip2</a></li>
       <li><a href="pack.html#bzip2">bzip2</a></li>
       <li><a href="archive.html#cpio">cpio</a></li>
+      <li><a href="pack.html#deflate">deflate</a></li>
       <li><a href="unpack.html#gunzip">gunzip</a></li>
       <li><a href="pack.html#gzip">gzip</a></li>
       <li><a href="pack.html#pack200">pack200</a></li>
@@ -59,6 +60,7 @@
       <li><a href="expand.html#unar">unar</a></li>
       <li><a href="expand.html#unarj">unarj</a></li>
       <li><a href="expand.html#uncpio">uncpio</a></li>
+      <li><a href="unpack.html#undeflate">undeflate</a></li>
       <li><a href="expand.html#undump">undump</a></li>
       <li><a href="unpack.html#unlzma">unlzma</a></li>
       <li><a href="unpack.html#unpack200">unpack200</a></li>
@@ -82,6 +84,7 @@
       <li><a href="compresource.html#bzip2resource">bzip2resource</a></li>
       <li><a href="entry.html#cpioentry">cpioentry</a></li>
       <li><a href="fileset.html#cpiofileset">cpiofileset</a></li>
+      <li><a href="compresource.html#deflateresource">deflateresource</a></li>
       <li><a href="entry.html#dumpentry">dumpentry</a></li>
       <li><a href="fileset.html#dumpfileset">dumpfileset</a></li>
       <li><a href="compresource.html#gzipresource">gzipresource</a></li>
@@ -113,7 +116,7 @@
     <h3>Installing and Using</h3>
 
     <p>This Antlib requires Apache Ant 1.8.0 or higher, Apache
-      Commons Compress 1.6 or higher and Java5 or higher.</p>
+      Commons Compress 1.13 or higher and Java7 or higher.</p>
 
     <p>If you are building the Antlib from sources, run
       the <code>antlib</code> target and you'll get a

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/docs/pack.html
----------------------------------------------------------------------
diff --git a/docs/pack.html b/docs/pack.html
index 89c3f52..67738e5 100644
--- a/docs/pack.html
+++ b/docs/pack.html
@@ -98,6 +98,36 @@
   <p>Is a <a href="#pack">compressing task</a> that uses the BZIP2
     compression algorithm.</p>
 
+  <h3><a name="deflate">Deflate</a></h3>
+
+  <p>Is a <a href="#pack">compressing task</a> that uses the DEFLATE
+    compression algorithm.</p>
+
+  <p><em>Since Compress Antlib 1.5</em>
+
+  <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).</td>
+      <td valign="top" align="center">No</td>
+    </tr>
+    <tr>
+      <td valign="top">zlibheader</td>
+      <td valign="top">Whether to write ZLIB headers.</td>
+      <td valign="top" align="center">No, defaults to <code>true</code></td>
+    </tr>
+  </table>
+
   <h3><a name="gzip">GZip</a></h3>
 
   <p>Is a <a href="#pack">compressing task</a> that uses the GZIP

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/docs/unpack.html
----------------------------------------------------------------------
diff --git a/docs/unpack.html b/docs/unpack.html
index 1487a73..81d4f0f 100644
--- a/docs/unpack.html
+++ b/docs/unpack.html
@@ -93,6 +93,30 @@ resource collection</h4>
   the <a href="#decompressConcatenated">decompressConcatenated</a>
   attribute.</p>
 
+<h3><a name="gunzip">Undeflate</a></h3>
+
+<p>Is an <a href="#unpack">uncompressing task</a> that uses the DEFLATE
+  compression algorithm.</p>
+
+  <p><em>Since Compress Antlib 1.5</em>
+
+  <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">zlibheader</td>
+      <td valign="top">Whether to expect ZLIB headers. Unfortunately
+      it is currently not possible to detect whether zlib headers have
+      been used.</td>
+      <td valign="top" align="center">No, defaults to <code>true</code></td>
+    </tr>
+  </table>
+
 <h3><a name="unlzma">UnLZMA</a></h3>
 
 <p>Is an <a href="#unpack">uncompressing task</a> that uses the LZMA

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/main/org/apache/ant/compress/antlib.xml
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/antlib.xml b/src/main/org/apache/ant/compress/antlib.xml
index 57392e9..161c64c 100644
--- a/src/main/org/apache/ant/compress/antlib.xml
+++ b/src/main/org/apache/ant/compress/antlib.xml
@@ -33,6 +33,10 @@
      classname="org.apache.ant.compress.taskdefs.Uncpio"
      />
   <taskdef
+     name="undeflate"
+     classname="org.apache.ant.compress.taskdefs.Undeflate"
+     />
+  <taskdef
      name="undump"
      classname="org.apache.ant.compress.taskdefs.Undump"
      />
@@ -93,6 +97,10 @@
      classname="org.apache.ant.compress.taskdefs.BZip2"
      />
   <taskdef
+     name="deflate"
+     classname="org.apache.ant.compress.taskdefs.Deflate"
+     />
+  <taskdef
      name="gzip"
      classname="org.apache.ant.compress.taskdefs.GZip"
      />
@@ -183,6 +191,10 @@
      classname="org.apache.ant.compress.resources.BZip2Resource"
      />
   <typedef
+     name="deflateresource"
+     classname="org.apache.ant.compress.resources.DeflateResource"
+     />
+  <typedef
      name="gzipresource"
      classname="org.apache.ant.compress.resources.GZipResource"
      />

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/main/org/apache/ant/compress/resources/DeflateResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/resources/DeflateResource.java b/src/main/org/apache/ant/compress/resources/DeflateResource.java
new file mode 100644
index 0000000..a66f7fb
--- /dev/null
+++ b/src/main/org/apache/ant/compress/resources/DeflateResource.java
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+package org.apache.ant.compress.resources;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.ant.compress.util.DeflateStreamFactory;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateParameters;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * A DEFLATE compressed resource.
+ * @since Apache Compress Antlib 1.5
+ */
+public final class DeflateResource extends CommonsCompressCompressorResource {
+    private boolean zlibHeader = true;
+    private static final String NAME = "DEFLATE";
+
+    public DeflateResource() {
+        super(NAME);
+        setFactory();
+    }
+
+    public DeflateResource(ResourceCollection other) {
+        super(NAME, other);
+        setFactory();
+    }
+
+    /**
+     * Whether to expect or write a ZLIB header.
+     *
+     * <p>Default is {@code true}.</p>
+     * @param zlib whether to expect or write a ZLIB header
+     */
+    public void setZlibHeader(boolean zlib) {
+        zlibHeader = zlib;
+    }
+
+    private void setFactory() {
+        setFactory(new DeflateStreamFactory() {
+            @Override
+            public CompressorOutputStream getCompressorStream(OutputStream stream)
+                throws IOException {
+                DeflateParameters params = new DeflateParameters();
+                params.setWithZlibHeader(zlibHeader);
+                return new DeflateCompressorOutputStream(stream, params);
+            }
+            @Override
+            public CompressorInputStream getCompressorStream(InputStream stream)
+                throws IOException {
+                DeflateParameters params = new DeflateParameters();
+                params.setWithZlibHeader(zlibHeader);
+                return new DeflateCompressorInputStream(stream, params);
+            }
+        });
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/main/org/apache/ant/compress/taskdefs/Deflate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/taskdefs/Deflate.java b/src/main/org/apache/ant/compress/taskdefs/Deflate.java
new file mode 100644
index 0000000..f2b3d5b
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/Deflate.java
@@ -0,0 +1,78 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+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.DeflateResource;
+import org.apache.ant.compress.util.DeflateStreamFactory;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateParameters;
+import org.apache.tools.ant.types.Resource;
+
+/**
+ * Compresses using deflate.
+ * @since Apache Compress Antlib 1.5
+ */
+public final class Deflate extends PackBase {
+    private boolean zlibHeader = true;
+    private int level = Deflater.DEFAULT_COMPRESSION;
+
+    public Deflate() {
+        super(new PackBase.ResourceWrapper() {
+                @Override
+                public CommonsCompressCompressorResource wrap(Resource dest) {
+                    return new DeflateResource(dest);
+                }
+            });
+        setFactory(new DeflateStreamFactory() {
+                @Override
+                public CompressorOutputStream getCompressorStream(OutputStream stream)
+                    throws IOException {
+                    DeflateParameters params = new DeflateParameters();
+                    params.setCompressionLevel(level);
+                    params.setWithZlibHeader(zlibHeader);
+                    return new DeflateCompressorOutputStream(stream, params);
+                }
+            });
+    }
+
+    /**
+     * Set the compression level to use.  Default is
+     * Deflater.DEFAULT_COMPRESSION.
+     * @param level compression level.
+     */
+    public void setLevel(int level) {
+        this.level = level;
+    }
+
+    /**
+     * Whether to write a ZLIB header.
+     *
+     * <p>Default is {@code true}.</p>
+     * @param zlib whether to write a ZLIB header
+     */
+    public void setZlibHeader(boolean zlib) {
+        zlibHeader = zlib;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/main/org/apache/ant/compress/taskdefs/Undeflate.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/taskdefs/Undeflate.java b/src/main/org/apache/ant/compress/taskdefs/Undeflate.java
new file mode 100644
index 0000000..1d1fdb4
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/Undeflate.java
@@ -0,0 +1,59 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ant.compress.taskdefs;
+
+import java.io.InputStream;
+import java.io.IOException;
+
+import org.apache.ant.compress.util.DeflateStreamFactory;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateParameters;
+
+/**
+ * Expands a DEFLATE archive.
+ * @since Apache Compress Antlib 1.5
+ */
+public final class Undeflate extends UnpackBase {
+
+    private boolean zlibHeader = true;
+
+    public Undeflate() {
+        super(".dfl");
+        setFactory(new DeflateStreamFactory() {
+            @Override
+            public CompressorInputStream getCompressorStream(InputStream stream)
+                throws IOException {
+                DeflateParameters params = new DeflateParameters();
+                params.setWithZlibHeader(zlibHeader);
+                return new DeflateCompressorInputStream(stream, params);
+            }
+        });
+    }
+
+    /**
+     * Whether to expect a ZLIB header.
+     *
+     * <p>Default is {@code true}.</p>
+     * @param zlib whether to expect a ZLIB header
+     */
+    public void setZlibHeader(boolean zlib) {
+        zlibHeader = zlib;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/main/org/apache/ant/compress/util/DeflateStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/util/DeflateStreamFactory.java b/src/main/org/apache/ant/compress/util/DeflateStreamFactory.java
new file mode 100644
index 0000000..a9ad766
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/DeflateStreamFactory.java
@@ -0,0 +1,53 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ */
+
+package org.apache.ant.compress.util;
+
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorInputStream;
+import org.apache.commons.compress.compressors.deflate.DeflateCompressorOutputStream;
+
+/**
+ * Creates streams for the standalone DEFLATE format.
+ * @since Apache Compress Antlib 1.5
+ */
+public class DeflateStreamFactory implements CompressorStreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     */
+    @Override
+    public CompressorInputStream getCompressorStream(InputStream stream)
+        throws IOException {
+        return new DeflateCompressorInputStream(stream);
+    }
+
+    /**
+     * @param stream the stream to write to, should be buffered
+     */
+    @Override
+    public CompressorOutputStream getCompressorStream(OutputStream stream)
+        throws IOException {
+        return new DeflateCompressorOutputStream(stream);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/tests/antunit/deflate-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/deflate-test.xml b/src/tests/antunit/deflate-test.xml
new file mode 100644
index 0000000..090186f
--- /dev/null
+++ b/src/tests/antunit/deflate-test.xml
@@ -0,0 +1,110 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+    http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+  -->
+<project default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:cond="antlib:org.apache.tools.ant.types.conditions"
+         xmlns:cmp="antlib:org.apache.ant.compress">
+
+  <import file="antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${output}" />
+    <mkdir dir="${output}/empty" />
+    <touch file="${output}/fileone" />
+    <touch file="${output}/filetwo" />
+  </target>
+
+  <target name="testFailNone" depends="setUp">
+    <au:expectfailure expectedmessage="source is required.">
+      <cmp:deflate destfile="${output}/file.dfl">
+        <fileset dir="${output}/empty" />
+      </cmp:deflate>
+    </au:expectfailure>
+  </target>
+
+  <target name="testFailTwo" depends="setUp">
+    <au:expectfailure expectedmessage="Can only have one source.">
+      <cmp:deflate destfile="${output}/file.dfl">
+        <fileset dir="${output}" />
+      </cmp:deflate>
+    </au:expectfailure>
+  </target>
+
+  <target name="testFailNoDest" depends="setUp">
+    <au:expectfailure expectedmessage="dest resource is required.">
+      <cmp:deflate src="${output}/fileone">
+        <dest>
+          <fileset dir="${output}/empty" />
+        </dest>
+      </cmp:deflate>
+    </au:expectfailure>
+  </target>
+
+  <target name="testFailTwoDests" depends="setUp">
+    <au:expectfailure expectedmessage="Can only have one destination resource.">
+      <cmp:deflate src="${output}/fileone">
+        <dest>
+          <fileset dir="${output}" />
+        </dest>
+      </cmp:deflate>
+    </au:expectfailure>
+  </target>
+
+  <target name="testRealTest" depends="setUp">
+    <cmp:deflate src="../resources/asf-logo.gif"
+              destfile="${output}/asf-logo.gif.dfl" />
+    <au:assertLogContains text="Building: asf-logo.gif.dfl"/>
+    <au:assertFileExists file="${output}/asf-logo.gif.dfl"/>
+  </target>
+
+  <target name="testRealTestWithResource" depends="setUp">
+    <cmp:deflate destfile="${output}/asf-logo.gif.dfl">
+      <file file="../resources/asf-logo.gif"/>
+    </cmp:deflate>
+    <au:assertLogContains text="Building: asf-logo.gif.dfl"/>
+    <au:assertFileExists file="${output}/asf-logo.gif.dfl"/>
+  </target>
+
+  <target name="testDateCheck" depends="setUp">
+    <touch file="${output}/asf-logo.gif.dfl"/>
+    <cmp:deflate src="../resources/asf-logo.gif"
+              destfile="${output}/asf-logo.gif.dfl" />
+    <au:assertLogContains text="Nothing to do: asf-logo.gif.dfl is up to date."/>
+  </target>
+
+  <target name="testNestedTask" depends="setUp">
+    <cmp:deflate destfile="${output}/asf-logo.tar.dfl">
+      <cmp:tar>
+        <cmp:cpiofileset src="../resources/asf-logo.gif.bin.cpio"
+                         includes="asf-logo.gif"/>
+      </cmp:tar>
+    </cmp:deflate>
+    <au:assertFileExists file="${output}/asf-logo.tar.dfl"/>
+    <au:assertTrue>
+      <cond:islastmodified datetime="2009-07-31-20:11:13 +0200"
+                           pattern="yyyy-MM-dd-HH:mm:ss Z">
+        <cmp:tarentry name="asf-logo.gif">
+          <cmp:deflateresource>
+            <file file="${output}/asf-logo.tar.dfl"/>
+          </cmp:deflateresource>
+        </cmp:tarentry>
+      </cond:islastmodified>
+    </au:assertTrue>
+  </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/tests/antunit/deflateresource-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/deflateresource-test.xml b/src/tests/antunit/deflateresource-test.xml
new file mode 100644
index 0000000..8b47e7e
--- /dev/null
+++ b/src/tests/antunit/deflateresource-test.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<project default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:cond="antlib:org.apache.tools.ant.types.conditions"
+         xmlns:cmp="antlib:org.apache.ant.compress">
+
+  <import file="antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${output}"/>
+  </target>    
+
+  <target name="testNativeDeflate" depends="setUp">
+    <copy todir="${output}">
+      <cmp:deflateresource zlibHeader="false">
+        <file file="../resources/asf-logo.gif.dfl"/>
+      </cmp:deflateresource>
+      <globmapper from="*.dfl" to="*"/>
+    </copy>
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+  <target name="testDeflateTask" depends="setUp">
+    <cmp:deflate dest="${output}/asf-logo.gif.dfl" src="../resources/asf-logo.gif"/>
+    <copy todir="${output}">
+      <cmp:deflateresource>
+        <file file="${output}/asf-logo.gif.dfl"/>
+      </cmp:deflateresource>
+      <globmapper from="*.dfl" to="*"/>
+    </copy>
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/tests/antunit/undeflate-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/undeflate-test.xml b/src/tests/antunit/undeflate-test.xml
new file mode 100644
index 0000000..02ffb0b
--- /dev/null
+++ b/src/tests/antunit/undeflate-test.xml
@@ -0,0 +1,74 @@
+<?xml version="1.0"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+-->
+
+<project default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:cond="antlib:org.apache.tools.ant.types.conditions"
+         xmlns:cmp="antlib:org.apache.ant.compress">
+
+  <import file="antunit-base.xml" />
+
+  <target name="setUp">
+    <mkdir dir="${output}"/>
+  </target>    
+
+  <target name="test1">
+    <au:expectfailure>
+      <cmp:undeflate/>
+    </au:expectfailure>
+  </target>
+
+  <target name="test2">
+    <au:expectfailure>
+      <cmp:undeflate src=""/>
+    </au:expectfailure>
+  </target>
+
+  <target name="testDeflateTask" depends="setUp">
+    <cmp:deflate src="../resources/asf-logo.gif"
+                 destfile="${output}/asf-logo.gif.dfl"/>
+    <cmp:undeflate src="${output}/asf-logo.gif.dfl" dest="${output}/asf-logo.gif" />
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+  <target name="testAntlibDeflateTaskWithLevel" depends="setUp">
+    <cmp:deflate src="../resources/asf-logo.gif" level="9"
+                 destfile="${output}/asf-logo.gif.dfl"/>
+    <cmp:undeflate src="${output}/asf-logo.gif.dfl" dest="${output}/asf-logo.gif" />
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+  <target name="testNativeDeflate" depends="setUp">
+    <cmp:undeflate src="../resources/asf-logo.gif.dfl"
+                   zlibHeader="false"
+                   dest="${output}/asf-logo.gif" />
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+  <target name="testWithResource" depends="setUp">
+    <cmp:undeflate dest="${output}/asf-logo.gif" zlibHeader="false">
+      <file file="../resources/asf-logo.gif.dfl"/>
+    </cmp:undeflate>
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/85a1f823/src/tests/resources/asf-logo.gif.dfl
----------------------------------------------------------------------
diff --git a/src/tests/resources/asf-logo.gif.dfl b/src/tests/resources/asf-logo.gif.dfl
new file mode 100644
index 0000000..d68eb6b
Binary files /dev/null and b/src/tests/resources/asf-logo.gif.dfl differ


Mime
View raw message