Ant根据列表大小属性动态设置列表

时间:2018-03-28 09:48:25

标签: ant ant-contrib

我有以下Ant脚本:

<target name="make-ears">
    <for list="1,2,3,4" param="clone-nr">
        <sequential>
            <!-- Do stuff -->
        </sequential>
    </for>
</target>

我更喜欢使用以下方式动态设置大小:

<property name="nr_clones" value="4" />

有类似的东西:

<for list="**1 to ${nr_clones}**" param="clone-nr"> <!-- ** Not working but would like to ** -->

1 个答案:

答案 0 :(得分:0)

通过使用Javascript:

解决了这个问题
<property name="nr_clones" value="4" />

<!-- Build list -->
<script language="javascript">
    <![CDATA[
    var start = 1;
    var end   = FileToJRKScheduler.getProperty("nr_clones");
    var list = start;
    for (i = parseInt(start) + 1; i <= end; i++) {
      list += "," + i.toString();
    }
    FileToJRKScheduler.setProperty("list_clones", list);
  ]]>
</script>

然后使用:

<for list="${list_clones}" param="clone-nr">

致谢:https://eureka.ykyuen.info/2014/01/17/apache-ant-iteration-within-a-specific-number-range/