ANT:缺少资源时强制发生错误?

发布于 2024-08-11 22:58:15 字数 1411 浏览 2 评论 0原文

我继承了一个包含许多资源的 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 技术交流群。

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

发布评论

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

评论(1

无名指的心愿 2024-08-18 22:58:15

下面是一种方法的说明。要点 将

  • 您的文件转换为文件列表 - 这些可以包含文件系统中不存在的文件的名称,与文件集和文件不同,它们会忽略不存在的条目
  • 使用 restrict 检查是否存在
  • 当缺少某些内容时使用 fail 来出错

您需要添加“antlib:org.apache .tools.ant.types.resources.selectors”命名空间到项目中以使用如下所示的资源选择器。使用早于 1.7.0 的 Ant 版本时您会遇到麻烦。

<project name="so" default="checkfiles" basedir="."
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">

<filelist id="app1.lib.jars">
  <file name="${java}/jre/lib/jsse.jar"/>
  <file name="${work.lib}/jtidy.jar"/>
  ...
</filelist>

<restrict id="missing.app1.lib.jars">
  <filelist refid="app1.lib.jars"/>
  <rsel:not>
    <rsel:exists/>
  </rsel:not>
</restrict>

<property name="missing.files" refid="missing.app1.lib.jars" />
<fail message="These files are missing: ${missing.files}">
  <condition>
    <length string="${missing.files}" when="greater" length="0" />
  </condition>
</fail>
<pathconvert property="found.files" refid="app1.lib.jars" />
<echo message="Found files ${found.files}" />

或者,您可以按照您的建议使用“复制”任务,但使用文件列表而不是文件。
当尝试处理第一个不存在的资源时,副本应该失败。

Here's an illustration of one method. Key points

  • Convert your 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 exist
  • Use a restrict to check for existence
  • Use a fail to error when something is missing

You'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.

<project name="so" default="checkfiles" basedir="."
xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors">

<filelist id="app1.lib.jars">
  <file name="${java}/jre/lib/jsse.jar"/>
  <file name="${work.lib}/jtidy.jar"/>
  ...
</filelist>

<restrict id="missing.app1.lib.jars">
  <filelist refid="app1.lib.jars"/>
  <rsel:not>
    <rsel:exists/>
  </rsel:not>
</restrict>

<property name="missing.files" refid="missing.app1.lib.jars" />
<fail message="These files are missing: ${missing.files}">
  <condition>
    <length string="${missing.files}" when="greater" length="0" />
  </condition>
</fail>
<pathconvert property="found.files" refid="app1.lib.jars" />
<echo message="Found files ${found.files}" />

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.

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