Browse Source

Change behavior of getName(); refine compareTo().

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@278493 13f79535-47bb-0310-9956-ffa450edef68
master
Matthew Jason Benson 20 years ago
parent
commit
3bfca0664b
1 changed files with 20 additions and 3 deletions
  1. +20
    -3
      src/main/org/apache/tools/ant/types/resources/FileResource.java

+ 20
- 3
src/main/org/apache/tools/ant/types/resources/FileResource.java View File

@@ -124,7 +124,9 @@ public class FileResource extends Resource implements Touchable {
} }


/** /**
* Get the name of this FileResource relative to its baseDir, if any.
* Get the name of this FileResource. If the basedir is set,
* the name will be relative to that. Otherwise the basename
* only will be returned.
* @return the name of this resource. * @return the name of this resource.
*/ */
public String getName() { public String getName() {
@@ -132,7 +134,7 @@ public class FileResource extends Resource implements Touchable {
return ((Resource) getCheckedRef()).getName(); return ((Resource) getCheckedRef()).getName();
} }
File b = getBaseDir(); File b = getBaseDir();
return b == null ? getNotNullFile().getAbsolutePath()
return b == null ? getNotNullFile().getName()
: FILE_UTILS.removeLeadingPath(b, getNotNullFile()); : FILE_UTILS.removeLeadingPath(b, getNotNullFile());
} }


@@ -220,7 +222,22 @@ public class FileResource extends Resource implements Touchable {
if (isReference()) { if (isReference()) {
return ((Comparable) getCheckedRef()).compareTo(another); return ((Comparable) getCheckedRef()).compareTo(another);
} }
return this.equals(another) ? 0 : super.compareTo(another);
if (this.equals(another)) {
return 0;
}
if (another.getClass().equals(getClass())) {
FileResource otherfr = (FileResource) another;
File f = getFile();
if (f == null) {
return -1;
}
File of = otherfr.getFile();
if (of == null) {
return 1;
}
return f.compareTo(of);
}
return super.compareTo(another);
} }


/** /**


Loading…
Cancel
Save