ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r329409 - in /ant/core/trunk: docs/manual/CoreTasks/ src/etc/testcases/taskdefs/ src/main/org/apache/tools/ant/taskdefs/ src/testcases/org/apache/tools/ant/taskdefs/
Date Sat, 29 Oct 2005 13:09:52 GMT
Author: bodewig
Date: Sat Oct 29 06:09:43 2005
New Revision: 329409

URL: http://svn.apache.org/viewcvs?rev=329409&view=rev
Log:
resource collections for [bg]unzip2?

Modified:
    ant/core/trunk/docs/manual/CoreTasks/unpack.html
    ant/core/trunk/src/etc/testcases/taskdefs/bunzip2.xml
    ant/core/trunk/src/etc/testcases/taskdefs/gunzip.xml
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/GUnzip.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Unpack.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java

Modified: ant/core/trunk/docs/manual/CoreTasks/unpack.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/unpack.html?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/unpack.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/unpack.html Sat Oct 29 06:09:43 2005
@@ -10,13 +10,13 @@
 
 <h2><a name="unpack">GUnzip/BUnzip2</a></h2>
 <h3>Description</h3>
-<p>Expands a file packed using GZip or BZip2.</p>
+<p>Expands a resource packed using GZip or BZip2.</p>
 
 <p>If <i>dest</i> is a directory the name of the destination file is
 the same as <i>src</i> (with the &quot;.gz&quot; or &quot;.bz2&quot;
 extension removed if present). If <i>dest</i> is omitted, the parent
 dir of <i>src</i> is taken. The file is only expanded if the source
-file is newer than the destination file, or when the destination file
+resource is newer than the destination file, or when the destination file
 does not exist.</p>
 
 <h3>Parameters</h3>
@@ -29,7 +29,7 @@
   <tr>
     <td valign="top">src</td>
     <td valign="top">the file to expand.</td>
-    <td align="center" valign="top">Yes</td>
+    <td align="center" valign="top">Yes, or a nested resource collection.</td>
   </tr>
   <tr>
     <td valign="top">dest</td>
@@ -37,6 +37,13 @@
     <td align="center" valign="top">No</td>
   </tr>
 </table>
+<h3>Parameters specified as nested elements</h3>
+
+<h4>any <a href="../CoreTypes/resources.html">resource</a> or single element
+resource collection</h4>
+
+<p>The specified resource will be used as src.</p>
+
 <h3>Examples</h3>
 <blockquote><pre>
 &lt;gunzip src=&quot;test.tar.gz&quot;/&gt;
@@ -55,6 +62,13 @@
 </pre></blockquote>
 <p>expands <i>test.tar.gz</i> to <i>subdir/test.tar</i> (assuming
 subdir is a directory).</p>
+<blockquote><pre>
+&lt;gunzip dest=&quot;.&quot;&gt;
+  &lt;url url="http://example.org/archive.tar.gz"/&gt;
+&lt;/gunzip&gt;
+</pre></blockquote>
+<p>downloads <i>http://example.org/archive.tar.gz</i> and expands it
+to <i>archive.tar</i> in the project's basedir on the fly.</p>
 
 <h3>Related tasks</h3>
 

Modified: ant/core/trunk/src/etc/testcases/taskdefs/bunzip2.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/bunzip2.xml?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/bunzip2.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/bunzip2.xml Sat Oct 29 06:09:43 2005
@@ -6,6 +6,12 @@
     <bunzip2 src="expected/asf-logo-huge.tar.bz2" dest="asf-logo-huge.tar" />
   </target>
 
+  <target name="realTestWithResource">
+    <bunzip2 dest="asf-logo-huge.tar">
+      <file file="expected/asf-logo-huge.tar.bz2"/>
+    </bunzip2>
+  </target>
+
   <target name="cleanup">
     <delete file="asf-logo-huge.tar" />
     <delete file="expected/asf-logo-huge.tar" />

