I need to compare two string args, from which I used to get one arg as runtime input (e.g. platform=windows,ios,mac
) and another one has list of values, defined under build.properties
(e.g. project.supportedplatforms=windows,mac
). If the condition matches, then it should return "true" else "fail" from one macrodef to some 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>
When ${platforms}
and ${project.supportedplatforms}
having same value it should call the specified target. But in this snippets, the macrodef-for loop will executes for n times and at last what the value is assigned for @{returnproperty}
, is going to throw for target "build", if it happens like this with valid input, it will not do my stuff, because for loop will execute in sequential manner. (e.g. platforms=windows,mac,android
, project.supportedplatforms=ios,android,windows
, if my list looks like this means, is there any possible way to get my result).
<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>
<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>
Use sequential
task for running for ant-contrib task like:
<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>
I have an example that returns the time from a call to <tstamp>
Hope this helps!
<macrodef name="gettime">
<attribute name="time-stamp" default=""/>
<sequential>
<tstamp>
<format property="time-stamp" pattern="yyyyMMdd_HHmmss" />
</tstamp>
</sequential>
</macrodef>
<target name="test-time">
<gettime/>
<echo message="${time-stamp}" />
</target>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With