Browse Source

Improve logging when <available> is being used as a condition.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@270616 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
cf745efc64
1 changed files with 18 additions and 4 deletions
  1. +18
    -4
      src/main/org/apache/tools/ant/taskdefs/Available.java

+ 18
- 4
src/main/org/apache/tools/ant/taskdefs/Available.java View File

@@ -84,6 +84,7 @@ public class Available extends Task implements Condition {
private Path classpath;
private AntClassLoader loader;
private String value = "true";
private boolean isTask = false;

public void setClasspath(Path classpath) {
createClasspath().append(classpath);
@@ -155,6 +156,7 @@ public class Available extends Task implements Condition {
throw new BuildException("property attribute is required", location);
}

isTask = true;
if (eval()) {
String lSep = System.getProperty("line.separator");
if (null != project.getProperty(property)) {
@@ -165,6 +167,7 @@ public class Available extends Task implements Condition {
}
this.project.setProperty(property, value);
}
isTask = false;
}

public boolean eval() throws BuildException {
@@ -183,22 +186,29 @@ public class Available extends Task implements Condition {
this.loader = new AntClassLoader(project, classpath);
}

String appendix = "";
if (isTask) {
appendix = " to set property " + property;
} else {
setTaskName("available");
}

if ((classname != null) && !checkClass(classname)) {
log("Unable to load class " + classname + " to set property " + property, Project.MSG_VERBOSE);
log("Unable to load class " + classname + appendix, Project.MSG_VERBOSE);
return false;
}

if ((file != null) && !checkFile()) {
if (type != null) {
log("Unable to find " + type + " " + file + " to set property " + property, Project.MSG_VERBOSE);
log("Unable to find " + type + " " + file + appendix, Project.MSG_VERBOSE);
} else {
log("Unable to find " + file + " to set property " + property, Project.MSG_VERBOSE);
log("Unable to find " + file + appendix, Project.MSG_VERBOSE);
}
return false;
}

if ((resource != null) && !checkResource(resource)) {
log("Unable to load resource " + resource + " to set property " + property, Project.MSG_VERBOSE);
log("Unable to load resource " + resource + appendix, Project.MSG_VERBOSE);
return false;
}

@@ -206,6 +216,10 @@ public class Available extends Task implements Condition {
loader.cleanup();
}

if (!isTask) {
setTaskName(null);
}

return true;
}



Loading…
Cancel
Save