You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by gs...@apache.org on 2008/03/07 14:41:14 UTC
svn commit: r634670 - in /ant/ivy/core/trunk:
src/java/org/apache/ivy/ant/IvyCacheFileset.java
test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
Author: gscokart
Date: Fri Mar 7 05:41:13 2008
New Revision: 634670
URL: http://svn.apache.org/viewvc?rev=634670&view=rev
Log:
IVY-759 : cachefileset doesn't support directory name starting with the same characters
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCacheFileset.java
ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCacheFileset.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCacheFileset.java?rev=634670&r1=634669&r2=634670&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCacheFileset.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/ant/IvyCacheFileset.java Fri Mar 7 05:41:13 2008
@@ -19,6 +19,7 @@
import java.io.File;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import org.apache.ivy.core.report.ArtifactDownloadReport;
@@ -110,22 +111,35 @@
* the file for which the new base directory should be returned.
* @return the common base directory between a current base directory and a given file.
*/
- private File getBaseDir(File base, File file) {
+ File getBaseDir(File base, File file) {
if (base == null) {
- return file.getParentFile();
+ return file.getParentFile().getAbsoluteFile();
} else {
- String basePath = base.getAbsolutePath();
- String filePath = file.getAbsolutePath();
- for (int i = 0; i < basePath.length(); i++) {
- if (i >= filePath.length()) {
- return file.getParentFile();
- }
- if (basePath.charAt(i) != filePath.charAt(i)) {
- return new File(basePath.substring(0, i));
+ Iterator bases = getParents(base).iterator();
+ Iterator fileParents = getParents(file.getAbsoluteFile()).iterator();
+ File result = null;
+ while (bases.hasNext() && fileParents.hasNext()) {
+ File next = (File) bases.next();
+ if (next.equals(fileParents.next())) {
+ result = next;
+ } else {
+ break;
}
}
- return base;
+ return result;
+ }
+ }
+
+ /**
+ * @return a list of files, starting with the root and ending with the file itself
+ */
+ private LinkedList/*<File>*/ getParents(File file) {
+ LinkedList r = new LinkedList();
+ while (file != null) {
+ r.addFirst(file);
+ file = file.getParentFile();
}
+ return r;
}
}
Modified: ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java?rev=634670&r1=634669&r2=634670&view=diff
==============================================================================
--- ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java (original)
+++ ant/ivy/core/trunk/test/java/org/apache/ivy/ant/IvyCacheFilesetTest.java Fri Mar 7 05:41:13 2008
@@ -162,4 +162,16 @@
}
}
+
+ public void testGetBaseDir() {
+ File base = null;
+ base = fileset.getBaseDir(base, new File("x/aa/b/c"));
+ assertEquals(new File("x/aa/b").getAbsoluteFile(), base);
+
+ base = fileset.getBaseDir(base, new File("x/aa/b/d/e"));
+ assertEquals(new File("x/aa/b").getAbsoluteFile(), base);
+
+ base = fileset.getBaseDir(base, new File("x/ab/b/d"));
+ assertEquals(new File("x").getAbsoluteFile(), base);
+ }
}