ANT:缺少资源时强制发生错误?
我继承了一个包含许多资源的 Ant 构建系统 像这样设置定义:
<files id="app1.lib.jars">
<include name="${java}/jre/lib/jsse.jar"/>
<include name="${work.lib}/jtidy.jar"/>
...
</files>
<files id="app2.lib.jars">
<include name="${work.lib}/itext.jar"/>
<include name="${work.lib}/commons-httpclient.jar"/>
...
</files>
<files id="app3.lib.jars">
<include name="${work.lib}/jdom.jar"/>
<include name="${ant.lib}/ant.jar"/>
...
</files>
可能有十几个这样的定义,每个都可以包含以下任意位置 5 到 50 个文件。问题是我正在重新设计这个系统以使用 Ivy 用于依赖管理,并在此过程中进行一些 引用现在指向不存在的文件。不幸的是,蚂蚁 不提供任何帮助来查找这些坏指针。当这些资源 集合用于定义任何
标签的类路径 指向丢失文件的指向将被默默忽略。
我认为我可以通过使用集合作为强制错误
的来源,但即使使用 failonerror="true"
它也只是 忽略了错误的引用。
命令行 -v
(详细)和 -d
(调试)选项没有帮助 任何一个。输出承认有些缺失,但没有 实际上向他们展示了
[echo] app1.lib.jars
[copy] C:\dev\src\tomcat6\work\java\jre\lib\jsse.jar omitted as C:\dev\src\tomcat6\work\verify\jsse.jar is up to date.
[copy] C:\dev\src\tomcat6\work\lib\axis-ant.jar omitted as C:\dev\src\tomcat6\work\verify\axis-ant.jar is up to date.
...
[copy] No sources found.
[echo] app2.lib.jars
...
作为一次性解决方案,我从 Ant 文件中的资源集并将其与目录列表进行比较 将所有文件(在 Ant 中)复制到临时文件中的结果 目录,经过适当的排序。
问题:有没有办法让 Ant 在资源指向时告诉我 丢失的文件,最好是在定义资源时?
I've inherited an Ant build system that contains many resource
set definitions like this:
<files id="app1.lib.jars">
<include name="${java}/jre/lib/jsse.jar"/>
<include name="${work.lib}/jtidy.jar"/>
...
</files>
<files id="app2.lib.jars">
<include name="${work.lib}/itext.jar"/>
<include name="${work.lib}/commons-httpclient.jar"/>
...
</files>
<files id="app3.lib.jars">
<include name="${work.lib}/jdom.jar"/>
<include name="${ant.lib}/ant.jar"/>
...
</files>
There are perhaps a dozen of these, and each can contain anywhere from
5 to 50 files. The problem is that I'm reworking this system to use
Ivy for dependency management, and in the process some of the
references now point to non-existent files. Unfortunately, Ant does
not provide any help finding these bad pointers. When these resource
collections are used to define a classpath any <include...>
tags
pointing to missing files are silently ignored.
I thought I could force an error by using the collections as the
source of a <copy...>
, but even with failonerror="true"
it just
ignored the bad references.
The command-line -v
(verbose) and -d
(debug) option didn't help
either. The output acknowledged that some were missing but didn't
actually show them
[echo] app1.lib.jars
[copy] C:\dev\src\tomcat6\work\java\jre\lib\jsse.jar omitted as C:\dev\src\tomcat6\work\verify\jsse.jar is up to date.
[copy] C:\dev\src\tomcat6\work\lib\axis-ant.jar omitted as C:\dev\src\tomcat6\work\verify\axis-ant.jar is up to date.
...
[copy] No sources found.
[echo] app2.lib.jars
...
For a one-time solution I extracted all the filenames from the
resource sets in the Ant file and compared that to a directory listing
of the result of copying all the files (in Ant) into a temporary
directory, after appropriate sorting.
Question: Is there a way to get Ant to tell me when a resource points
to a missing file, preferably at the time the resource is defined?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
下面是一种方法的说明。要点 将
文件
转换为文件列表 - 这些可以包含文件系统中不存在的文件的名称,与文件集和文件不同,它们会忽略不存在的条目fail
来出错您需要添加“antlib:org.apache .tools.ant.types.resources.selectors”命名空间到项目中以使用如下所示的资源选择器。使用早于 1.7.0 的 Ant 版本时您会遇到麻烦。
或者,您可以按照您的建议使用“复制”任务,但使用文件列表而不是文件。
当尝试处理第一个不存在的资源时,副本应该失败。
Here's an illustration of one method. Key points
files
to filelists - these can contain names of files that don't exist in the file system, unlike filesets and files, that ignore entries that don't existfail
to error when something is missingYou'll need to add the "antlib:org.apache.tools.ant.types.resources.selectors" namespace to the project to use the resource selectors shown below. You'll hit snags with Ant versions older than 1.7.0.
Alternatively, you could use the 'copy' task, as you suggest, but with filelists instead of files.
The copy should fail when it tries to process the first resource that doesn't exist.