ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r804859 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ArchiveBase.java tests/antunit/untar-test.xml
Date Mon, 17 Aug 2009 04:31:43 GMT
Author: bodewig
Date: Mon Aug 17 04:31:43 2009
New Revision: 804859

URL: http://svn.apache.org/viewvc?rev=804859&view=rev
Log:
create intermediate directories

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/untar-test.xml

Modified: ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java?rev=804859&r1=804858&r2=804859&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
(original)
+++ ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
Mon Aug 17 04:31:43 2009
@@ -25,8 +25,10 @@
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Set;
 import java.util.zip.ZipException;
 
 import org.apache.ant.compress.resources.ArFileSet;
@@ -189,6 +191,7 @@
         throws IOException {
         FileUtils fu = FileUtils.getFileUtils();
         ArchiveOutputStream out = null;
+        Set addedDirectories = new HashSet();
         try {
             out =
                 factory.getArchiveStream(new BufferedOutputStream(dest
@@ -197,6 +200,10 @@
                                          ? null : encoding);
             for (int i = 0; i < src.length; i++) {
 
+                if (!filesOnly) {
+                    ensureParentDirs(out, src[i], addedDirectories);
+                }
+
                 ArchiveEntry ent = builder.buildEntry(src[i]);
                 out.putArchiveEntry(ent);
                 if (!src[i].getResource().isDirectory()) {
@@ -223,6 +230,37 @@
     }
 
     /**
+     * Adds records for all parent directories of the given resource
+     * that haven't already been added.
+     *
+     * <p>Flags for the "missing" directories will be taken from the
+     * ResourceCollection that contains the resource to be added.</p>
+     */
+    protected void ensureParentDirs(ArchiveOutputStream out,
+                                    ResourceWithFlags r,
+                                    Set directoriesAdded)
+        throws IOException {
+
+        String[] parentStack = FileUtils.getPathStack(r.getName());
+        String currentParent = "";
+        for (int i = 0; i < parentStack.length - 1; i++) {
+            currentParent += parentStack[i] + "/";
+            if (directoriesAdded.add(currentParent)) {
+                Resource dir = new Resource(currentParent, true,
+                                            System.currentTimeMillis(),
+                                            true);
+                ResourceWithFlags artifical =
+                    new ResourceWithFlags(currentParent,
+                                          dir, r.getCollectionFlags(),
+                                          new ResourceFlags());
+                ArchiveEntry ent = builder.buildEntry(artifical);
+                out.putArchiveEntry(ent);
+                out.closeArchiveEntry();
+            }
+        }
+    }
+
+    /**
      * Extracts flags from a resource.
      *
      * <p>ZipExceptions are only here for the code that translates
@@ -534,12 +572,39 @@
         private final Resource r;
         private final ResourceCollectionFlags rcFlags;
         private final ResourceFlags rFlags;
+        private final String name;
 
         public ResourceWithFlags(Resource r, ResourceCollectionFlags rcFlags,
                                  ResourceFlags rFlags) {
+            this(null, r, rcFlags, rFlags);
+        }
+
+        public ResourceWithFlags(String name, Resource r,
+                                 ResourceCollectionFlags rcFlags,
+                                 ResourceFlags rFlags) {
             this.r = r;
             this.rcFlags = rcFlags;
             this.rFlags = rFlags;
+
+            if (name == null) {
+                name = r.getName();
+                if (rcFlags.hasFullpath()) {
+                    name = rcFlags.getFullpath();
+                } else if (rcFlags.hasPrefix()) {
+                    String prefix = rcFlags.getPrefix();
+                    if (!prefix.endsWith("/")) {
+                        prefix = prefix + "/";
+                    }
+                    name = prefix + name;
+                }
+            }
+            if (r.isDirectory() && !name.endsWith("/")) {
+                name += "/";
+            } else if (r.isDirectory() && name.endsWith("/")) {
+                name = name.substring(0, name.length() - 1);
+            }
+
+            this.name = name;
         }
 
         public Resource getResource() { return r; }
@@ -555,21 +620,6 @@
          * never will.</p>
          */
         public String getName() {
-            String name = r.getName();
-            if (rcFlags.hasFullpath()) {
-                name = rcFlags.getFullpath();
-            } else if (rcFlags.hasPrefix()) {
-                String prefix = rcFlags.getPrefix();
-                if (!prefix.endsWith("/")) {
-                    prefix = prefix + "/";
-                }
-                name = prefix + name;
-            }
-            if (r.isDirectory() && !name.endsWith("/")) {
-                name += "/";
-            } else if (r.isDirectory() && name.endsWith("/")) {
-                name = name.substring(0, name.length() - 1);
-            }
             return name;
         }
     }

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/untar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/untar-test.xml?rev=804859&r1=804858&r2=804859&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/untar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/untar-test.xml Mon Aug 17 04:31:43
2009
@@ -39,13 +39,13 @@
   </target>
 
   <target name="testAgainstAntlibTarTask" depends="setUp">
-    <cmp:tar destfile="${input}/test.tar">
-      <fileset dir="."/>
+    <cmp:tar destfile="${input}/test.tar" filesonly="false">
+      <fileset dir=".." includes="**/*.xml"/>
     </cmp:tar>
     <cmp:untar src="${input}/test.tar" dest="${output}"/>
-    <au:assertFileExists file="${output}/untar-test.xml"/>
+    <au:assertFileExists file="${output}/antunit/untar-test.xml"/>
     <au:assertFilesMatch
-       actual="${output}/untar-test.xml"
+       actual="${output}/antunit/untar-test.xml"
        expected="untar-test.xml"
        />
   </target>



Mime
View raw message