Skip to content

Instantly share code, notes, and snippets.

@mathieucarbou
Created August 16, 2011 00:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mathieucarbou/1148180 to your computer and use it in GitHub Desktop.
Save mathieucarbou/1148180 to your computer and use it in GitHub Desktop.
Subversion recursive update in Groovy using Java 7 Fork/Join framework
#!/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));
@mathieucarbou
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment