我需要比较两个字符串 args,我曾经从中获取一个 arg 作为运行时输入(例如platform=windows,ios,mac
),另一个具有在build.properties
(例如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>
Run Code Online (Sandbox Code Playgroud)
当${platforms}
并且${project.supportedplatforms}
具有相同的值时,它应该调用指定的目标。但是在这个片段中,macrodef-for 循环将执行 n 次,最后分配给什么值@{returnproperty}
,将抛出目标“build”,如果它发生这种情况并且输入有效,它不会做我的事情,因为 for 循环将按顺序执行。(例如platforms=windows,mac,android
, project.supportedplatforms=ios,android,windows
如果我的列表看起来像这样,是否有任何可能的方法来获得我的结果)。
<for list="${platforms}" param="platformparam" trim="true">
<sequential>
<isItemExists returnProperty="returnProp" platforms="@{platformparam}" />
<if>
<equals arg1="${returnProp}" arg2="true" />
<then>
<antcall target="package.@{platformparam}" />
</then>
</if>
</sequential>
</for>
<macrodef name="isItemExists">
<attribute name="platform" />
<attribute name="returnProperty" />
<sequential>
<var name="@{returnProperty}" unset="true" />
<for list="${project.supportedplatforms}" param="listparam" trim="true">
<if>
<equals arg1="@{listparam}" arg2="@{platform}" />
<then>
<property name="@{returnProperty}" value="true" />
</then>
<else>
<property name="@{returnProperty}" value="false" />
</else>
</if>
</sequential>
</macrodef>
Run Code Online (Sandbox Code Playgroud)
小智 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>
Run Code Online (Sandbox Code Playgroud)
使用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>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4037 次 |
最近记录: |