ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1170535 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ tests/antunit/
Date Wed, 14 Sep 2011 11:20:03 GMT
Author: bodewig
Date: Wed Sep 14 11:20:02 2011
New Revision: 1170535

URL: http://svn.apache.org/viewvc?rev=1170535&view=rev
Log:
Allow caching strategy of Pack200 streams to be set

Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnPack200.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
    ant/antlibs/compress/trunk/src/tests/antunit/pack200-test.xml
    ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200.java?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/Pack200.java Wed
Sep 14 11:20:02 2011
@@ -18,9 +18,20 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.InputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
 import org.apache.ant.compress.resources.Pack200Resource;
-import org.apache.ant.compress.util.Pack200StreamFactory;
+import org.apache.ant.compress.util.CompressorStreamFactory;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.CompressorOutputStream;
+import org.apache.commons.compress.compressors.pack200.Pack200CompressorOutputStream;
+import org.apache.commons.compress.compressors.pack200.Pack200Strategy;
+import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.Resource;
 
 /**
@@ -28,13 +39,70 @@ import org.apache.tools.ant.types.Resour
  */
 public final class Pack200 extends PackBase {
 
+    private Pack200StrategyEnum strategy = Pack200StrategyEnum.IN_MEMORY;
+
     public Pack200() {
-        super(new Pack200StreamFactory(),
-              new PackBase.ResourceWrapper() {
+        super(new PackBase.ResourceWrapper() {
                 public CommonsCompressCompressorResource wrap(Resource dest) {
                     return new Pack200Resource(dest);
                 }
             });
+        setFactory(new CompressorStreamFactory() {
+                public CompressorOutputStream
+                    getCompressorStream(OutputStream stream)
+                    throws IOException {
+                    return new Pack200CompressorOutputStream(stream,
+                                                             strategy
+                                                             .getStrategy());
+                }
+                public CompressorInputStream
+                    getCompressorStream(InputStream stream)
+                    throws IOException {
+                    throw new UnsupportedOperationException();
+                }
+            });
+    }
+
+    /**
+     * Whether to cache archive data in memory (the default) or a
+     * temporary file.
+     *
+     * @since Commons Compress 1.1
+     */
+    public void setPack200Strategy(Pack200StrategyEnum s) {
+        strategy = s;
     }
 
+    /**
+     * Pack200Strategy to use: cache in memory or use a temporary file.
+     *
+     * @since Commons Compress 1.1
+     */
+    public static final class Pack200StrategyEnum extends EnumeratedAttribute {
+        private static final Map STRATEGIES = new HashMap();
+        private static final String IN_MEMORY_KEY = "in-memory";
+        private static final String TEMP_FILE_KEY = "temp-file";
+        static {
+            STRATEGIES.put(IN_MEMORY_KEY, Pack200Strategy.IN_MEMORY);
+            STRATEGIES.put(TEMP_FILE_KEY, Pack200Strategy.TEMP_FILE);
+        }
+
+        public String[] getValues() {
+            return new String[] {IN_MEMORY_KEY, TEMP_FILE_KEY};
+        }
+
+        static final Pack200StrategyEnum IN_MEMORY =
+            new Pack200StrategyEnum(IN_MEMORY_KEY);
+
+        private Pack200StrategyEnum(String name) {
+            setValue(name);
+        }
+
+        public Pack200StrategyEnum() {
+        }
+
+        public Pack200Strategy getStrategy() {
+            return (Pack200Strategy) STRATEGIES.get(getValue());
+        }
+    }
 }
\ No newline at end of file

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java Wed
Sep 14 11:20:02 2011
@@ -45,7 +45,7 @@ public abstract class PackBase extends T
 
     private static final int BUFFER_SIZE = 8 * 1024;
 
-    private final CompressorStreamFactory factory;
+    private CompressorStreamFactory factory;
     private final ResourceWrapper wrapper;
 
     private Resource src;
@@ -54,11 +54,25 @@ public abstract class PackBase extends T
 
     protected PackBase(CompressorStreamFactory factory,
                        ResourceWrapper wrapper) {
-        this.factory = factory;
+        this(wrapper);
+        setFactory(factory);
+    }
+
+    /**
+     * @since Apache Compress Antlib 1.1
+     */
+    protected PackBase(ResourceWrapper wrapper) {
         this.wrapper = wrapper;
     }
 
     /**
+     * @since Apache Compress Antlib 1.1
+     */
+    protected final void setFactory(CompressorStreamFactory factory) {
+        this.factory = factory;
+    }
+
+    /**
      * the required destination file.
      */
     public void setDestfile(File dest) {

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnPack200.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnPack200.java?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnPack200.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnPack200.java Wed
Sep 14 11:20:02 2011
@@ -18,15 +18,50 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
 import org.apache.ant.compress.util.Pack200StreamFactory;
+import org.apache.commons.compress.compressors.CompressorInputStream;
+import org.apache.commons.compress.compressors.pack200.Pack200CompressorInputStream;
 
 /**
  * Expands a pack200 archive.
+ * @since Apache Compress Antlib 1.1
  */
 public final class UnPack200 extends UnpackBase {
 
+    private Pack200.Pack200StrategyEnum strategy =
+        Pack200.Pack200StrategyEnum.IN_MEMORY;
+
     public UnPack200() {
-        super(".pack", new Pack200StreamFactory());
+        super(".pack");
+        setFactory(new Pack200StreamFactory() {
+                public CompressorInputStream
+                    getCompressorStream(InputStream stream)
+                    throws IOException {
+                    return new Pack200CompressorInputStream(stream,
+                                                            strategy
+                                                            .getStrategy());
+                }
+                public CompressorInputStream getCompressorInputStream(File file)
+                    throws IOException {
+                    return new Pack200CompressorInputStream(file,
+                                                            strategy
+                                                            .getStrategy());
+                }
+            });
+    }
+
+    /**
+     * Whether to cache archive data in memory (the default) or a
+     * temporary file.
+     *
+     * @since Commons Compress 1.1
+     */
+    public void setPack200Strategy(Pack200.Pack200StrategyEnum s) {
+        strategy = s;
     }
 
 }
\ No newline at end of file

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/UnpackBase.java Wed
Sep 14 11:20:02 2011
@@ -39,11 +39,25 @@ public abstract class UnpackBase extends
     private static final int BUFFER_SIZE = 8 * 1024;
 
     private final String defaultExtension;
-    private final CompressorStreamFactory factory;
+    private CompressorStreamFactory factory;
 
     protected UnpackBase(String defaultExtension,
                          CompressorStreamFactory factory) {
+        this(defaultExtension);
+        setFactory(factory);
+    }
+
+    /**
+     * @since Apache Compress Antlib 1.1
+     */
+    protected UnpackBase(String defaultExtension) {
         this.defaultExtension = defaultExtension;
+    }
+
+    /**
+     * @since Apache Compress Antlib 1.1
+     */
+    protected final void setFactory(CompressorStreamFactory factory) {
         this.factory = factory;
     }
 

Modified: ant/antlibs/compress/trunk/src/tests/antunit/pack200-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/pack200-test.xml?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/pack200-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/pack200-test.xml Wed Sep 14 11:20:02 2011
@@ -67,4 +67,13 @@
       </cond:islastmodified>
     </au:assertTrue>
   </target>
+
+  <target name="testTempFileStrategy" depends="setUp">
+    <cmp:pack200 src="../resources/asf-logo.gif.zip"
+                 destfile="${output}/asf-logo.gif.pack"
+                 pack200strategy="temp-file"/>
+    <au:assertLogContains text="Building: asf-logo.gif.pack"/>
+    <au:assertFileExists file="${output}/asf-logo.gif.pack"/>
+  </target>
+
 </project>

Modified: ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml?rev=1170535&r1=1170534&r2=1170535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/unpack200-test.xml Wed Sep 14 11:20:02 2011
@@ -51,4 +51,16 @@
        expected="../resources/asf-logo.gif"
        />
   </target>
+
+  <target name="testTempFileStrategy" depends="setUp">
+    <cmp:unpack200 src="../resources/asf-logo.gif.pack"
+                   dest="${input}/test.zip"
+                   pack200strategy="temp-file"/>
+    <cmp:unzip src="${input}/test.zip" dest="${output}" />
+    <au:assertFileExists file="${output}/asf-logo.gif"/>
+    <au:assertFilesMatch
+       actual="${output}/asf-logo.gif"
+       expected="../resources/asf-logo.gif"
+       />
+  </target>
 </project>



Mime
View raw message