ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r809805 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ tests/antunit/
Date Tue, 01 Sep 2009 03:04:04 GMT
Author: bodewig
Date: Tue Sep  1 03:04:04 2009
New Revision: 809805

URL: http://svn.apache.org/viewvc?rev=809805&view=rev
Log:
<gzip> and <bzip2> can now wrap an archiving task

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/BZip2.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/bzip2-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/gzip-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/BZip2.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/BZip2.java?rev=809805&r1=809804&r2=809805&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/BZip2.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/BZip2.java
Tue Sep  1 03:04:04 2009
@@ -18,7 +18,10 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import org.apache.ant.compress.resources.BZip2Resource;
+import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
 import org.apache.ant.compress.util.BZip2StreamFactory;
+import org.apache.tools.ant.types.Resource;
 
 /**
  * Compresses using gzip.
@@ -26,7 +29,12 @@
 public final class BZip2 extends PackBase {
 
     public BZip2() {
-        super(new BZip2StreamFactory());
+        super(new BZip2StreamFactory(),
+              new PackBase.ResourceWrapper() {
+                public CommonsCompressCompressorResource wrap(Resource dest) {
+                    return new BZip2Resource(dest);
+                }
+            });
     }
 
 }
\ No newline at end of file

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java?rev=809805&r1=809804&r2=809805&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/GZip.java
Tue Sep  1 03:04:04 2009
@@ -18,7 +18,10 @@
 
 package org.apache.ant.compress.taskdefs;
 
+import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
+import org.apache.ant.compress.resources.GZipResource;
 import org.apache.ant.compress.util.GZipStreamFactory;
+import org.apache.tools.ant.types.Resource;
 
 /**
  * Compresses using gzip.
@@ -26,7 +29,12 @@
 public final class GZip extends PackBase {
 
     public GZip() {
-        super(new GZipStreamFactory());
+        super(new GZipStreamFactory(),
+              new PackBase.ResourceWrapper() {
+                public CommonsCompressCompressorResource wrap(Resource dest) {
+                    return new GZipResource(dest);
+                }
+            });
     }
 
 }
\ No newline at end of file

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java?rev=809805&r1=809804&r2=809805&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/PackBase.java
Tue Sep  1 03:04:04 2009
@@ -25,6 +25,7 @@
 import java.io.OutputStream;
 import java.util.Iterator;
 
+import org.apache.ant.compress.resources.CommonsCompressCompressorResource;
 import org.apache.ant.compress.util.CompressorStreamFactory;
 import org.apache.commons.compress.utils.IOUtils;
 import org.apache.tools.ant.BuildException;
@@ -43,12 +44,16 @@
     private static final int BUFFER_SIZE = 8 * 1024;
 
     private final CompressorStreamFactory factory;
+    private final ResourceWrapper wrapper;
 
     private Resource src;
+    private ArchiveBase srcTask;
     private Resource dest;
 
-    protected PackBase(CompressorStreamFactory factory) {
+    protected PackBase(CompressorStreamFactory factory,
+                       ResourceWrapper wrapper) {
         this.factory = factory;
+        this.wrapper = wrapper;
     }
 
     /**
@@ -91,8 +96,8 @@
      * @param src resource to expand
      */
     public void setSrc(Resource src) {
-        if (this.src != null) {
-            throw new BuildException("Can only have one source resource.");
+        if (this.src != null || srcTask != null) {
+            throw new BuildException("Can only have one source.");
         }
         if (src.isDirectory()) {
             throw new BuildException("the source can't be a directory");
@@ -110,16 +115,24 @@
         }
     }
 
+    public void add(ArchiveBase task) {
+        if (src != null || srcTask != null) {
+            throw new BuildException("Can only have one source.");
+        }
+        srcTask = task;
+    }
+
     /**
      * validation routine
      * @throws BuildException if anything is invalid
      */
     private void validate() throws BuildException {
-        if (src == null) {
-            throw new BuildException("source resource is required.",
+        if (src == null && srcTask == null) {
+            throw new BuildException("source is required.",
                                      getLocation());
         }
 
+        if (src !=  null) {
         if (src.isDirectory()) {
             throw new BuildException("source resource must not "
                                      + "represent a directory!", getLocation());
@@ -128,6 +141,7 @@
         if (!src.isExists()) {
             throw new BuildException("source resource must exist.");
         }
+        }
 
         if (dest == null) {
             throw new BuildException("dest resource is required.",
@@ -148,6 +162,11 @@
     public void execute() throws BuildException {
         validate();
 
+        if (srcTask != null) {
+            srcTask.setDest(wrapper.wrap(dest));
+            srcTask.setTaskName(getTaskName());
+            srcTask.execute();
+        } else
         if (dest.isExists() && dest.getLastModified() > src.getLastModified())
{
             log("Nothing to do: " + dest.getName() + " is up to date.");
         } else {
@@ -176,4 +195,8 @@
             FileUtils.close(out);
         }
     }
+
+    public static interface ResourceWrapper {
+        CommonsCompressCompressorResource wrap(Resource dest);
+    }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/bzip2-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/bzip2-test.xml?rev=809805&r1=809804&r2=809805&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/bzip2-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/bzip2-test.xml Tue Sep  1 03:04:04
2009
@@ -17,6 +17,7 @@
   -->
 <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" />
@@ -29,7 +30,7 @@
   </target>
 
   <target name="testFailNone" depends="setUp">
-    <au:expectfailure expectedmessage="source resource is required.">
+    <au:expectfailure expectedmessage="source is required.">
       <cmp:bzip2 destfile="${output}/file.bz2">
         <fileset dir="${output}/empty" />
       </cmp:bzip2>
@@ -37,7 +38,7 @@
   </target>
 
   <target name="testFailTwo" depends="setUp">
-    <au:expectfailure expectedmessage="Can only have one source resource.">
+    <au:expectfailure expectedmessage="Can only have one source.">
       <cmp:bzip2 destfile="${output}/file.bz2">
         <fileset dir="${output}" />
       </cmp:bzip2>
@@ -95,4 +96,24 @@
     <au:assertFileExists file="${output}/asf-logo-huge.tar.bz2"/>
   </target>
 
+  <target name="testNestedTask" depends="setUp">
+    <cmp:bzip2 destfile="${output}/asf-logo.tar.bz2">
+      <cmp:tar>
+        <cmp:cpiofileset src="../resources/asf-logo.gif.cpio"
+                         includes="asf-logo.gif"/>
+      </cmp:tar>
+    </cmp:bzip2>
+    <au:assertFileExists file="${output}/asf-logo.tar.bz2"/>
+    <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">
+          <bzip2resource>
+            <file file="${output}/asf-logo.tar.bz2"/>
+          </bzip2resource>
+        </cmp:tarentry>
+      </cond:islastmodified>
+    </au:assertTrue>
+  </target>
+
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/gzip-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/gzip-test.xml?rev=809805&r1=809804&r2=809805&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/gzip-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/gzip-test.xml Tue Sep  1 03:04:04
2009
@@ -17,6 +17,7 @@
   -->
 <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" />
@@ -29,7 +30,7 @@
   </target>
 
   <target name="testFailNone" depends="setUp">
-    <au:expectfailure expectedmessage="source resource is required.">
+    <au:expectfailure expectedmessage="source is required.">
       <cmp:gzip destfile="${output}/file.gz">
         <fileset dir="${output}/empty" />
       </cmp:gzip>
@@ -37,7 +38,7 @@
   </target>
 
   <target name="testFailTwo" depends="setUp">
-    <au:expectfailure expectedmessage="Can only have one source resource.">
+    <au:expectfailure expectedmessage="Can only have one source.">
       <cmp:gzip destfile="${output}/file.gz">
         <fileset dir="${output}" />
       </cmp:gzip>
@@ -85,4 +86,24 @@
               destfile="${output}/asf-logo.gif.gz" />
     <au:assertLogContains text="Nothing to do: asf-logo.gif.gz is up to date."/>
   </target>
+
+  <target name="testNestedTask" depends="setUp">
+    <cmp:gzip destfile="${output}/asf-logo.tar.gz">
+      <cmp:tar>
+        <cmp:cpiofileset src="../resources/asf-logo.gif.cpio"
+                         includes="asf-logo.gif"/>
+      </cmp:tar>
+    </cmp:gzip>
+    <au:assertFileExists file="${output}/asf-logo.tar.gz"/>
+    <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">
+          <gzipresource>
+            <file file="${output}/asf-logo.tar.gz"/>
+          </gzipresource>
+        </cmp:tarentry>
+      </cond:islastmodified>
+    </au:assertTrue>
+  </target>
 </project>



Mime
View raw message