2017-09-15 36 views
0

我有一個屬性文件,用戶應該可以自由選擇Ant環境中的任何可用屬性。 E.g。::如何檢查未展開的Ant屬性

property.action=${other.property} 

但在運行時我需要知道property.action實際上是擴展到一個值。但是,如果未設置引用屬性,則以下內容會打印三次'$ {other.property}'。

<property name="value" prop="property.action" /> 
<echo> 
    1: ${property.action} 
    2: ${other.property} 
    3: ${value} 
</echo> 

它不可能知道在用戶值包含哪些屬性的運行時間,所以我不能簡單地檢查每一個使用isset,如果/等於等(我用螞蟻的contrib)。

我會解決這可能與一個正則表達式的結果值,檢查有沒有可變的佔位符那裏。但是,Java/Ant沒有更好的解決方案嗎?

回答

0

使用正則表達式是禁食的解決方案,無w/o。附加腳本::

<propertyregex property="check" select="\1" defaultValue="" input="${value}" regexp=".*(\$\{[A-Za-z0-9_\.-]+\}).*" /> 
<fail message="User setting failure, unexpanded variable: ${value}"> 
<condition> 
    <not><equals arg1="${check}" arg2=""/></not> 
</condition> 
</fail>