You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/05/08 16:58:45 UTC

ant-antlibs-compress git commit: add read-only Brotli support

Repository: ant-antlibs-compress
Updated Branches:
  refs/heads/compress-1.14 cfb57edd2 -> 0d561ceba


add read-only Brotli support


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/0d561ceb
Tree: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/tree/0d561ceb
Diff: http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/diff/0d561ceb

Branch: refs/heads/compress-1.14
Commit: 0d561cebab37b6f0f6662f1154d616e9313c1347
Parents: cfb57ed
Author: Stefan Bodewig <bo...@apache.org>
Authored: Mon May 8 18:58:25 2017 +0200
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Mon May 8 18:58:25 2017 +0200

----------------------------------------------------------------------
 changes.xml                                     |   6 +-
 docs/compresource.html                          |  22 +++++++
 docs/index.html                                 |  18 ++++--
 docs/unpack.html                                |   7 +++
 ivy.xml                                         |   4 +-
 src/main/org/apache/ant/compress/antlib.xml     |   8 +++
 .../ant/compress/resources/BrotliResource.java  |  37 ++++++++++++
 .../apache/ant/compress/taskdefs/UnBrotli.java  |  33 +++++++++++
 .../ant/compress/util/BrotliStreamFactory.java  |  52 +++++++++++++++++
 src/tests/antunit/brotliresource-test.xml       |  41 +++++++++++++
 src/tests/antunit/unbrotli-test.xml             |  58 +++++++++++++++++++
 src/tests/resources/asf-logo.gif.br             | Bin 0 -> 6944 bytes
 12 files changed, 279 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/changes.xml
----------------------------------------------------------------------
diff --git a/changes.xml b/changes.xml
index 085cbcd..6d34883 100644
--- a/changes.xml
+++ b/changes.xml
@@ -42,7 +42,8 @@
         The Apache Compress Antlib now requires Apache Commons
         Compress 1.14 or later for 7z, DEFLATE, LZ4 and write support
         for LZMA and Snappy.
-        XZ for Java 1.6 is required for write support for LZMA.
+        XZ for Java 1.6 or later is required for write support for LZMA.
+        Brotli dec 0.1.2 or later is required for Brotli support.
       </action>
       <action type="add">
         A new keepCompression flag can be used to keep the content
@@ -69,6 +70,9 @@
       <action type="add">
         Added support for the LZ4 format.
       </action>
+      <action type="add">
+        Added read-only support for the Brotli format.
+      </action>
     </release>
 
     <release version="1.4" date="2014-01-29">

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/docs/compresource.html
----------------------------------------------------------------------
diff --git a/docs/compresource.html b/docs/compresource.html
index 3091c72..714fece 100644
--- a/docs/compresource.html
+++ b/docs/compresource.html
@@ -39,6 +39,28 @@
   value false only the first stream is uncompressed.</p>
 </a>
 
+<h2><a name="brotliresource">brotliresource</a></h2>
+
+<p>This is a <a href="#compresource">compressed resource</a> using the
+  Brotli compression.</p>
+
+  <p><em>Since Compress Antlib 1.5</em>
+
+<h4>Examples</h4>
+
+<pre>
+&lt;cmp:tarentry xmlns:cmp="antlib:org.apache.ant.compress"
+    name="some-file.txt"&gt;
+  &lt;cmp:brotliresource&gt;
+    &lt;file file="some-archive.tar.br"/&gt;
+  &lt;/cmp:brotliresource&gt;
+&lt;/cmp:tarentry&gt;
+</pre>
+
+<p>Represents the entry named some-file.txt in archive
+  some-archive.tar.br where the <code>brotliresource</code> provides
+  the decompression of the archive.</p>
+
 <h2><a name="bzip2resource">bzip2resource</a></h2>
 
 <p>This is a <a href="#compresource">compressed resource</a> using the

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/docs/index.html
----------------------------------------------------------------------
diff --git a/docs/index.html b/docs/index.html
index c249f43..b16a16a 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -30,9 +30,10 @@
       based on <a href="http://commons.apache.org/compress/">Apache
       Commons Compress</a>.  Using Apache Commons Compress 1.14 this
       Antlib supports gzip, bzip2, lzma standalone, xz, .Z, DEFLATE,
-      Snappy, LZ4 and pack200 compression and ar, arj, cpio, 7z, Unix
-      dump, tar and zip archives.  Support for arj, .Z and dump is
-      read-only.  7z can only be used on filesystem resources.</p>
+      Snappy, LZ4, Brotli and pack200 compression and ar, arj, cpio,
+      7z, Unix dump, tar and zip archives.  Support for arj, .Z,
+      Brotli and dump is read-only.  7z can only be used on filesystem
+      resources.</p>
 
     <h3>Known Limitations</h3>
 
