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 2014/03/14 17:41:17 UTC

svn commit: r1577607 - in /ant/antlibs/compress/trunk: ./ docs/ src/main/org/apache/ant/compress/taskdefs/ src/main/org/apache/ant/compress/util/ src/tests/antunit/

Author: bodewig
Date: Fri Mar 14 16:41:17 2014
New Revision: 1577607

URL: http://svn.apache.org/r1577607
Log:
support for multiple content methods in 7z

Modified:
    ant/antlibs/compress/trunk/changes.xml
    ant/antlibs/compress/trunk/docs/archive.html
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/SevenZ.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java
    ant/antlibs/compress/trunk/src/tests/antunit/sevenz-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml

Modified: ant/antlibs/compress/trunk/changes.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/changes.xml?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/changes.xml (original)
+++ ant/antlibs/compress/trunk/changes.xml Fri Mar 14 16:41:17 2014
@@ -38,6 +38,19 @@
     </properties>
 
     <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.
+      </action>
+      <action type="add">
+        A new keepCompression flag can be used to keep the content
+        compression methods the same they have been when updating a 7z
+        archive or adding entries from a sevenzfileset.
+      </action>
+      <action type="add">
+        Multiple content compression/encryption/filter methods can now
+        be specified via nested elements of the sevenz task.
+      </action>
     </release>
 
     <release version="1.4" date="2014-01-29">

Modified: ant/antlibs/compress/trunk/docs/archive.html
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/docs/archive.html?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/docs/archive.html (original)
+++ ant/antlibs/compress/trunk/docs/archive.html Fri Mar 14 16:41:17 2014
@@ -278,7 +278,7 @@
   <p><em>Since Compress Antlib 1.3</em></p>
 
   <p>An <a href="#archive">archiving task</a> creating archives of the
-    7z format.  As of Commons Compress 1.6 this task only supports
+    7z format.  As of Commons Compress 1.8 this task only supports
     writing unencrypted archives.</p>
 
   <h3>Parameters</h3>
@@ -291,8 +291,8 @@
     <tr>
       <td valign="top">contentCompression</td>
       <td valign="top">compression algorithm to use for entry
-        contents.</td>
-      <td valign="top">As of Commons Compress 1.6 this can be "LZMA2",
+        contents.<br></br>
+        As of Commons Compress 1.8 this can be "LZMA2",
         "BZIP2", "DEFLATE" or "COPY" where "COPY" means no compression
         at all.</td>
       <td valign="top" align="center">No, default is LZMA2.</td>
@@ -308,6 +308,52 @@
     </tr>
   </table>
 
+  <h3>Parameters specified as nested elements</h3>
+
+  <h4>contentMethod</h4>
+
+  <p>Specifies and configures a content method to use when creating an
+  archive.  Multiple methods build a pipeline where the first method
+  is used to process the original input and its output is sent ot the
+  next method until the final output is written to the archive.</p>
+
+  <p>As of Commons Compress 1.8 in addition to the compression methods
+    "LZMA2", "BZIP2", "DEFLATE" or "COPY" filters can be used.  Names
+    of filter methods end with "_FILTER" and must not be used as final
+    method - this is neither enforced by this antlib or Commons
+    Compress but 7z may fail to extract the archive.  As of Commons
+    Compress 1.8 the supported filters are "BCJ_X86_FILTER",
+    "BCJ_PPC_FILTER", "BCJ_IA64_FILTER", "BCJ_ARM_FILTER",
+    "BCJ_ARM_THUMB_FILTER", "BCJ_SPARC_FILTER" and "DELTA_FILTER".
+    The "BCJ" filters may improve compression ratio for executables
+    for a given platform.</p>
+
+  <p>Some methods support additional options, "DELTA_FILTER" even
+    requires one.  The interpretation or even the type of an option
+    depends on the method -
+    see <a href="http://commons.apache.org/proper/commons-compress/javadocs/api-1.8/org/apache/commons/compress/archivers/sevenz/SevenZMethodConfiguration.html">Commons
+    Compress' documentation</a>.  As of version 1.5 only numeric
+    options are supported.</p>
+
+  <strong>Parameters of contentMethod</strong>
+  <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">method</td>
+      <td valign="top">method to use.</td>
+      <td valign="top" align="center">Yes.</td>
+    </tr>
+    <tr>
+      <td valign="top">option</td>
+      <td valign="top">Numeric option for this method.</td>
+      <td align="center" valign="top">No</td>
+    </tr>
+  </table>
+
   <h3><a name="tar">Tar</a></h3>
 
   <p>An <a href="#archive">archiving task</a> creating archives of the

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/SevenZ.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/SevenZ.java?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/SevenZ.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/SevenZ.java Fri Mar 14 16:41:17 2014
@@ -20,7 +20,9 @@ package org.apache.ant.compress.taskdefs
 
 import java.io.IOException;
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Date;
+import java.util.List;
 import java.util.Locale;
 
 import org.apache.ant.compress.resources.SevenZFileSet;
