<foreach> 下的 <param> 不支持嵌套文件集元素

<param> under <foreach> doesn't support nested fileset element

我正在尝试执行一项应该遍历一组文件的任务。为此,我正在使用 ant-contrib-0.3.jar 中的 foreach 任务。问题是我试图将(作为参数)传递给目标而不是文件路径,而是文件目录路径。

这是项目:

<project basedir="../../../" name="do-report" default="copy-all-unzipped">
    <xmlproperty keeproot="false" file="implementation/xml/ant/text-odt-properties.xml"/>
    <!--    -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties">
        <classpath>
            <pathelement location="${path.infrastructure}/apache-ant-1.9.6/lib/ant-contrib-0.3.jar"/>
        </classpath>
    </taskdef>
    <!--    -->
    <target name="copy-all-unzipped">
        <foreach target="copy-unzipped">
            <param name="file-path">
                <fileset dir="${path.unzipped}">
                    <include name="**/content.xml"/>
                </fileset>
            </param>
        </foreach>
    </target>
    <!--    -->
    <target name="copy-unzipped">
        <echo>${file-path}</echo>
    </target>
</project>

运行 脚本我收到以下消息:

BUILD FAILED

C:\Users\rmrd001\git\xslt-framework\implementation\xml\ant\text-odt-build.xml:13: param doesn't support the nested "fileset" element.

我可以在互联网上的几个地方(例如 axis.apache.org)读到 param 可以有一个嵌套的 fileset 元素。

请参阅 http://ant-contrib.sourceforge.net/tasks/tasks/foreach.html 了解如何使用 foreachparam 必须是 属性 而不是嵌套元素:

<target name="copy-all-unzipped">
    <foreach target="copy-unzipped" param="file-path">
        <fileset dir="${path.unzipped}">
            <include name="**/content.xml"/>
        </fileset>
    </foreach>
</target>

您 link <foreach> 的示例来自 Apache Axis 1.x Ant tasks project. This is a different <foreach> than the one from the Ant-Contrib 项目。

正如 manouti 所说,Ant-Contrib <foreach> 不支持嵌套的 param 元素。相反,<fileset>id 可以传递给 <target> 并且 <target> 可以引用 id.

或者,您可以使用 Ant-Contrib 的 <for> task (not "<foreach>") which can call a <macrodef>...

<target name="copy-all-unzipped">
    <for param="file">
        <path>
            <fileset dir="${path.unzipped}">
                <include name="**/content.xml"/>
            </fileset>
        </path>
        <sequential>
            <copy-unzipped file-path="@{file}"/>
        </sequential>
    </for>
</target>

<macrodef name="copy-unzipped">
    <attribute name="file-path"/>
    <sequential>
        <echo>@{file-path}</echo>
    </sequential>
</macrodef>