Browse Source

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>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269309 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
cf3d817333
4 changed files with 21 additions and 51 deletions
  1. +4
    -0
      WHATSNEW
  2. +12
    -27
      src/main/org/apache/tools/ant/Project.java
  3. +1
    -1
      src/main/org/apache/tools/ant/ProjectHelper.java
  4. +4
    -23
      src/main/org/apache/tools/ant/types/Path.java

+ 4
- 0
WHATSNEW View File

@@ -24,6 +24,10 @@ Changes that could break older environments:
* 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:
--------------



+ 12
- 27
src/main/org/apache/tools/ant/Project.java View File

@@ -314,19 +314,17 @@ public class Project {

// 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 @@ public class Project {
try {
setBasedir(".");
} catch (BuildException ex) {
ex.printStackTrace();
ex.printStackTrace();
}
}
return baseDir;
@@ -553,13 +551,7 @@ public class Project {

// 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 @@ public class Project {
}
}

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
- 1
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -326,7 +326,7 @@ public class ProjectHelper {
if ((new File(baseDir)).isAbsolute()) {
project.setBasedir(baseDir);
} else {
project.setBasedir((new File(buildFileParent, baseDir)).getAbsolutePath());
project.setBaseDir(project.resolveFile(baseDir, buildFileParent));
}
}
}


+ 4
- 23
src/main/org/apache/tools/ant/types/Path.java View File

@@ -112,16 +112,7 @@ public class Path extends DataType implements Cloneable {
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 @@ public class Path extends DataType implements Cloneable {
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 @@ public class Path extends DataType implements Cloneable {
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;
}


Loading…
Cancel
Save