如何检查未展开的 Ant 属性
How to check for unexpanded Ant properties
我有一个 属性 文件,用户可以在其中自由 select Ant 环境中可用的任何 属性。例如::
property.action=${other.property}
但在 运行 时我需要知道 property.action
实际上已扩展为一个值。但是,如果未设置引用的 属性,则以下内容会打印 3 次“${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就没有更好的解决方案吗?
使用正则表达式是最快速的解决方案,w/o。附加脚本::
<propertyregex property="check" select="" 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>
我有一个 属性 文件,用户可以在其中自由 select Ant 环境中可用的任何 属性。例如::
property.action=${other.property}
但在 运行 时我需要知道 property.action
实际上已扩展为一个值。但是,如果未设置引用的 属性,则以下内容会打印 3 次“${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就没有更好的解决方案吗?
使用正则表达式是最快速的解决方案,w/o。附加脚本::
<propertyregex property="check" select="" 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>