2009/9/8 Jan.Materne <jan.mate...@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-unsubscr...@ant.apache.org
For additional commands, e-mail: user-h...@ant.apache.org

Reply via email to