ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r721376 - /ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java
Date Fri, 28 Nov 2008 08:12:12 GMT
Author: bodewig
Date: Fri Nov 28 00:12:12 2008
New Revision: 721376

URL: http://svn.apache.org/viewvc?rev=721376&view=rev
Log:
some refactoring

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java?rev=721376&r1=721375&r2=721376&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/resources/Archives.java Fri Nov 28
00:12:12 2008
@@ -23,6 +23,7 @@
 import java.util.Stack;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.ArchiveFileSet;
 import org.apache.tools.ant.types.DataType;
 import org.apache.tools.ant.types.Resource;
 import org.apache.tools.ant.types.ResourceCollection;
@@ -65,13 +66,17 @@
     }
 
     /**
-     * Iterates through the collections and counts.
+     * Sums the sizes of nested archives.
      */
     public int size() {
         if (isReference()) {
             return ((Archives) getCheckedRef()).size();
         }
-        return grabResources().size();
+        int total = 0;
+        for (Iterator i = grabArchives(); i.hasNext(); ) {
+            total += ((ResourceCollection) i.next()).size();
+        }
+        return total;
     }
 
     /**
@@ -81,7 +86,12 @@
         if (isReference()) {
             return ((Archives) getCheckedRef()).iterator();
         }
-        return grabResources().iterator();
+        List l = new LinkedList();
+        for (Iterator i = grabArchives(); i.hasNext(); ) {
+            l.addAll(CollectionUtils
+                     .asCollection(((ResourceCollection) i.next()).iterator()));
+        }
+        return l.iterator();
     }
 
     /**
@@ -111,28 +121,34 @@
         }
     }
 
-    // TODO this is a pretty expensive operation and so the result is
-    // cached.
+    // TODO this is a pretty expensive operation and so the result
+    // should be cached.
     /**
-     * Performs the job by iterating over all archives, turning them
-     * into the correct type of ArchiveFileSet and iterating through
-     * their contents.
+     * Turns all nested resources into corresponding ArchiveFileSets
+     * and returns an iterator over the collected archives.
      */
-    protected List grabResources() {
+    protected Iterator/*<ArchiveFileset>*/ grabArchives() {
         List l = new LinkedList();
         for (Iterator iter = zips.iterator(); iter.hasNext(); ) {
-            ZipFileSet zfs = new ZipFileSet();
-            zfs.setProject(getProject());
-            zfs.setSrcResource((Resource) iter.next());
-            l.addAll(CollectionUtils.asCollection(zfs.iterator()));
+            l.add(configureArchive(new ZipFileSet(),
+                                   (Resource) iter.next()));
         }
         for (Iterator iter = tars.iterator(); iter.hasNext(); ) {
-            TarFileSet tfs = new TarFileSet();
-            tfs.setProject(getProject());
-            tfs.setSrcResource((Resource) iter.next());
-            l.addAll(CollectionUtils.asCollection(tfs.iterator()));
+            l.add(configureArchive(new TarFileSet(),
+                                   (Resource) iter.next()));
         }
-        return l;
+        return l.iterator();
+    }
+
+    /**
+     * Configures the archivefileset based on this type's settings,
+     * set the source.
+     */
+    protected ArchiveFileSet configureArchive(ArchiveFileSet afs,
+                                              Resource src) {
+        afs.setProject(getProject());
+        afs.setSrcResource(src);
+        return afs;
     }
 
     /**
@@ -150,13 +166,15 @@
         if (isReference()) {
             super.dieOnCircularReference(stk, p);
         } else {
-            stk.push(zips);
-            invokeCircularReferenceCheck(zips, stk, p);
-            stk.pop();
-            stk.push(tars);
-            invokeCircularReferenceCheck(tars, stk, p);
-            stk.pop();
+            checkForCircularReference(zips, stk, p);
+            checkForCircularReference(tars, stk, p);
             setChecked(true);
         }
     }
+
+    protected void checkForCircularReference(DataType t, Stack stk, Project p) {
+        stk.push(t);
+        invokeCircularReferenceCheck(t, stk, p);
+        stk.pop();
+    }
 }
\ No newline at end of file



Mime
View raw message