You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Mahlen Morris <mm...@yaltacomm.com> on 2000/10/06 03:32:49 UTC

Personally defined properties.

I'm trying to figure out a way (in Ant 1.1) to allow the individual
users of my Ant files to specify their own values for properties before
my defaults are set. However, the way properties are set is not as I'm
expecting.

For example, consider these two files:

test.xml:
<?xml version="1.0"?>
<project name="foobar" default="init" basedir=".">
 
  <target name="init" >
    <available property="myprops" file="myprops.xml"/>
    <ant dir="." target="getmyprops" />
    <echo message="test1: ${dest}" />
    <property name="dest" value="c:\build" />
    <echo message="test2: ${dest}" />
  </target>

  <target name="getmyprops" if="myprops" >
    <ant dir="." antfile="myprops.xml" />
  </target>
</project>

myprops.xml:
<?xml version="1.0"?>
<project name="Yalta UN" default="myprops" basedir=".">
  <target name="myprops" >
    <property name="dest" value="c:\build2" />
    <echo message="myprops1: ${dest}" />
  </target>
</project>

My intent is that test.xml could live in source control, but if the
individual builder on their own machine regularly wants to set dest to
"c:\build2" instead of the default, they can just make a myprops.xml
file and i would set that before setting my defaults. However, the
results i get are:

C:\src\src>ant -buildfile test.xml
Buildfile: test.xml

init:

getmyprops:

myprops:
myprops1: c:\build
test1: ${dest}
test2: c:\build

BUILD SUCCESSFUL

Total time: 0 seconds

So, what appears to be happening to my fragile, procedural-language mind
is that myprops.xml gets the default value of 'dest' from test.xml, and
then test.xml forgets the defualt value, and then learns it again! Color
me confused, but this is wonderous strange! Is there a way to do what
I'm intending, i.e.,

C:\src\src>ant -buildfile test.xml
Buildfile: test.xml

init:

getmyprops:

myprops:
myprops1: c:\build2
test1: c:\build2
test2: c:\build2

BUILD SUCCESSFUL

Total time: 0 seconds

mahlen

If fortune turns against you, even jelly breaks your tooth.
        --Persian proverb

Re: Personally defined properties.

Posted by Stefan Bodewig <bo...@bost.de>.
The <ant> task is the wrong approach here as properties set in child
projects have no meaning to the parent project.

I think you should take a look at the file attribute of the <property>
task. You could load in user defined properties from say
${user.dir}/.ant.properties at the top of your projects and define
your defaults after that.

Stefan