Ant -how can I return a value from a macrodef?

I need to compare two string arguments from which I used to get one argument as a run-time input (e.g., platform=windows,ios,mac), and the other has a list of values ​​defined in build.properties(e.g., project.supportedplatforms=windows,mac). If the condition is met, then it should return "true" else "fail" from one macrodef to any target.

<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} ${project.supportedplatforms} , . macrodef-for n , , , @{returnproperty}, "", , , , . (, 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>
+4
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

Source: https://habr.com/ru/post/1544303/


All Articles