Location: JWare Software » AntXtras » Documents » Function Shortcuts » conditions
conditions
The AntXtras condition function shortcuts let you perform simple boolean tests without having to create independent <condition> or <criteria> objects. Condition funcuts are most useful as tests for optionally executed tasksets like <do> and <domatch>. The bulk of the funcuts map to the AntXtras conditions indicated by the funcut’s scheme name.
The various condition funcuts are automatically installed and enabled by the standard AntXtras antlib. You can also explicitly install these funcut handlers; read the Examples section to see how.
Parameters
The general form of a condition function shortcut is: $condition:testvalue[?option] where condition is one of the predefined short hand conditions like “isclass” or “isnumber” and testvalue is the value against which the condition is applied. Exactly what options are available, if any, depends on the short hand condition being used; read your condition’s javadocs for details. Below is a partial listing of the predefined condition schemes with examples; read the function shortcut antlib definitions for a complete listing and each funcut’s javadocs for its options.
| Scheme | Example Usage |
|---|---|
| $isdefined: | <do true=“${$isdefined:@{classpathref}}”> |
| $istask: | <do true=“${$istask:emmajava}”> |
| $noneset: | <emma enabled=“${$noneset:disable.emma,disable.metrics}”…> |
| $anyset: | <property value=“${$anyset:get-jars.errs,get-config.errs}”…/> |
| $notwhitespace: | <domatch value=“${$notwhitespace:@{prefix}}”> |
| $filenotempty: | <do true=“${$filenotempty:${filtersfile}}”> |
| $iszero: | <do false=“${$iszero:${i}}”> |
| $not: | <javac debug=“@{debug}” optimize=“${$not:@{debug}}”…> |
| $issettrue: | <arg line=“–failquick ${$issettrue:DEBUGMODE}”/> |
Examples
Installing shortcuts
The following snippet explicitly declares three condition function shortcuts: the standard ‘$isset:’, ‘$issettrue:’, and ‘$anyset:’ schemes. If you choose to activate individual condition shortcuts manually, you’ll need to do something like this at the start of your Ant script’s execution.
1: <oja:managefuncuts action="enable"> 2: <parameter name="isset" 3: value="${ojac}.ConditionFunctionShortcuts"/> 4: <parameter name="issettrue" 5: value="${ojac}.ConditionFunctionShortcuts"/> 6: <parameter name="anyset" 7: value="${ojac}.ConditionFunctionShortcuts"/> 8: </oja:managefuncuts>
Using “$isdefined:” to test optional macro parameters
The following snippet shows how you can use the $isdefined: condition funcut to handle optional macro parameters. The hilighted taskset is executed if and only if the failproperty is defined as a non-blank value.
1: <macrodef name="run-smoketests"> 2: <attribute name="failproperty" default=""/> 3: <sequential> 4: ... 5: <do true="${$isdefined:@{failproperty}}"> 6: <do false="${$var:_errorcount|$iszero:}"> 7: ... 8: </do> 9: </do> 10: ... 11: </sequential> 12: </macrodef>
Using “$iszero:” to test a counter
The following snippet shows how you can use the $iszero: condition funcut to determine when a counter is at least one (1) in size. The hilighted taskset is executed if and only if the failproperty is defined as a non-blank value.
1: <macrodef name="run-smoketests"> 2: <attribute name="failproperty" default=""/> 3: <sequential> 4: <assign var="_errorcount" value="0"/> 5: {a looped-over taskset} 6: <do false="${$var:_errorcount|$iszero:}"> 7: ... 8: </do> 9: ... 10: </sequential> 11: </macrodef>
Related Topics
- The latest ConditionFunctionShortcuts javadocs with more examples.
- The $isdefined: overview gives you more information about $isdefined funcut.