ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Abley <>
Subject Utility macrodef to verify all filterset tokens are replaced
Date Fri, 05 Aug 2005 08:02:52 GMT
Inspired by a comment from Jan earlier this week on the list, here is
one of my commonly used macrodefs. 

We find it very useful to use prior to building a war or similar
artifact for deployment. With the number of environments that we have,
it is a great time saver to detect that you don't have a configuration
setting of @image.server@ still in a config file before you deploy to a
production environment.

        Macrodef for searching for unreplaced filterset tokens prior to
building a war file
    <macrodef name="check-filterset-tokens" 
        description="search a fileset for a given token, outputting any
matches to the file specified in the attribute outFile">
        <attribute name="outFile" 
        description="name of the file to output any matching lines to"
        <attribute name="pattern" default='[">]@[^@]+@'
        description="regex to check the filterset for. Default matches a
double quote or greater than char followed by a standard filterset token
- typically found in an xml file to be templated by the build" />
        <element name="files" implicit="yes" 
        description="fileset containing the files to search. This can be
any ANT path-like structure" />
            <delete file="@{outFile}" />
            <concat destfile="@{outFile}">
                <files />
                        <regexp pattern="@{pattern}" />   
            <loadfile property="antutils.check.filtersets.file"
srcfile="@{outFile}" />
            <fail message="
            Some filterset tokens have not been replaced.
${line.separator}Please see the file @{outFile}">
                    <!-- check that the property was set by the loadfile
task -->
                    <isset property="antutils.check.filtersets.file" />

            <delete file="@{outFile}" />

To fully leverage it, it helps to know regular expressions fairly well,
but that's no bad skill to master.

Sample usage:

        Check that all filterset tokens have been included and all
properties have been defined
    <target name="-check-filterset-tokens">
        <path id="templated-files">
            <fileset dir="${temp.dir}">
                <include name="**/*" />
                <exclude name="**/*.jar" />

        <property name="filterset.results.file"
location="filterset/results.txt" />

            default check looking for unreplaced tokens (element
            data or attribute) in xml files [">]@xxx@
        <check-filterset-tokens outfile="${filterset.results.file}">
            <path refid="templated-files" />

            a more complex check here to see that all properties used in
            filtersets have been defined. Since there are some
            in the xml files of the form ${xxx}, we assume that all
            will be of the form ${xxx.yyy}
        <check-filterset-tokens outfile="${filterset.results.file}"
            <path refid="templated-files" />

        <!-- check in properties files for simple @xxx@ -->
        <check-filterset-tokens outfile="${filterset.results.file}"
            <path refid="templated-files" />

Hope others find it useful or can improve it, or point out how it could
be done in a simpler way.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message