I can think of several cases for unsetting or resetting  a property:

1. <timestamp/> cannot be called repeatedly with the same property.
2. Ditto for <input/>
3. Depending on which set of unit tests fail, I want to send e-mail to a particular individual or group. I cannot do <property name="mail.to" value="[EMAIL PROTECTED]"/>, <antcall target="sendMessage"/> followed by <property name="mail.to" value="[EMAIL PROTECTED]"/>, <antcall target"sendMessage"/>. Instead I have to do something like <property name="mail.to.firstgroup" value="..."/> etc. Same logic applies to subject, message body, and mail server.
4. Building a list of modules for the <foreach/> task. I know this isn't an official task, but it is handy in certain situations. It would be nice to be able to append to a property depending on what modules are available.


There are many more, these are just off the top of my head. I realize that the original intent of Ant was to NOT be a scripting language, but in day to day use, that is exactly what it has become. Getting properties set from calling <ant> or <antcall> is a common question on the user list. Many Ant users are Java programmers, and are looking for similar constructs in Ant that they are used to in Java.

I've written a number of tasks that address these "problems". I realize they are not necessarily the "Ant way" of doing things, but are a natural way for many developers. In particular, I've written a <var> task that is a mutable property. This is a flat out misuse of Ant properties, but is very handy. Basically, it uses the publicly accessible user properties hashtable in org.apache.ant.Project to read and write properties. As the user property hashtable takes precedence over the other properties hashtable, it is also possible to override a regular property. So constructs like this are possible:

<property name="a" value="a"/>
<echo>${a}</echo> <!-- will print out a -->
<var name="a" value="b"/>
<echo>${a}</echo> <!-- will print out b -->
<property name="a" value="c"/>
<echo>${a}</echo> <!-- property can't override, will print out b -->

There are a couple ofother constructs that I've written tasks for that turn out to be very intuitive for Java developers to use: try/catch/finally and if/else. One of the hardest parts I had in learning about Ant was this:

<property name="doit" value="false"/>
<target name="dosomething" if="doit">
...
</target>

It is counter-intuitive to think that the "dosomething" target would execute since "doit" is false. This is much more intuitive:
<property name="doit" value="false"/>
<target name="dosomething">
<if name="doit" value="true">
<!-- now do it -->
</if>
</target>


Anyway, I've rambled and ranted enough. The tasks I mentioned are available at antelope.sourceforge.net. Just this morning I finished <antcallback>, which is identical to <antcall> except it supports a "return" parameter, so you can do something like this:
<target...>
<antcallback target="setAValue" return="a"/>
<echo>${a}</echo> <!-- will print out got it -->
</target>


<target name="setAValue">
   <property name="a" value="got it"/>
</target>

I'll probably post this task on sourceforge tomorrow. There is already an <antfetch> which does almost the same thing for <ant>.

Dale Anson
[EMAIL PROTECTED]



Erik Hatcher wrote:

No, you cannot unset a property.

Do you have a reasonable use-case that explains why you'd need such a thing? To date, I've yet to see a scenario that could not be accomplished some other (usually cleaner) way.

    Erik

On Wednesday, February 5, 2003, at 10:31 AM, [EMAIL PROTECTED] wrote:

Hi,


is there a way to easily unset a property within a project ?




As with Ant1.5 the getProperties() returns a copy of the hashtable I cannot



see a elegant way to do this.






any suggestions `?






thanks,


detlef

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Reply via email to