0

大家好,这些都是我的 file.properties 文件的内容,我想打印那些具有真实价值的平台及其安装程序位置,可以确定具有真实价值的平台只有安装程序: platform.win-x86=true platform.win-x86-client=false platform.win-x64=true platform.linux-x86=false installer-zip.win-x86=E:\\abc\\abc.jar installer-zip.win-x64=E:\\def\\def.jar

尝试了很多东西,但我用过的东西之一就是

 <propertyselector property="platform.list"
                         delim`enter code here`iter=","
                         match="platform\.([^\.]*)"
                         select="\1"
                         casesensitive="false" />


    <propertyselector property="zip.list"
                         delimiter=","
                         match="installer-zip\.([^\.]*)"
                         select="\1"
                         casesensitive="false" />


   <target name="print.name" >
      <propertycopy name="platform.name" from="platform.${platform.id}" />
      <if> <equals arg1="${platform.name}" arg2="true" />
            <then>
                <echo>PlatForm.Id====>${platform.id}</echo>
                <echo message="${platform.name}" />
                <echo file="platform.properties" append="yes">${new.platform-name}=Yes${line.separator}</echo>
            </then>

        </if>
    </target> 


    <target name="print.zipname" >
        <propertycopy name="zip.name" from="installer-zip.${zip.id}" />
        <echo>zip.Id====>${zip.id}</echo>
        <echo message="${zip.name}" />

    </target> 


    <target name="first">  
         <foreach list="${platform.list}"
                delimiter=","
                target="print.name"
                param="platform.id" />

        <foreach list="${zip.list}"
                delimiter=","
                target="print.zipname"
                param="zip.id" />
    </target> 

虽然它为所有真正的平台打印值,但对于安装程序它只打印 1,然后中断..你能帮忙吗

4

1 回答 1

3

这不是直接回答您的问题,而是向您展示如何使用相同的属性在构建中执行条件目标。

<project default="build">

    <property file="platform.properties"/>

    <condition property="build.win-x86">
        <and>
            <istrue value="${platform.win-x86}"/>
            <isset property="installer-zip.win-x86"/>
        </and>
    </condition>
    <condition property="build.win-x86-client">
        <and>
            <istrue value="${platform.win-x86-client}"/>
            <isset property="installer-zip.win-x86-client"/>
        </and>
    </condition>
    <condition property="build.win-x64">
        <and>
            <istrue value="${platform.win-x64}"/>
            <isset property="installer-zip.win-x64"/>
        </and>
    </condition>
    <condition property="build.linux-x86">
        <and>
            <istrue value="${platform.linux-x86}"/>
            <isset property="installer-zip.linux-x86"/>
        </and>
    </condition>


    <target name="build" depends="win-x86, win-x86-client, win-x64, linux-x86"/>

    <target name="win-x86" depends="win-x86-build, win-x86-installer"/>
    <target name="win-x86-client" depends="win-x86-client-build, win-x86-client-installer"/>
    <target name="win-x64" depends="win-x64-build, win-x64-installer"/>
    <target name="linux-x86" depends="linux-x86-build, linux-x86-installer"/>


    <target name="win-x86-build" if="${build.win-x86}">
        <echo message="executing win-x86-build"/>
    </target>
    <target name="win-x86-installer" if="${build.win-x86}">
        <echo message="installer: ${installer-zip.win-x86}"/>
    </target>


    <target name="win-x86-client-build" if="${build.win-x86-client}">
        <echo message="executing win-x86-client-build"/>
    </target>
    <target name="win-x86-client-installer" if="${build.win-x86-client}">
        <echo message="installer: ${installer-zip.win-x86-client}"/>
    </target>


    <target name="win-x64-build" if="${build.win-x64}">
        <echo message="executing win-x64-build"/>
    </target>
    <target name="win-x64-installer" if="${build.win-x64}">
        <echo message="installer: ${installer-zip.win-x64}"/>
    </target>

    <target name="linux-x86-build" if="${build.linux-x86}">
        <echo message="executing linux-x86-build"/>
    </target>
    <target name="linux-x86-installer" if="${build.linux-x86}">
        <echo message="installer: ${installer-zip.linux-x86}"/>
    </target>

</project>

基于您的属性文件的输出如下。请注意,实际上只执行了 win-x86 和 win-64 目标。其他的因为不满足要求的条件而被跳过:

win-x86-build:
     [echo] executing win-x86-build

win-x86-installer:
     [echo] installer: E:\abc\abc.jar

win-x86:

win-x86-client-build:

win-x86-client-installer:

win-x86-client:

win-x64-build:
     [echo] executing win-x64-build

win-x64-installer:
     [echo] installer: E:\def\def.jar

win-x64:

linux-x86-build:

linux-x86-installer:

linux-x86:

build:

BUILD SUCCESSFUL
Total time: 0 seconds
于 2012-05-18T13:03:01.813 回答