ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Brent Bain <>
Subject Ant Contrib <if> and <macrodef> question
Date Thu, 02 Jun 2005 16:08:57 GMT

I'm trying to write a macro to check if a property has been set in a xml
property file.  If it has not been set then I want to give it a default
value.  This is running in a loop (using the xmltask's call) to create db
property files for several different environments.  The loop works great
after some minor tweaking (thanks Brian!) but I've hit another stumbling
My macro looks like this:
 <macrodef name="replaceDefaults">
  <attribute name="varName" />
  <attribute name="currentDefault" />
  <attribute name="checkIsSet" />
   <echo message="checkIsSet: @{checkIsSet}" />
   <property name="temp.checkIsSet" value="@{checkIsSet}" />
    <isset property="temp.checkIsSet" />
     <echo message="isset" />
     <var name="@{varName}" value="@{checkIsSet}" />
     <echo message="else" />
     <var name="@{varName}" value="@{currentDefault}" />
I've tried this several different ways and keep hitting what I think is an
error between the macrodef @{property} and how the ant contrib's <if>
handles the <isset> condition.
If I call it like this:
<property name="temp.dbServer" value="dbServer2" />
<replaceDefaults varName="testVar" currentDefault="dbServer1"
checkIsSet="${temp.dbServer}" />
It correctly enters the <then> and sets the testVar = dbServer2
If I call it like this (NOT setting the property first):
<replaceDefaults varName="testVar" currentDefault="dbServer1"
checkIsSet="${temp.dbServer}" />
It still enters the <then>
If I remove the line <property name="temp.checkIsSet" value="@{checkIsSet}"
/> and then also change <isset property="checkIsSet" /> then it always
enteres the <else>
Is there something obviously wrong that I'm doing or is this just a
"limitation" of the contrib task and macrodef?  Is there some more obvious
way to set properties (I'm using ant contrib's <var>'s so I can do my
looping) with defaults??
Any tips would be greatly appreciated!

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message