How to generate a comma separated list in Ant?
How can I generate a comma-separated list from a for loop in Ant?
I can loop through a source property with ant-contrib for, but I'm not sure how to output to the destination property:
<ac:for list="${comma_seperated}" pa开发者_Python百科ram="entry">
<sequential>
<if>
<isset property="@{entry}_enabled" />
<then>
<!-- append to property enabled_list here -->
</then>
</if>
</sequential>
</ac:for>
Some snippet using Ant Addon Flaka to iterate over a csv property and append stuff per iteration :
<project xmlns:fl="antlib:it.haefelinger.flaka">
<property name="foobar" value="Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda"/>
<property name="foobaz" value="My,Ny,Xi,Omikron,Pi,Rho,Sigma,Tau,Ypsilon,Phi,Chi,Psi,Omega"/>
<fl:for var="item" in="split('${foobaz}', ',')">
<fl:let>foobar ::= concat('${foobar}',',#{item}')</fl:let>
</fl:for>
<echo>$${foobar} => ${foobar}</echo>
</project>
output :
[echo] ${foobaz} => Alpha,Beta,Gamma,Delta,Epsilon,Zeta,Eta,Theta,Iota,Kappa,Lambda,My,Ny,Xi,Omikron,Pi,Rho,Sigma,Tau,Ypsilon,Phi,Chi,Psi,Omega
EDIT
glad you got the idea, though my snippet was somewhat stupid, as one would achieve
the some result with simply
<property name=someproperty value=${foobar},${foobaz}>
don't know the details of your requirements, but here's an adapted snippet, adding a /length suffix to any item
of your csv property :
<project xmlns:fl="antlib:it.haefelinger.flaka">
<property name="foobar" value="Alpha,Beta,Gamma,Delta"/>
<property name="foobaz" value=""/>
<fl:for var="item" in="split('${foobar}', ',')">
<fl:choose>
<!-- avoid a leading ',' -->
<fl:when test="'${foobaz}'.length eq 0">
<fl:let>foobaz ::= concat('${foobaz}','#{item}/length#{item.length}')</fl:let>
</fl:when>
<fl:otherwise>
<fl:let>foobaz ::= concat('${foobaz}',',#{item}/length#{item.length}')</fl:let>
</fl:otherwise>
</fl:choose>
</fl:for>
<!-- optionally overwrite ${foobar} with ${foobaz} -->
<fl:let>foobar ::= '${foobaz}'</fl:let>
<echo>$${foobar} => ${foobar}</echo>
</project>
output :
[echo] ${foobar} => Alpha/length5,Beta/length4,Gamma/length5,Delta/length5
Try using the standard Ant task <pathconvert>
. See http://ant.apache.org/manual/Tasks/pathconvert.html.
精彩评论