ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andy Stevens <>
Subject Re: calculating relative paths
Date Wed, 09 Sep 2009 14:23:21 GMT
2009/9/9  <>:
> The enhancement of <property location/> seems to be good candidate.
> <property location="my/file.txt" relative="true" basedir="my/dir"/>
> --> ../my/file.txt

../file.txt, surely?  my/dir + .. -> my, my/dir + ../my -> my/my,
my/dir + ../my/file.txt -> my/my/file.txt

You might also like to add a test case for

<property location="dir1/file.txt" relative="true" basedir="dir2"/>
--> ../dir1/file.txt

which I don't think is covered by the others.  Also, I notice all the
test cases you mentioned have a file as the location; I assume it'll
work the same way when location is a directory?  In which case, there
probably ought to be a test case for

<property location="my/dir" relative="true" basedir="my/dir"/>

probably expecting "." to be returned, though you could make a
reasonable argument in favour of "" instead.

Actually, that gives me a thought about the extra "../" I was seeing
with your earlier FileUtils.getRelativePath suggestion - could it be
that it assumes the first argument (the base for the relative path) is
always a directory?  That would explain why foo/1 -> foo/2 is returned
as ../2 rather than just 2, it's actually doing foo/1/ -> foo/2.  In
which case, your use of baseFile in the scriptdef was slightly
misleading, baseDir would have been a better name.
Alternatively, perhaps getRelativePath ought to check
File.isDirectory()/File.isFile() and adjust accordingly?

--  Open source java sudoku application

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

View raw message