拥有真正的“文件任务”的最简单方法在 ANT

发布于 2024-08-09 18:09:02 字数 801 浏览 1 评论 0原文

我仍在学习如何很好地使用 ANT,我想了解是否有一些合理的方法可以在其中执行文件任务,类似于 Rake 和 Make:

http://martinfowler.com/articles/rake.html#FileTasks

“对于文件,您引用的是实际文件而不是任务名称。 dev/rake.html' 和 'dev/rake.xml' 是实际文件,html 文件是此任务的输出,xml 文件是输入,您可以将文件任务视为告诉构建系统如何生成。输出文件 - 实际上这正是 make 中的概念 - 您列出所需的输出文件并告诉 make 如何生成它们,

文件任务的一个重要部分是除非您需要运行它,否则它不会运行构建系统。查看文件,并且仅在输出文件不存在或其修改日期早于输入文件时才运行任务,因此当您逐个文件考虑问题时,文件任务非常有效。”

换句话说,假设我想运行一个自定义二进制文件,并且我只希望在任何文件发生更改时运行该二进制文件。这与这个 问题,但我根本不想运行二进制文件,而不仅仅是传递文件集的一部分(即文件集中只有一个,我根本不想运行该工具)。

理想的解决方案也不会是一件很麻烦的事情,而是可以轻松应用于任何目标——也许使用一些 ANT JavaScript 或自定义任务?

I am still learning how to use ANT well, and I wanted to understand if there is some reasonable way to do file tasks in it, similar to Rake and Make:

http://martinfowler.com/articles/rake.html#FileTasks

"With a file you are referring to actual files rather than task names. So 'build/dev/rake.html' and 'dev/rake.xml' are actual files. The html file is the output of this task and the xml file is the input. You can think of a file task as telling the build system how to make the output file - indeed this is exactly the notion in make - you list the output files you want and tell make how to make them.

An important part of the file task is that it's not run unless you need to run it. The build system looks at the files and only runs the task if the output file does not exist or it's modification date is earlier than the input file. File tasks therefore work extremely well when you're thinking of things at a file by file basis."

So in other words, let's say I want to run a custom binary and I only want that binary to run if any of the files have changed. This is related to this question, but I don't want to run the binary at all, not only pass a part of the fileset (i.e. there is only one in the fileset and I don't want the tool to run at all).

The ideal solution would also not be a loooong thing, but rather could be easily applied to any target -- perhaps using some ANT JavaScript or custom task?

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

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

发布评论

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

评论(1

陈独秀 2024-08-16 18:09:02

使用 ant-contrib 过时任务。它完全具有您所要求的属性。这是 ant-contrib 网站

以下是有关如何将其集成到您的构建中的模板:

<taskdef
  resource="net/sf/antcontrib/antlib.xml"
>
  <classpath>
    <pathelement location="${ant-contrib.jar}"/>
</taskdef>

<outofdate>
 <sourcefiles path="dev/rake.xml"/>
 <targetfiles path="build/dev/rake.html"/>
 <sequential>
   ... do your work here ...
   ... will only run if rake.html is older than rake.xml ...
 </sequential>
</outofdate>

Use ant-contrib outofdate task. It has exactly the properties you are asking for. Here is ant-contrib website.

Here is a template on how to integrate it into your build:

<taskdef
  resource="net/sf/antcontrib/antlib.xml"
>
  <classpath>
    <pathelement location="${ant-contrib.jar}"/>
</taskdef>

<outofdate>
 <sourcefiles path="dev/rake.xml"/>
 <targetfiles path="build/dev/rake.html"/>
 <sequential>
   ... do your work here ...
   ... will only run if rake.html is older than rake.xml ...
 </sequential>
</outofdate>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文