我怎么能从macrodef返回值?

时间:2014-06-12 10:07:35

标签: ant ant-contrib

我需要比较两个字符串args,我用它来获取一个arg作为运行时输入(例如platform=windows,ios,mac),另一个具有值列表,在build.properties下定义(例如{{1} }})。如果条件匹配,那么它应该从一个macrodef返回“true”,否则“fail”返回到某个目标。

project.supportedplatforms=windows,mac

<for list="${platform}" param="platformparam" trim="true"> <sequential> <if> <isItemExists retToProp="@{platformparam}" /> <then> <antcall target="package.@{platformParam}" /> </then> </if> </sequential> </for> <macrodef name="isItemExists"> <attribute name="retToProp" /> <property name="itemtosearch" value="@{retToProp}" /> <for list="${project.supportedplatforms}" param="listparam" trim="true"> <if> <equals arg1="@{listparam}" arg2="@{platformparam}" /> <then> <!-- return true --> </then> <else> <!-- return false --> </else> </if> </for> </macrodef> ${platforms}具有相同的值时,它应该调用指定的目标。但是在这个片段中,macrodef-for循环将执行n次,最后为${project.supportedplatforms}指定的值将为目标“build”抛出,如果它发生这样的有效输入,它不会做我的东西,因为for循环将按顺序执行。 (例如@{returnproperty}platforms=windows,mac,android,如果我的列表看起来像这意味着,是否有任何可能的方式来获取我的结果。)

project.supportedplatforms=ios,android,windows

2 个答案:

答案 0 :(得分:1)

<target name="some-test-target">
        <for list="${platform}" param="platformparam" trim="true">
            <sequential>
                <isItemExists platform="@{platformparam}" returnProperty="returnProp" />
                <if>
                    <equals arg1="${returnProp}" arg2="true"/>
                    <then>
                        <antcall target="package.@{platformparam}"/>
                    </then>
                </if>
            </sequential>
        </for>
</target>

使用sequential任务运行ant-contrib任务,如:

<macrodef name="isItemExists">
        <attribute name="platform"/>
        <attribute name="returnProperty"/>
        <sequential>
            <var name="@{returnProperty}" unset="true"/>
            <for list="${project.supportedplatforms}" param="listparam" trim="true">
                <sequential>
                <if>
                    <equals arg1="@{listparam}" arg2="@{platform}"/>
                    <then>
                        <property name="@{returnProperty}" value="true"/>
                    </then>
                    <else>
                        <property name="@{returnProperty}" value="false"/>
                    </else>
                </if>
                </sequential>
            </for>
        </sequential>
</macrodef>

答案 1 :(得分:1)

我有一个示例,该示例返回从通话到response.Content = new StringContent("{\"name\":\"John Doe\",\"age\":33}", Encoding.UTF8, "application/json");//CONTENT-TYPE header

的时间

希望这会有所帮助!

<tstamp>
相关问题