ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r801285 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/antlib.xml main/org/apache/ant/compress/resources/ZipResource.java tests/antunit/zipentry-test.xml
Date Wed, 05 Aug 2009 16:20:18 GMT
Author: bodewig
Date: Wed Aug  5 16:20:18 2009
New Revision: 801285

URL: http://svn.apache.org/viewvc?rev=801285&view=rev
Log:
zipentry resource

Added:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
  (contents, props changed)
      - copied, changed from r801240, ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zipentry-test.xml
      - copied, changed from r801271, ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarentry-test.xml
Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml?rev=801285&r1=801284&r2=801285&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/antlib.xml Wed Aug
 5 16:20:18 2009
@@ -45,4 +45,8 @@
     name="cpioentry"
     classname="org.apache.ant.compress.resources.CpioResource"
     />
+  <typedef
+    name="zipentry"
+    classname="org.apache.ant.compress.resources.ZipResource"
+    />
 </antlib>

Copied: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
(from r801240, ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java)
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java&r1=801240&r2=801285&rev=801285&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/ZipResource.java (original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
Wed Aug  5 16:20:18 2009
@@ -15,29 +15,32 @@
  *  limitations under the License.
  *
  */
-package org.apache.tools.ant.types.resources;
+package org.apache.ant.compress.resources;
 
 import java.io.File;
 import java.io.InputStream;
-import java.io.OutputStream;
 import java.io.IOException;
 import java.io.FilterInputStream;
+import java.util.Date;
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileProvider;
 import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.zip.ZipFile;
-import org.apache.tools.zip.ZipEntry;
-import org.apache.tools.zip.ZipExtraField;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
+import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
+import org.apache.commons.compress.archivers.zip.ZipExtraField;
+import org.apache.commons.compress.archivers.zip.ZipFile;
 
 /**
  * A Resource representation of an entry in a zipfile.
- * @since Ant 1.7
  */
-public class ZipResource extends ArchiveResource {
+public class ZipResource extends CommonsCompressArchiveResource {
 
     private String encoding;
     private ZipExtraField[] extras;
@@ -55,10 +58,21 @@
      * @param enc the encoding used for filenames.
      * @param e the ZipEntry.
      */
-    public ZipResource(File z, String enc, ZipEntry e) {
-        super(z, true);
+    public ZipResource(File z, String enc, ZipArchiveEntry e) {
+        super(z, e);
+        setEncoding(enc);
+    }
+
+    /**
+     * Construct a ZipResource representing the specified
+     * entry in the specified zip archive.
+     * @param z the zipfile as File.
+     * @param enc the encoding used for filenames.
+     * @param e the ZipEntry.
+     */
+    public ZipResource(Resource z, String enc, ZipArchiveEntry e) {
+        super(z, e);
         setEncoding(enc);
-        setEntry(e);
     }
 
     /**
@@ -70,24 +84,20 @@
     }
 
     /**
-     * Get the zipfile that holds this ZipResource.
-     * @return the zipfile as a File.
+     * Set the zipfile that holds this ZipResource.
+     * @param z the zipfile as a Resource.
      */
-    public File getZipfile() {
-        FileResource r = (FileResource) getArchive();
-        return r.getFile();
+    public void setZipfile(Resource z) {
+        addConfigured(z);
     }
 
     /**
-     * Sets the archive that holds this as a single element Resource
-     * collection.
-     * @param a the archive as a single element Resource collection.
+     * Get the zipfile that holds this ZipResource.
+     * @return the zipfile as a File or null if it is not a file.
      */
-    public void addConfigured(ResourceCollection a) {
-        super.addConfigured(a);
-        if (!a.isFilesystemOnly()) {
-            throw new BuildException("only filesystem resources are supported");
-        }
+    public File getZipfile() {
+        FileProvider fp = (FileProvider) getArchive().as(FileProvider.class);
+        return fp != null ? fp.getFile() : null;
     }
 
     /**
@@ -129,8 +139,13 @@
         if (isReference()) {
             return ((Resource) getCheckedRef()).getInputStream();
         }
-        final ZipFile z = new ZipFile(getZipfile(), getEncoding());
-        ZipEntry ze = z.getEntry(getName());
+        File f = getZipfile();
+        if (f == null) {
+            return super.getInputStream();
+        }
+
+        final ZipFile z = new ZipFile(f, getEncoding());
+        ZipArchiveEntry ze = z.getEntry(getName());
         if (ze == null) {
             z.close();
             throw new BuildException("no entry " + getName() + " in "
@@ -152,25 +167,8 @@
     }
 
     /**
-     * Get an OutputStream for the Resource.
-     * @return an OutputStream to which content can be written.
-     * @throws IOException if unable to provide the content of this
-     *         Resource as a stream.
-     * @throws UnsupportedOperationException if OutputStreams are not
-     *         supported for this Resource type.
-     */
-    public OutputStream getOutputStream() throws IOException {
-        if (isReference()) {
-            return ((Resource) getCheckedRef()).getOutputStream();
-        }
-        throw new UnsupportedOperationException(
-            "Use the zip task for zip output.");
-    }
-
-    /**
      * Retrieves extra fields.
      * @return an array of the extra fields
-     * @since Ant 1.8.0
      */
     public ZipExtraField[] getExtraFields() {
         if (extras == null) {
@@ -183,6 +181,12 @@
      * fetches information from the named entry inside the archive.
      */
     protected void fetchEntry() {
+        File f = getZipfile();
+        if (f == null) {
+            super.fetchEntry();
+            return;
+        }
+
         ZipFile z = null;
         try {
             z = new ZipFile(getZipfile(), getEncoding());
@@ -191,28 +195,31 @@
             log(e.getMessage(), Project.MSG_DEBUG);
             throw new BuildException(e);
         } finally {
-            if (z != null) {
-                try {
-                    z.close();
-                } catch (IOException e) {
-                    //?
-                }
-            }
+            ZipFile.closeQuietly(z);
         }
     }
 
-    private void setEntry(ZipEntry e) {
-        if (e == null) {
-            setExists(false);
-            return;
+    protected void setEntry(ArchiveEntry e) {
+        super.setEntry(e);
+        if (e != null) {
+            extras = ((ZipArchiveEntry) e).getExtraFields();
         }
-        setName(e.getName());
-        setExists(true);
-        setLastModified(e.getTime());
-        setDirectory(e.isDirectory());
-        setSize(e.getSize());
-        setMode(e.getUnixMode());
-        extras = e.getExtraFields();
     }
 
+    protected ArchiveInputStream getArchiveStream(InputStream is)
+        throws IOException {
+        return new ZipArchiveInputStream(is, getEncoding(), true);
+    }
+
+    protected Date getLastModified(ArchiveEntry entry) {
+        return new Date(((ZipArchiveEntry) entry).getTime());
+    }
+
+    protected int getMode(ArchiveEntry e) {
+        return ((ZipArchiveEntry) e).getUnixMode();
+    }
+
+    protected String getArchiveType() {
+        return "zip";
+    }
 }

Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
------------------------------------------------------------------------------
    svn:mergeinfo = 

Copied: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zipentry-test.xml (from r801271,
ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarentry-test.xml)
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zipentry-test.xml?p2=ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zipentry-test.xml&p1=ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarentry-test.xml&r1=801271&r2=801285&rev=801285&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarentry-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zipentry-test.xml Wed Aug  5 16:20:18
2009
@@ -26,11 +26,11 @@
     <mkdir dir="${input}"/>
   </target>
 
-  <target name="testTarSource" depends="setUp">
+  <target name="testZipSource" depends="setUp">
     <copy todir="${output}">
-      <cmp:tarentry name="asf-logo.gif">
-        <file file="../resources/asf-logo.gif.tar"/>
-      </cmp:tarentry>
+      <cmp:zipentry name="asf-logo.gif">
+        <file file="../resources/asf-logo.gif.zip"/>
+      </cmp:zipentry>
     </copy>
     <au:assertFilesMatch
        actual="${output}/asf-logo.gif"
@@ -39,14 +39,14 @@
   </target>
 
   <target name="testUncompressSource" depends="setUp">
-    <gzip destfile="${input}/asf-logo.gif.tar.gz"
-          src="../resources/asf-logo.gif.tar"/>
+    <gzip destfile="${input}/asf-logo.gif.zip.gz"
+          src="../resources/asf-logo.gif.zip"/>
     <copy todir="${output}">
-      <cmp:tarentry name="asf-logo.gif">
+      <cmp:zipentry name="asf-logo.gif">
         <gzipresource>
-          <file file="${input}/asf-logo.gif.tar.gz"/>
+          <file file="${input}/asf-logo.gif.zip.gz"/>
         </gzipresource>
-      </cmp:tarentry>
+      </cmp:zipentry>
     </copy>
     <au:assertFilesMatch
        actual="${output}/asf-logo.gif"



Mime
View raw message