How to execute ANT tasks on only files that have b

2019-01-25 05:58发布

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.

标签: eclipse ant
4条回答
爷、活的狠高调
2楼-- · 2019-01-25 06:00

Provided you don't want to change/rewrite the S3 task and want to stay purely in XML, you could use the Uptodate Task and 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.

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.

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

查看更多
淡お忘
3楼-- · 2019-01-25 06:15

You may want to consider the OutOfDate Ant 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.

Check out this SO thread:

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

查看更多
冷血范
4楼-- · 2019-01-25 06:16

You can select a fileset with a modified date tag. The modified tag is insanely powerful, so check it out: 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:

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

查看更多
来,给爷笑一个
5楼-- · 2019-01-25 06:17

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.

查看更多
登录 后发表回答