> ----- Original Message ----- 
> From: "Chekan, Vadim" <[EMAIL PROTECTED]>
> To: <nant-users@lists.sourceforge.net>
> Sent: Thursday, March 09, 2006 3:18 AM
> Subject: [NAnt-users] <available> replacement
>

> Hello there!
>
> I'm porting my scripts from ant and have a question how to port
> <available> task. What it does is execute "svn up" if sources already
> exist and execute "svn co" if not.
>
> What I have:
>
> <available file="${sln.dir}" type="dir" property="haveSources"/>
> ...
> <target if="haveSources" name="scc_up">
>     <exec executable="utils\svn.exe" failonerror="true"
> dir="${sln.dir}">
> <arg line="up" />
>     </exec>
> </target>
> <target unless="${bool::parse('${haveSources}')}" name="scc_co">
> <mkdir dir="${sources.folder}"/>
>     <exec executable="utils\svn.exe" failonerror="true"
> dir="${sources.folder}">
> <arg line="co ${src.url} ." />
>     </exec>
> </target>
>
> What I'm trying to do is:
>
> <property name="haveSources" if="${directory::exists('${sln.dir}')}"
> value="true"/>

This should have been:

<property name="haveSources" value="${directory::exists(sln.dir)}" />

> But then it fails saying:
> Expression: ${bool::parse('${haveSources}')}
>               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>     String was not recognized as a valid Boolean.
>
> I can implement it by inlining if="${directory::exists('${sln.dir}')}"
> in all tasks, but it becomes less easy to read. I'd prefer to preserve
> "haveSources" variable.
>
> Any advises?

You could:

1. use the directory::exists function in the if/unless attributes of
<target>:

<target name="scc_up" if="${directory::exists(sln.dir)}">
    <exec executable="utils\svn.exe" failonerror="true" dir="${sln.dir}">
        <arg line="up" />
    </exec>
</target>
<target name="scc_co" unless="${directory::exists(sln.dir)}">
    <mkdir dir="${sources.folder}"/>
    <exec executable="utils\svn.exe" failonerror="true"
dir="${sources.folder}">
        <arg line="co ${src.url} ." />
    </exec>
</target>

2. use a single target and perform the test in there:

<if test="${directory::exists(sln.dir)}">
    <exec executable="utils\svn.exe" failonerror="true" dir="${sln.dir}">
        <arg line="up" />
    </exec>
</if>

<if test="${not(directory::exists(sln.dir))}">
    <mkdir dir="${sources.folder}"/>
    <exec executable="utils\svn.exe" failonerror="true"
dir="${sources.folder}">
        <arg line="co ${src.url} ." />
    </exec>
</if>

If you also use a recent NAntContrib nightly build, then you can do this
(which is much cleaner than the two <if> tasks):

<choose>
    <when test="test="${directory::exists(sln.dir)}">
        <exec executable="utils\svn.exe" failonerror="true"
dir="${sln.dir}">
            <arg line="up" />
        </exec>
    </when>
    <otherwise>
        <mkdir dir="${sources.folder}"/>
        <exec executable="utils\svn.exe" failonerror="true"
dir="${sources.folder}">
            <arg line="co ${src.url} ." />
        </exec>
    </otherwise>
</choose>

Hope this helps,

Gert


-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
NAnt-users mailing list
NAnt-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nant-users

Reply via email to