2013-05-27 24 views
0

我正嘗試在匹配任務的幫助下處理/跳過任務。 但我得到「誤報」,當我認爲它應該返回false時,匹配返回true。
以下代碼是使用:
螞蟻匹配給出誤報

<property name="moduleList" value="AP|MR"/> 
<echo message="ModuleList is ${moduleList}" /> 
...some for loop here... 
<echo message="Found ${zipFilename}" /> 
<if> 
    <matches pattern="${moduleList}" string="${zipFilename}" /> 
    <then> 
     <echo message="Creating ${zipFilename}" /> 
    </then> 
    <else> 
     <echo message="Skipping ${zipFilename}" /> 
    </else> 
</if> 

的zipfileName是通過文件夾循環和取文件的基名,正遇到zipfileNames確定是AP,MR和VAP
這段代碼的結果:

[echo] ModuleList is AP|MR 
[echo] Found AP 
[echo] Creating AP 
[echo] Found MR 
[echo] Creating MR 
[echo] Found VAP 
[echo] Creating VAP 
[echo] Found eFormsPolicy 
[echo] Skipping eFormsPolicy 

所以根據我VAP是假陽性。
或者我的比賽有問題嗎?

AFAIK ant.regexp.regexpimpl沒有設置,那麼螞蟻利用Jdk14Regexp實施

回答

1

會不會是你所得到的誤報,因爲VAPAP結束?如果您將您的比賽模式更改爲^(${moduleList})$,該怎麼辦?當moduleList被實際替換時,它將變成^(AP|MR)$,這將不匹配VAP

+0

+1 - 儘管它的名字是'',但如果你想將匹配定位到末尾,那麼''使用'Matcher.find()',而不要'matches()',並且需要'^'和'$'字符串。 –

+0

這就是它,我懷疑它與正則表達式有關,但是我的正則表達式知識並不是那麼好。 (@Ian通過它的行爲,我也懷疑它是使用find) – Niek

+0

與此有一個陷阱是,在一個空的moduleList將匹配任何東西之前。現在它什麼都不匹配。所以我需要添加一個'<等於arg1 =「$ {moduleList}」arg2 =「」/>>'或者填充moduleList爲'。*' – Niek