Ant:如何从命令行传入的逗号分隔列表中设置属性? [英] Ant: How do I set a properties from a comma-separated list passed in on command line?

查看:21
本文介绍了Ant:如何从命令行传入的逗号分隔列表中设置属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Ant 1.8.1.如果我在命令行上传入一个参数......

I'm using Ant 1.8.1. If I passed in an argument on the command line ...

-DenableProperties=abc,def,ghi,jkl

如何在我的 Ant 脚本中设置单个属性(为 true/false)?

How do I set individual properties (to true/false) in my Ant script?

<property name="abc" value="???" />
<property name="def" value="???" />

请注意,在上面的示例中,我希望 Ant 可以访问设置为 true 的属性${abc}",而如果它尝试访问属性${mno}",该属性将为假,或至少为真以外的某个值.

Note that in the above example, I'd want Ant to have access to a property "${abc}" that is set to true, whereas if it tried to access the property "${mno}" that property would be false, or at least some value other than true.

谢谢,-戴夫

推荐答案

在核心 Ant 中想不出办法做到这一点.您可以使用 ant-contrib 的 For task 来实现.>

Can't think of a way to do this in core Ant. You could do it with the For task of ant-contrib.

<project default="test">

  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="C:/lib/ant-contrib/ant-contrib-1.0b3.jar"/>
    </classpath>
  </taskdef>

  <target name="test">
    <for list="${enableProperties}" param="prop">
      <sequential>
         <property name="@{prop}" value="true"/>
      </sequential>
    </for>
    <for list="${enableProperties}" param="prop">
      <sequential>
         <echo message="@{prop}=${@{prop}}"/>
      </sequential>
    </for>
  </target>

</project>

输出:

$ ant -DenableProperties=abc,def,ghi,jkl
Buildfile: build.xml

test:
     [echo] abc=true
     [echo] def=true
     [echo] ghi=true
     [echo] jkl=true

BUILD SUCCESSFUL
Total time: 0 seconds

这篇关于Ant:如何从命令行传入的逗号分隔列表中设置属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