在Ant中的macrodef内复制后的空文件集

时间:2016-09-30 15:54:23

标签: ant

我整天都在靠墙撞击我的头!

在下面的宏中,我总是以一个空文件集结束:

<macrodef name="gzipAndUploadFileset">
    <attribute name="mimeType"/>
    <element name="fileset"/>
    <sequential>

        <delete dir="${staging}" />

        <copy toDir="${staging}">
            <fileset refid="fileset"/>
        </copy>

        <fileset id="sfs" dir="${staging}" includes="**/*"/>

        <echo>
            ${staging}
            ${ant.refid:sfs}
        </echo>
    </sequential>
</macrodef>

设置了staging属性,并在复制操作后填充了50多个文件。

这就是echo&#39; d:

    [echo]              /path/to/staging
    [echo]              ${ant.refid:sfs}

我认为这意味着&#34; sfs&#34; fileset为空。我在includes中添加了以查看该显式设置是否拾取了文件...但没有。

我试图在复制后进入睡眠状态,以防复制任务没有阻止。没有帮助。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

您应该使用与现有ant任务相同的名称命名宏元素。我建议您将fileset元素重命名为files,例如:

<macrodef name="gzipAndUploadFileset">
    <attribute name="mimeType"/>
    <element name="files"/>

    <sequential>

    <delete dir="${staging}" />

    <copy toDir="${staging}">
        <files/>
    </copy>

    <fileset id="sfs" dir="${staging}" includes="**/*"/>

    <echo>
        ${staging}
        ${ant.refid:sfs}
    </echo>
</sequential>

您可以将files元素视为占位符,在执行宏时将其替换为内容(请参阅macroDef)。 现在你可以像这样调用你的宏:

<target name="testmacro">
    <gzipAndUploadFileset mimeType="application/x-gzip">
        <files>
            <fileset dir="src">
                 <includes name="**/*"/>
            </fileset>
        <files>
</target>
相关问题