ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Stevens <insomniacpeng...@googlemail.com>
Subject Re: calculating relative paths
Date Tue, 08 Sep 2009 19:03:05 GMT
2009/9/8 Jan.Materne <Jan.Materne@rzf.fin-nrw.de>:
> I am not aware of any built in task, but there is a method in FileUtils you could use.
>
> Jan
>
>        <scriptdef name="relpath" language="javascript">
>            <attribute name="property"/>
>            <attribute name="base"/>
>            <attribute name="file"/>
>            <![CDATA[
>                importClass(Packages.org.apache.tools.ant.util.FileUtils);
>                importClass(Packages.java.io.File);
>                propName = attributes.get("property");
>                baseFile = attributes.get("base");
>                file     = attributes.get("file");
>                relPath  = FileUtils.getRelativePath(new File(baseFile), new File(file)
);
>                project.setNewProperty(propName, relPath);
>            ]]>
>        </scriptdef>
>        <relpath property="rel" base="x/a/b" file="x/a/b/c/d/e/f/g/file.txt"/>

Strange, that looks like it ought to be just the job, but with
  build.dir=build
  build.xsltdoc.dir=${build.dir}/xsltdoc
  build.xsltdoc.config=${build.xsltdoc.dir}/XSLTdocConfig.xml
  dist.dir=dist
  dist.xsltdoc.dir=${dist.dir}/xsltdoc
  src.dir=src
then
        <relpath property="xsltdoc.config.target"
base="${build.xsltdoc.config}" file="${dist.xsltdoc.dir}"/>
        <relpath property="xsltdoc.config.source"
base="${build.xsltdoc.config}" file="${src.dir}"/>
results in
  xsltdoc.config.target=../../../dist/xsltdoc
  xsltdoc.config.source=../../../src
which is one "../" too many in each case :-(
A bug in FileUtils.getRelativePath, perhaps?
        <relpath property="relpath.test" base="${build.xsltdoc.dir}/1"
file="${build.xsltdoc.dir}/2"/>
        <echo message="relpath.test=${relpath.test}"/>
or even
        <relpath property="relpath.test" base="1" file="2"/>
both display
  relpath.test=../2
when I'd have expected just "2".


Andy
-- 
http://pseudoq.sourceforge.net/  Open source java sudoku solver

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


Mime
View raw message