如何在 ant build 中测试操作系统

How to test for operating system in ant build

看来 ant 唯一可靠地提供 属性 的是 "os.name" 属性。然而这个名字有变体;谎言"Windows 8" "Windows 7" etc

但就我而言两者都是 "Windows" -

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

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

您可以使用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>