ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbmdharris <>
Subject Re: Inserting different relative paths into multiple files using the same token
Date Mon, 10 Nov 2008 04:47:35 GMT

After trying many things (including the foreach task which also cannot call
the task in which it is written recursively), I went back to trying to strip
the absolute paths down instead of building up the relative path
recursively.  This is what I have so far and it seems to work... but I'm
still looking for better ideas on how to do this.

    <!-- Computes root relative paths and substitutes them into the output
for the @DOCROOTPATH@ keyword -->
    <target name="processRootPath">
        <!-- param passed in: name="keyword" value="DOCROOTPATH"
               param passed in: name="rootPath" value="${dir.tmphtml}/doc" 
        <!-- compute the fully-qualified root path. This changes all slashes
to platform versions so we have to change 
            them all back to forward slash. rootPath may be fully qualified,
but we shouldn't assume this. -->
        <property name="rootPathFQ" location="${rootPath}"/>
        <propertyregex property="rootPathFQForwardSlashes"
input="${rootPathFQ}" regexp="\\" replace="/" defaultValue=""
        <echo message="rootPath=${rootPath}"/>
        <echo message="rootPathFQ=${rootPathFQ}"/>

        <!-- Iterate through all directories, compute a relative upPath back
to the docRoot and substitute that value into every file in that directory
in place of the keyword -->
        <for param="currentDir">
                <dirset dir="${rootPath}"/>
                <!-- currentDir comes back fully qualified with all slashes
in platform versions.  So change them back to forward slash to compare with
the doc root -->
                <propertyregex property="currentDirForwardSlashes"
input="@{currentDir}" regexp="\\" replace="/" defaultValue=""

                <!-- strip the fully-qualified root path off of the
fully-qualified current directory... this assumes that the root path is
normalized and matches exactly. -->
                <propertyregex property="relativePath"
regexp="${rootPathFQForwardSlashes}(.*?)" replace="\1" defaultValue=""
                <echo message="relativePath=${relativePath}"/>

                <!-- strip everything out of the relative path except for
the slashes -->
                <propertyregex property="relativePathSlashesOnly"
input="${relativePath}" regexp="[^/]" replace="" defaultValue=""

                <!-- change / to ../ -->
                <propertyregex property="upPathToRoot"
input="${relativePathSlashesOnly}" regexp="/" replace="../" defaultValue=""
                <echo message="upPathToRoot=${upPathToRoot}"/>

                <!-- replace the keyword in all files in the current
directory -->
                <replaceregexp match="@${keyword}@"
replace="${upPathToRoot}" flags="sg" byline="false">
                    <fileset dir="@{currentDir}" includes="*"/>


View this message in context:
Sent from the Ant - Users mailing list archive at

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

View raw message