add support for the XZ format. Requires Commons Compress trunk and XZ for Java
git-svn-id: https://svn.apache.org/repos/asf/ant/antlibs/compress/trunk@1197895 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/changes.xml b/changes.xml
index cf5d20d..6455946 100644
--- a/changes.xml
+++ b/changes.xml
@@ -37,6 +37,17 @@
<title>Apache Compress Ant Library</title>
</properties>
+ <release version="1.2" date="unreleased">
+ <action type="update" breaks-bwc="true">
+ The Apache Compress Antlib now requires Apache Commons
+ Compress 1.4 and the public domain XZ for Java library if you
+ want to use the XZ format.
+ </action>
+ <action type="add">
+ Support for xz compression has been added.
+ </action>
+ </release>
+
<release version="1.1" date="2011-11-05">
<action type="update" breaks-bwc="true">
The Apache Compress Antlib now requires Apache Commons
diff --git a/docs/compresource.html b/docs/compresource.html
index ddd3c0d..3ec3425 100644
--- a/docs/compresource.html
+++ b/docs/compresource.html
@@ -92,3 +92,23 @@
JAR some-archive.pack where the <code>pack200resource</code>
provides the decompression of the archive.</p>
+<h2><a name="xzresource">xzresource</a></h2>
+
+<p>This is a <a href="#compresource">compressed resource</a> using the
+ XZ compression.</p>
+
+<h4>Examples</h4>
+
+<pre>
+<cmp:tarentry xmlns:cmp="antlib:org.apache.ant.compress"
+ name="some-file.txt">
+ <cmp:xzresource>
+ <file file="some-archive.tar.xz"/>
+ </cmp:xzresource>
+</cmp:tarentry>
+</pre>
+
+<p>Represents the entry named some-file.txt in archive
+ some-archive.tar.xz where the <code>xzresource</code> provides
+ the decompression of the archive.</p>
+
diff --git a/docs/index.html b/docs/index.html
index 18d6346..b299963 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.3 this
- Antlib supports gzip, bzip2 and pack200 compression and ar, cpio, Unix
+ Commons Compress</a>. Using Apache Commons Compress 1.4 this
+ Antlib supports gzip, bzip2, xz and pack200 compression and ar, cpio, Unix
dump, tar and zip archives. Support for dump is read-only.</p>
<h3>Known Limitations</h3>
@@ -57,7 +57,9 @@
<li><a href="expand.html#undump">undump</a></li>
<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="expand.html#unzip">unzip</a></li>
+ <li><a href="pack.html#xz">xz</a></li>
<li><a href="archive.html#zip">zip</a></li>
</ul>
@@ -76,6 +78,7 @@
<li><a href="compresource.html#pack200resource">pack200resource</a></li>
<li><a href="entry.html#tarentry">tarentry</a></li>
<li><a href="fileset.html#tarfileset">tarfileset</a></li>
+ <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>
</ul>
diff --git a/docs/pack.html b/docs/pack.html
index 6b33fb3..40ebb00 100644
--- a/docs/pack.html
+++ b/docs/pack.html
@@ -161,6 +161,11 @@
</tr>
</table>
+ <h3><a name="xz">XZ</a></h3>
+
+ <p>Is a <a href="#pack">compressing task</a> that uses the XZ
+ compression algorithm.</p>
+
<h3>Examples</h3>
<pre>
<cmp:gzip src="test.tar" dest="test.tar.gz"
diff --git a/docs/unpack.html b/docs/unpack.html
index 19da76d..c01153e 100644
--- a/docs/unpack.html
+++ b/docs/unpack.html
@@ -131,6 +131,11 @@
</tr>
</table>
+<h3><a name="unxz">UnXZ</a></h3>
+
+<p>Is an <a href="#unpack">uncompressing task</a> that uses the XZ
+ compression algorithm.</p>
+
<h3>Examples</h3>
<blockquote><pre>
<cmp:gunzip src="test.tar.gz" xmlns:cmp="antlib:org.apache.ant.compress"/>
diff --git a/project-template.ivy.xml b/project-template.ivy.xml
index 0619f2f..4ce4872 100644
--- a/project-template.ivy.xml
+++ b/project-template.ivy.xml
@@ -52,6 +52,7 @@
</publications>
<dependencies>
<dependency org="org.apache.commons" name="commons-compress"
- rev="1.3"/>
+ rev="1.4"/>
+ <dependency org="org.tukaani" name="xz" rev="1.0"/>
</dependencies>
</ivy-module>
diff --git a/project-template.pom b/project-template.pom
index 5e5ef93..4c489dc 100644
--- a/project-template.pom
+++ b/project-template.pom
@@ -50,7 +50,12 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
- <version>[1.3,)</version>
+ <version>1.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.tukaani</groupId>
+ <artifactId>xz</artifactId>
+ <version>1.0</version>
</dependency>
</dependencies>
</project>
diff --git a/src/main/org/apache/ant/compress/antlib.xml b/src/main/org/apache/ant/compress/antlib.xml
index c69d58d..baf6e45 100644
--- a/src/main/org/apache/ant/compress/antlib.xml
+++ b/src/main/org/apache/ant/compress/antlib.xml
@@ -65,6 +65,10 @@
classname="org.apache.ant.compress.taskdefs.UnPack200"
/>
<taskdef
+ name="unxz"
+ classname="org.apache.ant.compress.taskdefs.UnXZ"
+ />
+ <taskdef
name="bzip2"
classname="org.apache.ant.compress.taskdefs.BZip2"
/>
@@ -80,6 +84,10 @@
name="pack200normalize"
classname="org.apache.ant.compress.taskdefs.Pack200Normalize"
/>
+ <taskdef
+ name="xz"
+ classname="org.apache.ant.compress.taskdefs.XZ"
+ />
<typedef
name="arentry"
@@ -138,6 +146,10 @@
name="pack200resource"
classname="org.apache.ant.compress.resources.Pack200Resource"
/>
+ <typedef
+ name="xzresource"
+ classname="org.apache.ant.compress.resources.XZResource"
+ />
<componentdef
name="hasusername"
diff --git a/src/main/org/apache/ant/compress/resources/XZResource.java b/src/main/org/apache/ant/compress/resources/XZResource.java
new file mode 100644
index 0000000..f9b9fcb
--- /dev/null
+++ b/src/main/org/apache/ant/compress/resources/XZResource.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.XZStreamFactory;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * An XZ compressed resource.
+ * @since Apache Compress Antlib 1.2
+ */
+public final class XZResource extends CommonsCompressCompressorResource {
+ private static final String NAME = "XZ";
+
+ public XZResource() {
+ super(NAME, new XZStreamFactory());
+ }
+
+ public XZResource(ResourceCollection other) {
+ super(NAME, new XZStreamFactory(), other);
+ }
+}
diff --git a/src/main/org/apache/ant/compress/taskdefs/UnXZ.java b/src/main/org/apache/ant/compress/taskdefs/UnXZ.java
new file mode 100644
index 0000000..3f533dd
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/UnXZ.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.XZStreamFactory;
+
+/**
+ * Expands an xz archive.
+ * @since Apache Compress Antlib 1.2
+ */
+public final class UnXZ extends UnpackBase {
+
+ public UnXZ() {
+ super(".xz", new XZStreamFactory());
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/org/apache/ant/compress/taskdefs/XZ.java b/src/main/org/apache/ant/compress/taskdefs/XZ.java
new file mode 100644
index 0000000..d9f50a8
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/XZ.java
@@ -0,0 +1,41 @@
+/*
+ * 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.resources.CommonsCompressCompressorResource;
+import org.apache.ant.compress.resources.XZResource;
+import org.apache.ant.compress.util.XZStreamFactory;
+import org.apache.tools.ant.types.Resource;
+
+/**
+ * Compresses using XZ.
+ * @since Apache Compress Antlib 1.2
+ */
+public final class XZ extends PackBase {
+
+ public XZ() {
+ super(new XZStreamFactory(),
+ new PackBase.ResourceWrapper() {
+ public CommonsCompressCompressorResource wrap(Resource dest) {
+ return new XZResource(dest);
+ }
+ });
+ }
+
+}
\ No newline at end of file
diff --git a/src/main/org/apache/ant/compress/util/XZStreamFactory.java b/src/main/org/apache/ant/compress/util/XZStreamFactory.java
new file mode 100644
index 0000000..58d2930
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/XZStreamFactory.java
@@ -0,0 +1,52 @@
+/*
+ * 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.xz.XZCompressorInputStream;
+import org.apache.commons.compress.compressors.xz.XZCompressorOutputStream;
+
+/**
+ * Creates streams for the supported compression formats.
+ * @since Apache Compress Antlib 1.2
+ */
+public class XZStreamFactory implements CompressorStreamFactory {
+
+ /**
+ * @param stream the stream to read from, should be buffered
+ */
+ public CompressorInputStream getCompressorStream(InputStream stream)
+ throws IOException {
+ return new XZCompressorInputStream(stream);
+ }
+
+
+ /**
+ * @param stream the stream to write to, should be buffered
+ */
+ public CompressorOutputStream getCompressorStream(OutputStream stream)
+ throws IOException {
+ return new XZCompressorOutputStream(stream);
+ }
+}
\ No newline at end of file
diff --git a/src/tests/antunit/unxz-test.xml b/src/tests/antunit/unxz-test.xml
new file mode 100644
index 0000000..1ceec01
--- /dev/null
+++ b/src/tests/antunit/unxz-test.xml
@@ -0,0 +1,65 @@
+<?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:unxz/>
+ </au:expectfailure>
+ </target>
+
+ <target name="test2">
+ <au:expectfailure>
+ <cmp:unxz src=""/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testXZTask" depends="setUp">
+ <cmp:xz src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.xz"/>
+ <cmp:unxz src="${output}/asf-logo.gif.xz" dest="${output}/asf-logo.gif" />
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+ <target name="testNativeXZ" depends="setUp">
+ <cmp:unxz src="../resources/asf-logo.gif.xz"
+ dest="${output}/asf-logo.gif" />
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+ <target name="testWithResource" depends="setUp">
+ <cmp:unxz dest="${output}/asf-logo.gif">
+ <file file="../resources/asf-logo.gif.xz"/>
+ </cmp:unxz>
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+</project>
diff --git a/src/tests/antunit/xz-test.xml b/src/tests/antunit/xz-test.xml
new file mode 100644
index 0000000..fd44987
--- /dev/null
+++ b/src/tests/antunit/xz-test.xml
@@ -0,0 +1,109 @@
+<?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:xz destfile="${output}/file.xz">
+ <fileset dir="${output}/empty" />
+ </cmp:xz>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailTwo" depends="setUp">
+ <au:expectfailure expectedmessage="Can only have one source.">
+ <cmp:xz destfile="${output}/file.xz">
+ <fileset dir="${output}" />
+ </cmp:xz>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailNoDest" depends="setUp">
+ <au:expectfailure expectedmessage="dest resource is required.">
+ <cmp:xz src="${output}/fileone">
+ <dest>
+ <fileset dir="${output}/empty" />
+ </dest>
+ </cmp:xz>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailTwoDests" depends="setUp">
+ <au:expectfailure expectedmessage="Can only have one destination resource.">
+ <cmp:xz src="${output}/fileone">
+ <dest>
+ <fileset dir="${output}" />
+ </dest>
+ </cmp:xz>
+ </au:expectfailure>
+ </target>
+
+ <target name="testRealTest" depends="setUp">
+ <cmp:xz src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.xz" />
+ <au:assertLogContains text="Building: asf-logo.gif.xz"/>
+ <au:assertFileExists file="${output}/asf-logo.gif.xz"/>
+ </target>
+
+ <target name="testRealTestWithResource" depends="setUp">
+ <cmp:xz destfile="${output}/asf-logo.gif.xz">
+ <file file="../resources/asf-logo.gif"/>
+ </cmp:xz>
+ <au:assertLogContains text="Building: asf-logo.gif.xz"/>
+ <au:assertFileExists file="${output}/asf-logo.gif.xz"/>
+ </target>
+
+ <target name="testDateCheck" depends="setUp">
+ <touch file="${output}/asf-logo.gif.xz"/>
+ <cmp:xz src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.xz" />
+ <au:assertLogContains text="Nothing to do: asf-logo.gif.xz is up to date."/>
+ </target>
+
+ <target name="testNestedTask" depends="setUp">
+ <cmp:xz destfile="${output}/asf-logo.tar.xz">
+ <cmp:tar>
+ <cmp:cpiofileset src="../resources/asf-logo.gif.bin.cpio"
+ includes="asf-logo.gif"/>
+ </cmp:tar>
+ </cmp:xz>
+ <au:assertFileExists file="${output}/asf-logo.tar.xz"/>
+ <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:xzresource>
+ <file file="${output}/asf-logo.tar.xz"/>
+ </cmp:xzresource>
+ </cmp:tarentry>
+ </cond:islastmodified>
+ </au:assertTrue>
+ </target>
+</project>
diff --git a/src/tests/antunit/xzresource-test.xml b/src/tests/antunit/xzresource-test.xml
new file mode 100644
index 0000000..3390a98
--- /dev/null
+++ b/src/tests/antunit/xzresource-test.xml
@@ -0,0 +1,40 @@
+<?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="testNativeXZ" depends="setUp">
+ <copy todir="${output}">
+ <cmp:xzresource>
+ <file file="../resources/asf-logo.gif.xz"/>
+ </cmp:xzresource>
+ <globmapper from="*.xz" 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.xz b/src/tests/resources/asf-logo.gif.xz
new file mode 100644
index 0000000..139eea4
--- /dev/null
+++ b/src/tests/resources/asf-logo.gif.xz
Binary files differ
diff --git a/version.properties b/version.properties
index 9a5025c..cce379b 100644
--- a/version.properties
+++ b/version.properties
@@ -12,4 +12,4 @@
# 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.
-artifact.version=1.1Alpha
+artifact.version=1.2Alpha