ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r803788 - in /ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress: resources/ util/
Date Thu, 13 Aug 2009 06:16:28 GMT
Author: bodewig
Date: Thu Aug 13 06:16:28 2009
New Revision: 803788

URL: http://svn.apache.org/viewvc?rev=803788&view=rev
Log:
extract mode/uid and gid handling for single entry resources

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArResource.java
Thu Aug 13 06:16:28 2009
@@ -18,13 +18,9 @@
 package org.apache.ant.compress.resources;
 
 import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
 import org.apache.ant.compress.util.ArStreamFactory;
-import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
 
 /**
@@ -32,14 +28,11 @@
  */
 public class ArResource extends CommonsCompressArchiveResource {
 
-    private int    uid;
-    private int    gid;
-
     /**
      * Default constructor.
      */
     public ArResource() {
-        super(new ArStreamFactory());
+        super(new ArStreamFactory(), "ar");
     }
 
     /**
@@ -49,7 +42,7 @@
      * @param e the ArEntry.
      */
     public ArResource(File a, ArArchiveEntry e) {
-        super(new ArStreamFactory(), a, e);
+        super(new ArStreamFactory(), "ar", a, e);
     }
 
     /**
@@ -59,43 +52,7 @@
      * @param e the ArEntry.
      */
     public ArResource(Resource a, ArArchiveEntry e) {
-        super(new ArStreamFactory(), a, e);
-    }
-
-    /**
-     * @return the uid for the ar entry
-     */
-    public int getUid() {
-        if (isReference()) {
-            return ((ArResource) getCheckedRef()).getUid();
-        }
-        return uid;
-    }
-
-    /**
-     * @return the uid for the ar entry
-     */
-    public int getGid() {
-        if (isReference()) {
-            return ((ArResource) getCheckedRef()).getGid();
-        }
-        return uid;
-    }
-
-    protected void setEntry(ArchiveEntry e) {
-        super.setEntry(e);
-        if (e != null) {
-            ArArchiveEntry ae = (ArArchiveEntry) e;
-            uid = ae.getUserId();
-            gid = ae.getGroupId();
-        }
+        super(new ArStreamFactory(), "ar", a, e);
     }
 
-    protected int getMode(ArchiveEntry e) {
-        return ((ArArchiveEntry) e).getMode();
-    }
-
-    protected String getArchiveType() {
-        return "ar";
-    }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
Thu Aug 13 06:16:28 2009
@@ -22,10 +22,10 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.io.IOException;
-import java.util.Date;
 
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.ArchiveResource;
 import org.apache.tools.ant.util.FileUtils;
@@ -41,12 +41,18 @@
 
     private String encoding;
     private final StreamFactory factory;
+    private final String archiveType;
+
+    // not supported for zip
+    private int gid, uid;
 
     /**
      * Default constructor.
      */
-    protected CommonsCompressArchiveResource(StreamFactory factory) {
+    protected CommonsCompressArchiveResource(StreamFactory factory,
+                                             String archiveType) {
         this.factory = factory;
+        this.archiveType = archiveType;
     }
 
     /**
@@ -55,10 +61,12 @@
      * @param a the archive as File.
      * @param e the ArchiveEntry.
      */
-    protected CommonsCompressArchiveResource(StreamFactory factory, File a,
-                                             ArchiveEntry e) {
+    protected CommonsCompressArchiveResource(StreamFactory factory,
+                                             String archiveType,
+                                             File a, ArchiveEntry e) {
         super(a, true);
         this.factory = factory;
+        this.archiveType = archiveType;
         setEntry(e);
     }
 
@@ -68,10 +76,12 @@
      * @param a the archive as Resource.
      * @param e the ArchiveEntry.
      */
-    protected CommonsCompressArchiveResource(StreamFactory factory, Resource a,
-                                             ArchiveEntry e) {
+    protected CommonsCompressArchiveResource(StreamFactory factory,
+                                             String archiveType,
+                                             Resource a, ArchiveEntry e) {
         super(a, true);
         this.factory = factory;
+        this.archiveType = archiveType;
         setEntry(e);
     }
 
@@ -95,6 +105,17 @@
     }
 
     /**
+     * Overrides the super version.
+     * @param r the Reference to set.
+     */
+    public void setRefid(Reference r) {
+        if (getEncoding() != null) {
+            throw tooManyAttributes();
+        }
+        super.setRefid(r);
+    }
+
+    /**
      * Return an InputStream for reading the contents of this Resource.
      * @return an InputStream object.
      * @throws IOException if the archive cannot be opened,
@@ -121,11 +142,6 @@
     }
 
     /**
-     * The name of the archive type.
-     */
-    protected abstract String getArchiveType();
-
-    /**
      * 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
@@ -137,13 +153,33 @@
         if (isReference()) {
             return ((Resource) getCheckedRef()).getOutputStream();
         }
-        throw new UnsupportedOperationException("Use the " + getArchiveType()
+        throw new UnsupportedOperationException("Use the " + archiveType
                                                 + " task for "
-                                                + getArchiveType()
+                                                + archiveType
                                                 + " output.");
     }
 
     /**
+     * @return the uid for the entry
+     */
+    public int getUid() {
+        if (isReference()) {
+            return ((CommonsCompressArchiveResource) getCheckedRef()).getUid();
+        }
+        return uid;
+    }
+
+    /**
+     * @return the gid for the entry
+     */
+    public int getGid() {
+        if (isReference()) {
+            return ((CommonsCompressArchiveResource) getCheckedRef()).getGid();
+        }
+        return uid;
+    }
+
+    /**
      * fetches information from the named entry inside the archive.
      */
     protected void fetchEntry() {
@@ -170,11 +206,6 @@
         setEntry(null);
     }
 
-    /**
-     * Determines the mode for the given entry.
-     */
-    protected abstract int getMode(ArchiveEntry e);
-
     protected void setEntry(ArchiveEntry e) {
         if (e == null) {
             setExists(false);
@@ -185,7 +216,9 @@
         setLastModified(EntryHelper.getLastModified(e).getTime());
         setDirectory(e.isDirectory());
         setSize(e.getSize());
-        setMode(getMode(e));
+        setMode(EntryHelper.getMode(e));
+        uid = EntryHelper.getUserId(e);
+        gid = EntryHelper.getGroupId(e);
     }
 
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioResource.java
Thu Aug 13 06:16:28 2009
@@ -18,13 +18,9 @@
 package org.apache.ant.compress.resources;
 
 import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
 import org.apache.ant.compress.util.CpioStreamFactory;
-import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
 
 /**
@@ -32,14 +28,11 @@
  */
 public class CpioResource extends CommonsCompressArchiveResource {
 
-    private long    uid;
-    private long    gid;
-
     /**
      * Default constructor.
      */
     public CpioResource() {
-        super(new CpioStreamFactory());
+        super(new CpioStreamFactory(), "cpio");
     }
 
     /**
@@ -49,7 +42,7 @@
      * @param e the CpioEntry.
      */
     public CpioResource(File a, CpioArchiveEntry e) {
-        super(new CpioStreamFactory(), a, e);
+        super(new CpioStreamFactory(), "cpio", a, e);
     }
 
     /**
@@ -59,43 +52,7 @@
      * @param e the CpioEntry.
      */
     public CpioResource(Resource a, CpioArchiveEntry e) {
-        super(new CpioStreamFactory(), a, e);
-    }
-
-    /**
-     * @return the uid for the cpio entry
-     */
-    public long getUid() {
-        if (isReference()) {
-            return ((CpioResource) getCheckedRef()).getUid();
-        }
-        return uid;
-    }
-
-    /**
-     * @return the uid for the cpio entry
-     */
-    public long getGid() {
-        if (isReference()) {
-            return ((CpioResource) getCheckedRef()).getGid();
-        }
-        return uid;
-    }
-
-    protected void setEntry(ArchiveEntry e) {
-        super.setEntry(e);
-        if (e != null) {
-            CpioArchiveEntry ce = (CpioArchiveEntry) e;
-            uid = ce.getUID();
-            gid = ce.getGID();
-        }
+        super(new CpioStreamFactory(), "cpio", a, e);
     }
 
-    protected int getMode(ArchiveEntry e) {
-        return (int) ((CpioArchiveEntry) e).getMode();
-    }
-
-    protected String getArchiveType() {
-        return "cpio";
-    }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarResource.java
Thu Aug 13 06:16:28 2009
@@ -18,9 +18,6 @@
 package org.apache.ant.compress.resources;
 
 import java.io.File;
-import java.io.InputStream;
-import java.io.IOException;
-import java.util.Date;
 
 import org.apache.tools.ant.types.Resource;
 import org.apache.ant.compress.util.TarStreamFactory;
@@ -34,14 +31,12 @@
 
     private String userName = "";
     private String groupName = "";
-    private int    uid;
-    private int    gid;
 
     /**
      * Default constructor.
      */
     public TarResource() {
-        super(new TarStreamFactory());
+        super(new TarStreamFactory(), "tar");
     }
 
     /**
@@ -51,7 +46,7 @@
      * @param e the TarEntry.
      */
     public TarResource(File a, TarArchiveEntry e) {
-        super(new TarStreamFactory(), a, e);
+        super(new TarStreamFactory(), "tar", a, e);
     }
 
     /**
@@ -61,7 +56,7 @@
      * @param e the TarEntry.
      */
     public TarResource(Resource a, TarArchiveEntry e) {
-        super(new TarStreamFactory(), a, e);
+        super(new TarStreamFactory(), "tar", a, e);
     }
 
     /**
@@ -84,42 +79,13 @@
         return groupName;
     }
 
-    /**
-     * @return the uid for the tar entry
-     */
-    public int getUid() {
-        if (isReference()) {
-            return ((TarResource) getCheckedRef()).getUid();
-        }
-        return uid;
-    }
-
-    /**
-     * @return the uid for the tar entry
-     */
-    public int getGid() {
-        if (isReference()) {
-            return ((TarResource) getCheckedRef()).getGid();
-        }
-        return uid;
-    }
-
     protected void setEntry(ArchiveEntry e) {
         super.setEntry(e);
         if (e != null) {
             TarArchiveEntry te = (TarArchiveEntry) e;
             userName = te.getUserName();
             groupName = te.getGroupName();
-            uid = te.getUserId();
-            gid = te.getGroupId();
         }
     }
 
-    protected int getMode(ArchiveEntry e) {
-        return ((TarArchiveEntry) e).getMode();
-    }
-
-    protected String getArchiveType() {
-        return "tar";
-    }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipResource.java
Thu Aug 13 06:16:28 2009
@@ -21,13 +21,11 @@
 import java.io.InputStream;
 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.resources.FileProvider;
-import org.apache.tools.ant.types.Reference;
 import org.apache.tools.ant.util.FileUtils;
 
 import org.apache.ant.compress.util.ZipStreamFactory;
@@ -48,7 +46,7 @@
      * Default constructor.
      */
     public ZipResource() {
-        super(new ZipStreamFactory());
+        super(new ZipStreamFactory(), "zip");
     }
 
     /**
@@ -59,7 +57,7 @@
      * @param e the ZipEntry.
      */
     public ZipResource(File z, String enc, ZipArchiveEntry e) {
-        super(new ZipStreamFactory(), z, e);
+        super(new ZipStreamFactory(), "zip", z, e);
         setEncoding(enc);
     }
 
@@ -71,7 +69,7 @@
      * @param e the ZipEntry.
      */
     public ZipResource(Resource z, String enc, ZipArchiveEntry e) {
-        super(new ZipStreamFactory(), z, e);
+        super(new ZipStreamFactory(), "zip", z, e);
         setEncoding(enc);
     }
 
@@ -101,17 +99,6 @@
     }
 
     /**
-     * Overrides the super version.
-     * @param r the Reference to set.
-     */
-    public void setRefid(Reference r) {
-        if (getEncoding() != null) {
-            throw tooManyAttributes();
-        }
-        super.setRefid(r);
-    }
-
-    /**
      * Return an InputStream for reading the contents of this Resource.
      * @return an InputStream object.
      * @throws IOException if the zip file cannot be opened,
@@ -188,11 +175,4 @@
         }
     }
 
-    protected int getMode(ArchiveEntry e) {
-        return ((ZipArchiveEntry) e).getUnixMode();
-    }
-
-    protected String getArchiveType() {
-        return "zip";
-    }
 }

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java?rev=803788&r1=803787&r2=803788&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/util/EntryHelper.java
Thu Aug 13 06:16:28 2009
@@ -58,4 +58,79 @@
         throw new BuildException("archive entry " + entry.getClass()
                                  + " is not supported.");
     }
+
+    // REVISIT: are the "mode" formats really compatible with each other?
+    /**
+     * Extracts the permission bits from an entry.
+     */
+    public static int getMode(ArchiveEntry entry) {
+        if (entry == null) {
+            throw new IllegalArgumentException("entry must not be null.");
+        }
+
+        if (entry instanceof ArArchiveEntry) {
+            return ((ArArchiveEntry) entry).getMode();
+        }
+        if (entry instanceof CpioArchiveEntry) {
+            return (int) ((CpioArchiveEntry) entry).getMode();
+        }
+        if (entry instanceof TarArchiveEntry) {
+            return ((TarArchiveEntry) entry).getMode();
+        }
+        if (entry instanceof ZipArchiveEntry) {
+            return ((ZipArchiveEntry) entry).getUnixMode();
+        }
+        throw new BuildException("archive entry " + entry.getClass()
+                                 + " is not supported.");
+    }
+
+    public static int UNKNOWN_ID = Integer.MIN_VALUE;
+
+    /**
+     * Extracts the user id an entry.
+     */
+    public static int getUserId(ArchiveEntry entry) {
+        if (entry == null) {
+            throw new IllegalArgumentException("entry must not be null.");
+        }
+
+        if (entry instanceof ArArchiveEntry) {
+            return ((ArArchiveEntry) entry).getUserId();
+        }
+        if (entry instanceof CpioArchiveEntry) {
+            return (int) ((CpioArchiveEntry) entry).getUID();
+        }
+        if (entry instanceof TarArchiveEntry) {
+            return ((TarArchiveEntry) entry).getUserId();
+        }
+        if (entry instanceof ZipArchiveEntry) {
+            return UNKNOWN_ID;
+        }
+        throw new BuildException("archive entry " + entry.getClass()
+                                 + " is not supported.");
+    }
+
+    /**
+     * Extracts the group id an entry.
+     */
+    public static int getGroupId(ArchiveEntry entry) {
+        if (entry == null) {
+            throw new IllegalArgumentException("entry must not be null.");
+        }
+
+        if (entry instanceof ArArchiveEntry) {
+            return ((ArArchiveEntry) entry).getGroupId();
+        }
+        if (entry instanceof CpioArchiveEntry) {
+            return (int) ((CpioArchiveEntry) entry).getGID();
+        }
+        if (entry instanceof TarArchiveEntry) {
+            return ((TarArchiveEntry) entry).getGroupId();
+        }
+        if (entry instanceof ZipArchiveEntry) {
+            return UNKNOWN_ID;
+        }
+        throw new BuildException("archive entry " + entry.getClass()
+                                 + " is not supported.");
+    }
 }
\ No newline at end of file



Mime
View raw message