'How to add fail to ant macrodef
I created a macro to search for a file in a number of directories. That part is working.
Now I'm trying to add fail to the macro if no file is found but this gives me an error
macrodef doesn't support the nested "fail" element.
Is there a way to achieve this ?
<macrodef name="searchfile">
<attribute name="file" />
<attribute name="path" default="${custom.buildconfig},${wst.basedir}" />
<attribute name="name" />
<attribute name="verbose" default="false" />
<sequential>
<first id="@{name}">
<multirootfileset basedirs="@{path}" includes="@{file}" erroronmissingdir="false" />
</first>
<property name="@{name}" value="${toString:@{name}}" />
<echo>property @{name} ${@{name}}</echo>
</sequential>
<fail message="${file}was not found in ${custom.buildconfig},${wst.basedir}">
<condition>
<equals arg1="${@{name}" arg2=""/>
</condition>
</fail>
</macrodef>
Solution 1:[1]
Credits to martin clayton for his comment, moving fail in the sequential fixes the issue.
<macrodef name="searchfile">
<attribute name="file" />
<attribute name="path" default="${custom.buildconfig},${wst.basedir}" />
<attribute name="name" />
<attribute name="verbose" default="false" />
<sequential>
<first id="@{name}">
<multirootfileset basedirs="@{path}" includes="@{file}" erroronmissingdir="false" />
</first>
<property name="@{name}" value="${toString:@{name}}" />
<echo>property @{name}=${toString:@{name}}</echo>
<fail message="@{file} was not found in ${custom.buildconfig},${wst.basedir}, customdir=${customdir}">
<condition>
<equals arg1="${toString:@{name}}" arg2=""/>
</condition>
</fail>
</sequential>
</macrodef>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | carl verbiest |