Re: Using "if" to test for existence of properties

"Pento, Michael" <[email protected]>
Newsgroups gmane.comp.windows.dotnet.nant.user
Message-ID <F94EF67DFC532744B6AC6719D5FF79C9047453FA@ENTDC1CCR01.metratech.com>
Hello,

Maybe I am missing something here, but, I tried this using the following:

<if test="${property::exists('MyProperty')}">
                                                <echo message="${MyProperty}" />
                                </if>

This executed without failure, but, I did not define "MyProperty" at all, so, I added this to the above, outside of the target that was running, i.e.:

<?xml version="1.0" encoding="utf-8" ?>
<project name="test" basedir="." default="build">

                                                <property name="MyProperty" value="" />

                                                <target name="build">
                                                                <if test="${property::exists('MyProperty')}">
                                                                                <echo message="${MyProperty}" />
                                                                </if>
                                                </target>
</project>

This also executed without failure, essentially echoing a "[echo]" with no text.

As I stated, I may be missing something here, but, this appears to work fine (in NAnt 0.86 ...). Please let me know if I have misunderstood your issue.

Thanks,
Mike

From: Durand Van Arnem [mailto:[email protected]]
Sent: Tuesday, April 13, 2010 10:33 AM
To: NAnt Users
Subject: [NAnt-users] Using "if" to test for existence of properties

Hello,

I could use some advice about how to handle this situation:

I have a property, MyProperty, that may or may not be set.  I want a task to execute if the property is set, e.g.
<echo messsage="Hello ${MyProperty}!" if="${property::exists('MyProperty')" />

If MyProperty is not set, this task fails because NAnt appears to evaluate the message portion regardless of the result of the IF evaluation.  I could rewrite like this:

<if test="${property::exists('MyProperty')}">
    <echo message="Hello ${MyProperty}!" />
</if>

However, I run into the same issue with filterchains:

<!-- FAILS if MyProperty is not set, because NAnt evaluates the tokens regardless of the IF result -->
<copy failonerror="true" verbose="true" todir="C:\Temp">
    <fileset refid="Deploy-FileSet" />
    <filterchain>
        <replacetokens begintoken="[" endtoken="]" ignorecase="true" if="${property::exists('MyProperty')}">
            <token key="ABC" value="${MyProperty}" />
        </replacetokens>
    </filterchain>
</copy>

I'd rather not enclose the whole definition of the copy in an IF, with a nearly identical "else" version for the case when MyProperty is not set.

How have you handled this situation?

Thanks,
Durand

------------------------------------------------------------------------------
Download Intel&#174; Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev

_______________________________________________
NAnt-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/nant-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.