ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <>
Subject AW: Inserting different relative paths into multiple files using the same token
Date Mon, 10 Nov 2008 06:46:43 GMT
Would that be ok?
        <scriptdef name="relpath" language="javascript">
            <attribute name="property"/>
            <attribute name="base"/>
            <attribute name="file"/>
                // Imports: Helper classes for Files
                // Access to the attributes
                propName = attributes.get("property");
                baseFile = new File(attributes.get("base"));
                file     = new File(attributes.get("file"));
                // The relative
                relPath = FileUtils.getRelativePath(file, baseFile);
                if (!file.isDirectory()) {
                    relPath = (relPath.length() >= 3) ? relPath.substring(3) : relPath;
                relPath += "/";

                // Store the result in a property
                project.setNewProperty(propName, relPath);
        <ac:for param="file">
            <fileset dir="." includes="**/file.txt"/>
                <relpath property="rel" base="x/a/b" file="@{file}"/>
                    File: @{file}
                    Base: x/a/b
                    rel : ${rel}
                <ac:var name="rel" unset="true"/>


>-----Urspr√ľngliche Nachricht-----
>Von: jbmdharris [] 
>Gesendet: Sonntag, 9. November 2008 22:50
>Betreff: Inserting different relative paths into multiple 
>files using the same token
>I have many different HTML files in different directories.  
>I'm already using
>the <copy> task with a <filterset> to replace tokens in these 
>files.  I'm
>trying to figure out how to create a token like @ROOTPATH@ 
>that will always
>resolve to the proper number of "../" patterns to get from the current
>directory to the root of the directory tree.  This would be used for
>example, like this:
>&lt;a href="@ROOTPATH@/foo/bar.html"&gt;some link&lt;/a&gt;
>In a file that then gets included into lots of other files in lots of
>different directories.  So the value of @ROOTPATH@ needs to be 
>depending upon the directory in which file containing it is 
>located.  I am
>unable to use absolute directory paths because this HTML is 
>only read off of
>a user's local disk instead of a webserver and an absolute 
>path beginning at
>the user's C: drive (or / if on Unix) isn't acceptable.  My 
>ant build tasks
>use <replaceregexp> to simulate SSI <!--#include --> to get 
>the contents of
>these files (like the banner) into all the other files.
>I've tried using this:
><for param="currentDir">
>   <path>
>      <dirset dir="${rootPath}"/>
>   </path>
>   <sequential>
>      <propertyregex property="currentDirForwardSlashes"
>input="@{currentDir}" regexp="\\" replace="/" 
>      <echo message="Path: ${currentDirForwardSlashes}"/>
>   </sequential>
>But the path always comes back fully-qualified and I can't 
>figure out how to
>truncate the ${rootPath} poriton of the path off the front of 
>the path and
>then change the remaining directories in the path to ".."
>I've also tried using a recursive technique with <dirset 
>includes="*"> so I
>only get one level at a time and then recursively call my task 
>"../" to a parameter.  However, I'm getting an error that 
><antcall> can't
>call tasks recursively.
>Does anyone have any ideas?
>View this message in context: 
>Sent from the Ant - Users mailing list archive at
>To unsubscribe, e-mail:
>For additional commands, e-mail:

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

View raw message