ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1150535 - in /ant/antlibs/compress/trunk/src: main/org/apache/ant/compress/resources/ tests/antunit/
Date Mon, 25 Jul 2011 04:20:22 GMT
Author: bodewig
Date: Mon Jul 25 04:20:20 2011
New Revision: 1150535

URL: http://svn.apache.org/viewvc?rev=1150535&view=rev
Log:
skipUnreadableEntries for filesets

Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipFileSet.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
    ant/antlibs/compress/trunk/src/tests/antunit/zipfileset-test.xml

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java Mon
Jul 25 04:20:20 2011
@@ -47,6 +47,8 @@ public class ArFileSet extends ArchiveFi
     private int    uid;
     private int    gid;
 
+    private boolean skipUnreadable = false;
+
     /** Constructor for ArFileSet */
     public ArFileSet() {
         super();
@@ -125,6 +127,15 @@ public class ArFileSet extends ArchiveFi
     }
 
     /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public void setSkipUnreadableEntries(boolean b) {
+        skipUnreadable = b;
+    }
+
+    /**
      * Create a new scanner.
      * @return the created scanner.
      */
@@ -135,7 +146,7 @@ public class ArFileSet extends ArchiveFi
                                               ArchiveEntry entry) {
                     return new ArResource(archive, (ArArchiveEntry) entry);
                 }
-            });
+            }, skipUnreadable, getProject());
     }
 
     /**

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
Mon Jul 25 04:20:20 2011
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.ant.compress.util.ArchiveStreamFactory;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.ArchiveScanner;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.util.FileUtils;
@@ -37,13 +38,39 @@ public class CommonsCompressArchiveScann
 
     private final ArchiveStreamFactory factory;
     private final ResourceBuilder builder;
+    private final boolean skipUnreadable;
+    private final Project project;
 
     public CommonsCompressArchiveScanner(ArchiveStreamFactory factory,
                                          ResourceBuilder builder) {
+        this(factory, builder, false, null);
+    }
+
+    public CommonsCompressArchiveScanner(ArchiveStreamFactory factory,
+                                         ResourceBuilder builder,
+                                         boolean skipUnreadableEntries,
+                                         Project project) {
         this.factory = factory;
         this.builder = builder;
+        skipUnreadable = skipUnreadableEntries;
+        this.project = project;
+    }
+
+    /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public boolean getSkipUnreadableEntries() {
+        return skipUnreadable;
     }
 
+    /**
+     * @since Compress Antlib 1.1
+     */
+    public Project getProject() {
+        return project;
+    }
 
     /**
      * Fills the file and directory maps with resources read from the
@@ -78,6 +105,11 @@ public class CommonsCompressArchiveScann
                 throw new BuildException("problem opening " + src, ex);
             }
             while ((entry = ai.getNextEntry()) != null) {
+                if (skipUnreadable && !ai.canReadEntryData(entry)) {
+                    project.log("skipping " + entry.getName()
+                                + ", Commons Compress cannot read it");
+                    continue;
+                }
                 Resource r = builder.buildResource(src, encoding, entry);
                 String name = entry.getName();
                 if (entry.isDirectory()) {

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
Mon Jul 25 04:20:20 2011
@@ -47,6 +47,8 @@ public class CpioFileSet extends Archive
     private int    uid;
     private int    gid;
 
+    private boolean skipUnreadable = false;
+
     /** Constructor for CpioFileSet */
     public CpioFileSet() {
         super();
@@ -125,6 +127,15 @@ public class CpioFileSet extends Archive
     }
 
     /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public void setSkipUnreadableEntries(boolean b) {
+        skipUnreadable = b;
+    }
+
+    /**
      * Create a new scanner.
      * @return the created scanner.
      */
@@ -135,7 +146,7 @@ public class CpioFileSet extends Archive
                                               ArchiveEntry entry) {
                     return new CpioResource(archive, (CpioArchiveEntry) entry);
                 }
