Get directories with modified files with Ant

一曲冷凌霜 提交于 2019-12-11 08:36:03

问题


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.

Is there a way?


回答1:


Tricky to do this with core ANT.

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>


来源:https://stackoverflow.com/questions/15688346/get-directories-with-modified-files-with-ant

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!