麻烦在字符串上使用ant长度条件

时间:2013-04-18 20:11:00

标签: ant

我正在尝试处理一个包含长错误消息的字符串,而不是在出现错误时使用短值。我的ant脚本包含以下代码:           

<!-- build.svnversion is invalid if it's longer than 15 characters --> 
<length property="build.svnversion.length" string="${build.svnversion}" />
<echo message="build.svnversion.length: ${build.svnversion.length}"/>

<condition property="build.svnversion" value="N/A" else="${build.svnversion}">
    <length string="${build.svnversion}" when="gt" length="15" />
</condition>
<echo message="build.svnversion: ${build.svnversion}" />

这会产生以下输出:

[echo] build.svnversion.length: 148
[echo] build.svnversion: svn: The path '.' appears to be part of a Subversion 1.7 or greater
[echo] working copy.  Please upgrade your Subversion client to use this
[echo] working copy.

为什么build.svnversion设置为N / A,因为它的长度明显大于15?

1 个答案:

答案 0 :(得分:3)

您是否尝试重置属性build.svnversion

设置属性后,无法取消设置或更改 1

<condition/>任务中,您必须使用其他属性名称。

<!-- build.svnversion is invalid if it's longer than 15 characters --> 
<length property="build.svnversion.length"
    string="${build.svnversion}" />

<echo message="build.svnversion.length: ${build.svnversion.length}"/>

<condition property="real.build.svnversion"
    value="N/A"
    else="${build.svnversion}">
    <length string="${real.build.svnversion}"
        when="gt" length="15" />
</condition>
<echo message="real.build.svnversion: ${real.build.svnversion}" />

1 。您可以使用Ant-Contrib的<var/>任务来更改属性的值或完全取消它的设置,但这被视为不良格式。