<property name "servers"="aaa,bbb,ccc"/> <property name "aaa.ip"="10.0.0.1"/> <property name "bbb.ip"="10.0.0.2"/> <property name "ccc.ip"="10.0.0.3"/>From above properties, I want to create a property whose value is "10.0.0.1,10.0.0.2,10.0.0.3".
I first tried propertyregex:
<propertyregex property="server.list" input="${servers}" regexp="([^,]+)" replace="${\1.ip}" global="true" /> <echo message="${server.list}"/>
But it does not work. The "server.list" becomes "${aaa.ip},${bbb.ip},${ccc.ip}"
Next I tried var and for:
<var name="server.list" value=""/> <for list="${servers}" param="server"> <sequential> <if> <equals arg1="${server.list}" arg2=""/> <then> <var name="server.list" value="${@{server}.ip}"/> </then> <else> <var name="server.list" value="${server.list},${@{server}.ip}"/> </else> </if> </sequential> </for>
Yes, this works. Now I get what I want.
No comments:
Post a Comment