ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1154203 - in /ant/antlibs/compress/trunk/src/main/org/apache/ant/compress: resources/CommonsCompressArchiveResource.java resources/CommonsCompressArchiveScanner.java taskdefs/ExpandBase.java
Date Fri, 05 Aug 2011 13:21:15 GMT
Author: bodewig
Date: Fri Aug  5 13:21:14 2011
New Revision: 1154203

URL: http://svn.apache.org/viewvc?rev=1154203&view=rev
Log:
even though no implementation currently uses it, make the code generic enough that InputStreams
that could take advantage of files can use them

Modified:
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
    ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java?rev=1154203&r1=1154202&r2=1154203&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
(original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveResource.java
Fri Aug  5 13:21:14 2011
@@ -28,7 +28,9 @@ import org.apache.tools.ant.BuildExcepti
 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.types.resources.FileProvider;
 import org.apache.tools.ant.util.FileUtils;
+import org.apache.ant.compress.util.FileAwareArchiveStreamFactory;
 import org.apache.ant.compress.util.ArchiveStreamFactory;
 import org.apache.ant.compress.util.EntryHelper;
 import org.apache.commons.compress.archivers.ArchiveEntry;
@@ -123,10 +125,7 @@ public abstract class CommonsCompressArc
         if (isReference()) {
             return ((Resource) getCheckedRef()).getInputStream();
         }
-        Resource archive = getArchive();
-        final ArchiveInputStream i =
-            factory.getArchiveStream(new BufferedInputStream(archive.getInputStream()),
-                                     getEncoding());
+        final ArchiveInputStream i = getStream();
         ArchiveEntry ae = null;
         while ((ae = i.getNextEntry()) != null) {
             if (ae.getName().equals(getName())) {
@@ -183,11 +182,9 @@ public abstract class CommonsCompressArc
      * fetches information from the named entry inside the archive.
      */
     protected void fetchEntry() {
-        Resource archive = getArchive();
         ArchiveInputStream i = null;
         try {
-            i = factory.getArchiveStream(archive.getInputStream(),
-                                         getEncoding());
+            i = getStream();
             ArchiveEntry ae = null;
             while ((ae = i.getNextEntry()) != null) {
                 if (ae.getName().equals(getName())) {
@@ -221,4 +218,18 @@ public abstract class CommonsCompressArc
         gid = EntryHelper.getGroupId(e);
     }
 
+    private ArchiveInputStream getStream() throws IOException {
+        Resource archive = getArchive();
+        if (factory instanceof FileAwareArchiveStreamFactory
+            && archive.as(FileProvider.class) != null) {
+            FileProvider p = (FileProvider) archive.as(FileProvider.class);
+            FileAwareArchiveStreamFactory f =
+                (FileAwareArchiveStreamFactory) factory;
+            return f.getArchiveInputStream(p.getFile(), getEncoding());
+        }
+        return 
+            factory.getArchiveStream(new BufferedInputStream(archive
+                                                             .getInputStream()),
+                                     getEncoding());
+    }
 }

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=1154203&r1=1154202&r2=1154203&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
Fri Aug  5 13:21:14 2011
@@ -23,11 +23,13 @@ import java.io.IOException;
 import java.util.Map;
 
 import org.apache.ant.compress.util.ArchiveStreamFactory;
+import org.apache.ant.compress.util.FileAwareArchiveStreamFactory;
 import org.apache.ant.compress.util.Messages;
 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.types.resources.FileProvider;
 import org.apache.tools.ant.util.FileUtils;
 import org.apache.commons.compress.archivers.ArchiveEntry;
 import org.apache.commons.compress.archivers.ArchiveInputStream;
@@ -91,10 +93,19 @@ public class CommonsCompressArchiveScann
 
         try {
             try {
+                if (factory instanceof FileAwareArchiveStreamFactory
+                    && src.as(FileProvider.class) != null) {
+                    FileProvider p =
+                        (FileProvider) src.as(FileProvider.class);
+                    FileAwareArchiveStreamFactory f =
+                        (FileAwareArchiveStreamFactory) factory;
+                    ai = f.getArchiveInputStream(p.getFile(), encoding);
+                } else {
                 ai =
                     factory.getArchiveStream(new BufferedInputStream(src
                                                                      .getInputStream()),
                                              encoding);
+                }
             } catch (IOException ex) {
                 throw new BuildException("problem opening " + src, ex);
             }

Modified: ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java
URL: http://svn.apache.org/viewvc/ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java?rev=1154203&r1=1154202&r2=1154203&view=diff
==============================================================================
--- ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java (original)
+++ ant/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ExpandBase.java Fri
Aug  5 13:21:14 2011
@@ -27,6 +27,7 @@ import java.util.Date;
 
 import org.apache.ant.compress.util.ArchiveStreamFactory;
 import org.apache.ant.compress.util.EntryHelper;
+import org.apache.ant.compress.util.FileAwareArchiveStreamFactory;
 import org.apache.ant.compress.util.Messages;
 
 import org.apache.tools.ant.BuildException;
@@ -102,16 +103,24 @@ public abstract class ExpandBase extends
                                      + " as the file does not exist",
                                      getLocation());
         }
-        FileInputStream fis = null;
+        InputStream is = null;
         try {
-            fis = new FileInputStream(srcF);
-            expandStream(srcF.getPath(), fis, dir);
+            if (factory instanceof FileAwareArchiveStreamFactory) {
+                FileAwareArchiveStreamFactory f =
+                    (FileAwareArchiveStreamFactory) factory;
+                is =  f.getArchiveInputStream(srcF, getEncoding());
+                expandArchiveStream(srcF.getPath(), (ArchiveInputStream) is,
+                                    dir);
+            } else {
+                is = new FileInputStream(srcF);
+                expandStream(srcF.getPath(), is, dir);
+            }
         } catch (IOException ioe) {
             throw new BuildException("Error while expanding " + srcF.getPath()
                                      + "\n" + ioe.toString(),
                                      ioe, getLocation());
         } finally {
-            FileUtils.close(fis);
+            FileUtils.close(is);
         }
     }
 
@@ -139,10 +148,19 @@ public abstract class ExpandBase extends
         throws IOException {
         ArchiveInputStream is = null;
         try {
-            FileNameMapper mapper = getMapper();
-            log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
             is = factory.getArchiveStream(new BufferedInputStream(stream),
                                           getEncoding());
+            expandArchiveStream(name, is, dir);
+        } finally {
+            FileUtils.close(is);
+        }
+    }
+
+    private void expandArchiveStream(String name, ArchiveInputStream is,
+                                     File dir)
+        throws IOException {
+            FileNameMapper mapper = getMapper();
+            log("Expanding: " + name + " into " + dir, Project.MSG_INFO);
             boolean empty = true;
             ArchiveEntry ent = null;
             while ((ent = is.getNextEntry()) != null) {
@@ -160,8 +178,5 @@ public abstract class ExpandBase extends
                 throw new BuildException("archive '" + name + "' is empty");
             }
             log("expand complete", Project.MSG_VERBOSE);
-        } finally {
-            FileUtils.close(is);
-        }
     }
 }



Mime
View raw message