【问题标题】:How to test for operating system in ant build如何在 ant build 中测试操作系统
【发布时间】:2015-05-29 03:26:36
【问题描述】:

似乎 ant 唯一可靠提供的属性是“os.name”属性。但是这个名称有变体;谎言“Windows 8”“Windows 7”等

但就我而言,两者都是“Windows”-

有没有办法根据另一个属性值的部分字符串匹配来有条件地设置属性,如下面的伪代码?特别是 os.name 作为源值?使用通用 ant 安装提供的默认任务集?

if(a.property 'contains' "Windows")
    another.property = "windows value"
else if(a.property contains 'Linux')
    another.property = "linux value"
endif

【问题讨论】:

    标签: ant build


    【解决方案1】:

    您可以使用os family

            <condition property="another.property" value="windows value" >
                <os family="windows"  />
            </condition>
    
    
            <condition property="another.property"  value="linux value" >
                <os family="unix"  name="Linux"/>
            </condition>
    

    【讨论】:

    • 我还注意到这个“条件”节点中的 else="value if not true"。现在看起来我真正想要的是有条件地定义一个“macrodef”一个版本的 windows 和一个 linux 以便所有扩展宏的任务适应 - 另一个问题:)
    • 如果 windows 和 Linux 是唯一的目标操作系统并且您没有部署在 AIX 或其他上,您可以使用 else
    • Oleg Pavliv - 是的,这种逻辑的性质更复杂的情况更像是由这些元素构成的“开关”。但坦率地说,这样做是立即摆脱 ant,因为它实际上是不可编程的,并且产生了一个基于 ruby​​/rake 的脚本,该脚本必须在 windows 反斜杠环境中使用“cmd”与任何 unix 变体不同地产生。 :) :)
    • 在ant中编程有它自己的小特点。与其他所有编程语言一样。您可以接受它们或切换到其他东西。现在咕噜声正在成为一种趋势
    猜你喜欢
    • 2012-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-24
    • 1970-01-01
    • 1970-01-01
    • 2010-10-14
    • 2012-02-05
    相关资源
    最近更新 更多