$isdefined:

   The $isdefined: function shortcut that returns “true” if the source value is not whitespace and does not contain unresolved property references. Otherwise, the funcut always returns “false”. You can use this shortcut, for example, to check whether optional parameters to a macrodef have actually been defined explicitly (as opposed to being defaulted). The $isdefined: funcut is a query only feature– you cannot use it to modify existing data.

The $isdefined: funcut is automatically installed and enabled by the standard AntXtras funcuts antlib. You can also explicitly install this funcut’s handler; read the Examples section to see how this is done.

Parameters

The general form of the function shortcut is: $isdefined:value where value is the source string to be checked. You would typically embed or pipeline this shortcut with another condition shortcut or other form of test.

Examples

Installing $isdefined: shortcut

The following snippet explicitly declares the isdefined function shortcut and links it to the ‘$isdefined:’ scheme. If you choose to activate 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="isdefined"
3:     value="${ojaf}.condition.IsDefinedFunctionShortcut"/>
4: </oja:managefuncuts>
Using to test macro arguments

The following snippet uses the $isdefined funcut to determine if a macro has been called with additional parameters; by default the optional parameter is defined to the empty string (which returns “false” from $isdefined:).

 1: <macrodef name="mymacro">
 2:   <attribute name="localopts" default=""/>
 3:   <sequential>
 4: 5:     <do true="${$isdefined:@{localopts}}">
 6:       [do customization for local options]
 7:     </do>
 8: 9:   </sequential>
10: </macrodef>
Using in condition tests

The following snippets uses the $isdefined funcut as the condition test for a simple if-then execution construct. If the password is defined to something other than whitespace (a malformed property definition would also return “false”), the password is set.

1: <do true="${$password:sa|$isdefined:}">
2:   <altertask name="login" password="${$password:sa}"/>
3: </do>

Related Topics


Navigation
Personal Tools