Antlion uses a concept called format strings throughout much of the
configuration of policies. These can be thought
of as similar to Ant property replacements, but their values are based on
each library and its entries, rather than a global pool of properties.
In Antlion, a format string is a specific line of text that contains
placeholders for <library>
and
<lib-entry>
attributes (depending on the context).
To better understand what happens, let's look at a
<library-repository>
as an example:
|
|
|
|
<library-repository id="3rdparty.repository"
basedir="${3rdparty.dir}">
<format text="[[[group]/[version]/[artifact]-[version].[x]" />
</library-repository>
|
|
|
|
|
Here, the basedir
attribute uses the Ant property replacement,
which will look up the 3rdparty.dir
property from the current
project when the <library-repository>
task
is executed, and replace the string "${3rdparty.dir}
" with the
value of the property.
Now let's see how Antlion works with format strings. The <format>
element defines the format string
"[[[group]/[version]/[artifact]-[version].[x] ]
". Antlion uses
the "[" and "]" pair of characters to denote an attribute replacement. If you
have a need to actually insert a "[" character into the text, then you can
escape it using two "[" characters ("[["), which will be transformed into
a single "[", just like you can escape a "$" in Ant using two "$" characters
("$$").
In order to see how this format string gets parsed, let's look at some context:
|
|
|
|
<library>
<lib-entry group="G" version="1.0"
artifact="widget" type="dtd" />
</library>
|
|
|
|
|
When the repository attempts to look up this particular library entry, it
uses this entry's defined attributes in the formatting of the above
format string:
-
The beginning
[[
characters are escaped into a single "["
character.
-
[group]
is replaced with the corresponding group attribute
value "G".
-
the two places where
[version]
appears are replaced with the
corresponding version attribute value "1.0".
-
[artifact]
is replaced with the corresponding artifact
attribute value "widget".
-
Since there is no attribute definition for
[x]
, the string
is left in-place.
-
Even though the
type
attribute is defined in the lib-entry,
it isn't used in the formatted string.
-
A closing "]" without an accompanied openeing "[" will not be considered
a special character.
Therefore, the final generated string would look like:
In this situation, however, the [x]
was not found in the library
entry's attribute context. If one or more attribute replacement cannot be
looked up, then the replacement will fail. Therefore, this library entry
for this repository will not be considered a match, and won't be discovered.
This differs from the standard Ant property behavior.