I have a build which has a task to copy a src directory to a target directory. We use perforce as our source code repository, which means that unless we have checked out a file for editing, it will be marked as read-only. By default, the Copy task preserves permissions, so the target files will be read only. But, if we checkout the source file and edit it and rerun this gradle task, we will get an exception, because we can’t overwrite the file marked as read only.
I initially worked around this by adding fileMode 777 to the copy task. But this is not ideal, as it then marks the files as executable.
I would rather implement some kind of java solution where I can essentially mimic unix ‘chmod +w file’
I thought I could do by passing eachFile a closure in the copy task. But this is having unexpected results.
Here is a code snip –
// this is in a custom plugin I'm writing
project.task([type: Copy], "customTask") {
from {"${project.devops.confSrcDir}" }
into { "${project.devops.confTgtDir}" }
eachFile { details ->
println "${details.mode} ${details.name}"
}
}
Right now, my eachFile is not doing anything other than displaying the mode, but that is where I get weird results –
Here are the permissions of some source files:
-r-xr-xr-x
conf/client-config.wsdd
-r--r--r--
conf/client_sign.properties
-r--r--r--
conf/bin_ranges.txt
-rw-r--r--
conf/dummy.txt
And here is what gets displayed when I run my build:
365 client-config.wsdd
292 client_sign.properties
292 bin_ranges.txt
420 dummy.txt
I would think I would get the following results:
555 client-config.wsdd
444 client_sign.properties
444 bin_ranges.txt
644 dummy.txt
For what its worth, I’m on gradle 1.4 on mac running 1.6.0.43
Are unix file modes working correctly in Gradle?
Thanks.