如何在 Ant 中生成逗号分隔的列表?

发布于 2024-11-24 06:01:55 字数 444 浏览 1 评论 0原文

如何从 Ant 中的 for 循环生成逗号分隔的列表?

我可以使用 ant-contrib for 循环遍历源属性,但我不确定如何输出到目标属性:

<ac:for list="${comma_seperated}" param="entry">
    <sequential>
         <if>
         <isset property="@{entry}_enabled" />
             <then>
             <!-- append to property enabled_list here -->
             </then>
         </if>
    </sequential>
</ac:for>

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}" param="entry">
    <sequential>
         <if>
         <isset property="@{entry}_enabled" />
             <then>
             <!-- append to property enabled_list here -->
             </then>
         </if>
    </sequential>
</ac:for>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

指尖上的星空 2024-12-01 06:01:55

使用 Ant Addon Flaka 迭代 csv 属性的一些代码片段每次迭代附加内容:

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

输出:

[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

编辑
很高兴你明白了这个想法,尽管我的代码片段有点愚蠢,正如人们所实现的那样
的一些结果

只是

不知道您的要求的详细信息,但这里有一个改编后的片段,将 /length 后缀添加到 csv 属性的任何项目

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

输出:

[echo] ${foobar} => Alpha/length5,Beta/length4,Gamma/length5,Delta/length5

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
陌伤浅笑 2024-12-01 06:01:55

尝试使用标准 Ant 任务 。请参阅http://ant.apache.org/manual/Tasks/pathconvert.html

Try using the standard Ant task <pathconvert>. See http://ant.apache.org/manual/Tasks/pathconvert.html.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文