add Zstandard support
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..38bc65e
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,9 @@
+*.ar binary
+*.arj binary
+*.java text diff=java
+*.md text
+*.txt text
+*.xml text
+*.yml text
+*.zstd binary
+.gitattributes text
diff --git a/changes.xml b/changes.xml
index e1875b4..f51f7a7 100644
--- a/changes.xml
+++ b/changes.xml
@@ -40,13 +40,17 @@
<release version="1.6" date="unreleased">
<action type="update" breaks-bwc="true">
The Apache Compress Antlib now requires Apache Commons
- Compress 1.16 or later for DEFLATE64 support.
+ Compress 1.16 or later for DEFLATE64 and Zstandard support.
+ zstd-jni 1.3.3-1 or later is required for Zstandard support.
</action>
<action type="add">
Added read-only support for the DEFLATE64 format. More
importantly we can now read zip and 7z entries using this
algorithm.
</action>
+ <action type="add">
+ Added support for the Zstandard format.
+ </action>
</release>
<release version="1.5" date="2017-06-13">
<action type="update" breaks-bwc="true">
diff --git a/docs/compresource.html b/docs/compresource.html
index 57e85b3..3270a4c 100644
--- a/docs/compresource.html
+++ b/docs/compresource.html
@@ -313,3 +313,26 @@
<p>Represents the entry named some-file.txt in archive
some-archive.tar.Z where the <code>zresource</code> provides
the decompression of the archive.</p>
+
+<h2><a name="zstdresource">zstdresource</a></h2>
+
+<p><em>Since Apache Compress Antlib 1.6</em>.</p>
+
+<p>This is a <a href="#compresource">compressed resource</a> using
+ Zstandard compression.</p>
+
+<h4>Examples</h4>
+
+<pre>
+<cmp:tarentry xmlns:cmp="antlib:org.apache.ant.compress"
+ name="some-file.txt">
+ <cmp:zstdresource>
+ <file file="some-archive.tar.zstd"/>
+ </cmp:zstdresource>
+</cmp:tarentry>
+</pre>
+
+<p>Represents the entry named some-file.txt in archive
+ some-archive.tar.zstd where the <code>zstdresource</code> provides
+ the decompression of the archive.</p>
+
diff --git a/docs/index.html b/docs/index.html
index 44c7e01..da9cc1b 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -30,7 +30,7 @@
based on <a href="http://commons.apache.org/compress/">Apache
Commons Compress</a>. Using Apache Commons Compress 1.16 this
Antlib supports gzip, bzip2, lzma standalone, xz, .Z, DEFLATE, DEFLATE64,
- Snappy, LZ4, Brotli and pack200 compression and ar, arj, cpio,
+ Snappy, LZ4, Brotli, Zstandard and pack200 compression and ar, arj, cpio,
7z, Unix dump, tar and zip archives. Support for arj, .Z,
Brotli, DEFLATE64 and dump is read-only. 7z can only be used on filesystem
resources.</p>
@@ -76,8 +76,10 @@
<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="unpack.html#unzstd">unzstd</a></li>
<li><a href="pack.html#xz">xz</a></li>
<li><a href="archive.html#zip">zip</a></li>
+ <li><a href="pack.html#zstd">zstd</a></li>
</ul>
<p>This Antlib contains the following resources:</p>
@@ -109,6 +111,7 @@
<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>
+ <li><a href="compresource.html#zstdresource">zstdresource</a></li>
</ul>
<p>This Antlib contains the following conditions that work on the
@@ -136,6 +139,10 @@
the <a href="https://github.com/google/brotli">Brotli dec</a>
library version 0.1.2 or later is required.</p>
+ <p>In order to use Zstandard
+ the <a href="https://github.com/luben/zstd-jni">zstd-jni</a>
+ library version 1.3.3-1 or later is required.</p>
+
<p>If you are building the Antlib from sources, run
the <code>antlib</code> target and you'll get a
file <code>ant-compress-VERSION.jar</code>. If you've
diff --git a/docs/pack.html b/docs/pack.html
index 2383102..7cc5499 100644
--- a/docs/pack.html
+++ b/docs/pack.html
@@ -277,6 +277,13 @@
<p>Is a <a href="#pack">compressing task</a> that uses the XZ
compression algorithm.</p>
+ <h3><a name="zstd">zstd</a></h3>
+
+ <p>Is a <a href="#pack">compressing task</a> that uses the Zstandard
+ compression algorithm.</p>
+
+ <p><em>Since Compress Antlib 1.6</em>
+
<h3>Examples</h3>
<pre>
<cmp:gzip src="test.tar" dest="test.tar.gz"
diff --git a/docs/unpack.html b/docs/unpack.html
index 9167598..24f226c 100644
--- a/docs/unpack.html
+++ b/docs/unpack.html
@@ -263,6 +263,13 @@
<p><em>Since Apache Compress Antlib 1.4</em>.</p>
+<h3><a name="unzstd">UnZstd</a></h3>
+
+<p>Is an <a href="#unpack">uncompressing task</a> that uses the Zstandard
+ compression algorithm.</p>
+
+<p><em>Since Apache Compress Antlib 1.6</em>.</p>
+
<h3>Examples</h3>
<blockquote><pre>
<cmp:gunzip src="test.tar.gz" xmlns:cmp="antlib:org.apache.ant.compress"/>
diff --git a/ivy.xml b/ivy.xml
index 9c3148d..c614585 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -59,6 +59,7 @@
<dependency org="org.apache.commons" name="commons-compress" rev="1.16" conf="default"/>
<dependency org="org.tukaani" name="xz" rev="1.8" conf="default"/>
<dependency org="org.brotli" name="dec" rev="0.1.2" conf="default"/>
+ <dependency org="com.github.luben" name="zstd-jni" rev="1.3.3-1" conf="default"/>
<dependency org="junit" name="junit" rev="4.12" conf="test->default"/>
<dependency org="org.apache.ant" name="ant-antunit" rev="1.3"
conf="test->default" transitive="false" />
diff --git a/src/main/org/apache/ant/compress/antlib.xml b/src/main/org/apache/ant/compress/antlib.xml
index 027b28b..91b9435 100644
--- a/src/main/org/apache/ant/compress/antlib.xml
+++ b/src/main/org/apache/ant/compress/antlib.xml
@@ -105,6 +105,10 @@
classname="org.apache.ant.compress.taskdefs.UnZ"
/>
<taskdef
+ name="unzstd"
+ classname="org.apache.ant.compress.taskdefs.UnZstd"
+ />
+ <taskdef
name="bzip2"
classname="org.apache.ant.compress.taskdefs.BZip2"
/>
@@ -144,6 +148,10 @@
name="lzma"
classname="org.apache.ant.compress.taskdefs.LZMA"
/>
+ <taskdef
+ name="zstd"
+ classname="org.apache.ant.compress.taskdefs.Zstd"
+ />
<typedef
name="arentry"
@@ -250,6 +258,10 @@
name="zresource"
classname="org.apache.ant.compress.resources.ZResource"
/>
+ <typedef
+ name="zstdresource"
+ classname="org.apache.ant.compress.resources.ZstdResource"
+ />
<componentdef
name="hasusername"
diff --git a/src/main/org/apache/ant/compress/resources/ZstdResource.java b/src/main/org/apache/ant/compress/resources/ZstdResource.java
new file mode 100644
index 0000000..be30719
--- /dev/null
+++ b/src/main/org/apache/ant/compress/resources/ZstdResource.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.ZstdStreamFactory;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * A Zstdandard compressed resource.
+ * @since Apache Compress Antlib 1.6
+ */
+public final class ZstdResource extends CommonsCompressCompressorResource {
+ private static final String NAME = "ZSTD";
+
+ public ZstdResource() {
+ super(NAME, new ZstdStreamFactory());
+ }
+
+ public ZstdResource(ResourceCollection other) {
+ super(NAME, new ZstdStreamFactory(), other);
+ }
+}
diff --git a/src/main/org/apache/ant/compress/taskdefs/UnZstd.java b/src/main/org/apache/ant/compress/taskdefs/UnZstd.java
new file mode 100644
index 0000000..c23d31a
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/UnZstd.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.ZstdStreamFactory;
+
+/**
+ * Expands a Zstandard archive.
+ * @since Apache Compress Antlib 1.6
+ */
+public final class UnZstd extends UnpackBase {
+
+ public UnZstd() {
+ super(".zstd", new ZstdStreamFactory());
+ }
+
+}
diff --git a/src/main/org/apache/ant/compress/taskdefs/Zstd.java b/src/main/org/apache/ant/compress/taskdefs/Zstd.java
new file mode 100644
index 0000000..1cea2ee
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/Zstd.java
@@ -0,0 +1,42 @@
+/*
+ * 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.ZstdResource;
+import org.apache.ant.compress.util.ZstdStreamFactory;
+import org.apache.tools.ant.types.Resource;
+
+/**
+ * Compresses using Zstandard.
+ * @since Apache Compress Antlib 1.6
+ */
+public final class Zstd extends PackBase {
+
+ public Zstd() {
+ super(new ZstdStreamFactory(),
+ new PackBase.ResourceWrapper() {
+ @Override
+ public CommonsCompressCompressorResource wrap(Resource dest) {
+ return new ZstdResource(dest);
+ }
+ });
+ }
+
+}
diff --git a/src/main/org/apache/ant/compress/util/ZstdStreamFactory.java b/src/main/org/apache/ant/compress/util/ZstdStreamFactory.java
new file mode 100644
index 0000000..0306269
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/ZstdStreamFactory.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.zstandard.ZstdCompressorInputStream;
+import org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
+
+/**
+ * Creates streams for the Zstandard format.
+ * @since Apache Compress Antlib 1.6
+ */
+public class ZstdStreamFactory implements CompressorStreamFactory {
+
+ /**
+ * @param stream the stream to read from, should be buffered
+ */
+ @Override
+ public CompressorInputStream getCompressorStream(InputStream stream)
+ throws IOException {
+ return new ZstdCompressorInputStream(stream);
+ }
+
+ /**
+ * @param stream the stream to write to, should be buffered
+ */
+ @Override
+ public CompressorOutputStream getCompressorStream(OutputStream stream)
+ throws IOException {
+ return new ZstdCompressorOutputStream(stream);
+ }
+}
diff --git a/src/tests/antunit/unzstd-test.xml b/src/tests/antunit/unzstd-test.xml
new file mode 100644
index 0000000..af7a041
--- /dev/null
+++ b/src/tests/antunit/unzstd-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:unzstd/>
+ </au:expectfailure>
+ </target>
+
+ <target name="test2">
+ <au:expectfailure>
+ <cmp:unzstd src=""/>
+ </au:expectfailure>
+ </target>
+
+ <target name="testZstdTask" depends="setUp">
+ <cmp:zstd src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.zstd"/>
+ <cmp:unzstd src="${output}/asf-logo.gif.zstd" dest="${output}/asf-logo.gif" />
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+ <target name="testNativeZstd" depends="setUp">
+ <cmp:unzstd src="../resources/asf-logo.gif.zstd"
+ dest="${output}/asf-logo.gif" />
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+ <target name="testWithResource" depends="setUp">
+ <cmp:unzstd dest="${output}/asf-logo.gif">
+ <file file="../resources/asf-logo.gif.zstd"/>
+ </cmp:unzstd>
+ <au:assertFilesMatch expected="../resources/asf-logo.gif"
+ actual="${output}/asf-logo.gif"/>
+ </target>
+
+</project>
diff --git a/src/tests/antunit/zstd-test.xml b/src/tests/antunit/zstd-test.xml
new file mode 100644
index 0000000..9045411
--- /dev/null
+++ b/src/tests/antunit/zstd-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:zstd destfile="${output}/file.zstd">
+ <fileset dir="${output}/empty" />
+ </cmp:zstd>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailTwo" depends="setUp">
+ <au:expectfailure expectedmessage="Can only have one source.">
+ <cmp:zstd destfile="${output}/file.zstd">
+ <fileset dir="${output}" />
+ </cmp:zstd>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailNoDest" depends="setUp">
+ <au:expectfailure expectedmessage="dest resource is required.">
+ <cmp:zstd src="${output}/fileone">
+ <dest>
+ <fileset dir="${output}/empty" />
+ </dest>
+ </cmp:zstd>
+ </au:expectfailure>
+ </target>
+
+ <target name="testFailTwoDests" depends="setUp">
+ <au:expectfailure expectedmessage="Can only have one destination resource.">
+ <cmp:zstd src="${output}/fileone">
+ <dest>
+ <fileset dir="${output}" />
+ </dest>
+ </cmp:zstd>
+ </au:expectfailure>
+ </target>
+
+ <target name="testRealTest" depends="setUp">
+ <cmp:zstd src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.zstd" />
+ <au:assertLogContains text="Building: asf-logo.gif.zstd"/>
+ <au:assertFileExists file="${output}/asf-logo.gif.zstd"/>
+ </target>
+
+ <target name="testRealTestWithResource" depends="setUp">
+ <cmp:zstd destfile="${output}/asf-logo.gif.zstd">
+ <file file="../resources/asf-logo.gif"/>
+ </cmp:zstd>
+ <au:assertLogContains text="Building: asf-logo.gif.zstd"/>
+ <au:assertFileExists file="${output}/asf-logo.gif.zstd"/>
+ </target>
+
+ <target name="testDateCheck" depends="setUp">
+ <touch file="${output}/asf-logo.gif.zstd"/>
+ <cmp:zstd src="../resources/asf-logo.gif"
+ destfile="${output}/asf-logo.gif.zstd" />
+ <au:assertLogContains text="Nothing to do: asf-logo.gif.zstd is up to date."/>
+ </target>
+
+ <target name="testNestedTask" depends="setUp">
+ <cmp:zstd destfile="${output}/asf-logo.tar.zstd">
+ <cmp:tar>
+ <cmp:cpiofileset src="../resources/asf-logo.gif.bin.cpio"
+ includes="asf-logo.gif"/>
+ </cmp:tar>
+ </cmp:zstd>
+ <au:assertFileExists file="${output}/asf-logo.tar.zstd"/>
+ <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:zstdresource>
+ <file file="${output}/asf-logo.tar.zstd"/>
+ </cmp:zstdresource>
+ </cmp:tarentry>
+ </cond:islastmodified>
+ </au:assertTrue>
+ </target>
+</project>
diff --git a/src/tests/antunit/zstdresource-test.xml b/src/tests/antunit/zstdresource-test.xml
new file mode 100644
index 0000000..2f5f601
--- /dev/null
+++ b/src/tests/antunit/zstdresource-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="testNativeZstd" depends="setUp">
+ <copy todir="${output}">
+ <cmp:zstdresource>
+ <file file="../resources/asf-logo.gif.zstd"/>
+ </cmp:zstdresource>
+ <globmapper from="*.zstd" 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.zstd b/src/tests/resources/asf-logo.gif.zstd
new file mode 100644
index 0000000..32a4750
--- /dev/null
+++ b/src/tests/resources/asf-logo.gif.zstd
Binary files differ