Modified: ant/core/trunk/src/etc/testcases/taskdefs/gunzip.xml
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/etc/testcases/taskdefs/gunzip.xml?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/etc/testcases/taskdefs/gunzip.xml (original)
+++ ant/core/trunk/src/etc/testcases/taskdefs/gunzip.xml Sat Oct 29 06:09:43 2005
@@ -24,6 +24,12 @@
     <gunzip src="expected/asf-logo.gif.gz" dest="asf-logo.gif" />
   </target>
 
+  <target name="realTestWithResource">
+    <gunzip dest="asf-logo.gif">
+      <file file="expected/asf-logo.gif.gz"/>
+    </gunzip>
+  </target>
+
   <target name="testDocumentationClaimsOnCopy">
     <copy todir=".">
       <gzipresource>

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/BUnzip2.java Sat Oct 29 06:09:43
2005
@@ -19,9 +19,9 @@
 
 
 import java.io.BufferedInputStream;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.tools.bzip2.CBZip2InputStream;
@@ -58,11 +58,11 @@
 
             FileOutputStream out = null;
             CBZip2InputStream zIn = null;
-            FileInputStream fis = null;
+            InputStream fis = null;
             BufferedInputStream bis = null;
             try {
                 out = new FileOutputStream(dest);
-                fis = new FileInputStream(source);
+                fis = srcResource.getInputStream();
                 bis = new BufferedInputStream(fis);
                 int b = bis.read();
                 if (b != 'B') {
@@ -89,5 +89,20 @@
                 FileUtils.close(zIn);
             }
         }
+    }
+
+    /**
+     * Whether this task can deal with non-file resources.
+     *
+     * <p>This implementation returns true only if this task is
+     * &lt;gunzip&gt;.  Any subclass of this class that also wants to
+     * support non-file resources needs to override this method.  We
+     * need to do so for backwards compatibility reasons since we
+     * can't expect subclasses to support resources.</p>
+     *
+     * @since Ant 1.7
+     */
+    protected boolean supportsNonFileResources() {
+        return getClass().equals(BUnzip2.class);
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/GUnzip.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/GUnzip.java?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/GUnzip.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/GUnzip.java Sat Oct 29 06:09:43
2005
@@ -17,9 +17,9 @@
 
 package org.apache.tools.ant.taskdefs;
 
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.zip.GZIPInputStream;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.util.FileUtils;
@@ -56,10 +56,10 @@
 
             FileOutputStream out = null;
             GZIPInputStream zIn = null;
-            FileInputStream fis = null;
+            InputStream fis = null;
             try {
                 out = new FileOutputStream(dest);
-                fis = new FileInputStream(source);
+                fis = srcResource.getInputStream();
                 zIn = new GZIPInputStream(fis);
                 byte[] buffer = new byte[8 * 1024];
                 int count = 0;
@@ -76,5 +76,20 @@
                 FileUtils.close(zIn);
             }
         }
+    }
+
+    /**
+     * Whether this task can deal with non-file resources.
+     *
+     * <p>This implementation returns true only if this task is
+     * &lt;gunzip&gt;.  Any subclass of this class that also wants to
+     * support non-file resources needs to override this method.  We
+     * need to do so for backwards compatibility reasons since we
+     * can't expect subclasses to support resources.</p>
+     *
+     * @since Ant 1.7
+     */
+    protected boolean supportsNonFileResources() {
+        return getClass().equals(GUnzip.class);
     }
 }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Unpack.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Unpack.java?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Unpack.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Unpack.java Sat Oct 29 06:09:43
