简体   繁体   中英

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. Eg::

property.action=${other.property}

But at run time I would need to know that property.action is actually expanded to a value. However the following prints '${other.property}' three times if the referred property is not set.

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

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?

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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