繁体   English   中英

如何检查未扩展的Ant属性

[英]How to check for unexpanded Ant properties

我有一个属性文件,用户可以在其中自由选择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,if / equals等来检查每个属性(我正在使用ant-contrib)。

我可能会通过对结果值使用正则表达式来解决此问题,请检查其中是否存在变量占位符。 但是,对于Java / Ant,没有更好的解决方案吗?

使用正则表达式是禁食的解决方案,没有。 其他脚本:

<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