Repository: ant-antlibs-compress Updated Branches: refs/heads/master c673a2c0a -> 64cc28864
add write-support for LZMA 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/64cc2886 Tree: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/tree/64cc2886 Diff: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/diff/64cc2886 Branch: refs/heads/master Commit: 64cc288646f79a65433c28a214a51fa7d69eb6ee Parents: c673a2c Author: Stefan Bodewig <[email protected]> Authored: Sun May 7 17:15:44 2017 +0200 Committer: Stefan Bodewig <[email protected]> Committed: Sun May 7 17:15:44 2017 +0200 ---------------------------------------------------------------------- changes.xml | 6 +- docs/pack.html | 7 ++ ivy.xml | 4 +- src/main/org/apache/ant/compress/antlib.xml | 4 + .../org/apache/ant/compress/taskdefs/LZMA.java | 41 +++++++ .../ant/compress/util/LZMAStreamFactory.java | 7 +- src/tests/antunit/lzma-test.xml | 111 +++++++++++++++++++ src/tests/antunit/unlzma-test.xml | 8 ++ 8 files changed, 182 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/changes.xml ---------------------------------------------------------------------- diff --git a/changes.xml b/changes.xml index 1fe9e6c..ec80e1f 100644 --- a/changes.xml +++ b/changes.xml @@ -40,7 +40,8 @@ <release version="1.5" date="unreleased"> <action type="update" breaks-bwc="true"> The Apache Compress Antlib now requires Apache Commons - Compress 1.8 or later for 7z, XZ for Java 1.5 is recommeded. + Compress 1.13 or later for 7z and write support for LZMA, XZ + for Java 1.6 is equired for write support for LZMA. </action> <action type="add"> A new keepCompression flag can be used to keep the content @@ -55,6 +56,9 @@ The gzip task has a new attribute that controls the level of compression. </action> + <action type="add"> + Added write support for the LZMA format. + </action> </release> <release version="1.4" date="2014-01-29"> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/docs/pack.html ---------------------------------------------------------------------- diff --git a/docs/pack.html b/docs/pack.html index f878a16..89c3f52 100644 --- a/docs/pack.html +++ b/docs/pack.html @@ -121,6 +121,13 @@ </tr> </table> + <h3><a name="lzma">LZMA</a></h3> + + <p>Is a <a href="#pack">compressing task</a> that uses the LZMA + compression algorithm.</p> + + <p><em>Since Compress Antlib 1.5</em> + <h3><a name="pack200">Pack200</a></h3> <p>Is a <a href="#pack">compressing task</a> that uses http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/ivy.xml ---------------------------------------------------------------------- diff --git a/ivy.xml b/ivy.xml index 7f9284e..87c0722 100644 --- a/ivy.xml +++ b/ivy.xml @@ -55,8 +55,8 @@ e:classifier="ivy"/> </publications> <dependencies> - <dependency org="org.apache.commons" name="commons-compress" rev="1.8" conf="default"/> - <dependency org="org.tukaani" name="xz" rev="1.5" conf="default"/> + <dependency org="org.apache.commons" name="commons-compress" rev="1.13" 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> </ivy-module> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/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 b2e03d4..57392e9 100644 --- a/src/main/org/apache/ant/compress/antlib.xml +++ b/src/main/org/apache/ant/compress/antlib.xml @@ -112,6 +112,10 @@ name="xz" classname="org.apache.ant.compress.taskdefs.XZ" /> + <taskdef + name="lzma" + classname="org.apache.ant.compress.taskdefs.LZMA" + /> <typedef name="arentry" http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/src/main/org/apache/ant/compress/taskdefs/LZMA.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/ant/compress/taskdefs/LZMA.java b/src/main/org/apache/ant/compress/taskdefs/LZMA.java new file mode 100644 index 0000000..ca98412 --- /dev/null +++ b/src/main/org/apache/ant/compress/taskdefs/LZMA.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.LZMAResource; +import org.apache.ant.compress.util.LZMAStreamFactory; +import org.apache.tools.ant.types.Resource; + +/** + * Compresses using LZMA. + * @since Apache Compress Antlib 1.5 + */ +public final class LZMA extends PackBase { + + public LZMA() { + super(new LZMAStreamFactory(), + new PackBase.ResourceWrapper() { + public CommonsCompressCompressorResource wrap(Resource dest) { + return new LZMAResource(dest); + } + }); + } + +} http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java ---------------------------------------------------------------------- diff --git a/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java b/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java index b96cd9b..d55cbcc 100644 --- a/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java +++ b/src/main/org/apache/ant/compress/util/LZMAStreamFactory.java @@ -25,10 +25,11 @@ import java.io.OutputStream; import org.apache.commons.compress.compressors.CompressorInputStream; import org.apache.commons.compress.compressors.CompressorOutputStream; import org.apache.commons.compress.compressors.lzma.LZMACompressorInputStream; +import org.apache.commons.compress.compressors.lzma.LZMACompressorOutputStream; /** * Creates streams for the standalone LZMA format. - * @since Apache Compress Antlib 1.3 + * @since Apache Compress Antlib 1.3, write support added with 1.4 */ public class LZMAStreamFactory implements CompressorStreamFactory { @@ -42,11 +43,11 @@ public class LZMAStreamFactory 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(); + return new LZMACompressorOutputStream(stream); } } http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/src/tests/antunit/lzma-test.xml ---------------------------------------------------------------------- diff --git a/src/tests/antunit/lzma-test.xml b/src/tests/antunit/lzma-test.xml new file mode 100644 index 0000000..ce2721c --- /dev/null +++ b/src/tests/antunit/lzma-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:lzma destfile="${output}/file.lzma"> + <fileset dir="${output}/empty" /> + </cmp:lzma> + </au:expectfailure> + </target> + + <target name="testFailTwo" depends="setUp"> + <au:expectfailure expectedmessage="Can only have one source."> + <cmp:lzma destfile="${output}/file.lzma"> + <fileset dir="${output}" /> + </cmp:lzma> + </au:expectfailure> + </target> + + <target name="testFailNoDest" depends="setUp"> + <au:expectfailure expectedmessage="dest resource is required."> + <cmp:lzma src="${output}/fileone"> + <dest> + <fileset dir="${output}/empty" /> + </dest> + </cmp:lzma> + </au:expectfailure> + </target> + + <target name="testFailTwoDests" depends="setUp"> + <au:expectfailure expectedmessage="Can only have one destination resource."> + <cmp:lzma src="${output}/fileone"> + <dest> + <fileset dir="${output}" /> + </dest> + </cmp:lzma> + </au:expectfailure> + </target> + + <target name="testRealTest" depends="setUp"> + <cmp:lzma src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.lzma" /> + <au:assertLogContains text="Building: asf-logo.gif.lzma"/> + <au:assertFileExists file="${output}/asf-logo.gif.lzma"/> + </target> + + <target name="testRealTestWithResource" depends="setUp"> + <cmp:lzma destfile="${output}/asf-logo.gif.lzma"> + <file file="../resources/asf-logo.gif"/> + </cmp:lzma> + <au:assertLogContains text="Building: asf-logo.gif.lzma"/> + <au:assertFileExists file="${output}/asf-logo.gif.lzma"/> + </target> + + <target name="testDateCheck" depends="setUp"> + <touch file="${output}/asf-logo.gif.lzma"/> + <cmp:lzma src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.lzma" /> + <au:assertLogContains text="Nothing to do: asf-logo.gif.lzma 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:lzma destfile="${output}/asf-logo.tar.lzma"> + <cmp:tar> + <cmp:cpiofileset src="../resources/asf-logo.gif.bin.cpio" + includes="asf-logo.gif"/> + </cmp:tar> + </cmp:lzma> + <au:assertFileExists file="${output}/asf-logo.tar.lzma"/> + <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:lzmaresource> + <file file="${output}/asf-logo.tar.lzma"/> + </cmp:lzmaresource> + </cmp:tarentry> + </cond:islastmodified> + </au:assertTrue> + </target> +</project> http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/64cc2886/src/tests/antunit/unlzma-test.xml ---------------------------------------------------------------------- diff --git a/src/tests/antunit/unlzma-test.xml b/src/tests/antunit/unlzma-test.xml index 5f25046..2fde762 100644 --- a/src/tests/antunit/unlzma-test.xml +++ b/src/tests/antunit/unlzma-test.xml @@ -39,6 +39,14 @@ </au:expectfailure> </target> + <target name="testLZMATask" depends="setUp"> + <cmp:lzma src="../resources/asf-logo.gif" + destfile="${output}/asf-logo.gif.lzma"/> + <cmp:unlzma src="${output}/asf-logo.gif.lzma" dest="${output}/asf-logo.gif" /> + <au:assertFilesMatch expected="../resources/asf-logo.gif" + actual="${output}/asf-logo.gif"/> + </target> + <target name="testNativeLZMA" depends="setUp"> <cmp:unlzma src="../resources/asf-logo.gif.lzma" dest="${output}/asf-logo.gif" />
