ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r803792 - in /ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources: ArFileSet.java ArScanner.java CommonsCompressArchiveScanner.java CpioFileSet.java CpioScanner.java TarFileSet.java TarScanner.java ZipScanner.java
Date Thu, 13 Aug 2009 06:35:59 GMT
Author: bodewig
Date: Thu Aug 13 06:35:59 2009
New Revision: 803792

URL: http://svn.apache.org/viewvc?rev=803792&view=rev
Log:
finalize interface extraction refactoring for StreamFactory

Removed:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArScanner.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioScanner.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java
Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java?rev=803792&r1=803791&r2=803792&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ArFileSet.java
Thu Aug 13 06:35:59 2009
@@ -17,6 +17,10 @@
  */
 package org.apache.ant.compress.resources;
 
+import org.apache.ant.compress.util.ArStreamFactory;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ar.ArArchiveEntry;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.AbstractFileSet;
@@ -24,6 +28,7 @@
 import org.apache.tools.ant.types.ArchiveScanner;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.Resource;
 
 /**
  * A ArFileSet is a FileSet with extra attributes useful in the context of
@@ -124,8 +129,13 @@
      * @return the created scanner.
      */
     protected ArchiveScanner newArchiveScanner() {
-        ArScanner zs = new ArScanner();
-        return zs;
+        return new CommonsCompressArchiveScanner(new ArStreamFactory(),
+                                                 new CommonsCompressArchiveScanner.ResourceBuilder()
{
+                public Resource buildResource(Resource archive, String encoding,
+                                              ArchiveEntry entry) {
+                    return new ArResource(archive, (ArArchiveEntry) entry);
+                }
+            });
     }
 
     /**

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java?rev=803792&r1=803791&r2=803792&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
Thu Aug 13 06:35:59 2009
@@ -19,10 +19,10 @@
 package org.apache.ant.compress.resources;
 
 import java.io.BufferedInputStream;
-import java.io.InputStream;
 import java.io.IOException;
 import java.util.Map;
 
+import org.apache.ant.compress.util.StreamFactory;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.ArchiveScanner;
 import org.apache.tools.ant.types.Resource;
@@ -33,21 +33,17 @@
 /**
  * Scans tar archives for resources.
  */
-public abstract class CommonsCompressArchiveScanner extends ArchiveScanner {
+public class CommonsCompressArchiveScanner extends ArchiveScanner {
 
-    /**
-     * Provides an ArchiveInputStream to a given archive.
-     */
-    protected abstract ArchiveInputStream getArchiveStream(InputStream is,
-                                                           String encoding)
-        throws IOException;
+    private final StreamFactory factory;
+    private final ResourceBuilder builder;
+
+    public CommonsCompressArchiveScanner(StreamFactory factory,
+                                         ResourceBuilder builder) {
+        this.factory = factory;
+        this.builder = builder;
+    }
 
-    /**
-     * Creates the matching archive entry resource.
-     */
-    protected abstract Resource getResource(Resource archive,
-                                            String encoding,
-                                            ArchiveEntry entry);
 
     /**
      * Fills the file and directory maps with resources read from the
@@ -74,14 +70,15 @@
 
         try {
             try {
-                ai = getArchiveStream(new BufferedInputStream(src
-                                                              .getInputStream()),
-                                      encoding);
+                ai =
+                    factory.getArchiveStream(new BufferedInputStream(src
+                                                                     .getInputStream()),
+                                             encoding);
             } catch (IOException ex) {
                 throw new BuildException("problem opening " + src, ex);
             }
             while ((entry = ai.getNextEntry()) != null) {
-                Resource r = getResource(src, encoding, entry);
+                Resource r = builder.buildResource(src, encoding, entry);
                 String name = entry.getName();
                 if (entry.isDirectory()) {
                     name = trimSeparator(name);
@@ -102,4 +99,12 @@
             FileUtils.close(ai);
         }
     }
+
+    public static interface ResourceBuilder {
+        /**
+         * Creates the matching archive entry resource.
+         */
+        Resource buildResource(Resource archive, String encoding,
+                               ArchiveEntry entry);
+    }
 }
\ No newline at end of file

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java?rev=803792&r1=803791&r2=803792&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CpioFileSet.java
Thu Aug 13 06:35:59 2009
@@ -17,6 +17,10 @@
  */
 package org.apache.ant.compress.resources;
 
