ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Peter Janes <pet...@liberate.com>
Subject Re: Relative FileSet?
Date Thu, 05 Apr 2001 17:07:14 GMT
Stefan Bodewig wrote:

> Peter Janes <peterj@liberate.com> wrote:
> 
>> I'm attempting to implement a wrapper for a tool that needs to
>> access the relative pathnames of the files in its FileSet.  For
>> example, given:
> 
> I this using <apply> in some way?

I originally tried using <apply> and <execon> with a <mapper>, but got 
absolute paths, as you mentioned.  Perhaps I should extend one of those 
tasks?

> <apply> and <execon> both convert the filenames to absolute paths, but
> from a coding point of view, DirectoryScanner gives the file names as
> relative paths in the first place.
> 
> When you look at <copy>, it is doing something like
> 
>             File fromDir = fs.getDir(project);
>             String[] srcFiles = ds.getIncludedFiles();
> 
> and later
> 
>             File src = new File(fromDir, srcFiles[i]);
> 
> to explicitely get absolute paths. You could simply pass the results
> from srcFiles to your command directly and they would be relative to
> fromDir.

I had seen that srcFiles had only relative paths, and tried this, but 
I'm still getting absolute paths for the directories I set in my FileSet 
and in my own task.

It appears that File arguments on setX methods are all made absolute by 
something higher up in Ant, and not the task.  Something like the 
following (which I've entered manually, but displays the behaviour I'm 
seeing):

<project name="test">
   <target name="test">
     <foo dir="bar"/>
   </target>
</project>

public class foo extends Task
{
     public void setDir(File dir)
     {
         System.err.println(dir.getPath());
     }
}

$ pwd
/home/peterj/test
$ ant test

gives output of "/home/peterj/test/bar" instead of "bar", which is what 
I'd expect.

Is there any way to make Ant not set absolute paths?  I don't want to 
change the default core functionality this drastically--I'd imagine a 
lot will break if Files start becoming relative.  Or is it best to 
simply parse out the project's basedir from the string given to 
setX(File) (which seems like it could be somewhat error-prone)?


This also affects another task I've been trying to accomplish.  Given a 
file relpath/to/Xfile.bin in /projectDir, I want to create Xfile.c 
containing something like

char *genXfile = "Something generated";

i.e. using the basename.  I can successfully use <mapper> to get the 
basename, but because Ant and <apply> provide absolute paths I wind up 
writing something like

char *gen/projectDir/relpath/to/Xfile = "Something generated";

which isn't right at all.

Thanks,
Peter J.
-- 
fix, n., v.  What one does when a problem has been reported too many
times to be ignored.
   --The New Hacker's Dictionary, 3rd ed.


Mime
View raw message