@@ -30,6 +32,8 @@ import org.apache.commons.compress.archi
 import org.apache.commons.compress.archivers.ArchiveOutputStream;
 import org.apache.commons.compress.archivers.sevenz.SevenZArchiveEntry;
 import org.apache.commons.compress.archivers.sevenz.SevenZMethod;
+import org.apache.commons.compress.archivers.sevenz.SevenZMethodConfiguration;
+import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.ArchiveFileSet;
 import org.apache.tools.ant.types.Resource;
 
@@ -40,6 +44,7 @@ public class SevenZ extends ArchiveBase 
 
     private boolean keepCompression = false;
     private String contentCompression;
+    private List/*<SevenZMethodConfiguration>*/ contentMethods;
 
     public SevenZ() {
         setFactory(new SevenZStreamFactory() {
@@ -49,11 +54,10 @@ public class SevenZ extends ArchiveBase 
                     SevenZArchiveOutputStream o = (SevenZArchiveOutputStream)
                         super.getArchiveOutputStream(f, encoding);
                     if (contentCompression != null) {
-                        SevenZMethod m = (SevenZMethod)
-                            Enum.valueOf(SevenZMethod.class,
-                                         contentCompression.toUpperCase(Locale
-                                                                        .US));
-                        o.setContentCompression(m);
+                        o.setContentCompression(asMethod(contentCompression));
+                    }
+                    if (contentMethods != null) {
+                        o.setContentMethods(contentMethods);
                     }
                     return o;
                 }
@@ -86,16 +90,34 @@ public class SevenZ extends ArchiveBase 
 
     /**
      * Sets the compression method to use for entry contents - the
-     * default is LZMA2.
+     * default is LZMA2 with no additional options.
      *
-     * <p>As of Commons Compress 1.6 only COPY (which means no
+     * <p>As of Commons Compress 1.8 only COPY (which means no
      * compression), LZMA2, BZIP2 and DEFLATE are supported.</p>
      */
     public void setContentCompression(String method) {
+        if (contentMethods != null && method != null) {
+            throw new BuildException("you must not specify contentCompression and nested contentMethod elements at the same time");
+        }
         this.contentCompression = method;
     }
 
     /**
+     * Adds a compression method to use for entry contents - the
+     * default is LZMA2 with no additional options.
+     * @since 1.5
+     */
+    public void addConfiguredContentMethod(ContentMethod cm) {
+        if (contentCompression != null) {
+            throw new BuildException("you must not specify contentCompression and nested contentMethod elements at the same time");
+        }
+        if (contentMethods == null) {
+            contentMethods = new ArrayList/*<SevenZMethodConfiguration>*/();
+        }
+        contentMethods.add(asMethodConfiguration(cm));
+    }
+
+    /**
      * Whether the original compression of entries coming from a 7z
      * archive should be kept (for example when updating an archive).
      * Default is false.
@@ -105,4 +127,37 @@ public class SevenZ extends ArchiveBase 
     public void setKeepCompression(boolean keep) {
         keepCompression = keep;
     }
+
+    private static SevenZMethod asMethod(String method) {
+        return (SevenZMethod) Enum.valueOf(SevenZMethod.class,
+                                           method.toUpperCase(Locale.US));
+    }
+
+    private static SevenZMethodConfiguration
+        asMethodConfiguration(ContentMethod cm) {
+        return new SevenZMethodConfiguration(asMethod(cm.method), cm.option);
+    }
+
+    /**
+     * Container for a supported 7z method and its configuration.
+     * @since 1.5
+     */
+    public static class ContentMethod {
+        private String method;
+        private Integer option;
+
+        /**
+         * The "method" which can be a compression method, an
+         * encryption method or a filter.
+         */
+        public void setMethod(String m) {
+            method = m;
+        }
+        /**
+         * Option for the method, must be understood by the method.
+         */
+        public void setOption(int o) {
+            option = Integer.valueOf(o);
+        }
+    }
 }

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/SevenZStreamFactory.java Fri Mar 14 16:41:17 2014
@@ -141,6 +141,10 @@ public class SevenZStreamFactory impleme
             zipFile.setContentCompression(method);
         }
 
