如何添加失败到ant macrodef

发布于 2025-01-25 17:14:30 字数 970 浏览 4 评论 0原文

我创建了一个宏来搜索许多目录中的文件。那部分在起作用。

现在,如果找不到文件,我正在尝试将宏添加到宏中,但这给了我一个错误 macrodef不支持嵌套的“失败”元素。

有没有办法实现这一目标?

<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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

祁梦 2025-02-01 17:14:30

信用马丁·克莱顿(Martin Clayton)发表评论,在顺序解决该问题的情况下移动失败。

   <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>

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文