Ant脚本:如何使用具有不同属性值的相同目标?

时间:2011-10-30 18:30:52

标签: ant flex4.5

我想调用一个目标,两次:第一次除非外部lib名称为“temp.swc”,第二次使用此外部lib。

<target name="build-trinity-client">
    <mxmlc 
        file="${src.dir}/${trinity.project}.mxml"
        output="${release.dir}/${trinity-client}.swf"
        locale="fr_FR"
        static-rsls="true"
        accessible="true"
        configname="air"
        debug="false"
        failonerror="true"
        fork="true"
        maxmemory="512m">
            <source-path path-element="${src.dir}"/>
            <external-library-path file="${FLEX_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
            <library-path dir="${ivy.cache.dir}" append="true">
                <include name="${puremvc.lib}"/>
                <include name="${kccalendar.lib}"/>
                <include name="${as3commons.lib}"/>
                <include name="d:/temp.swc"/>
            </library-path>             
    </mxmlc>

</target>

1 个答案:

答案 0 :(得分:1)

您应该使用antcall代码和if代码:

<taskdef resource="net/sf/antcontrib/antlib.xml"/>

<target name="build-trinity-client">
    <if>
        <isset property="swc.name"/>
        <then>
            <mxmlc 
                file="${src.dir}/${trinity.project}.mxml"
                output="${release.dir}/${trinity-client}.swf"
                locale="fr_FR"
                static-rsls="true"
                accessible="true"
                configname="air"
                debug="false"
                failonerror="true"
                fork="true"
                maxmemory="512m">
                <source-path path-element="${src.dir}"/>
                <external-library-path file="${FLEX_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
                <library-path dir="${ivy.cache.dir}" append="true">
                    <include name="${puremvc.lib}"/>
                    <include name="${kccalendar.lib}"/>
                    <include name="${as3commons.lib}"/>
                    <include name="${swc.name}"/>
                </library-path>             
            </mxmlc>
        </then>
        <else>
            <mxmlc 
                file="${src.dir}/${trinity.project}.mxml"
                output="${release.dir}/${trinity-client}.swf"
                locale="fr_FR"
                static-rsls="true"
                accessible="true"
                configname="air"
                debug="false"
                failonerror="true"
                fork="true"
                maxmemory="512m">
                <source-path path-element="${src.dir}"/>
                <external-library-path file="${FLEX_HOME}/frameworks/libs/air/airglobal.swc" append="true"/>
                <library-path dir="${ivy.cache.dir}" append="true">
                    <include name="${puremvc.lib}"/>
                    <include name="${kccalendar.lib}"/>
                    <include name="${as3commons.lib}"/>
                </library-path>             
            </mxmlc>
        </else>
    </if>
</target>

<target name="sample_call">
    <echo>First call: library name is passing</echo>
    <antcall target="build-trinity-client">
        <param name="swc.name" value="d:/temp.swc"/>
    </antcall> 

    <echo>Second call: don't use external library</echo>
    <antcall target="build-trinity-client">
        <param name="swc.name" value=""/>
    </antcall> 
</target>