Browse Source

Simplify some file resolution code to rely on FileUtils.

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

+ 8
- 14
src/main/org/apache/tools/ant/types/Path.java View File

@@ -26,10 +26,10 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.PathTokenizer;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.FileUtils;
import org.apache.tools.ant.util.JavaEnvUtils;



/**
* This object represents a path as used by CLASSPATH or PATH
* environment variable.
@@ -260,12 +260,8 @@ public class Path extends DataType implements Cloneable {
: null;

for (int i = 0; i < list.length; i++) {
File f = null;
if (getProject() != null) {
f = getProject().resolveFile(list[i]);
} else {
f = new File(list[i]);
}
File f = resolveFile(getProject(), list[i]);

// probably not the best choice, but it solves the problem of
// relative paths in CLASSPATH
if (tryUserDir && !f.exists()) {
@@ -383,7 +379,7 @@ public class Path extends DataType implements Cloneable {
while (tok.hasMoreTokens()) {
String pathElement = tok.nextToken();
try {
element.append(resolveFile(project, pathElement));
element.append(resolveFile(project, pathElement).getPath());
} catch (BuildException e) {
project.log("Dropping path element " + pathElement
+ " as it is not valid relative to the project",
@@ -483,12 +479,10 @@ public class Path extends DataType implements Cloneable {

/**
* Resolve a filename with Project's help - if we know one that is.
*
* <p>Assume the filename is absolute if project is null.</p>
*/
private static String resolveFile(Project project, String relativeName) {
return (project == null) ? relativeName
: project.resolveFile(relativeName).getAbsolutePath();
private static File resolveFile(Project project, String relativeName) {
return FileUtils.getFileUtils().resolveFile(
(project == null) ? null : project.getBaseDir(), relativeName);
}

/**
@@ -689,7 +683,7 @@ public class Path extends DataType implements Cloneable {

String[] dirs = extdirs.list();
for (int i = 0; i < dirs.length; i++) {
File dir = getProject().resolveFile(dirs[i]);
File dir = resolveFile(getProject(), dirs[i]);
if (dir.exists() && dir.isDirectory()) {
FileSet fs = new FileSet();
fs.setDir(dir);


Loading…
Cancel
Save