How can I get all the from() specifications that were passed to a CopySpec?


(Gabriele Del Prete) #1

For esample, assume I did this:

task copyMethod << {
    copy {
        from 'src/main/webapp'
        from 'mydir1'
        from 'mydir2'
        into 'build/explodedWar'
    }
}

… how can I get a collection containing ‘src/main/webapp’, ‘mydir1’, ‘mydir2’ ?


(Justin Ryan) #2

Technically that’s not a copy task, you’d want to define it as:

def copytask = task copyMethod(Copy) {
        from 'src/main/webapp'
        from 'mydir1'
        from 'mydir2'
        into 'build/explodedWar'
}

Then you can iterate over the spec as such (from a unit test):

copytask.rootSpec.allSpecs.find { CopySpecImpl csi ->

println “Looking at spec Source: ${csi.sourcePaths} Dest: ${csi.destPath}”

csi.sourcePaths.contains(project.file(‘application.properties.template’)) &&

csi.destPath.pathString == ‘application.properties’

}


(Simon McClenahan) #3

In Gradle 1.8 I’m getting an error:

No such property: allSpecs for class: org.gradle.api.internal.file.copy.DefaultCopySpec_Decorated