1

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?

Ray Wadkins
  • 876
  • 1
  • 7
  • 16
  • http://stackoverflow.com/questions/12111282/can-i-conditionally-stop-an-ant-script-based-on-file-last-modified-time , http://stackoverflow.com/questions/8215089/use-ant-modified-selector-with-arbitrary- – Jayan Mar 29 '13 at 01:29
  • Jayan, thanks for the links, but I already know how to get a list of modified files. What I can't figure out is how to reduce this list to a unique list of directories that contain those files (without a script). – Ray Wadkins Apr 01 '13 at 21:03

1 Answers1

0

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>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • Thanks, I have a – Ray Wadkins Apr 01 '13 at 21:04