@@ -62,6 +63,7 @@
       <li><a href="expand.html#un7z">un7z</a></li>
       <li><a href="expand.html#unar">unar</a></li>
       <li><a href="expand.html#unarj">unarj</a></li>
+      <li><a href="unpack.html#unbrotli">unbrotli</a></li>
       <li><a href="expand.html#uncpio">uncpio</a></li>
       <li><a href="unpack.html#undeflate">undeflate</a></li>
       <li><a href="expand.html#undump">undump</a></li>
@@ -85,6 +87,7 @@
       <li><a href="entry.html#arjentry">arjentry</a></li>
       <li><a href="fileset.html#arfileset">arfileset</a></li>
       <li><a href="fileset.html#arjfileset">arjfileset</a></li>
+      <li><a href="compresource.html#brotliresource">brotliresource</a></li>
       <li><a href="compresource.html#bzip2resource">bzip2resource</a></li>
       <li><a href="entry.html#cpioentry">cpioentry</a></li>
       <li><a href="fileset.html#cpiofileset">cpiofileset</a></li>
@@ -121,11 +124,15 @@
     <h3>Installing and Using</h3>
 
     <p>This Antlib requires Apache Ant 1.8.0 or higher, Apache
-      Commons Compress 1.13 or higher and Java7 or higher.</p>
+      Commons Compress 1.14 or higher and Java7 or higher.</p>
 
     <p>In order to use LZMA, XZ or most of the 7z support
       the <a href="https://tukaani.org/xz/java.html">XZ for Java</a>
-      version 1.6 or later is required.
+      version 1.6 or later is required.</p>
+
+    <p>In order to use Brotli
+      the <a href="https://github.com/google/brotli">Brotli dec</a>
+      library verision 0.1.2 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
@@ -155,6 +162,7 @@
           &lt;pathelement location="YOUR-PATH-TO/commons-compress-VERSION2.jar"/&gt;
           &lt;!-- optional dependencies --&gt;
           &lt;pathelement location="YOUR-PATH-TO/xz-VERSION3.jar"/&gt;
+          &lt;pathelement location="YOUR-PATH-TO/dec-VERSION4.jar"/&gt;
         &lt;/classpath&gt;
       &lt;/taskdef&gt;
 </pre>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/docs/unpack.html
----------------------------------------------------------------------
diff --git a/docs/unpack.html b/docs/unpack.html
index e36d97d..c47eae0 100644
--- a/docs/unpack.html
+++ b/docs/unpack.html
@@ -93,6 +93,13 @@ resource collection</h4>
   the <a href="#decompressConcatenated">decompressConcatenated</a>
   attribute.</p>
 
+<h3><a name="unbrotli">unbrotli</a></h3>
+
+<p>Is an <a href="#unpack">uncompressing task</a> that uses the Brotli
+  compression algorithm.</p>
+
+  <p><em>Since Compress Antlib 1.5</em>
+
 <h3><a name="undeflate">Undeflate</a></h3>
 
 <p>Is an <a href="#unpack">uncompressing task</a> that uses the DEFLATE

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/ivy.xml
----------------------------------------------------------------------
diff --git a/ivy.xml b/ivy.xml
index 4eadc03..eb034ac 100644
--- a/ivy.xml
+++ b/ivy.xml
@@ -29,7 +29,8 @@
     <description homepage="http://ant.apache.org/antlibs/compress/">
       Provides tasks and types that deal with AR, ARJ, CPIO, TAR,
       DUMP, 7Z and ZIP archives as well as BZIP2, PACK200, GZIP, LZMA,
-      Snappy, LZ4 and XZ compressed files based on Apache Commons Compress.
+      Snappy, LZ4, Brotli and XZ compressed files based on Apache
+      Commons Compress.
     </description>
   </info>
   <configurations>
@@ -57,6 +58,7 @@
   <dependencies>
     <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="org.brotli" name="dec" rev="0.1.2" 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/0d561ceb/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 00b762a..e4c8354 100644
--- a/src/main/org/apache/ant/compress/antlib.xml
+++ b/src/main/org/apache/ant/compress/antlib.xml
@@ -29,6 +29,10 @@
      classname="org.apache.ant.compress.taskdefs.Unarj"
      />
   <taskdef
+     name="unbrotli"
+     classname="org.apache.ant.compress.taskdefs.UnBrotli"
+     />
+  <taskdef
      name="uncpio"
      classname="org.apache.ant.compress.taskdefs.Uncpio"
      />
@@ -199,6 +203,10 @@
      classname="org.apache.ant.compress.resources.Archives"
      />
   <typedef
