Methods Summary |
---|
public void | addText(java.lang.String msg)Set a multiline message.
if (message == null) {
message = "";
}
message += getProject().replaceProperties(msg);
|
public org.apache.tools.ant.taskdefs.condition.ConditionBase | createCondition()Add a condition element.
if (nestedCondition != null) {
throw new BuildException("Only one nested condition is allowed.");
}
nestedCondition = new NestedCondition();
return nestedCondition;
|
public void | execute()Throw a BuildException to exit (fail) the build.
If specified, evaluate conditions:
A single nested condition is accepted, but requires that the
if /unless attributes be omitted.
If the nested condition evaluates to true, or the
ifCondition is true or unlessCondition is false, the build will exit.
The error message is constructed from the text fields, from
the nested condition (if specified), or finally from
the if and unless parameters (if present).
boolean fail = (nestedConditionPresent()) ? testNestedCondition()
: (testIfCondition() && testUnlessCondition());
if (fail) {
String text = null;
if (message != null && message.trim().length() > 0) {
text = message.trim();
} else {
if (ifCondition != null && ifCondition.length() > 0
&& getProject().getProperty(ifCondition) != null) {
text = "if=" + ifCondition;
}
if (unlessCondition != null && unlessCondition.length() > 0
&& getProject().getProperty(unlessCondition) == null) {
if (text == null) {
text = "";
} else {
text += " and ";
}
text += "unless=" + unlessCondition;
}
if (nestedConditionPresent()) {
text = "condition satisfied";
} else {
if (text == null) {
text = "No message";
}
}
}
log("failing due to " + text, Project.MSG_DEBUG);
throw ((status == null) ? new BuildException(text)
: new ExitStatusException(text, status.intValue()));
}
|
private boolean | nestedConditionPresent()test whether there is a nested condition.
return (nestedCondition != null);
|
public void | setIf(java.lang.String c)Only fail if a property of the given name exists in the current project.
ifCondition = c;
|
public void | setMessage(java.lang.String value)A message giving further information on why the build exited.
this.message = value;
|
public void | setStatus(int i)Set the status code to associate with the thrown Exception.
status = new Integer(i);
|
public void | setUnless(java.lang.String c)Only fail if a property of the given name does not
exist in the current project.
unlessCondition = c;
|
private boolean | testIfCondition()test the if condition
if (ifCondition == null || "".equals(ifCondition)) {
return true;
}
return getProject().getProperty(ifCondition) != null;
|
private boolean | testNestedCondition()test the nested condition
boolean result = nestedConditionPresent();
if (result && ifCondition != null || unlessCondition != null) {
throw new BuildException("Nested conditions "
+ "not permitted in conjunction with if/unless attributes");
}
return result && nestedCondition.eval();
|
private boolean | testUnlessCondition()test the unless condition
if (unlessCondition == null || "".equals(unlessCondition)) {
return true;
}
return getProject().getProperty(unlessCondition) == null;
|