bodewig 01/07/10 08:40:13
Modified: . WHATSNEW
src/main/org/apache/tools/ant Project.java
ProjectHelper.java
src/main/org/apache/tools/ant/types Path.java
Log:
Stop using canonical paths. This will change the behavior of Ant when
symbolic links are present (but in a way that is probably closer to
what the user expects) and remove some problems on platforms that use
"uncommon" native file names like OS/390 or VMS.
Submitted by: Jesse Glick <Jesse.Glick@netbeans.com>
Revision Changes Path
1.122 +4 -0 jakarta-ant/WHATSNEW
Index: WHATSNEW
===================================================================
RCS file: /home/cvs/jakarta-ant/WHATSNEW,v
retrieving revision 1.121
retrieving revision 1.122
diff -u -r1.121 -r1.122
--- WHATSNEW 2001/07/06 11:23:07 1.121
+++ WHATSNEW 2001/07/10 15:39:47 1.122
@@ -24,6 +24,10 @@
* JUnitResultFormater has two additional methods that must be
implemented by custom formatters.
+* Ant will no longer use the canonical version of a path internally -
+ this may yield different results on filesystems that support
+ symbolic links.
+
Other changes:
--------------
1.63 +12 -27 jakarta-ant/src/main/org/apache/tools/ant/Project.java
Index: Project.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Project.java,v
retrieving revision 1.62
retrieving revision 1.63
diff -u -r1.62 -r1.63
--- Project.java 2001/07/07 13:51:10 1.62
+++ Project.java 2001/07/10 15:39:58 1.63
@@ -314,19 +314,17 @@
// match basedir attribute in xml
public void setBasedir(String baseD) throws BuildException {
- try {
- setBaseDir(new File(new File(baseD).getCanonicalPath()));
- } catch (IOException ioe) {
- String msg = "Can't set basedir " + baseD + " due to " +
- ioe.getMessage();
- throw new BuildException(msg);
- }
+ setBaseDir(new File(baseD));
}
- public void setBaseDir(File baseDir) {
- this.baseDir = baseDir;
- setProperty( "basedir", baseDir.getAbsolutePath());
- String msg = "Project base dir set to: " + baseDir;
+ public void setBaseDir(File baseDir) throws BuildException {
+ if (!baseDir.exists())
+ throw new BuildException("Basedir " + baseDir.getAbsolutePath() + " does not
exist");
+ if (!baseDir.isDirectory())
+ throw new BuildException("Basedir " + baseDir.getAbsolutePath() + " is not
a directory");
+ this.baseDir = new File(baseDir.getAbsolutePath());
+ setProperty( "basedir", this.baseDir.getPath());
+ String msg = "Project base dir set to: " + this.baseDir;
log(msg, MSG_VERBOSE);
}
@@ -335,7 +333,7 @@
try {
setBasedir(".");
} catch (BuildException ex) {
- ex.printStackTrace();
+ ex.printStackTrace();
}
}
return baseDir;
@@ -553,13 +551,7 @@
// deal with absolute files
if (fileName.startsWith(File.separator)) {
- try {
- return new File(new File(fileName).getCanonicalPath());
- } catch (IOException e) {
- log("IOException getting canonical path for " + fileName
- + ": " + e.getMessage(), MSG_ERR);
- return new File(fileName);
- }
+ return new File(fileName);
}
// Eliminate consecutive slashes after the drive spec
@@ -608,14 +600,7 @@
}
}
- try {
- return new File(file.getCanonicalPath());
- }
- catch (IOException e) {
- log("IOException getting canonical path for " + file + ": " +
- e.getMessage(), MSG_ERR);
- return new File(file.getAbsolutePath());
- }
+ return new File(file.getAbsolutePath());
}
public File resolveFile(String fileName) {
1.53 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java
Index: ProjectHelper.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/ProjectHelper.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- ProjectHelper.java 2001/07/04 19:02:44 1.52
+++ ProjectHelper.java 2001/07/10 15:40:00 1.53
@@ -326,7 +326,7 @@
if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir);
} else {
- project.setBasedir((new File(buildFileParent, baseDir)).getAbsolutePath());
+ project.setBaseDir(project.resolveFile(baseDir, buildFileParent));
}
}
}
1.19 +4 -23 jakarta-ant/src/main/org/apache/tools/ant/types/Path.java
Index: Path.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Path.java,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Path.java 2001/07/07 14:05:27 1.18
+++ Path.java 2001/07/10 15:40:09 1.19
@@ -112,16 +112,7 @@
private String[] parts;
public void setLocation(File loc) {
- try {
- parts = new String[] {translateFile(loc.getCanonicalPath())};
- } catch(IOException e) {
- // XXX I'd like to log something here but if I don't
- // have a Project I can't
- if (project != null) {
- project.log(e.getMessage(), Project.MSG_WARN);
- }
- parts = new String[] {translateFile(loc.getAbsolutePath())};
- }
+ parts = new String[] {translateFile(loc.getAbsolutePath())};
}
public void setPath(String path) {
@@ -304,14 +295,9 @@
String[] s = ds.getIncludedFiles();
File dir = fs.getDir(project);
for (int j=0; j<s.length; j++) {
- String canonicalPath;
File f = new File(dir, s[j]);
- try {
- canonicalPath = f.getCanonicalPath();
- } catch(IOException e) {
- canonicalPath = f.getAbsolutePath();
- }
- addUnlessPresent(result, translateFile(canonicalPath));
+ String absolutePath = f.getAbsolutePath();
+ addUnlessPresent(result, translateFile(absolutePath));
}
}
}
@@ -454,12 +440,7 @@
private static String resolveFile(Project project, String relativeName) {
if (project != null) {
File f = project.resolveFile(relativeName);
- try {
- return f.getCanonicalPath();
- } catch(IOException e) {
- project.log(e.getMessage(), Project.MSG_WARN);
- return f.getAbsolutePath();
- }
+ return f.getAbsolutePath();
}
return relativeName;
}
|