add write support for Snappy framing format
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/5de99d93 Tree: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/tree/5de99d93 Diff: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/diff/5de99d93 Branch: refs/heads/compress-1.14 Commit: 5de99d936182c334f1448330f8b0954a2708052e Parents: 21789f1 Author: Stefan Bodewig <[email protected]> Authored: Mon May 8 06:33:38 2017 +0200 Committer: Stefan Bodewig <[email protected]> Committed: Mon May 8 06:33:38 2017 +0200 ---------------------------------------------------------------------- changes.xml | 7 +- docs/index.html | 1 + docs/pack.html | 26 +++++ docs/unpack.html | 4 +- ivy.xml | 2 +- src/main/org/apache/ant/compress/antlib.xml | 4 + .../apache/ant/compress/taskdefs/Snappy.java | 55 +++++++++ .../ant/compress/util/SnappyStreamFactory.java | 20 +++- src/tests/antunit/snappy-test.xml | 111 +++++++++++++++++++ src/tests/antunit/unsnappy-test.xml | 8 ++ 10 files changed, 229 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/changes.xml ---------------------------------------------------------------------- diff --git a/changes.xml b/changes.xml index 0927c18..014c051 100644 --- a/changes.xml +++ b/changes.xml @@ -40,8 +40,8 @@ <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, DEFLATE and write support - for LZMA. + Compress 1.14 or later for 7z, DEFLATE and write support + for LZMA and Snappy. XZ for Java 1.6 is required for write support for LZMA. </action> <action type="add"> @@ -63,6 +63,9 @@ <action type="add"> Added support for the DEFLATE format with and without ZLIB headers. </action> + <action type="add"> + Added write support for the Snappy format. + </action> </release> <release version="1.4" date="2014-01-29"> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/docs/index.html ---------------------------------------------------------------------- diff --git a/docs/index.html b/docs/index.html index 5a7b1e3..26f3fb6 100644 --- a/docs/index.html +++ b/docs/index.html @@ -56,6 +56,7 @@ <li><a href="pack.html#pack200">pack200</a></li> <li><a href="pack200normalize.html">pack200normalize</a></li> <li><a href="archive.html#sevenz">sevenz</a></li> + <li><a href="pack.html#snappy">snappy</a></li> <li><a href="archive.html#tar">tar</a></li> <li><a href="expand.html#un7z">un7z</a></li> <li><a href="expand.html#unar">unar</a></li> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/docs/pack.html ---------------------------------------------------------------------- diff --git a/docs/pack.html b/docs/pack.html index 67738e5..0a8700d 100644 --- a/docs/pack.html +++ b/docs/pack.html @@ -216,6 +216,32 @@ </tr> </table> + <h3><a name="snappy">Snappy</a></h3> + + <p>Is a <a href="#pack">compressing task</a> that uses + the <a href="https://github.com/google/snappy">Snappy</a> + compression algorithm.</p> + + <p><em>Since Compress Antlib 1.5</em> + +<h4>Parameters</h4> + <p>In addition to the attributes supported by all compressing task + this task also supports.</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">framed</td> + <td valign="top">Whether to use + the <a href="https://github.com/google/snappy/blob/master/framing_format.txt">framing + format</a>.</td> + <td align="center" valign="top">No, defaults to true.</td> + </tr> + </table> + <h3><a name="xz">XZ</a></h3> <p>Is a <a href="#pack">compressing task</a> that uses the XZ http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/docs/unpack.html ---------------------------------------------------------------------- diff --git a/docs/unpack.html b/docs/unpack.html index 7a7bf7a..2b96a70 100644 --- a/docs/unpack.html +++ b/docs/unpack.html @@ -181,7 +181,7 @@ resource collection</h4> <h3><a name="unsnappy">UnSnappy</a></h3> <p>Is an <a href="#unpack">uncompressing task</a> that uses - the <a href="http://code.google.com/p/snappy/">Snappy</a> + the <a href="https://github.com/google/snappy">Snappy</a> compression algorithm.</p> <p><em>Since Apache Compress Antlib 1.4</em>.</p> @@ -198,7 +198,7 @@ resource collection</h4> <tr> <td valign="top">framed</td> <td valign="top">Whether the input is expected to use - the <a href="http://code.google.com/p/snappy/source/browse/trunk/framing_format.txt">framing + the <a href="https://github.com/google/snappy/blob/master/framing_format.txt">framing format</a>.</td> <td align="center" valign="top">No, defaults to true.</td> </tr> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/ivy.xml ---------------------------------------------------------------------- diff --git a/ivy.xml b/ivy.xml index 3d32abb..65bf92b 100644 --- a/ivy.xml +++ b/ivy.xml @@ -55,7 +55,7 @@ e:classifier="ivy"/> </publications> <dependencies> - <dependency org="org.apache.commons" name="commons-compress" rev="1.13" conf="default"/> + <dependency org="org.apache.commons" name="commons-compress" rev="1.14" conf="default"/> <dependency org="org.tukaani" name="xz" rev="1.6" conf="default"/> <dependency org="junit" name="junit" rev="4.11" conf="test->default"/> </dependencies> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/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 161c64c..8f4ea91 100644 --- a/src/main/org/apache/ant/compress/antlib.xml +++ b/src/main/org/apache/ant/compress/antlib.xml @@ -117,6 +117,10 @@ classname="org.apache.ant.compress.taskdefs.SevenZ" /> <taskdef + name="snappy" + classname="org.apache.ant.compress.taskdefs.Snappy" + /> + <taskdef name="xz" classname="org.apache.ant.compress.taskdefs.XZ" /> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/src/main/org/apache/ant/compress/taskdefs/Snappy.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/ant/compress/taskdefs/Snappy.java b/src/main/org/apache/ant/compress/taskdefs/Snappy.java new file mode 100644 index 0000000..76528e4 --- /dev/null +++ b/src/main/org/apache/ant/compress/taskdefs/Snappy.java @@ -0,0 +1,55 @@ +/* + * 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.SnappyResource; +import org.apache.ant.compress.resources.CommonsCompressCompressorResource; +import org.apache.ant.compress.util.SnappyStreamFactory; +import org.apache.tools.ant.types.Resource; + +/** + * Compresses using snappy. + * @since Apache Compress Antlib 1.5 + */ +public final class Snappy extends PackBase { + + private final InnerSnappyStreamFactory factory; + + public Snappy() { + super(new PackBase.ResourceWrapper() { + @Override + public CommonsCompressCompressorResource wrap(Resource dest) { + return new SnappyResource(dest); + } + }); + setFactory(factory = new InnerSnappyStreamFactory()); + } + + /** + * Whether to use the "framing format". + * + * <p>Defaults to true.</p> + */ + public void setFramed(boolean framed) { + factory.setFramed(framed); + } + + private class InnerSnappyStreamFactory extends SnappyStreamFactory { + } +} http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/src/main/org/apache/ant/compress/util/SnappyStreamFactory.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/ant/compress/util/SnappyStreamFactory.java b/src/main/org/apache/ant/compress/util/SnappyStreamFactory.java index 3e911bc..5efd4eb 100644 --- a/src/main/org/apache/ant/compress/util/SnappyStreamFactory.java +++ b/src/main/org/apache/ant/compress/util/SnappyStreamFactory.java @@ -25,12 +25,13 @@ import java.io.OutputStream; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorOutputStream; import org.apache.commons.compress.compressors.snappy.FramedSnappyCompressorInputStream; +import org.apache.commons.compress.compressors.snappy.FramedSnappyCompressorOutputStream; import org.apache.commons.compress.compressors.snappy.SnappyCompressorInputStream; /** * Creates streams for the standalone Snappy format. - * @since Apache Compress Antlib 1.4 - * @see <a href="http://code.google.com/p/snappy/">Snappy Project</a> + * @since Apache Compress Antlib 1.4, write support added with 1.5 + * @see <a href="https://github.com/google/snappy">Snappy Project</a> */ public class SnappyStreamFactory implements CompressorStreamFactory { @@ -46,6 +47,13 @@ public class SnappyStreamFactory implements CompressorStreamFactory { } /** + * Whether to use the "framing format". + */ + protected boolean isFramed() { + return framed; + } + + /** * @param stream the stream to read from, should be buffered */ @Override @@ -56,11 +64,15 @@ public class SnappyStreamFactory implements CompressorStreamFactory { } /** - * Not implemented. + * @param stream the stream to write to, should be buffered */ @Override public CompressorOutputStream getCompressorStream(OutputStream stream) throws IOException { - throw new UnsupportedOperationException(); + if (!framed) { + throw new UnsupportedOperationException("Must know the uncompressed size" + + " for non-framed snappy"); + } + return new FramedSnappyCompressorOutputStream(stream); } } http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/src/tests/antunit/snappy-test.xml ---------------------------------------------------------------------- diff --git a/src/tests/antunit/snappy-test.xml b/src/tests/antunit/snappy-test.xml new file mode 100644 index 0000000..34531e7 --- /dev/null +++ b/src/tests/antunit/snappy-test.xml @@ -0,0 +1,111 @@ +<?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:snappy destfile="${output}/file.sz"> + <fileset dir="${output}/empty" /> + </cmp:snappy> + </au:expectfailure> + </target> + + <target name="testFailTwo" depends="setUp"> + <au:expectfailure expectedmessage="Can only have one source."> + <cmp:snappy destfile="${output}/file.sz"> + <fileset dir="${output}" /> + </cmp:snappy> + </au:expectfailure> + </target> + + <target name="testFailNoDest" depends="setUp"> + <au:expectfailure expectedmessage="dest resource is required."> + <cmp:snappy src="${output}/fileone"> + <dest> + <fileset dir="${output}/empty" /> + </dest> + </cmp:snappy> + </au:expectfailure> + </target> + + <target name="testFailTwoDests" depends="setUp"> + <au:expectfailure expectedmessage="Can only have one destination resource."> + <cmp:snappy src="${output}/fileone"> + <dest> + <fileset dir="${output}" /> + </dest> + </cmp:snappy> + </au:expectfailure> + </target> + + <target name="testRealTest" depends="setUp"> + <cmp:snappy src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.sz" /> + <au:assertLogContains text="Building: asf-logo.gif.sz"/> + <au:assertFileExists file="${output}/asf-logo.gif.sz"/> + </target> + + <target name="testRealTestWithResource" depends="setUp"> + <cmp:snappy destfile="${output}/asf-logo.gif.sz"> + <file file="../resources/asf-logo.gif"/> + </cmp:snappy> + <au:assertLogContains text="Building: asf-logo.gif.sz"/> + <au:assertFileExists file="${output}/asf-logo.gif.sz"/> + </target> + + <target name="testDateCheck" depends="setUp"> + <touch file="${output}/asf-logo.gif.sz"/> + <cmp:snappy src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.sz" /> + <au:assertLogContains text="Nothing to do: asf-logo.gif.sz is up to date."/> + </target> + + <!-- re-enable once we upgrade to CC 1.14, see + https://issues.apache.org/jira/browse/COMPRESS-393 --> + <target name="XtestNestedTask" depends="setUp"> + <cmp:snappy destfile="${output}/asf-logo.tar.sz"> + <cmp:tar> + <cmp:cpiofileset src="../resources/asf-logo.gif.bin.cpio" + includes="asf-logo.gif"/> + </cmp:tar> + </cmp:snappy> + <au:assertFileExists file="${output}/asf-logo.tar.sz"/> + <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:snappyresource> + <file file="${output}/asf-logo.tar.sz"/> + </cmp:snappyresource> + </cmp:tarentry> + </cond:islastmodified> + </au:assertTrue> + </target> +</project> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/5de99d93/src/tests/antunit/unsnappy-test.xml ---------------------------------------------------------------------- diff --git a/src/tests/antunit/unsnappy-test.xml b/src/tests/antunit/unsnappy-test.xml index d8f87db..d8970a8 100644 --- a/src/tests/antunit/unsnappy-test.xml +++ b/src/tests/antunit/unsnappy-test.xml @@ -39,6 +39,14 @@ </au:expectfailure> </target> + <target name="testSnappyTask" depends="setUp"> + <cmp:snappy src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.sz"/> + <cmp:unsnappy src="${output}/asf-logo.gif.sz" dest="${output}/asf-logo.gif" /> + <au:assertFilesMatch expected="../resources/asf-logo.gif" + actual="${output}/asf-logo.gif"/> + </target> + <target name="testNativeSnappy" depends="setUp"> <cmp:unsnappy src="../resources/asf-logo.gif.sz" dest="${output}/asf-logo.gif" />