2005
@@ -21,6 +21,9 @@
 import java.io.File;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileResource;
 
 /**
  * Abstract Base class for unpack tasks.
@@ -32,6 +35,7 @@
 
     protected File source;
     protected File dest;
+    protected Resource srcResource;
 
     /**
      * @deprecated setSrc(String) is deprecated and is replaced with
@@ -66,7 +70,39 @@
      * @param src file to expand
      */
     public void setSrc(File src) {
-        source = src;
+        setSrcResource(new FileResource(src));
+    }
+
+    /**
+     * The resource to expand; required.
+     * @param src resource to expand
+     */
+    public void setSrcResource(Resource src) {
+        if (!src.isExists()) {
+            throw new BuildException("the archive doesn't exist");
+        }
+        if (src.isDirectory()) {
+            throw new BuildException("the archive can't be a directory");
+        }
+        if (src instanceof FileResource) {
+            source = ((FileResource) src).getFile();
+        } else if (!supportsNonFileResources()) {
+            throw new BuildException("Only FileSystem resources are"
+                                     + " supported.");
+        }
+        srcResource = src;
+    }
+
+    /**
+     * Set the source Archive resource.
+     * @param a the archive as a single element Resource collection.
+     */
+    public void addConfigured(ResourceCollection a) {
+        if (a.size() != 1) {
+            throw new BuildException("only single argument resource collections"
+                                     + " are supported as archives");
+        }
+        setSrcResource((Resource) a.iterator().next());
     }
 
     /**
@@ -78,18 +114,10 @@
     }
 
     private void validate() throws BuildException {
-        if (source == null) {
+        if (srcResource == null) {
             throw new BuildException("No Src specified", getLocation());
         }
 
-        if (!source.exists()) {
-            throw new BuildException("Src doesn't exist", getLocation());
-        }
-
-        if (source.isDirectory()) {
-            throw new BuildException("Cannot expand a directory", getLocation());
-        }
-
         if (dest == null) {
             dest = new File(source.getParent());
         }
@@ -140,4 +168,16 @@
      * This is to be overridden by subclasses.
      */
     protected abstract void extract();
+
+    /**
+     * Whether this task can deal with non-file resources.
+     *
+     * <p>This implementation returns false.</p>
+     *
+     * @since Ant 1.7
+     */
+    protected boolean supportsNonFileResources() {
+        return false;
+    }
+
 }

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/BUnzip2Test.java Sat Oct 29
06:09:43 2005
@@ -42,17 +42,22 @@
         executeTarget("cleanup");
     }
 
-    public void testRealTest() throws IOException {
-        executeTarget("realTest");
+    public void testRealTest() throws java.io.IOException {
+        testRealTest("realTest");
+    }
+
+    public void testRealTestWithResource() throws java.io.IOException {
+        testRealTest("realTestWithResource");
+    }
+
+    private void testRealTest(String target) throws java.io.IOException {
+        executeTarget(target);
         assertTrue("File content mismatch after bunzip2",
             FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"),
                                     project.resolveFile("asf-logo-huge.tar")));
     }
 
     public void testDocumentationClaimsOnCopy() throws java.io.IOException {
-        executeTarget("testDocumentationClaimsOnCopy");
-        assertTrue("File content mismatch after bunzip2",
-            FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar"),
-                                    project.resolveFile("asf-logo-huge.tar")));
+        testRealTest("testDocumentationClaimsOnCopy");
     }
 }

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java?rev=329409&r1=329408&r2=329409&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/taskdefs/GUnzipTest.java Sat Oct 29
06:09:43 2005
@@ -47,20 +47,24 @@
     }
 
     public void testRealTest() throws java.io.IOException {
-        executeTarget("realTest");
+        testRealTest("realTest");
+    }
+
+    public void testRealTestWithResource() throws java.io.IOException {
+        testRealTest("realTestWithResource");
+    }
+
+    private void testRealTest(String target) throws java.io.IOException {
+        executeTarget(target);
         assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
                                            project.resolveFile("asf-logo.gif")));
     }
 
     public void testTestGzipTask() throws java.io.IOException {
-        executeTarget("testGzipTask");
-        assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
-                                           project.resolveFile("asf-logo.gif")));
+        testRealTest("testGzipTask");
     }
 
     public void testDocumentationClaimsOnCopy() throws java.io.IOException {
-        executeTarget("testDocumentationClaimsOnCopy");
-        assertTrue(FILE_UTILS.contentEquals(project.resolveFile("../asf-logo.gif"),
-                                           project.resolveFile("asf-logo.gif")));
+        testRealTest("testDocumentationClaimsOnCopy");
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message