Created
August 16, 2011 00:07
-
-
Save mathieucarbou/1148180 to your computer and use it in GitHub Desktop.
Subversion recursive update in Groovy using Java 7 Fork/Join framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env groovy | |
import java.util.concurrent.ForkJoinPool | |
import java.util.concurrent.RecursiveAction | |
import java.util.concurrent.TimeUnit | |
def root = (args && args[0] ? args[0] : '.' as File).canonicalFile | |
def cpus = Runtime.runtime.availableProcessors() | |
println "Updating all projects in ${root}..." | |
println "Working threads: ${cpus}" | |
class Updater extends RecursiveAction { | |
File dir | |
Updater(File dir) { | |
this.dir = dir | |
} | |
protected void compute() { | |
if (dir.isDirectory()) { | |
if (new File(dir, '.svn').exists()) { | |
dir = dir.canonicalFile | |
['svn', 'cleanup', '--non-interactive', dir.path].execute().waitFor() | |
Process proc = ['svn', 'up', '--non-interactive', dir.path].execute() | |
println "[${Thread.currentThread().name}] Updating project ${dir} ...\n${proc.waitFor() != 0 ? proc.err.text : proc.in.text}" | |
} else { | |
def tasks = dir.listFiles({dir.isDirectory()} as FileFilter).collect({new Updater(it)}) | |
if (tasks) invokeAll(tasks) | |
} | |
} | |
} | |
} | |
ForkJoinPool pool = new ForkJoinPool(cpus); | |
pool.invoke(new Updater(root)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Blog entry: http://blog.mycila.com/2011/08/subversion-recursive-update-with-java-7.html