Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy tree with gradle and change structure?

Can gradle alter the structure of the tree while copying?

original

  • mod/a/src
  • mod/b/src

desired

  • dest/mod-a/source
  • dest/mod-b/source
  • dest/mod-c/source

I'm not sure where I should create a closure and override the copy tree logic

I'd like to do the gradle equivalent of ant's globmapper functionality

<property name="from.dir" location=".."/>      
<property name="to.dir" location="dbutil"/>
<copy>
    <fileset dir="${from.dir}" ... />
    <globmapper from="${from.dir}/*/db" to="${to.dir}"/> 
</copy>

Thanks

Peter

like image 731
Peter Kahn Avatar asked Nov 08 '12 20:11

Peter Kahn


1 Answers

When changing file name, rename seems a good approach. When changing path you can override eachFile and modify the destination path.

This works pretty well.

    copy {
    from("${sourceDir}") {
        include 'modules/**/**'
    }
    into(destDir)
    eachFile {details ->

        // Top Level Modules
        def targetPath = rawPathToModulesPath(details.path)
        details.path = targetPath
    }
}
....
def rawPathToModulesPath(def path) {
// Standard case modules/name/src -> module-name/src
def modified=path.replaceAll('modules/([^/]+)/.*src/(java/)?(.*)', {"module-${it[1]}/src/${it[3]}"})
return modified
}
like image 129
Peter Kahn Avatar answered Oct 19 '22 23:10

Peter Kahn