net.sf.antcontrib.logic

Class Assert

public class Assert extends Task implements TaskContainer

Based on the Sequential task. Similar to Java's 'assert' keyword, verifies that a given property has a given value. Throws a BuildException if the property value is not as expected or the property does not exist.

Also like Java's 'assert' keyword, the Assert task must be 'turned on' using the property "ant.enable.asserts". If not set, or is set to false, the Assert task works exactly like the Sequential task.

Can hold other tasks including Assert. Attributes:

Method Summary
voidaddBool(BooleanConditionTask boolTask)
voidaddTask(Task task)
Add a nested task to execute.
voidexecute()
Execute this task and all nested Tasks.
static voidmain(String[] args)
voidmaybeConfigure()
Override org.apache.tools.ant.Task#maybeConfigure maybeConfigure in a way that leaves the nested tasks unconfigured until they get executed.
static intrunTests()
voidsetExecute(String execute)
Ant boolean, if true, execute any contained tasks.
voidsetExists(String exists)
Set the 'exists' attribute.
voidsetFailonerror(String fail)
Ant boolean, stop the build process if the assertion fails.
voidsetMessage(String msg)
voidsetName(String name)
Set the name of the property to test.
voidsetValue(String value)
Set the expected value of the property.

Method Detail

addBool

public void addBool(BooleanConditionTask boolTask)

addTask

public void addTask(Task task)
Add a nested task to execute.

Parameters: task Nested task to execute.

execute

public void execute()
Execute this task and all nested Tasks.

main

public static void main(String[] args)

maybeConfigure

public void maybeConfigure()
Override org.apache.tools.ant.Task#maybeConfigure maybeConfigure in a way that leaves the nested tasks unconfigured until they get executed.

Since: Ant 1.5

runTests

public static int runTests()

setExecute

public void setExecute(String execute)
Ant boolean, if true, execute any contained tasks. Optional, default is true. Can also be set globally by setting the value of "assert.execute" to true or false. The local setting overrides the global setting.

Parameters: execute Ant boolean, whether to execute contained tasks.

setExists

public void setExists(String exists)
Set the 'exists' attribute. If true, throws BuildException if the property does not exist. Optional, default is true.

Parameters: exists Ant boolean, whether the value must exist.

setFailonerror

public void setFailonerror(String fail)
Ant boolean, stop the build process if the assertion fails. Defaults to true. Setting this to false is contrary to the intented use of assertions, but may be useful in certain situations.

Parameters: fail Ant boolean, whether to stop the build on assertion error.

setMessage

public void setMessage(String msg)

setName

public void setName(String name)
Set the name of the property to test. Required.

Parameters: name the name of the property to test.

setValue

public void setValue(String value)
Set the expected value of the property. Implies 'exists'. Throws BuildException if the actual value is not the same as this value. Optional.

Parameters: value the expected value of the property.