net.sf.antcontrib.logic

Class Assert

Implemented Interfaces:
TaskContainer

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:

Version:
$Revision: 1.3 $
Author:
Dale Anson, danson@germane-software.com
Since:
Ant 1.5

Method Summary

void
addBool(BooleanConditionTask boolTask)
void
addTask(Task task)
Add a nested task to execute.
void
execute()
Execute this task and all nested Tasks.
static void
main(String[] args)
void
maybeConfigure()
Override maybeConfigure in a way that leaves the nested tasks unconfigured until they get executed.
static int
runTests()
void
setExecute(String execute)
Ant boolean, if true, execute any contained tasks.
void
setExists(String exists)
Set the 'exists' attribute.
void
setFailonerror(String fail)
Ant boolean, stop the build process if the assertion fails.
void
setMessage(String msg)
void
setName(String name)
Set the name of the property to test.
void
setValue(String value)
Set the expected value of the property.

Method Details

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()
            throws BuildException
Execute this task and all nested Tasks.

main

public static void main(String[] args)

maybeConfigure

public void maybeConfigure()
            throws BuildException
Override 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.