You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2016/02/07 16:38:41 UTC

[2/2] ant git commit: take name into account when comparing FileResources

take name into account when comparing FileResources

https://bz.apache.org/bugzilla/show_bug.cgi?id=57965


Project: http://git-wip-us.apache.org/repos/asf/ant/repo
Commit: http://git-wip-us.apache.org/repos/asf/ant/commit/592aa749
Tree: http://git-wip-us.apache.org/repos/asf/ant/tree/592aa749
Diff: http://git-wip-us.apache.org/repos/asf/ant/diff/592aa749

Branch: refs/heads/master
Commit: 592aa749733cf20247ebfa5dd9dd571216e71bf3
Parents: be00fcc
Author: Stefan Bodewig <bo...@apache.org>
Authored: Sun Feb 7 16:38:07 2016 +0100
Committer: Stefan Bodewig <bo...@apache.org>
Committed: Sun Feb 7 16:38:07 2016 +0100

----------------------------------------------------------------------
 .../tools/ant/types/resources/FileResource.java      |  6 ++++--
 .../tools/ant/types/resources/FileResourceTest.java  | 15 +++++++++++++++
 2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ant/blob/592aa749/src/main/org/apache/tools/ant/types/resources/FileResource.java
----------------------------------------------------------------------
diff --git a/src/main/org/apache/tools/ant/types/resources/FileResource.java b/src/main/org/apache/tools/ant/types/resources/FileResource.java
index 3ed49b8..e967907 100644
--- a/src/main/org/apache/tools/ant/types/resources/FileResource.java
+++ b/src/main/org/apache/tools/ant/types/resources/FileResource.java
@@ -282,7 +282,9 @@ public class FileResource extends Resource implements Touchable, FileProvider,
             if (of == null) {
                 return 1;
             }
-            return f.compareTo(of);
+            int compareFiles = f.compareTo(of);
+            return compareFiles != 0 ? compareFiles
+                : getName().compareTo(another.getName());
         }
         return super.compareTo(another);
     }
@@ -305,7 +307,7 @@ public class FileResource extends Resource implements Touchable, FileProvider,
         FileResource otherfr = (FileResource) another;
         return getFile() == null
             ? otherfr.getFile() == null
-            : getFile().equals(otherfr.getFile());
+            : getFile().equals(otherfr.getFile()) && getName().equals(otherfr.getName());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/ant/blob/592aa749/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
index ae592c8..c6413ea 100644
--- a/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
@@ -25,6 +25,7 @@ import org.junit.Before;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
 
 /**
  * Test Java API of {@link FileResource}.
@@ -119,4 +120,18 @@ public class FileResourceTest {
         assertEquals(root, parentSibling.getBaseDir());
         assertEquals("bar", parentSibling.getName());
     }
+
+    @Test
+    public void testEqualsUsesFiles() {
+        FileResource f1 = new FileResource(new File(root, "foo/a"));
+        FileResource f2 = new FileResource(new File(root + "/foo"), "a");
+        assertEquals(f1, f2);
+    }
+
+    @Test
+    public void testEqualsUsesRelativeNames() {
+        FileResource f1 = new FileResource(root, "foo/a");
+        FileResource f2 = new FileResource(new File(root + "/foo"), "a");
+        assertNotEquals(f1, f2);
+    }
 }