Browse Source

If DestFile or DestDir does not exist, ensure that the path representing the

directory or the file is valid, by checking if the path contains any existing
non-directory element, thereby making sure the file/dir is constructible.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270385 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
f1b5585024
2 changed files with 51 additions and 20 deletions
  1. +24
    -8
      src/main/org/apache/tools/ant/types/DestDir.java
  2. +27
    -12
      src/main/org/apache/tools/ant/types/DestFile.java

+ 24
- 8
src/main/org/apache/tools/ant/types/DestDir.java View File

@@ -64,21 +64,21 @@ import org.apache.tools.ant.BuildException;
*/ */
public final class DestDir extends ValidatedFileAttribute { public final class DestDir extends ValidatedFileAttribute {


/**
private String message = null;

/**
* empty constructor * empty constructor
*/ */
public DestDir() {} public DestDir() {}
/**
* file constructor; performs validation
/**
* file constructor; performs validation
* @param file the file to use * @param file the file to use
*/ */
public DestDir(File file) throws BuildException { public DestDir(File file) throws BuildException {
setFile(file);
setFile(file);
} }
private String message = null;


protected final String getMessage() { protected final String getMessage() {
return message; return message;
@@ -98,6 +98,22 @@ public final class DestDir extends ValidatedFileAttribute {
message = "DestDir " + f + " is not a directory."; message = "DestDir " + f + " is not a directory.";
return false; return false;
} }
//If DestDir does not exist, make sure it is well formed.
if (!f.exists()) {
File tmp = f;
while (tmp.getParent() != null) {
File parent = new File(tmp.getParent());
if (parent.exists()) {
if (!parent.isDirectory()) {
message = "DestDir " + f + " contains the path "
+ parent + " that is not a directory.";
return false;
}
break;
}
tmp = parent;
}
}
return true; return true;
} }
} }

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

@@ -64,22 +64,21 @@ import org.apache.tools.ant.BuildException;
*/ */
public final class DestFile extends ValidatedFileAttribute { public final class DestFile extends ValidatedFileAttribute {


private String message;


/**
/**
* empty constructor * empty constructor
*/ */
public DestFile() {} public DestFile() {}
/**
* file constructor; performs validation
/**
* file constructor; performs validation
* @param file the file to use * @param file the file to use
*/ */
public DestFile(File file) throws BuildException { public DestFile(File file) throws BuildException {
setFile(file);
setFile(file);
} }
private String message;


protected final String getMessage() { protected final String getMessage() {
return message; return message;
@@ -99,9 +98,25 @@ public final class DestFile extends ValidatedFileAttribute {
message = "DestFile " + f + " is not a file."; message = "DestFile " + f + " is not a file.";
return false; return false;
} }
//If DestFile does not exist, make sure it is well formed.
if (!f.exists()) {
File tmp = f;
while (tmp.getParent() != null) {
File parent = new File(tmp.getParent());
if (parent.exists()) {
if (!parent.isDirectory()) {
message = "DestFile " + f + " contains the path "
+ parent + " that is not a directory.";
return false;
}
break;
}
tmp = parent;
}
}
return true; return true;
} }
/** /**
* test for the dest file being newer than the file passed in. * test for the dest file being newer than the file passed in.
* returns true iff the dest exists and is the same age or newer * returns true iff the dest exists and is the same age or newer
@@ -112,13 +127,13 @@ public final class DestFile extends ValidatedFileAttribute {
public boolean isUpToDate(File dependent) { public boolean isUpToDate(File dependent) {
if(!getFile().exists()) if(!getFile().exists())
return false; return false;
return getFile().lastModified() >= dependent.lastModified();
return getFile().lastModified() >= dependent.lastModified();
} }
/** /**
* test for the dest file being newer than the SrcFile passed in. * test for the dest file being newer than the SrcFile passed in.
* returns true iff the dest exists and is the same age or newer * returns true iff the dest exists and is the same age or newer
* @pre getFile()!=null
* @pre getFile()!=null
* @pre dependent!=null && depedent.getFile!=null; * @pre dependent!=null && depedent.getFile!=null;
* @param dependent file we are dependent on * @param dependent file we are dependent on
* @return true iff we are up to date * @return true iff we are up to date


Loading…
Cancel
Save