Read-Only support for traditional Unix compress (.Z) format
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/compress/trunk@1553276 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/changes.xml b/changes.xml
index 5dee2f0..b0c6130 100644
--- a/changes.xml
+++ b/changes.xml
@@ -38,6 +38,10 @@
</properties>
<release version="1.4" date="unreleased">
+ <action type="add">
+ Read-only support for tradional Unix Compress (.Z) has been
+ added.
+ </action>
</release>
<release version="1.3" date="2013-11-07">
diff --git a/docs/compresource.html b/docs/compresource.html
index 0ee8f33..5e56869 100644
--- a/docs/compresource.html
+++ b/docs/compresource.html
@@ -154,3 +154,24 @@
some-archive.tar.xz where the <code>xzresource</code> provides
the decompression of the archive.</p>
+<h2><a name="zresource">zresource</a></h2>
+
+<p><em>Since Apache Compress Antlib 1.4</em>.</p>
+
+<p>This is a <a href="#compresource">compressed resource</a> using the
+ traditional Unix compress (.Z) compression.</p>
+
+<h4>Examples</h4>
+
+<pre>
+<cmp:tarentry xmlns:cmp="antlib:org.apache.ant.compress"
+ name="some-file.txt">
+ <cmp:zresource>
+ <file file="some-archive.tar.Z"/>
+ </cmp:zresource>
+</cmp:tarentry>
+</pre>
+
+<p>Represents the entry named some-file.txt in archive
+ some-archive.tar.gz where the <code>zresource</code> provides
+ the decompression of the archive.</p>
diff --git a/docs/index.html b/docs/index.html
index 2cf3f0c..f1fbf26 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -29,9 +29,9 @@
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 and pack200
+ Antlib supports gzip, bzip2, lzma standalone, xz, .Z and pack200
compression and ar, arj, cpio, 7z, Unix dump, tar and zip
- archives. Support for lzma, arj and dump is read-only. 7z can
+ archives. Support for lzma, arj, .Z and dump is read-only. 7z can
only be used on filesystem resources.</p>
<h3>Known Limitations</h3>
@@ -64,6 +64,7 @@
<li><a href="unpack.html#unpack200">unpack200</a></li>
<li><a href="expand.html#untar">untar</a></li>
<li><a href="unpack.html#unxz">unxz</a></li>
+ <li><a href="unpack.html#unz">unz</a></li>
<li><a href="expand.html#unzip">unzip</a></li>
<li><a href="pack.html#xz">xz</a></li>
<li><a href="archive.html#zip">zip</a></li>
@@ -92,6 +93,7 @@
<li><a href="compresource.html#xzresource">xzresource</a></li>
<li><a href="entry.html#zipentry">zipentry</a></li>
<li><a href="fileset.html#zipfileset">zipfileset</a></li>
+ <li><a href="compresource.html#zresource">zresource</a></li>
</ul>
<p>This Antlib contains the following conditions that work on the
diff --git a/docs/unpack.html b/docs/unpack.html
index 65e97a9..63397bc 100644
--- a/docs/unpack.html
+++ b/docs/unpack.html
@@ -163,6 +163,11 @@
the <a href="#decompressConcatenated">decompressConcatenated</a>
attribute.</p>
+<h3><a name="unz">UnZ</a></h3>
+
+<p>Is an <a href="#unpack">uncompressing task</a> that uses the .Z
+ compression algorithm.</p>
+
<h3>Examples</h3>
<blockquote><pre>
<cmp:gunzip src="test.tar.gz" xmlns:cmp="antlib:org.apache.ant.compress"/>
diff --git a/src/main/org/apache/ant/compress/antlib.xml b/src/main/org/apache/ant/compress/antlib.xml
index ff3f14f..1075e23 100644
--- a/src/main/org/apache/ant/compress/antlib.xml
+++ b/src/main/org/apache/ant/compress/antlib.xml
@@ -81,6 +81,10 @@
classname="org.apache.ant.compress.taskdefs.UnXZ"
/>
<taskdef
+ name="unz"
+ classname="org.apache.ant.compress.taskdefs.UnZ"
+ />
+ <taskdef
name="bzip2"
classname="org.apache.ant.compress.taskdefs.BZip2"
/>
@@ -186,6 +190,10 @@
name="xzresource"
classname="org.apache.ant.compress.resources.XZResource"
/>
+ <typedef
+ name="zresource"
+ classname="org.apache.ant.compress.resources.ZResource"
+ />
<componentdef
name="hasusername"
diff --git a/src/main/org/apache/ant/compress/resources/ZResource.java b/src/main/org/apache/ant/compress/resources/ZResource.java
new file mode 100644
index 0000000..417dc70
--- /dev/null
+++ b/src/main/org/apache/ant/compress/resources/ZResource.java
@@ -0,0 +1,37 @@
+/*
+ * 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 org.apache.ant.compress.util.ZStreamFactory;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * A .Z compressed resource.
+ * @since Apache Compress Antlib 1.4
+ */
+public final class ZResource extends CommonsCompressCompressorResource {
+ private static final String NAME = "Z";
+
+ public ZResource() {
+ super(NAME, new ZStreamFactory());
+ }
+
+ public ZResource(ResourceCollection other) {
+ super(NAME, new ZStreamFactory(), other);
+ }
+}
diff --git a/src/main/org/apache/ant/compress/taskdefs/UnZ.java b/src/main/org/apache/ant/compress/taskdefs/UnZ.java
new file mode 100644
index 0000000..3142e3c
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/UnZ.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.apache.ant.compress.util.ZStreamFactory;
+
+/**
+ * Expands a traditional Unix compress (.Z) archive.
+ * @since Apache Compress Antlib 1.4
+ */
+public final class UnZ extends UnpackBase {
+
+ public UnZ() {
+ super(".Z", new ZStreamFactory());
+ }
+
+}
diff --git a/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java b/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java
index 5f3407f..2c9cede 100644
--- a/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java
+++ b/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java
@@ -27,7 +27,7 @@
import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream;
/**
- * Creates streams for the supported compression formats.
+ * Creates streams for the standalone LZMA format.
* @since Apache Compress Antlib 1.3
*/
public class LZMAStreamFactory implements CompressorStreamFactory {
diff --git a/src/main/org/apache/ant/compress/util/ZStreamFactory.java b/src/main/org/apache/ant/compress/util/ZStreamFactory.java
new file mode 100644
index 0000000..53609de
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/ZStreamFactory.java
@@ -0,0 +1,50 @@
+/*
+ * 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.z.ZCompressorInputStream;
+
+/**
+ * Creates streams for the traditional Unix compress format.
+ * @since Apache Compress Antlib 1.4
+ */
+public class ZStreamFactory implements CompressorStreamFactory {
+
+ /**
+ * @param stream the stream to read from, should be buffered
+ */
+ public CompressorInputStream getCompressorStream(InputStream stream)
+ throws IOException {
+ return new ZCompressorInputStream(stream);
+ }
+
+ /**
+ * Not implemented.
+ */
+ public CompressorOutputStream getCompressorStream(OutputStream stream)
+ throws IOException {
+ throw new UnsupportedOperationException();
+ }
+}
diff --git a/src/tests/antunit/unz-test.xml b/src/tests/antunit/unz-test.xml
new file mode 100644
index 0000000..42a67b6
--- /dev/null
+++ b/src/tests/antunit/unz-test.xml
@@ -0,0 +1,58 @@
+<?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:unz/>
+ </au:expectfailure>
+ </target>
+
+ <target name="test2">
+ <au:expectfailure>
+ <cmp:unz src=""/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testNativeZ" depends="setUp">
+ <cmp:unz src="../resources/asf-logo.gif.Z"
+ dest="${output}/asf-logo.gif" />
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+ <target name="testWithResource" depends="setUp">
+ <cmp:unz dest="${output}/asf-logo.gif">
+ <file file="../resources/asf-logo.gif.Z"/>
+ </cmp:unz>
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+
+</project>
diff --git a/src/tests/antunit/zresource-test.xml b/src/tests/antunit/zresource-test.xml
new file mode 100644
index 0000000..112b56d
--- /dev/null
+++ b/src/tests/antunit/zresource-test.xml
@@ -0,0 +1,41 @@
+<?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="testNativeZ" depends="setUp">
+ <copy todir="${output}">
+ <cmp:zresource>
+ <file file="../resources/asf-logo.gif.Z"/>
+ </cmp:zresource>
+ <globmapper from="*.Z" to="*"/>
+ </copy>
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+</project>
diff --git a/src/tests/resources/asf-logo.gif.Z b/src/tests/resources/asf-logo.gif.Z
new file mode 100644
index 0000000..d741a7c
--- /dev/null
+++ b/src/tests/resources/asf-logo.gif.Z
Binary files differ