ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r806793 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ArchiveBase.java tests/antunit/antunit-base.xml tests/antunit/cpio-test.xml
Date Sat, 22 Aug 2009 06:15:21 GMT
Author: bodewig
Date: Sat Aug 22 06:15:21 2009
New Revision: 806793

URL: http://svn.apache.org/viewvc?rev=806793&view=rev
Log:
Tests and fixes for directory handling

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/antunit-base.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-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=806793&r1=806792&r2=806793&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
Sat Aug 22 06:15:21 2009
@@ -170,8 +170,13 @@
             ResourceCollectionFlags rcFlags = getFlags(rc);
             for (Iterator rs = rc.iterator(); rs.hasNext(); ) {
                 Resource r = (Resource) rs.next();
-                if (!filesOnly || !r.isDirectory()) {
-                    l.add(new ResourceWithFlags(r, rcFlags, getFlags(r)));
+                if ((!filesOnly || !r.isDirectory())) {
+                    ResourceWithFlags rwf =
+                        new ResourceWithFlags(r, rcFlags, getFlags(r));
+                    if (!"".equals(rwf.getName())
+                        && !"/".equals(rwf.getName())) {
+                        l.add(rwf);
+                    }
                 }
             }
         }
@@ -215,6 +220,8 @@
                     } finally {
                         fu.close(in);
                     }
+                } else {
+                    addedDirectories.add(src[i].getName());
                 }
                 out.closeArchiveEntry();
 
@@ -238,7 +245,9 @@
 
         String[] parentStack = FileUtils.getPathStack(r.getName());
         String currentParent = "";
-        for (int i = 0; i < parentStack.length - 1; i++) {
+        int skip = r.getName().endsWith("/") ? 2 : 1;
+        for (int i = 0; i < parentStack.length - skip; i++) {
+            if ("".equals(parentStack[i])) continue;
             currentParent += parentStack[i] + "/";
             if (directoriesAdded.add(currentParent)) {
                 Resource dir = new Resource(currentParent, true,
@@ -599,7 +608,7 @@
             }
             if (r.isDirectory() && !name.endsWith("/")) {
                 name += "/";
-            } else if (r.isDirectory() && name.endsWith("/")) {
+            } else if (!r.isDirectory() && name.endsWith("/")) {
                 name = name.substring(0, name.length() - 1);
             }
 

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/antunit-base.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/antunit-base.xml?rev=806793&r1=806792&r2=806793&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/antunit-base.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/antunit-base.xml Sat Aug 22 06:15:21
2009
@@ -15,7 +15,9 @@
   See the License for the specific language governing permissions and
   limitations under the License.
 -->
-<project name="antunit-base">
+<project name="antunit-base"
+         xmlns:cond="antlib:org.apache.tools.ant.types.conditions"
+         xmlns:au="antlib:org.apache.ant.antunit">
 
   <property name="input" location="${java.io.tmpdir}/testinput"/>
   <property name="output" location="${java.io.tmpdir}/testoutput"/>
@@ -32,4 +34,25 @@
     </antunit>
   </target>
 
+  <!-- should go into AntUnit -->
+  <macrodef name="assertResourceExists">
+    <element name="resource" implicit="true"/>
+    <sequential>
+      <au:assertTrue>
+        <cond:resourceexists>
+          <resource/>
+        </cond:resourceexists>
+      </au:assertTrue>
+    </sequential>
+  </macrodef>
+  <macrodef name="assertResourceDoesntExist">
+    <element name="resource" implicit="true"/>
+    <sequential>
+      <au:assertFalse>
+        <cond:resourceexists>
+          <resource/>
+        </cond:resourceexists>
+      </au:assertFalse>
+    </sequential>
+  </macrodef>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml?rev=806793&r1=806792&r2=806793&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml Sat Aug 22 06:15:21
2009
@@ -24,6 +24,8 @@
 
   <target name="setUp">
     <mkdir dir="${output}"/>
+    <mkdir dir="${input}/subdir"/>
+    <copy todir="${input}/subdir" file="../resources/asf-logo.gif"/>
     <property name="dest" location="${output}/test.cpio"/>
     <macrodef name="checkProperties">
       <attribute name="dateTime"/>
@@ -127,4 +129,53 @@
     <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="33188"
                      uid="1000" gid="1000"/>
   </target>
+
+  <target name="testNoDirectoriesByDefault" depends="setUp">
+    <cmp:cpio destfile="${dest}">
+      <fileset dir="${input}"/>
+      <dirset dir="${input}"/>
+    </cmp:cpio>
+    <assertResourceExists>
+      <cmp:cpioentry name="subdir/asf-logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="subdir/">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testWithDirectories" depends="setUp">
+    <cmp:cpio destfile="${dest}" filesonly="false">
+      <dirset dir="${input}" excludes="."/>
+    </cmp:cpio>
+    <assertResourceExists>
+      <cmp:cpioentry name="subdir/">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="subdir/asf-logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testWithImplicitDirectories" depends="setUp">
+    <cmp:cpio destfile="${dest}" filesonly="false">
+      <fileset dir="${input}"/>
+    </cmp:cpio>
+    <assertResourceExists>
+      <cmp:cpioentry name="subdir/">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+    <assertResourceExists>
+      <cmp:cpioentry name="subdir/asf-logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+  </target>
 </project>



Mime
View raw message