Ant-如何比较字符串列表?

时间:2014-06-11 10:08:26

标签: ant

 <target name="build">
 <for list="${platform}" param="platform" trim="true">
 <sequential>
 <if>
 <equals arg1="${platform}" arg2="${project.SuppoortedPlatforms}" />
 <then>
 <antcall target="package.${platform}" />
 </then>
 </if>
 </sequential>
 </for>
 </target>

我在运行时获取平台值(例如:windows,ios)和project.SuppoortedPlatforms在build.properties下声明(例如:android,ios)。我该如何比较字符串列表? 谁能帮我解决这个问题?

谢谢, sandhiya

2 个答案:

答案 0 :(得分:1)

您正在循环使用逗号分隔的平台列表,并且每个平台都会检查它是否包含在project.SuppoortedPlatforms中支持的平台列表中。这应该是这样的:

<for list="${platform}" param="platformParam" trim="true">
    <sequential>
    <if>
       <contains string="${project.SuppoortedPlatforms}" substring="@{platformParam}" />
        <then>
          <antcall target="package.@{platformParam}" />
        </then>
      </if>
       </sequential>
     </for>

应使用@代替$来访问循环中的参数。此外,最好重命名参数以提高可读性(platformParam而不是platform)。

答案 1 :(得分:0)

  Instead of using contains task, i myself tried with the nested for loop, its cool working fine. 


  <for list="${platforms}" param="platformparam" trim="true">
 <sequential>
    <for list="${project.SupportedPlatforms}" param="supplatformparam" trim="true">
    <sequential>
        <if>
        <equals arg1="@{platformparam}" arg2="@{supplatformparam}" />
        <then>
            <antcall target="package.@{platformParam}" />
        </then>
        </if>
    </sequential>
    </for>
</sequential>
</for>
相关问题