public void execute() {
if ((dirs == null) && (files == null)) {
throw new BuildException(
"ConditionalTasks: You must supply at least one of either the files or dirs properties");
}
if (name == null) {
throw new BuildException(
"ConditionalTasks: You must supply a name for these conditional tasks!");
}
log("Verifying conditions for " + name);
if (family != null) {
StringTokenizer tokenizer = new StringTokenizer(dirs, ",");
boolean familyMatch = false;
while (tokenizer.hasMoreElements() && !familyMatch) {
String condition = (String) tokenizer.nextElement();
if (condition.equals(family)) {
familyMatch = true;
}
}
if (!familyMatch) {
log("ConditionalTasks: OS Family '" + family +
"' does not match; " + name + " will not be performed");
return;
}
}
File basedir = getProject().getBaseDir();
if (dirs != null) {
StringTokenizer tokenizer = new StringTokenizer(dirs, ",");
File f;
while (tokenizer.hasMoreElements()) {
String condition = (String) tokenizer.nextElement();
f = new File(basedir, condition);
if (!f.exists()) {
f = new File(condition);
if (!f.exists()) {
log("ConditionalTasks: Directory '" + condition +
"' does not exist; " + name +
" will not be performed");
return;
}
}
}
}
if (files != null) {
StringTokenizer tokenizer = new StringTokenizer(files, ",");
File f;
while (tokenizer.hasMoreElements()) {
String condition = (String) tokenizer.nextElement();
f = new File(basedir, condition);
if (!f.exists()) {
log("ConditionalTasks: File '" + condition +
"' does not exist; " + name + " will not be performed");
return;
}
}
}
System.out.println("Executing Conditional Tasks");
Iterator it = tasks.iterator();
Task task;
while (it.hasNext()) {
task = (Task) it.next();
task.setProject(getProject());
task.setOwningTarget(getOwningTarget());
task.setLocation(getLocation());
task.perform();
}
}
|