$message:

   The $message: function shortcut lets you display an entry from an installed AntXtras messages resource bundle (<messagesbundle>) without first copying the parsed string into a property or variable. The $message: funcut also lets you substitute runtime values into message parameters used in the source string (as defined by the standard Java MessageFormat syntax); the resulting string is the funcut’s output value. You would use $message: to supply values from resource bundles to macro attributes, displayed messages, or any standard Ant component that uses strings. The $message: funcut is a query only feature– you cannot use it to modify existing data.

The $message: funcut (and its alias $string:) 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 you can do this.

Parameters

The general form of the function shortcut is: $message:resource-id[?arg0[,,arg1…,,arg9]] where resource-id is the name or key of the resource message being read, and arg0 through arg9 are replacement values for the indexth parameter in the source message; for example the value at parameter arg0 would be used to replace the “{0}” parameter.

For template messages AntXtras will automatically provide the enclosing task’s name and script location for use at positions {0} and {1} if and only if you have not provided your own values. It’s up to you whether or not you need to use these provided values in your strings.

Examples

Installing $message: shortcut

The following snippet explicitly declares the message function shortcuts and links it to the ‘$message:’ and ‘$string:’ 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="message"
3:     value="${oja}.messages.MessageFunctionShortcut"/>
4:   <parameter name="string"
5:     value="${oja}.messages.MessageFunctionShortcut"/>
6: </oja:managefuncuts>
Displaying plain messages

The following snippet uses the $message: funcut to display a startup message ‘greeting.msg’ from a previously installed global messages bundle.

1: [@ startup...]
2: <oja:managemessages resource="META-INF.my-messages"/>
3:4: [elsewhere...]
5: <echo message="${$message:greeting.msg}"/>
6:
Displaying parameterized messages

The following snippet does the same as the preceding example, except this time the ‘greeting.msg’ string is a template that requires two arguments. The script supplies two property values stored in ${starttime} and ${projectname}.

1: [@ startup...]
2: <oja:managemessages resource="META-INF.my-messages"/>
3:4: [elsewhere...]
5: <echo message="${$message:greeting.msg?${starttime},,${projectname}}"/>
6:
Loading configuration values

The following snippet declares a macro that uses the $string: funcut to define some default attribute values.

1: <macrodef name="update-dashboard">
2:   <attribute name="source" default="${$string:project.label}"/>
3:   <attribute name="status" default="${$string:default.result|$literal:FAIL}"/>
4:

Aliases

  • $message:
  • $string:

Related Topics

  • The latest MessageFunctionShortcut javadocs with more examples.
  • The $shorten: funcut lets you restrict a string’s length to a specified maximum.
  • The transformation funcuts let you apply formatting transformations to strings and other simple data types like numbers or paths.

Navigation
Personal Tools