使用 Ant 获取包含修改文件的目录 [英] Get directories with modified files with Ant

查看:22
本文介绍了使用 Ant 获取包含修改文件的目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果目录中至少有一个修改过的文件,我需要对其进行处理.我写了一个块,将文件集缩减为包含这些文件的目录的唯一列表,但我认为如果有一种没有脚本的方法来做到这一点会更容易.

I need to process a directory if it has at least one modified file in it. I wrote a block that reduces a fileset to a unique list of the directories that contain those files, but I think this would be easier if there was a way to do this without the script.

有办法吗?

推荐答案

使用核心 ANT 很难做到这一点.

Tricky to do this with core ANT.

以下是使用嵌入式 groovy 脚本的示例:

Here's an example using an embedded groovy script:

<project name="demo" default="process-modified-dirs">

    <path id="build.path">
        <pathelement location="/path/to/groovy-all/jar/groovy-all-2.1.1.jar"/>
    </path>

    <fileset id="modifiedfiles" dir="src">
        <modified/>
    </fileset>

    <target name="process-modified-dirs">
        <taskdef name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpathref="build.path"/>
        <groovy>
            dirs = project.references.modifiedfiles.collect {
                new File(it.toString()).parent
            }

            dirs.unique().each {
                ant.echo("Do something with this dir: ${it}")
            }
        </groovy>
    </target>

</project>

这篇关于使用 Ant 获取包含修改文件的目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