Author: bodewig
Date: Thu Aug  6 19:50:22 2009
New Revision: 801795

URL: http://svn.apache.org/viewvc?rev=801795&view=rev
Log:
tarfileset

Added:
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
   (contents, props changed)
      - copied, changed from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
   (contents, props changed)
      - copied, changed from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarFileSet.java
    
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java
   (contents, props changed)
      - copied, changed from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml   
(contents, props changed)
      - copied, changed from r801240, 
ant/core/trunk/src/tests/antunit/types/tarfileset-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=801795&r1=801794&r2=801795&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 
Thu Aug  6 19:50:22 2009
@@ -49,4 +49,9 @@
     name="zipentry"
     classname="org.apache.ant.compress.resources.ZipResource"
     />
+
+  <typedef
+    name="tarfileset"
+    classname="org.apache.ant.compress.resources.TarFileSet"
+    />
 </antlib>

Copied: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
 (from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java)
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java&r1=801240&r2=801795&rev=801795&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java 
(original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
 Thu Aug  6 19:50:22 2009
@@ -16,21 +16,36 @@
  *
  */
 
-package org.apache.tools.ant.types;
+package org.apache.ant.compress.resources;
 
+import java.io.InputStream;
 import java.io.IOException;
 import java.util.Map;
 
 import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.resources.TarResource;
+import org.apache.tools.ant.types.ArchiveScanner;
+import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.tar.TarEntry;
-import org.apache.tools.tar.TarInputStream;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
 
 /**
  * Scans tar archives for resources.
  */
-public class TarScanner extends ArchiveScanner {
+public abstract class CommonsCompressArchiveScanner extends ArchiveScanner {
+
+    /**
+     * Provides an ArchiveInputStream to a given archive.
+     */
+    protected abstract ArchiveInputStream getArchiveStream(InputStream is)
+        throws IOException;
+
+    /**
+     * 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
@@ -52,17 +67,17 @@
     protected void fillMapsFromArchive(Resource src, String encoding,
                                        Map fileEntries, Map matchFileEntries,
                                        Map dirEntries, Map matchDirEntries) {
-        TarEntry entry = null;
-        TarInputStream ti = null;
+        ArchiveEntry entry = null;
+        ArchiveInputStream ai = null;
 
         try {
             try {
-                ti = new TarInputStream(src.getInputStream());
+                ai = getArchiveStream(src.getInputStream());
             } catch (IOException ex) {
-                throw new BuildException("problem opening " + srcFile, ex);
+                throw new BuildException("problem opening " + src, ex);
             }
-            while ((entry = ti.getNextEntry()) != null) {
-                Resource r = new TarResource(src, entry);
+            while ((entry = ai.getNextEntry()) != null) {
+                Resource r = getResource(src, encoding, entry);
                 String name = entry.getName();
                 if (entry.isDirectory()) {
                     name = trimSeparator(name);
@@ -78,9 +93,9 @@
                 }
             }
         } catch (IOException ex) {
-            throw new BuildException("problem reading " + srcFile, ex);
+            throw new BuildException("problem reading " + src, ex);
         } finally {
-            FileUtils.close(ti);
+            FileUtils.close(ai);
         }
     }
 }
\ No newline at end of file

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

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/CommonsCompressArchiveScanner.java
------------------------------------------------------------------------------
    svn:executable = *

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

Copied: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
 (from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarFileSet.java)
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/types/TarFileSet.java&r1=801240&r2=801795&rev=801795&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/TarFileSet.java 
(original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
 Thu Aug  6 19:50:22 2009
@@ -15,10 +15,15 @@
  *  limitations under the License.
  *
  */
-package org.apache.tools.ant.types;
+package org.apache.ant.compress.resources;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.AbstractFileSet;
+import org.apache.tools.ant.types.ArchiveFileSet;
+import org.apache.tools.ant.types.ArchiveScanner;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Reference;
 
 /**
  * A TarFileSet is a FileSet with extra attributes useful in the context of

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

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarFileSet.java
------------------------------------------------------------------------------
    svn:executable = *

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

Copied: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java
 (from r801240, 
ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java)
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java?p2=ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java&p1=ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java&r1=801240&r2=801795&rev=801795&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/TarScanner.java 
(original)
+++ 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java
 Thu Aug  6 19:50:22 2009
@@ -16,71 +16,29 @@
  *
  */
 
-package org.apache.tools.ant.types;
+package org.apache.ant.compress.resources;
 
+import java.io.InputStream;
 import java.io.IOException;
-import java.util.Map;
 
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.resources.TarResource;
-import org.apache.tools.ant.util.FileUtils;
-import org.apache.tools.tar.TarEntry;
-import org.apache.tools.tar.TarInputStream;
+import org.apache.tools.ant.types.Resource;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+import org.apache.commons.compress.archivers.ArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 
 /**
  * Scans tar archives for resources.
  */
-public class TarScanner extends ArchiveScanner {
+public class TarScanner extends CommonsCompressArchiveScanner {
 
-    /**
-     * Fills the file and directory maps with resources read from the
-     * archive.
-     *
-     * @param src the archive to scan.
-     * @param encoding encoding used to encode file names inside the archive.
-     * @param fileEntries Map (name to resource) of non-directory
-     * resources found inside the archive.
-     * @param matchFileEntries Map (name to resource) of non-directory
-     * resources found inside the archive that matched all include
-     * patterns and didn't match any exclude patterns.
-     * @param dirEntries Map (name to resource) of directory
-     * resources found inside the archive.
-     * @param matchDirEntries Map (name to resource) of directory
-     * resources found inside the archive that matched all include
-     * patterns and didn't match any exclude patterns.
-     */
-    protected void fillMapsFromArchive(Resource src, String encoding,
-                                       Map fileEntries, Map matchFileEntries,
-                                       Map dirEntries, Map matchDirEntries) {
-        TarEntry entry = null;
-        TarInputStream ti = null;
-
-        try {
-            try {
-                ti = new TarInputStream(src.getInputStream());
-            } catch (IOException ex) {
-                throw new BuildException("problem opening " + srcFile, ex);
-            }
-            while ((entry = ti.getNextEntry()) != null) {
-                Resource r = new TarResource(src, entry);
-                String name = entry.getName();
-                if (entry.isDirectory()) {
-                    name = trimSeparator(name);
-                    dirEntries.put(name, r);
-                    if (match(name)) {
-                        matchDirEntries.put(name, r);
-                    }
-                } else {
-                    fileEntries.put(name, r);
-                    if (match(name)) {
-                        matchFileEntries.put(name, r);
-                    }
-                }
-            }
-        } catch (IOException ex) {
-            throw new BuildException("problem reading " + srcFile, ex);
-        } finally {
-            FileUtils.close(ti);
-        }
+    protected ArchiveInputStream getArchiveStream(InputStream is)
+        throws IOException {
+        return new TarArchiveInputStream(is);
+    }
+
+    protected Resource getResource(Resource archive, String encoding,
+                                   ArchiveEntry entry) {
+        return new TarResource(archive, (TarArchiveEntry) entry);
     }
 }
\ No newline at end of file

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

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/resources/TarScanner.java
------------------------------------------------------------------------------
    svn:executable = *

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

Copied: 
ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml (from 
r801240, ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml)
URL: 
http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml?p2=ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml&p1=ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml&r1=801240&r2=801795&rev=801795&view=diff
==============================================================================
--- ant/core/trunk/src/tests/antunit/types/tarfileset-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml 
Thu Aug  6 19:50:22 2009
@@ -15,14 +15,16 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit">
-  <import file="../antunit-base.xml"/>
+<project default="antunit"
+         xmlns:au="antlib:org.apache.ant.antunit"
+         xmlns:cmp="antlib:org.apache.ant.compress">
+  <import file="antunit-base.xml"/>
 
   <target name="testMissingArchive">
     <mkdir dir="${output}"/>
     <au:expectfailure expectedMessage="The archive foo.tar doesn't exist">
       <copy todir="${output}">
-        <tarfileset src="foo.tar"/>
+        <cmp:tarfileset src="foo.tar"/>
       </copy>
     </au:expectfailure>
   </target>
@@ -30,7 +32,7 @@
   <target name="testMissingArchiveDoesntMatter">
     <mkdir dir="${output}"/>
     <copy todir="${output}">
-      <tarfileset src="foo.tar" errorOnMissingArchive="false"/>
+      <cmp:tarfileset src="foo.tar" errorOnMissingArchive="false"/>
     </copy>
   </target>
 

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tarfileset-test.xml
------------------------------------------------------------------------------
    svn:mergeinfo = 


Reply via email to