Location: JWare Software » AntXtras » Documents » Function Shortcuts » $fixture:
$fixture:
The $fixture: (or more commonly just $x:) function shortcut lets you extract simple bits of fixture information about the Ant execution cycle including active projects, targets, and running tasks. You would use $x: to supply well-defined but hard-to-obtain values from the Ant runtime like the enclosing target’s name or the script line number of the executing task. The $context: funcut is a query only feature– you cannot use it to modify fixture data.
The $fixture: funcut (and its alias $x:) is automatically installed and enabled by the standard AntXtras funcuts antlib. You can also explicitly install this funcut’s handler; read the Examples section below to see how.
Parameters
The general form of the function shortcut is: $fixture:<selector>[?arg0,,argN] where <selector> is the identifier of the fixture information to extract, and arg0 through argN are optional arguments whose specific purpose and legal values depend on the given <selector>. As of AntXtras 2.0.0, you can choose one of the following as a <selector> value:
- project[name]: caller’s project’s name
- target[name]: caller’s target’s name
- thread: caller’s thread's name
- location, file, line[number]: caller’s location information
- cycle: execution cycle information query (sub-selector argument needed)
Examples
Installing $fixture: shortcut
The following snippet explicitly declares the fixture function shortcut and links it to the ‘$fixture:’ and ‘$x:’ schemes. 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="x" 3: value="${ojaf}.info.FixtureFunctionShortcut"/> 4: <parameter name="fixture" 5: value="${ojaf}.info.FixtureFunctionShortcut"/> 6: </oja:managefuncuts>
Displaying entry into a macrodef
The following snippet uses the $x: funcut to display a entry message whenever a particular macro is invoked. If the macro is invoked from multiple targets or from a single target multiple times, the funcuts will display the correct source information (not the macro’s definition location).
1: <macrodef name="setUp"> 2: <echo level="info" message="${$iso:} in ${$x:target}:${$x:location}"/> 3: …
Displaying current thread's name and a timestamp with message
The following snippet does the same as the preceding example, except this time the displayed string includes the enclosing thread's name and a ISO formatted date-time string.
1: <presetdef name="tick"> 2: <echo level="info" message="T[${$x:thread}] ${$iso:}"/> 3: </presetdef> 4: … 5: [elsewhere...] 6: <tick/>
Aliases
- $x:
- $fixture:
- $context:
Related Topics
- The latest FixtureFunctionShortcut javadocs with more examples.