+import org.apache.ant.compress.util.CpioStreamFactory;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.AbstractFileSet;
@@ -24,6 +28,7 @@
 import org.apache.tools.ant.types.ArchiveScanner;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.Resource;
 
 /**
  * A CpioFileSet is a FileSet with extra attributes useful in the context of
@@ -124,8 +129,13 @@
      * @return the created scanner.
      */
     protected ArchiveScanner newArchiveScanner() {
-        CpioScanner zs = new CpioScanner();
-        return zs;
+        return new CommonsCompressArchiveScanner(new CpioStreamFactory(),
+                                                 new CommonsCompressArchiveScanner.ResourceBuilder()
{
+                public Resource buildResource(Resource archive, String encoding,
+                                              ArchiveEntry entry) {
+                    return new CpioResource(archive, (CpioArchiveEntry) entry);
+                }
+            });
     }
 
     /**

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java?rev=803792&r1=803791&r2=803792&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
Thu Aug 13 06:35:59 2009
@@ -17,6 +17,10 @@
  */
 package org.apache.ant.compress.resources;
 
+import org.apache.ant.compress.util.TarStreamFactory;
+
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.types.AbstractFileSet;
@@ -24,6 +28,7 @@
 import org.apache.tools.ant.types.ArchiveScanner;
 import org.apache.tools.ant.types.FileSet;
 import org.apache.tools.ant.types.Reference;
+import org.apache.tools.ant.types.Resource;
 
 /**
  * A TarFileSet is a FileSet with extra attributes useful in the context of
@@ -184,8 +189,13 @@
      * @return the created scanner.
      */
     protected ArchiveScanner newArchiveScanner() {
-        TarScanner zs = new TarScanner();
-        return zs;
+        return new CommonsCompressArchiveScanner(new TarStreamFactory(),
+                                                 new CommonsCompressArchiveScanner.ResourceBuilder()
{
+                public Resource buildResource(Resource archive, String encoding,
+                                              ArchiveEntry entry) {
+                    return new TarResource(archive, (TarArchiveEntry) entry);
+                }
+            });
     }
 
     /**

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java?rev=803792&r1=803791&r2=803792&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/ZipScanner.java
Thu Aug 13 06:35:59 2009
@@ -19,16 +19,15 @@
 package org.apache.ant.compress.resources;
 
 import java.io.File;
-import java.io.InputStream;
 import java.io.IOException;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.zip.ZipException;
 
+import org.apache.ant.compress.util.ZipStreamFactory;
+
 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.ZipFile;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.types.Resource;
@@ -39,15 +38,15 @@
  */
 public class ZipScanner extends CommonsCompressArchiveScanner {
 
-    protected ArchiveInputStream getArchiveStream(InputStream is,
-                                                  String encoding)
-        throws IOException {
-        return new ZipArchiveInputStream(is, encoding, true);
-    }
-
-    protected Resource getResource(Resource archive, String encoding,
-                                   ArchiveEntry entry) {
-        return new ZipResource(archive, encoding, (ZipArchiveEntry) entry);
+    public ZipScanner() {
+        super(new ZipStreamFactory(),
+              new CommonsCompressArchiveScanner.ResourceBuilder() {
+                public Resource buildResource(Resource archive, String encoding,
+                                            ArchiveEntry entry) {
+                    return new ZipResource(archive, encoding,
+                                           (ZipArchiveEntry) entry);
+                }
+            });
     }
 
     /**
@@ -70,20 +69,19 @@
     protected void fillMapsFromArchive(Resource src, String encoding,
                                        Map fileEntries, Map matchFileEntries,
                                        Map dirEntries, Map matchDirEntries) {
-        ZipArchiveEntry entry = null;
-        ZipFile zf = null;
 
-        File srcFile = null;
         FileProvider fp = (FileProvider) src.as(FileProvider.class);
-        if (fp != null) {
-            srcFile = fp.getFile();
-        } else {
+        if (fp == null) {
             super.fillMapsFromArchive(src, encoding, fileEntries,
                                       matchFileEntries, dirEntries,
                                       matchDirEntries);
             return;
         }
 
+        File srcFile = fp.getFile();
+        ZipArchiveEntry entry = null;
+        ZipFile zf = null;
+
         try {
             try {
                 zf = new ZipFile(srcFile, encoding);



Mime
View raw message