2017-09-15 42 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>