eclipse 如何仅对已修改的文件执行 ANT 任务

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/497850/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 13:30:29  来源:igfitidea点击:

How to execute ANT tasks on only files that have been modified

eclipseant

提问by Akeem

I have a build script that does a number of things (minimize javascript, upload to amazon s3 etc). The minimize ANT task only operates on the javascript that I have modified and ignores the rest (I didn't write this script). I would like to do something similar for the amazon s3 task where only the updated content is upload in the task. Any leads on how to do this would be greatly appreciated.

我有一个构建脚本,可以做很多事情(最小化 javascript,上传到 amazon s3 等)。最小化 ANT 任务仅对我修改过的 javascript 进行操作,而忽略其余部分(我没有编写此脚本)。我想为亚马逊 s3 任务做类似的事情,其中​​只有更新的内容被上传到任务中。任何关于如何做到这一点的线索将不胜感激。

回答by Nathan Strutz

You can select a fileset with a modified date tag. The modified tag is insanely powerful, so check it out: Ant Selectors - Modified.

您可以选择带有修改日期标签的文件集。修改后的标签非常强大,所以请查看:Ant Selectors - Modified

In order for it to tell what has changed, it can keep a cache in a property file, which updates after each successful build, unless you use the delayupdate attribute - so perhaps to test it, you can have:

为了让它知道发生了什么变化,它可以在属性文件中保留一个缓存,在每次成功构建后更新,除非您使用 delayupdate 属性 - 所以也许为了测试它,您可以:

<param name="commitUpdate" value="false" />
[...]
<ftp ...>
    <fileset dir="src">
        <modified delayupdate="${commitUpdate}" />
    </fileset>
</ftp>

And of course you could set that commitUpdate via a command-line param or something.

当然,您可以通过命令行参数或其他方式设置该 commitUpdate。

回答by ricosrealm

You may want to consider the OutOfDateAnt Task provided by the Ant-contrib library. It allows you to set a sequential/parallel task to execute for each source file in a fileset. You can apply a file mapper to define the target files to test the source files against so only the files that have been modified run the specific sequential/parallel task.

您可能需要考虑Ant-contrib 库提供的OutOfDateAnt Task。它允许您为文件集中的每个源文件设置要执行的顺序/并行任务。您可以应用文件映射器来定义目标文件来测试源文件,因此只有经过修改的文件才能运行特定的顺序/并行任务。

Check out this SO thread:

看看这个SO线程:

How to execute an Ant task only when source files have been modified?

如何仅在修改源文件时执行 Ant 任务?

回答by Peter Hilton

In general you can do this for tasks that have source and destination files using File Mappers, so that the task is only applied to source files that have changed. I don't know if there's a way to do something where Ant cannot see the destination files, like uploading.

通常,您可以使用File Mappers对具有源文件和目标文件的任务执行此操作,以便该任务仅应用于已更改的源文件。我不知道是否有办法在 Ant 无法看到目标文件的情况下执行某些操作,例如上传。

回答by Olaf Kock

Provided you don't want to change/rewrite the S3 task and want to stay purely in XML, you could use the Uptodate Taskand a shadow directory to mimic this behaviour - e.g. keep a copy of your uploads (potentially huge) or just an empty file with the creation date of the last time you uploaded. The examples on the manual page should provide a lot of hints where to go.

如果您不想更改/重写 S3 任务并希望完全保留在 XML 中,您可以使用Uptodate 任务和影子目录来模仿这种行为 - 例如保留您上传的副本(可能很大)或只是一个创建日期为上次上传的空文件。手册页上的示例应该提供很多提示。

Of course you could write your own S2Uptodate task as well, connecting to S3 to compare the dates. The preferred solution depends upon how many files there are (e.g. a few huge ones where you'd be able to check each one in a distinct operation or a near infinite number of small ones that you'd tackle differently.

当然,您也可以编写自己的 S2Uptodate 任务,连接到 S3 以比较日期。首选的解决方案取决于有多少文件(例如,您可以在不同的操作中检查每个文件的几个大文件,或者您可以以不同方式处理的几乎无限数量的小文件。

You might also get inspired by the Xjc task's usage of and elements, though this of course operates purely on local files.

您可能还会受到Xjc 任务对 和 元素的使用的启发,尽管这当然纯粹是对本地文件进行操作。