+        public void setContentMethods(Iterable methods) {
+            zipFile.setContentMethods(methods);
+        }
+
     }
 
 }

Modified: ant/antlibs/compress/trunk/src/tests/antunit/sevenz-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/sevenz-test.xml?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/sevenz-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/sevenz-test.xml Fri Mar 14 16:41:17 2014
@@ -432,4 +432,29 @@
     </au:assertFalse>
   </target>
 
+  <target
+      name="testThrowsWhenAddingMethodViaAttributeAndNestedElements">
+    <au:expectfailure
+       message="you must not specify contentCompression and nested contentMethod elements at the same time">
+      <cmp:sevenz dest="${dest}" src="${input}"
+                  contentCompression="bzip2">
+        <contentMethod method="lzma2"/>
+      </cmp:sevenz>
+    </au:expectfailure>
+  </target>
+
+  <target name="testPlainFileSetWithFilter" depends="setUp">
+    <mkdir dir="${input}"/>
+    <copy todir="${input}" file="../resources/asf-logo.gif"/>
+    <touch datetime="2009-08-19-05:49:21 +0200"
+           pattern="yyyy-MM-dd-HH:mm:ss Z"
+           file="${input}/asf-logo.gif"/>
+    <cmp:sevenz destfile="${dest}">
+      <contentMethod method="delta_filter" option="4"/>
+      <contentMethod method="lzma2"/>
+      <fileset dir="${input}" includes="asf-logo.gif"/>
+    </cmp:sevenz>
+    <checkProperties dateTime="2009-08-19-05:49:21 +0200"/>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml?rev=1577607&r1=1577606&r2=1577607&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/un7z-test.xml Fri Mar 14 16:41:17 2014
@@ -86,6 +86,20 @@
        />
   </target>
 
+  <target name="testAgainstAntlib7zTaskDeltaPlusLZMA2" depends="setUp">
+    <cmp:sevenz destfile="${input}/test.7z">
+      <contentMethod method="delta_filter" option="2"/>
+      <contentMethod method="lzma2"/>
+      <fileset dir="." includes="un7z-test.xml"/>
+    </cmp:sevenz>
+    <cmp:un7z src="${input}/test.7z" dest="${output}"/>
+    <au:assertFileExists file="${output}/un7z-test.xml"/>
+    <au:assertFilesMatch
+       actual="${output}/un7z-test.xml"
+       expected="un7z-test.xml"
+       />
+  </target>
+
   <target name="testAgainstNative7z" depends="setUp">
     <cmp:un7z src="../resources/asf-logo.gif.7z" dest="${output}" />
     <au:assertFileExists file="${output}/asf-logo.gif"/>