Browse Source

Add filepath attribute/element to available to search for a file in a

given path - handy if you want to search for an executable for example.

Submitted by:	John Morrison <John.Morrison@uk.experian.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269334 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
1e41b4c0f2
2 changed files with 34 additions and 8 deletions
  1. +3
    -0
      WHATSNEW
  2. +31
    -8
      src/main/org/apache/tools/ant/taskdefs/Available.java

+ 3
- 0
WHATSNEW View File

@@ -112,6 +112,9 @@ Other changes:

* added vssver.scc to the default excludes

* <available> has a new filepath attribute/nested element that allows
you top search for a file in a given path.

Fixed bugs:
-----------



+ 31
- 8
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -70,6 +70,7 @@ public class Available extends Task {
private String property;
private String classname;
private File file;
private Path filepath;
private String resource;
private String type;
private Path classpath;
@@ -77,11 +78,7 @@ public class Available extends Task {
private String value = "true";

public void setClasspath(Path classpath) {
if (this.classpath == null) {
this.classpath = classpath;
} else {
this.classpath.append(classpath);
}
createClasspath().append(classpath);
}

public Path createClasspath() {
@@ -95,6 +92,17 @@ public class Available extends Task {
createClasspath().setRefid(r);
}

public void setFilepath(Path filepath) {
createFilepath().append(filepath);
}
public Path createFilepath() {
if (this.filepath == null) {
this.filepath = new Path(project);
}
return this.filepath.createPath();
}

public void setProperty(String property) {
this.property = property;
}
@@ -145,7 +153,7 @@ public class Available extends Task {
return;
}
if ((file != null) && !checkFile(file)) {
if ((file != null) && !checkFile()) {
log("Unable to find " + file + " to set property " + property, Project.MSG_VERBOSE);
return;
}
@@ -158,11 +166,26 @@ public class Available extends Task {
this.project.setProperty(property, value);
}

private boolean checkFile() {
if (filepath == null) {
return checkFile(file);
} else {
String[] paths = filepath.list();
for(int i = 0; i < paths.length; ++i) {
log("Searching " + paths[i], Project.MSG_VERBOSE);
if(new File(paths[i], file.getName()).isFile()) {
return true;
}
}
}
return false;
}

private boolean checkFile(File file) {
if (type != null) {
if (type.equalsIgnoreCase("dir")){
if (type.equalsIgnoreCase("dir")) {
return file.isDirectory();
} else if (type.equalsIgnoreCase("file")){
} else if (type.equalsIgnoreCase("file")) {
return file.isFile();
}
}


Loading…
Cancel
Save