Answering my own question here for the sake of anyone who refers to this thread in the
future ;-)
<target name="build">
<ifnot propertyexists="project.name">
<property name="project.name" value="build1" />
</ifnot>
</target>
It's a bit messy as the property definitions can't sit at the top of the file any more
- they have to be inside a target and ifnot block - and also the property cannot be
used in the if clause of a target definition presumably since the property must exist
before any code such as that inside the build target is executed, so booleanproperty
below would fail at dothis below:
<target name="build">
<ifnot propertyexists="booleanproperty">
<property name="booleanproperty" value="true" />
</ifnot>
</target>
<target name="dothis" if="${booleanproperty}">
....
</target>
but at least it's a workaround for what I want to do.
-----Original Message-----
From: Kenton Price
Sent: Tue 08/07/2003 16:22
To: Ian MacLean
Cc: [EMAIL PROTECTED]
Subject: RE: [Nant-users] Passing attributes when calling <nant... >?
Hmmm, I think I've found an answer to this. If I take out the declaration of
the project.name property in build1.build, it works fine. Presumably it's because the
inherited properties aren't read-only, as they would be had they been typed from the
command line - and as it looks like they once were:
http://www.geocrawler.com/archives/3/14603/2002/6/100/8862373/
I guess my scenario is one of the reasons that Ant had inherited properties
read-only.
OK, so I guess what I need to do is to be able to know if a property exists,
something like this:
build1.build:
<project name="build1" default="build" basedir=".">
<property name="local.project.name" value="build1" />
<target name="build">
<[if project.name property exists]>
<property name="local.project.name" value="${project.name}" />
</[if]>
<echo message="Child project name ${local.project.name}" />
</target>
</project>
build2.build:
<project name="build2" default="build" basedir=".">
<property name="project.name" value="build2" />
<target name="build">
<echo message="Parent project name ${project.name}" />
<nant buildfile="build1.build" inheritall="true" />
</target>
</project>
Does such a function
<[if project.name property exists]>
exist?
Thanks
Kenton Price
-----Original Message-----
From: Kenton Price
Sent: Tue 08/07/2003 16:00
To: Ian MacLean
Cc: [EMAIL PROTECTED]
Subject: RE: [Nant-users] Passing attributes when calling <nant... >?
Thanks hugely for this Ian - that's exactly the functionality I was
looking for, so I guess it's not there yet. Unfortunately I seem to have misunderstood
inheritall too! What I'm trying to do is effectively have default parameters in a
build file that can be overridden when called from another build file. For example:
build1.build:
<project name="build1" default="build" basedir=".">
<property name="project.name" value="build1" />
<target name="build">
<echo message="Child project name ${project.name}" />
</target>
</project>
build2.build:
<project name="build2" default="build" basedir=".">
<property name="project.name" value="build2" />
<target name="build">
<echo message="Parent project name ${project.name}" />
<nant buildfile="build1.build" inheritall="true" />
</target>
</project>
When calling nant on build1.build, as expected it returns "Child
project name build1".
I would have hoped that when build2 calls nant on build1, it would
return "Child project name build2" - unfortunately when you run this, it's still
"build1". I'm using version 0.8.2.
Can you or anyone think of a way of doing what I'm trying to do?
Many thanks
Kenton Price
-----Original Message-----
From: Ian MacLean [mailto:[EMAIL PROTECTED]
Sent: Tue 08/07/2003 15:43
To: Kenton Price
Cc: [EMAIL PROTECTED]
Subject: Re: [Nant-users] Passing attributes when calling
<nant... >?
Kenton,
right now you can use the inheritall attribute to get all of
them. There
is no way right now of passing selected properties. Maybe it
would be
useful to have an optionset under the nant task so you could
do:
<nant buildfile="[buildfile2]" target="build >
<properties>
<property name="attribute1"
value="${attribute1}" />
</properties>
</nant>
Ian
>Hi
>
>Apologies if this has been answered before, but I'm trying to
pass selected specific attributes when calling <nant>. I don't want to inherit all
attributes, just some of them. I was hoping to be able to do something like this:
>
> <nant buildfile="[buildfile2]" target="build
-D:attribute1=${attribute1} -D:attribute3=${attribute3} />
>
>but it falls over. Is there a way of doing what I'm trying to
do?
>
>Many thanks
>
>Kenton Price
>?????????????????????????????????????????ӆ+?^?隊[)?{([EMAIL PROTECTED];"??"??nv)?
>?ZE?h????(?g?q?Ϣ?Z??ڝ?h??j?????i?^????'?????Zɩ?z{^??0?v?\???b??J?????????w???brO?_ܢo??lkM5?M4???ثy??j?ڲ???]???5?M????????????????????????????????????Z????왨??x%??Mj{??ǫ??b??????q?????a??l????l??.?ǟ???w??X?????b????????
>
>
N�HS^�隊[)�{(��[���j��J뢺k���y���Ʈ�����^�ا�j+x:0�Zu�ڕg�*)�jw`z֟�盢�0�
Z��(~�(���W���(}�i�֧���ɚ�X��X��֧����b��,���y�+��m����+-��.�ǟ�����+-��b�ا~��j{n���