我想知道是否有一种方法可以使用 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.
发布评论
评论(1)
不要使用
文件集
(它只包含文件系统中确实存在的文件,并默默地忽略那些不存在的文件),而是尝试使用文件列表
。文件列表可以包含文件系统中不存在的文件,因此可以用于您的检查 - 当 Ant 尝试处理文件列表中不存在的文件时,它会抛出错误。小例子:
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 afilelist
. 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: