如何检查 Ant 构建中是否存在一组文件?

发布于 2024-09-26 19:19:43 字数 733 浏览 6 评论 0 原文

我想知道是否有一种方法可以使用 Ant 检查磁盘上是否有多个文件可用。 目前,我有一个如下所示的任务:

<target name="copyArtworkToOutputDir" if="artworkContent">
  <copy todir="${imageOutputDir}" failonerror="true">
    <fileset dir="${sourceDir}" includesfile="${buildDir}/artworklist"/>
  </copy>
</target>

“artworklist”是在构建之前创建的文件列表。我可以将其作为文件集传递给“复制”任务,并且我应该最终得到一个包含列表中所有文件的文件夹。不幸的是,有时这不起作用,并且由于缺少资源,构建可能会在后续步骤中急剧失败。

我尝试将 'failonerror' 设置为 true,希望如果 artworklist 中指定的文件在源位置不存在,它会抛出异常。无论出于何种原因,这似乎并不像我预期的那样工作。

因此,我的下一个想法是使用“可用”任务之类的东西来验证艺术品列表的内容现在存在于输出位置。不过,可用似乎仅限于单个文件。所以我在这里也有点死胡同。

有人可以建议一种方法,让我可以验证复制后我期望在 ${buildDir} 中的所有文件是否确实存在吗?此时,我正在考虑自定义 Ant 任务,但也许有更明显的东西。

I'm wondering if there's a way to, using Ant, check if several files are available on disk.
Currently, I have a task that looks like this:

<target name="copyArtworkToOutputDir" if="artworkContent">
  <copy todir="${imageOutputDir}" failonerror="true">
    <fileset dir="${sourceDir}" includesfile="${buildDir}/artworklist"/>
  </copy>
</target>

'artworklist' is a list of files created earlier in the build. I can pass it as a fileset to the 'copy' task, and I should end up with a folder that contains all of the files in the list. Unfortunately, sometimes that doesn't work, and builds can fail dramatically at a later step because of a missing resource.

I've tried setting 'failonerror' to true in the hope that it will throw an exception if a file specified in the artworklist doesn't exist in the source location. For whatever reason this doesn't seem to work as I expect.

So, my next thought was to use something like the 'available' task to validate that the contents of the artwork list now exist at the output location. Available seems to be restricted to single files though. So I dead-ended a bit here too.

Can someone suggest a way that I can verify that all of the files that I expect to be in ${buildDir} after the copy are actually there? At this point, I'm thinking of a custom Ant task, but maybe there's something more obvious.

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

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

发布评论

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

评论(1

陌上芳菲 2024-10-03 19:19:43

不要使用文件集(它只包含文件系统中确实存在的文件,并默默地忽略那些不存在的文件),而是尝试使用文件列表。文件列表可以包含文件系统中不存在的文件,因此可以用于您的检查 - 当 Ant 尝试处理文件列表中不存在的文件时,它会抛出错误。

小例子:

<filelist
    id="artworkfiles"
    dir="${src.dir}"
    files="foo.xml,bar.xml"/>

<copy todir="${dest.dir}" failonerror="true" >
    <filelist refid="artworkfiles" />
</copy>

...
BUILD FAILED
build.xml:14: Warning: Could not find resource file ".../src/bar.xml" to copy.

$ ls src
foo.xml    # No bar.xml in src dir.

Rather than using a fileset, which will only include files that do exist in the file system, and silently ignore those that don't, try a filelist. Filelists can contain files that don't exist in the file system, so can be used for your check - Ant will throw an error when it tries to process a non-existent file in the filelist.

Small example:

<filelist
    id="artworkfiles"
    dir="${src.dir}"
    files="foo.xml,bar.xml"/>

<copy todir="${dest.dir}" failonerror="true" >
    <filelist refid="artworkfiles" />
</copy>

...
BUILD FAILED
build.xml:14: Warning: Could not find resource file ".../src/bar.xml" to copy.

$ ls src
foo.xml    # No bar.xml in src dir.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文