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=""
override="true"/>
        <echo message="rootPath=${rootPath}"/>
        <echo message="rootPathFQ=${rootPathFQ}"/>
        <echo
message="rootPathFQForwardSlashes=${rootPathFQForwardSlashes}"/>

        <!-- 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">
            <path>
                <dirset dir="${rootPath}"/>
            </path>
            <sequential>
                <!-- 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=""
override="true"/>
                <echo
message="currentDirForwardSlashes=${currentDirForwardSlashes}"/>

                <!-- 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"
input="${currentDirForwardSlashes}"
regexp="${rootPathFQForwardSlashes}(.*?)" replace="\1" defaultValue=""
override="true"/>
                <echo message="relativePath=${relativePath}"/>

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

                <!-- change / to ../ -->
                <propertyregex property="upPathToRoot"
input="${relativePathSlashesOnly}" regexp="/" replace="../" defaultValue=""
override="true"/>
                <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="*"/>
                </replaceregexp>
            </sequential>
        </for>

    </target>

-- 
View this message in context: 
http://www.nabble.com/Inserting-different-relative-paths-into-multiple-files-using-the-same-token-tp20411245p20414294.html
Sent from the Ant - Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to