Install Messages

Q: How do I install message bundles for use?

   There are two ways to install message bundles depending on what you’re trying to accomplish. Both methods require that you have one or more readable resource bundles (typically properties-based files). Currently you can read properties files on the file system or via any URL type supported by your Ant runtime.

Installing a single default or ‘fall back’ message bundle

If you have a single message bundle that you want all AntXtras-based components to use, installing a fall back message bundle with <managemessages> is the most straightforward thing to do as shown in the next snippet. Note that there can be only ONE fall back message bundle and you should install it before using any AntXtras component that uses messages. While you don’t have to uninstall a fall back bundle, you can by passing ‘uninstall-fallback’ as an action for the manage task as demonstrated below.

 1: [Declare your message bundle…]
 2: <messagesbundle id="allmessages" mustexist="yes"
 3:    resource="staging.META-INF.build-messages"/>
 4:
 5: [Install your message bundle as default…]
 6: <managemessages action="install-fallback"
 7:    bundleid="allmessages"/>
 8:
 9: [Read messages using any bundle-enabled component…]
10: <show messageid="LF.build.started" arg0="${$isodatetime:}"/>
11:
12: [Read messages using the $message: funcut…]
13: <echo message="{$message:LF.build.started?${$iso:}}"/>
14:
15: [If you have a "shutdown" include this…]
16: <managemessages action="uninstall-fallback"/>

:!: The big caveat with AntXtras messages is that in order to leverage the JRE’s automatic locale selection, you must refer to your bundles using a ‘resource’ parameter; files and URLs are loaded as generic resources exactly as specified.

Installing a message bundle for a specific set of tasks

If you want to install a message bundle for only a specific set of tasks (aka a scoped configuration) you need to use the <overlaymessages>[advanced antlib] taskset as shown in the snippet below.

 1:  <macrodef name="mkapidocs">
 2:    <attribute name="my.d"/>
 3:    ...
 4:    <sequential>
 5:      <overlaymessages file="@{my.d}/messages">
 6:         <show messageid="LF.apidocs.started".../>
 7:         [...Other tasks to generate API documentation...]
 8:      </overlaymessages>
 9:    </sequential>
10:  </macrodef>

The <overlaymessages> configuration taskset is nestable meaning you can nest one <overlaymessages> within another one (or more). Each newly nested taskset will use the nearest parent overlay as its default automatically unless you tell it not to explicitly by setting the ‘inheritance’ parameter to “off”. By turning inheritance off, you also stop AntXtras from using any installed default or root message bundles.

 1:  <macrodef name="mkdocs">
 2:    <attribute name="my.d"/>
 3:    ...
 4:    <sequential>
 5:      <overlaymessages file="@{my.d}/messages" inheritance="off">
 6:         <apidocs/>
 7:         <programmertests-reports/>
 8:         <coverage-reports/>
 9:         [...Generate other documentation...]
10:      </overlaymessages>
11:    </sequential>
12:  </macrodef>

Related Tips


Navigation
Personal Tools