Package org.apache.tools.ant
Class TaskConfigurationChecker
java.lang.Object
org.apache.tools.ant.TaskConfigurationChecker
public class TaskConfigurationChecker
extends java.lang.Object
Helper class for the check of the configuration of a given task.
This class provides methods for making assumptions about the task configuration.
After collecting all violations with assert* and fail
methods the checkErrors will throw a BuildException with all collected
messages or does nothing if there wasn't any error.
Example:
public class MyTask extends Task {
...
public void execute() {
TaskConfigurationChecker checker = TaskConfigurationChecker(this);
checker.assertConfig(
srcdir != null,
"Attribute 'srcdir' must be set.
);
checker.assertConfig(
srcdir.exists(),
"Srcdir (" + srcdir + ") must exist."
);
if (someComplexCondition()) {
fail("Complex condition failed.");
}
checker.checkErrors();
}
}
- See Also:
- Notification Pattern
-
Constructor Summary
Constructors Constructor Description TaskConfigurationChecker(Task task)Constructor. -
Method Summary
Modifier and Type Method Description voidassertConfig(boolean condition, java.lang.String errormessage)Asserts that a condition is true.voidcheckErrors()Checks if there are any collected errors and throws a BuildException with all messages if there was one or more.voidfail(java.lang.String errormessage)Registers an error.
-
Constructor Details
-
TaskConfigurationChecker
Constructor.- Parameters:
task- which task should be checked
-
-
Method Details
-
assertConfig
public void assertConfig(boolean condition, java.lang.String errormessage)Asserts that a condition is true.- Parameters:
condition- which condition to checkerrormessage- errormessage to throw if a condition failed
-
fail
public void fail(java.lang.String errormessage)Registers an error.- Parameters:
errormessage- the message for the registered error
-
checkErrors
Checks if there are any collected errors and throws a BuildException with all messages if there was one or more.- Throws:
BuildException- if one or more errors were registered
-