简体   繁体   English

如何检查未扩展的Ant属性

[英]How to check for unexpanded Ant properties

I have a property file in which the user should be free to select any property available in the Ant environment. 我有一个属性文件,用户可以在其中自由选择Ant环境中可用的任何属性。 Eg:: 例如::

property.action=${other.property}

But at run time I would need to know that property.action is actually expanded to a value. 但是在运行时,我需要知道property.action实际上是扩展为一个值。 However the following prints '${other.property}' three times if the referred property is not set. 但是,如果未设置所引用的属性,则以下命令将打印“ $ {other.property}”三次。

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

Its not possible to know at run time what properties the user value contains, so I cannot simply check each one using isset, if/equals, etc. (I'm using ant-contrib). 在运行时无法知道用户值包含哪些属性,因此我不能简单地使用isset,if / equals等来检查每个属性(我正在使用ant-contrib)。

I would solve this perhaps with a regex on the resulting value, check that there are no variable placeholders there. 我可能会通过对结果值使用正则表达式来解决此问题,请检查其中是否存在变量占位符。 But is there not a better solution for Java/Ant? 但是,对于Java / Ant,没有更好的解决方案吗?

Using regex was the fasted solution, w/o. 使用正则表达式是禁食的解决方案,没有。 additional scripting:: 其他脚本:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM