ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r807469 - in /ant/sandbox/antlibs/compress/trunk/src: main/org/apache/ant/compress/taskdefs/ArchiveBase.java tests/antunit/ar-test.xml tests/antunit/cpio-test.xml tests/antunit/tar-test.xml tests/antunit/zip-test.xml
Date Tue, 25 Aug 2009 04:05:33 GMT
Author: bodewig
Date: Tue Aug 25 04:05:32 2009
New Revision: 807469

URL: http://svn.apache.org/viewvc?rev=807469&view=rev
Log:
port preserveLeadingSlashes from core <tar>

Modified:
    ant/sandbox/antlibs/compress/trunk/src/main/org/apache/ant/compress/taskdefs/ArchiveBase.java
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/cpio-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
    ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-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=807469&r1=807468&r2=807469&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
Tue Aug 25 04:05:32 2009
@@ -75,6 +75,7 @@
     private boolean filesOnly = true;
     private boolean preserve0permissions = false;
     private boolean roundUp = true;
+    private boolean preserveLeadingSlashes = false;
 
     protected ArchiveBase(StreamFactory factory) {
         this.factory = factory;
@@ -158,6 +159,16 @@
         roundUp = r;
     }
 
+    /**
+     * Flag to indicates whether leading `/'s should
+     * be preserved in the file names.
+     * Optional, default is <code>false</code>.
+     * @param b the leading slashes flag.
+     */
+    public void setPreserveLeadingSlashes(boolean b) {
+        this.preserveLeadingSlashes = b;
+    }
+
     public void execute() {
         validate();
         if (!dest.isExists()) {
@@ -464,7 +475,8 @@
     }
 
     /**
-     * Ensures a forward slash is used as file separator.
+     * Ensures a forward slash is used as file separator and strips
+     * leading slashes if preserveLeadingSlashes is false.
      */
     protected String bendSlashesForward(String s) {
         if (s != null) {
@@ -472,6 +484,9 @@
             if (File.separatorChar != '/' && File.separatorChar != '\\') { 
                 s = s.replace(File.separatorChar, '/');
             }
+            while (!preserveLeadingSlashes && s.startsWith("/")) {
+                s = s.substring(1);
+            }
         }
         return s;
     }

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml?rev=807469&r1=807468&r2=807469&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/ar-test.xml Tue Aug 25 04:05:32 2009
@@ -289,4 +289,41 @@
     <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
                      uid="1000" gid="1000"/>
   </target>
+
+  <target name="testRemoveLeadingSlashes" depends="setUp">
+    <cmp:ar destfile="${dest}">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+    <assertResourceExists>
+      <cmp:arentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:arentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testPreserveLeadingSlashes" depends="setUp">
+    <cmp:ar destfile="${dest}" preserveleadingslashes="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:ar>
+    <assertResourceExists>
+      <cmp:arentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:arentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:arentry>
+    </assertResourceDoesntExist>
+  </target>
+
 </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=807469&r1=807468&r2=807469&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 Tue Aug 25 04:05:32
2009
@@ -321,4 +321,40 @@
     <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
                      uid="1000" gid="1000"/>
   </target>
+
+  <target name="testRemoveLeadingSlashes" depends="setUp">
+    <cmp:cpio destfile="${dest}">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:cpio>
+    <assertResourceExists>
+      <cmp:cpioentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testPreserveLeadingSlashes" depends="setUp">
+    <cmp:cpio destfile="${dest}" preserveleadingslashes="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:cpio>
+    <assertResourceExists>
+      <cmp:cpioentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:cpioentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:cpioentry>
+    </assertResourceDoesntExist>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml?rev=807469&r1=807468&r2=807469&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/tar-test.xml Tue Aug 25 04:05:32
2009
@@ -337,4 +337,42 @@
     <checkProperties dateTime="2009-07-31-20:11:13 +0200" mode="0"
                      uid="1000" gid="1000"/>
   </target>
+
+  <target name="testRemoveLeadingSlashes" depends="setUp">
+    <cmp:tar destfile="${dest}">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:tar>
+    <assertResourceExists>
+      <cmp:tarentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:tarentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <!-- doesn't work because TarEntry strips leading slashes, will be
+       fixed for Apache Commons Compress 1.1 -->
+  <target name="fail-testPreserveLeadingSlashes" depends="setUp">
+    <cmp:tar destfile="${dest}" preserveleadingslashes="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:tar>
+    <assertResourceExists>
+      <cmp:tarentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:tarentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:tarentry>
+    </assertResourceDoesntExist>
+  </target>
 </project>

Modified: ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml
URL: http://svn.apache.org/viewvc/ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml?rev=807469&r1=807468&r2=807469&view=diff
==============================================================================
--- ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml (original)
+++ ant/sandbox/antlibs/compress/trunk/src/tests/antunit/zip-test.xml Tue Aug 25 04:05:32
2009
@@ -319,4 +319,39 @@
                      />
   </target>
 
+  <target name="testRemoveLeadingSlashes" depends="setUp">
+    <cmp:zip destfile="${dest}">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:zip>
+    <assertResourceExists>
+      <cmp:zipentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:zipentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceDoesntExist>
+  </target>
+
+  <target name="testPreserveLeadingSlashes" depends="setUp">
+    <cmp:zip destfile="${dest}" preserveleadingslashes="true">
+      <cmp:arfileset src="../resources/asf-logo.gif.ar"
+                     fullpath="/logo.gif"
+                     includes="asf-logo.gif"/>
+    </cmp:zip>
+    <assertResourceExists>
+      <cmp:zipentry name="/logo.gif">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceExists>
+    <assertResourceDoesntExist>
+      <cmp:zipentry name="logo.gif">
+        <file file="${dest}"/>
+      </cmp:zipentry>
+    </assertResourceDoesntExist>
+  </target>
 </project>



Mime
View raw message