You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by David Corbin <dc...@machturtle.com> on 2003/02/23 15:55:01 UTC
Ant Task and paths
If I write an ant task, how should it handle paths. Is it the
responsibility of the "build.xml-writer" to specify full paths for all
path related arguments? Or should paths all be relative to ${basedir}?
Or should the task accept either? (If the latter, how do I distinguish
between the two formats?)
Thanks
David
Re: Ant Task and paths
Posted by David Corbin <dc...@machturtle.com>.
Jesse Stockall wrote:
> On Sunday, February 23, 2003, at 11:31 AM, David Corbin wrote:
>
>>> If you use a relative path then Ant will resolve the path based on
>>> what ${basedir} is set to. i.e.
>>
>>
>> How? Do you mean ant will do that using the FileUtils you
>> mentioned? Otherwise, I don't see how Ant will know that a given
>> attribute/property is a filesystem reference.
>
>
> Ant 'knows' it's a file system reference because the task requires it,
> for example in the <jar> task the 'destdir' attribute must be a
> reference to a file, the setter in Jar.java is 'setDestfile(File
> jarFile)' If you specify something that can't be resolved to a file,
> the task will fail.
Ah! That's my mistake. I need to convert mine from Strings to Files.
Thanks.
David
Re: Ant Task and paths
Posted by Jesse Stockall <je...@cryptocard.com>.
On Sunday, February 23, 2003, at 11:31 AM, David Corbin wrote:
>> If you use a relative path then Ant will resolve the path based on
>> what ${basedir} is set to. i.e.
>
> How? Do you mean ant will do that using the FileUtils you mentioned?
> Otherwise, I don't see how Ant will know that a given
> attribute/property is a filesystem reference.
Ant 'knows' it's a file system reference because the task requires it,
for example in the <jar> task the 'destdir' attribute must be a
reference to a file, the setter in Jar.java is 'setDestfile(File
jarFile)' If you specify something that can't be resolved to a file,
the task will fail.
> When I spoke about absolute paths, what I meant was this: as the
> writer of the build.xml, I can convert all relative paths by an
> explicit reference to ${basedir}. What I was unsure of, was if
> requireing this was standard behavior for tasks, or not. Apparently
> not.
There is no need to reference ${basedir} when defining your properties.
Assume build.xml lives in c:\source
<project name="myproj" basedir=".">
<property name="mypath" value="build/lib"/>
</project>
The ${mypath} property will be resolved to c:\source\build\lib when it
is used in a task that requires a file or directory
Jesse Stockall - jesse@cryptocard.com
CRYPTOCard Corp.
Re: Ant Task and paths
Posted by David Corbin <dc...@machturtle.com>.
Jesse Stockall wrote:
> On Sunday, February 23, 2003, at 10:48 AM, Martin wrote:
>
>> Jesse-
>> Many of the Unix installations use Relative Path with 100% success
>> but the
>> absolute path gets munged because
>> of the difference of the treatment of <root> between Unix vs Windoze
>> Has this been resolved?
>
>
> I'm not really sure what you are asking.
>
> If you use absolute paths they will not resolve on anything but their
> native platform i.e.
>
> 'c:\pathname' will only work on Windows, '/pathname' will only work on
> Unix platforms and 'volume:\pathname' will work only on NetWare
>
> If you use a relative path then Ant will resolve the path based on
> what ${basedir} is set to. i.e.
How? Do you mean ant will do that using the FileUtils you mentioned?
Otherwise, I don't see how Ant will know that a given attribute/property
is a filesystem reference.
> Path in build file = 'build/lib'
>
> On Windows if ${basedir} = 'c:\path', it will be resolved to
> 'c:\path\build\lib'
>
> On Unix if ${basedir} = '/home/jesse', it will be resolved to
> '/home/jesse/build/lib'
>
> I have had no problems using relative paths (cross platform) and
> absolute paths (single platform)
When I spoke about absolute paths, what I meant was this: as the writer
of the build.xml, I can convert all relative paths by an explicit
reference to ${basedir}. What I was unsure of, was if requireing this
was standard behavior for tasks, or not. Apparently not.
>
> Jesse Stockall - jesse@cryptocard.com
> CRYPTOCard Corp.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
Re: Ant Task and paths
Posted by Jesse Stockall <je...@cryptocard.com>.
On Sunday, February 23, 2003, at 10:48 AM, Martin wrote:
> Jesse-
> Many of the Unix installations use Relative Path with 100% success but
> the
> absolute path gets munged because
> of the difference of the treatment of <root> between Unix vs Windoze
> Has this been resolved?
I'm not really sure what you are asking.
If you use absolute paths they will not resolve on anything but their
native platform i.e.
'c:\pathname' will only work on Windows, '/pathname' will only work on
Unix platforms and 'volume:\pathname' will work only on NetWare
If you use a relative path then Ant will resolve the path based on what
${basedir} is set to. i.e.
Path in build file = 'build/lib'
On Windows if ${basedir} = 'c:\path', it will be resolved to
'c:\path\build\lib'
On Unix if ${basedir} = '/home/jesse', it will be resolved to
'/home/jesse/build/lib'
I have had no problems using relative paths (cross platform) and
absolute paths (single platform)
Jesse Stockall - jesse@cryptocard.com
CRYPTOCard Corp.
Re: Ant Task and paths
Posted by Martin <mg...@hotmail.com>.
Jesse-
Many of the Unix installations use Relative Path with 100% success but the
absolute path gets munged because
of the difference of the treatment of <root> between Unix vs Windoze
Has this been resolved?
-Martin
----- Original Message -----
From: "Jesse Stockall" <je...@cryptocard.com>
To: "Ant Users List" <us...@ant.apache.org>
Sent: Sunday, February 23, 2003 8:15 AM
Subject: Re: Ant Task and paths
> On Sunday, February 23, 2003, at 09:55 AM, David Corbin wrote:
> > If I write an ant task, how should it handle paths. Is it the
> > responsibility of the "build.xml-writer" to specify full paths for all
> > path related arguments? Or should paths all be relative to
> > ${basedir}? Or should the task accept either? (If the latter, how do I
> > distinguish between the two formats?)
>
> Your task should handle both, relative paths make for more portable
> build files, but some folks like to use absolute ones. Have a look at
> FileUtils, it can resolve relative files to absolute ones, taking into
> account platform specific requirements. You can also use the standard
> java.io.File methods.
>
> There are many examples to choose from in Ant's source.
>
> Jesse Stockall - jesse@cryptocard.com
> CRYPTOCard Corp.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
Re: Ant Task and paths
Posted by Jesse Stockall <je...@cryptocard.com>.
On Sunday, February 23, 2003, at 09:55 AM, David Corbin wrote:
> If I write an ant task, how should it handle paths. Is it the
> responsibility of the "build.xml-writer" to specify full paths for all
> path related arguments? Or should paths all be relative to
> ${basedir}? Or should the task accept either? (If the latter, how do I
> distinguish between the two formats?)
Your task should handle both, relative paths make for more portable
build files, but some folks like to use absolute ones. Have a look at
FileUtils, it can resolve relative files to absolute ones, taking into
account platform specific requirements. You can also use the standard
java.io.File methods.
There are many examples to choose from in Ant's source.
Jesse Stockall - jesse@cryptocard.com
CRYPTOCard Corp.