-            });
+            }, skipUnreadable, getProject());
     }
 
     /**

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
Mon Jul 25 04:20:20 2011
@@ -51,6 +51,8 @@ public class TarFileSet extends ArchiveF
     private int    uid;
     private int    gid;
 
+    private boolean skipUnreadable = false;
+
     /** Constructor for TarFileSet */
     public TarFileSet() {
         super();
@@ -185,6 +187,15 @@ public class TarFileSet extends ArchiveF
     }
 
     /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public void setSkipUnreadableEntries(boolean b) {
+        skipUnreadable = b;
+    }
+
+    /**
      * Create a new scanner.
      * @return the created scanner.
      */
@@ -195,7 +206,7 @@ public class TarFileSet extends ArchiveF
                                               ArchiveEntry entry) {
                     return new TarResource(archive, (TarArchiveEntry) entry);
                 }
-            });
+            }, skipUnreadable, getProject());
     }
 
     /**

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipFileSet.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipFileSet.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipFileSet.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipFileSet.java
Mon Jul 25 04:20:20 2011
@@ -37,6 +37,7 @@ import org.apache.tools.ant.types.Refere
 public class ZipFileSet extends ArchiveFileSet {
 
     private String encoding = null;
+    private boolean skipUnreadable = false;
 
     /** Constructor for ZipFileSet */
     public ZipFileSet() {
@@ -86,11 +87,20 @@ public class ZipFileSet extends ArchiveF
     }
 
     /**
+     * Whether to skip entries that Commons Compress signals it cannot read.
+     *
+     * @since Compress Antlib 1.1
+     */
+    public void setSkipUnreadableEntries(boolean b) {
+        skipUnreadable = b;
+    }
+
+    /**
      * Return a new archive scanner based on this one.
      * @return a new ZipScanner with the same encoding as this one.
      */
     protected ArchiveScanner newArchiveScanner() {
-        ZipScanner zs = new ZipScanner();
+        ZipScanner zs = new ZipScanner(skipUnreadable, getProject());
         zs.setEncoding(encoding);
         return zs;
     }

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
Mon Jul 25 04:20:20 2011
@@ -30,6 +30,7 @@ import org.apache.commons.compress.archi
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipFile;
 import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.resources.FileProvider;
 
@@ -39,6 +40,10 @@ import org.apache.tools.ant.types.resour
 public class ZipScanner extends CommonsCompressArchiveScanner {
 
     public ZipScanner() {
+        this(false, null);
+    }
+
+    public ZipScanner(boolean skipUnreadable, Project project) {
         super(new ZipStreamFactory(),
               new CommonsCompressArchiveScanner.ResourceBuilder() {
                 public Resource buildResource(Resource archive, String encoding,
@@ -46,7 +51,7 @@ public class ZipScanner extends CommonsC
                     return new ZipResource(archive, encoding,
                                            (ZipArchiveEntry) entry);
                 }
-            });
+            }, skipUnreadable, project);
     }
 
     /**
@@ -93,6 +98,11 @@ public class ZipScanner extends CommonsC
             Enumeration e = zf.getEntries();
             while (e.hasMoreElements()) {
                 entry = (ZipArchiveEntry) e.nextElement();
+                if (getSkipUnreadableEntries() && !zf.canReadEntryData(entry)) {
+                    getProject().log("skipping " + entry.getName()
+                                     + ", Commons Compress cannot read it");
+                    continue;
+                }
                 Resource r = new ZipResource(srcFile, encoding, entry);
                 String name = entry.getName();
                 if (entry.isDirectory()) {

Modified: ant/antlibs/compress/trunk/src/tests/antunit/zipfileset-test.xml
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/tests/antunit/zipfileset-test.xml?rev=1150535&r1=1150534&r2=1150535&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/tests/antunit/zipfileset-test.xml (original)
+++ ant/antlibs/compress/trunk/src/tests/antunit/zipfileset-test.xml Mon Jul 25 04:20:20 2011
@@ -119,4 +119,12 @@
       </copy>
     </au:expectfailure>
   </target>
+
+  <target name="testSkipUnreadableEntries" depends="setUp">
+    <copy todir="${output}">
+      <cmp:zipfileset src="../resources/password-encrypted.zip"
+                      skipUnreadableEntries="true"/>
+    </copy>
+    <au:assertLogContains text="Commons Compress cannot read it"/>
+  </target>
 </project>



Mime
View raw message