+     name="brotliresource"
+     classname="org.apache.ant.compress.resources.BrotliResource"
+     />
+  <typedef
      name="bzip2resource"
      classname="org.apache.ant.compress.resources.BZip2Resource"
      />

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/main/org/apache/ant/compress/resources/BrotliResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/resources/BrotliResource.java b/src/main/org/apache/ant/compress/resources/BrotliResource.java
new file mode 100644
index 0000000..6f35417
--- /dev/null
+++ b/src/main/org/apache/ant/compress/resources/BrotliResource.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.BrotliStreamFactory;
+import org.apache.tools.ant.types.ResourceCollection;
+
+/**
+ * A Brotli compressed resource.
+ * @since Apache Compress Antlib 1.5
+ */
+public final class BrotliResource extends CommonsCompressCompressorResource {
+    private static final String NAME = "Brotli";
+
+    public BrotliResource() {
+        super(NAME, new BrotliStreamFactory());
+    }
+
+    public BrotliResource(ResourceCollection other) {
+        super(NAME, new BrotliStreamFactory(), other);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/main/org/apache/ant/compress/taskdefs/UnBrotli.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/taskdefs/UnBrotli.java b/src/main/org/apache/ant/compress/taskdefs/UnBrotli.java
new file mode 100644
index 0000000..d1ae5a5
--- /dev/null
+++ b/src/main/org/apache/ant/compress/taskdefs/UnBrotli.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.BrotliStreamFactory;
+
+/**
+ * Expands a Brotli compressed resource.
+ * @since Apache Compress Antlib 1.5
+ */
+public final class UnBrotli extends UnpackBase {
+
+    public UnBrotli() {
+        super(".br", new BrotliStreamFactory());
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/main/org/apache/ant/compress/util/BrotliStreamFactory.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/ant/compress/util/BrotliStreamFactory.java b/src/main/org/apache/ant/compress/util/BrotliStreamFactory.java
new file mode 100644
index 0000000..eb19c84
--- /dev/null
+++ b/src/main/org/apache/ant/compress/util/BrotliStreamFactory.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.brotli.BrotliCompressorInputStream;
+
+/**
+ * Creates streams for the Brotli compression format.
+ * @since Apache Compress Antlib 1.5
+ */
+public class BrotliStreamFactory implements CompressorStreamFactory {
+
+    /**
+     * @param stream the stream to read from, should be buffered
+     */
+    @Override
+    public CompressorInputStream getCompressorStream(InputStream stream)
+        throws IOException {
+        return new BrotliCompressorInputStream(stream);
+    }
+
+    /**
+     * Not implemented.
+     */
+    @Override
+    public CompressorOutputStream getCompressorStream(OutputStream stream)
+        throws IOException {
+        throw new UnsupportedOperationException();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/tests/antunit/brotliresource-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/brotliresource-test.xml b/src/tests/antunit/brotliresource-test.xml
new file mode 100644
index 0000000..bdd5757
--- /dev/null
+++ b/src/tests/antunit/brotliresource-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="testNativeBrotli" depends="setUp">
+    <copy todir="${output}">
+      <cmp:brotliresource>
+        <file file="../resources/asf-logo.gif.br"/>
+      </cmp:brotliresource>
+      <globmapper from="*.br" to="*"/>
+    </copy>
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/tests/antunit/unbrotli-test.xml
----------------------------------------------------------------------
diff --git a/src/tests/antunit/unbrotli-test.xml b/src/tests/antunit/unbrotli-test.xml
new file mode 100644
index 0000000..9058969
--- /dev/null
+++ b/src/tests/antunit/unbrotli-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:unbrotli/>
+    </au:expectfailure>
+  </target>
+
+  <target name="test2">
+    <au:expectfailure>
+      <cmp:unbrotli src=""/>
+    </au:expectfailure>
+  </target>
+
+  <target name="testNativeBrotli" depends="setUp">
+    <cmp:unbrotli src="../resources/asf-logo.gif.br"
+                  dest="${output}/asf-logo.gif" />
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+  <target name="testWithResource" depends="setUp">
+    <cmp:unbrotli dest="${output}/asf-logo.gif">
+      <file file="../resources/asf-logo.gif.br"/>
+    </cmp:unbrotli>
+    <au:assertFilesMatch expected="../resources/asf-logo.gif"
+                         actual="${output}/asf-logo.gif"/>
+  </target>
+
+
+</project>

http://git-wip-us.apache.org/repos/asf/ant-antlibs-compress/blob/0d561ceb/src/tests/resources/asf-logo.gif.br
----------------------------------------------------------------------
diff --git a/src/tests/resources/asf-logo.gif.br b/src/tests/resources/asf-logo.gif.br
new file mode 100644
index 0000000..4ae17e2
Binary files /dev/null and b/src/tests/resources/asf-logo.gif.br differ