ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From <Jan.Mate...@rzf.fin-nrw.de>
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"/>
            <![CDATA[
                // Imports: Helper classes for Files
                importClass(Packages.org.apache.tools.ant.util.FileUtils);
                importClass(Packages.java.io.File);
                
                // 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);
            ]]>
        </scriptdef>
        <ac:for param="file">
            <fileset dir="." includes="**/file.txt"/>
            <sequential>
                <relpath property="rel" base="x/a/b" file="@{file}"/>
                <echo>
                    File: @{file}
                    Base: x/a/b
                    rel : ${rel}
                </echo>
                <ac:var name="rel" unset="true"/>
            </sequential>
        </ac:for>


Jan 

>-----Urspr√ľngliche Nachricht-----
>Von: jbmdharris [mailto:jbmdharris@hotmail.com] 
>Gesendet: Sonntag, 9. November 2008 22:50
>An: user@ant.apache.org
>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 
>different
>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="/" 
>defaultvalue="@{currentDir}"
>override="true"/>
>      <echo message="Path: ${currentDirForwardSlashes}"/>
>   </sequential>
></for>
>
>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 
>appending
>"../" 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: 
>http://www.nabble.com/Inserting-different-relative-paths-into-m
ultiple-files-using-the-same-token-tp20411245p20411245.html
>Sent from the Ant - Users mailing list archive at Nabble.com.
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
>For additional commands, e-mail: user-help@ant.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message