2012-04-18 68 views
4

我有一個ant任務應該比較兩個值是否相等。如果這兩個值不相等,我想失敗:Ant:檢查兩個數字是否相等

<condition property="versionDoesNotMatch"> 
    <not> 
    <equals arg1="applicationVersion" arg2="releaseNotesVersion"/> 
    </not> 
</condition> 
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/> 

根據螞蟻的輸出,這兩個值,releaseNotesVersion和applicationVersion具有相同的價值1.7但條件始終計算爲真 - 這因爲不是就意味着數字不相等。這讓我想知道,如果螞蟻會比較那些價值觀有麻煩嗎?

回答

13

你在你的例子中匹配兩個文字字符串;這些永遠不會是平等的,所以你的條件總是評估爲真。假設你的參數是螞蟻屬性,你需要評估像這樣的屬性值:

<condition property="versionDoesNotMatch"> 
    <not> 
    <equals arg1="${applicationVersion}" arg2="${releaseNotesVersion}"/> 
    </not> 
</condition> 
<fail if="versionDoesNotMatch" message="Version of Application and Release notes does not match."/> 
+0

+1謝謝!我一定是在我睡覺前睡覺的時候xD ...... – AgentKnopf 2012-04-19 08:24:28