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();
}
}
| Modifier and Type | Field and Description |
|---|---|
| private List | errors
List of all collected error messages. |
| private final Task | task
Task for which the configuration should be checked. |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public void | assertConfig(boolean
which condition to check condition, String errormessage to throw if a condition failed errormessage)Asserts that a condition is true. |
| public void | checkErrors()
Checks if there are any collected errors and throws a BuildException with all messages if there was one or more. |
| public void |
| errors | back to summary |
|---|---|
| private List<String> errors List of all collected error messages. | |
| task | back to summary |
|---|---|
| private final Task task Task for which the configuration should be checked. | |
| TaskConfigurationChecker | back to summary |
|---|---|
| public TaskConfigurationChecker(Task task) Constructor.
| |
| assertConfig | back to summary |
|---|---|
| public void assertConfig(boolean condition, String errormessage) Asserts that a condition is true.
| |
| checkErrors | back to summary |
|---|---|
| public void checkErrors() throws BuildException Checks if there are any collected errors and throws a BuildException with all messages if there was one or more.
| |
| fail | back to summary |
|---|---|
| public void fail(String errormessage) Registers an error.
| |