ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1026982 - in /ant/core/trunk: ./ src/main/org/apache/tools/ant/taskdefs/ src/main/org/apache/tools/ant/util/ src/tests/junit/org/apache/tools/ant/taskdefs/
Date Mon, 25 Oct 2010 09:09:53 GMT
Author: bodewig
Date: Mon Oct 25 09:09:52 2010
New Revision: 1026982

URL: http://svn.apache.org/viewvc?rev=1026982&view=rev
Log:
don't rely on IntorspectionHelper normalizing file names in signjar.  PR 50081.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java
    ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
    ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewvc/ant/core/trunk/WHATSNEW?rev=1026982&r1=1026981&r2=1026982&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Mon Oct 25 09:09:52 2010
@@ -161,6 +161,11 @@ Fixed bugs:
    make the exit codes work in environments where 4NT or MKS are installed
    Bugzilla Report 41039.
 
+ * <signjar> would fail if used via its Java API and the File passed
+   into the setJar method was not "normalized" (i.e. contained ".."
+   segments).
+   Bugzilla Report 50081
+
 Other changes:
 --------------
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java?rev=1026982&r1=1026981&r2=1026982&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/Move.java Mon Oct 25 09:09:52 2010
@@ -355,7 +355,7 @@ public class Move extends Copy {
                     + " is a no-op.", Project.MSG_VERBOSE);
                 return true;
             }
-            if (!(sourceFile.equals(destFile.getCanonicalFile()) || destFile.delete())) {
+            if (!(getFileUtils().areSame(sourceFile, destFile) || destFile.delete())) {
                 throw new BuildException("Unable to remove existing file " + destFile);
             }
         }

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java?rev=1026982&r1=1026981&r2=1026982&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/SignJar.java Mon Oct 25 09:09:52
2010
@@ -378,7 +378,7 @@ public class SignJar extends AbstractJar
      * @throws BuildException
      */
     private void signOneJar(File jarSource, File jarTarget)
-            throws BuildException {
+        throws BuildException {
 
 
         File targetFile = jarTarget;
@@ -401,12 +401,16 @@ public class SignJar extends AbstractJar
             addValue(cmd, value);
         }
 
+        try {
         //DO NOT SET THE -signedjar OPTION if source==dest
         //unless you like fielding hotspot crash reports
-        if (!jarSource.equals(targetFile)) {
+        if (!FILE_UTILS.areSame(jarSource, targetFile)) {
             addValue(cmd, "-signedjar");
             addValue(cmd, targetFile.getPath());
         }
+        } catch (IOException ioex) {
+            throw new BuildException(ioex);
+        }
 
         if (internalsf) {
             addValue(cmd, "-internalsf");

Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java?rev=1026982&r1=1026981&r2=1026982&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/FileUtils.java Mon Oct 25 09:09:52 2010
@@ -1257,6 +1257,25 @@ public class FileUtils {
     }
 
     /**
+     * Are the two File instances pointing to the same object on the
+     * file system?
+     * @since Ant 1.8.2
+     */
+    public boolean areSame(File f1, File f2) throws IOException {
+        if (f1 == null && f2 == null) {
+            return true;
+        }
+        if (f1 == null || f2 == null) {
+            return false;
+        }
+        File f1Normalized = normalize(f1.getAbsolutePath());
+        File f2Normalized = normalize(f2.getAbsolutePath());
+        return f1Normalized.equals(f2Normalized)
+            || f1Normalized.getCanonicalFile().equals(f2Normalized
+                                                      .getCanonicalFile());
+    }
+
+    /**
      * Renames a file, even if that involves crossing file system boundaries.
      *
      * <p>This will remove <code>to</code> (if it exists), ensure that
@@ -1285,8 +1304,7 @@ public class FileUtils {
             System.err.println("Rename of " + from + " to " + to + " is a no-op.");
             return;
         }
-        if (to.exists() &&
-            !(from.equals(to.getCanonicalFile()) || tryHardToDelete(to))) {
+        if (to.exists() && !(areSame(from, to) || tryHardToDelete(to))) {
             throw new IOException("Failed to delete " + to + " while trying to rename " +
from);
         }
         File parent = to.getParentFile();

Modified: ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java?rev=1026982&r1=1026981&r2=1026982&view=diff
==============================================================================
--- ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java (original)
+++ ant/core/trunk/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java Mon Oct
25 09:09:52 2010
@@ -106,4 +106,24 @@ public class SignJarTest extends BuildFi
         }
     }
 
+    /**
+     * @see https://issues.apache.org/bugzilla/show_bug.cgi?id=50081
+     */
+    public void testSignUnnormalizedJar() throws Exception {
+        executeTarget("jar");
+        File testJar = new File(getProject().getProperty("test.jar"));
+        File testJarParent = testJar.getParentFile();
+        File f = new File(testJarParent,
+                          "../" + testJarParent.getName() + "/"
+                          + testJar.getName());
+        assertFalse(testJar.equals(f));
+        assertEquals(testJar.getCanonicalPath(), f.getCanonicalPath());
+        SignJar s = new SignJar();
+        s.setProject(getProject());
+        s.setJar(f);
+        s.setAlias("testonly");
+        s.setStorepass("apacheant");
+        s.setKeystore("testkeystore");
+        s.execute();
+    }
 }



Mime
View raw message