You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Wesley Hall <we...@prociss.co.uk> on 2006/03/28 16:30:12 UTC

Absolute path properties...

Hello all,

I am in a situation where it makes sense for my ant script to compile two
path properties into one but because ant resolves all location properties to
absolute paths this is problematic. Let's say I have...

<property name="parent.dir" location="parent"/>
<property name="child.dir" location="child"/>

then

${parent.dir}/${child.dir}

will resolve to two absolute paths seperated by a slash. Clealy this wont
work at all.

I cannot use values rather than locations as in then the path seperators are
not converted between / and \ and we have windows and unix build
requirements.

I could define all my paths seperately but this would be a lot of properties
as there are many combinations.

My questions are....

Why does ant have to resolve locations to absolute paths? What is the
advantage of this over working relatively from the basedir?

Is there another way to specify a property as a relative path and still have
the seperators be localized to the platform?

Would anyone be interested if I patched ant to either support...

<property name="path" relativelocation="somepath"/>

or

<property name="path" location="somepath" relative="true"/>?

Thanks for your time

Regards

Wesley Hall

Re: Absolute path properties...

Posted by Wesley Hall <we...@prociss.co.uk>.
On 3/28/06, Matt Benson <gu...@yahoo.com> wrote:
>
> --- Wesley Hall <we...@prociss.co.uk> wrote:
>
> > Hello all,
> >
> > I am in a situation where it makes sense for my ant
> > script to compile two
> > path properties into one but because ant resolves
> > all location properties to
> > absolute paths this is problematic. Let's say I
> > have...
> >
> > <property name="parent.dir" location="parent"/>
> > <property name="child.dir" location="child"/>
> >
> > then
> >
> > ${parent.dir}/${child.dir}
> >
> > will resolve to two absolute paths seperated by a
> > slash. Clealy this wont
> > work at all.
>
> Maybe you should take a step back and explain what it
> is you are trying to achieve here.
>
> -Matt


 Perhaps you are right.

I am working on a project that consists of multiple modules. Each module has
an identical folder structure within it. Initially I started by having
multiple build scripts (one for each module) but this was a little
problematic because there are some dependancies between the modules. It
seemed ugly to have one module's build script call another so I went looking
for another solution. I found a best practice document that told me to lean
towards using a single build script where possible. This made sense to me
because if I had one master build script with targets to build each module
then I could manage the dependancies with the ant target 'depends'.
Dependancies would be intra-script rather than inter-script. I decided to
adopt this approach.

As I began to build the script I created properties like this....

<property name="module1.src.dir" location="modules/module1/src/java"/>
<property name="module2.src.dir" location="modules/module2/src/java"/>
.
.
etc


But when you have properties for docs directorys, lib directorys, classes
directorys etc etc and mutliply this by the number of modules it becomes
difficult to management and feels like there should be a better solution. I
decided that it would be better to have something like this....

<property name="module1.dir" location="modules/module1"/>
<property name="module2.dir" location="modules/module2"/>
.
.
.
<property name="src.dir" location="src/java"/>
<property name="docs.dir" location="docs"/>
<property name="api.dir" location="${docs.dir}/api"/>

As the structures in each module are identical I assumed I would be able to
refer to the module 2 src dir as "${module2.dir}/${src.dir}", but this
doesnt work because both module2.dir and src.dir are resolved to absolute
paths which messes up the combining of the paths.

My initial solution was to use value rather than location. I can get this to
work but then ant will no longer convert the path to one which can run on
the current platform (by converting / to \ on windows).

Hopefully this is a little clearer. I would definately appreciate any
suggestions. Assertions that I am a moron and coming about this in the
completely wrong way will be less appreciated, but still graciously accepted
:)

>
> > I cannot use values rather than locations as in then
> > the path seperators are
> > not converted between / and \ and we have windows
> > and unix build
> > requirements.
> >
> > I could define all my paths seperately but this
> > would be a lot of properties
> > as there are many combinations.
> >
> > My questions are....
> >
> > Why does ant have to resolve locations to absolute
> > paths? What is the
> > advantage of this over working relatively from the
> > basedir?
> >
> > Is there another way to specify a property as a
> > relative path and still have
> > the seperators be localized to the platform?
> >
> > Would anyone be interested if I patched ant to
> > either support...
> >
> > <property name="path" relativelocation="somepath"/>
> >
> > or
> >
> > <property name="path" location="somepath"
> > relative="true"/>?
> >
> > Thanks for your time
> >
> > Regards
> >
> > Wesley Hall
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
>
>

Re: Absolute path properties...

Posted by Matt Benson <gu...@yahoo.com>.
--- Wesley Hall <we...@prociss.co.uk> wrote:

> Hello all,
> 
> I am in a situation where it makes sense for my ant
> script to compile two
> path properties into one but because ant resolves
> all location properties to
> absolute paths this is problematic. Let's say I
> have...
> 
> <property name="parent.dir" location="parent"/>
> <property name="child.dir" location="child"/>
> 
> then
> 
> ${parent.dir}/${child.dir}
> 
> will resolve to two absolute paths seperated by a
> slash. Clealy this wont
> work at all.

Maybe you should take a step back and explain what it
is you are trying to achieve here.

-Matt


> 
> I cannot use values rather than locations as in then
> the path seperators are
> not converted between / and \ and we have windows
> and unix build
> requirements.
> 
> I could define all my paths seperately but this
> would be a lot of properties
> as there are many combinations.
> 
> My questions are....
> 
> Why does ant have to resolve locations to absolute
> paths? What is the
> advantage of this over working relatively from the
> basedir?
> 
> Is there another way to specify a property as a
> relative path and still have
> the seperators be localized to the platform?
> 
> Would anyone be interested if I patched ant to
> either support...
> 
> <property name="path" relativelocation="somepath"/>
> 
> or
> 
> <property name="path" location="somepath"
> relative="true"/>?
> 
> Thanks for your time
> 
> Regards
> 
> Wesley Hall
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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