Skip to content

Instantly share code, notes, and snippets.

@mlist
Created May 8, 2013 08:06
Show Gist options
  • Save mlist/5538956 to your computer and use it in GitHub Desktop.
Save mlist/5538956 to your computer and use it in GitHub Desktop.
Add license header to each groovy file in a folder using a groovy script
import static groovy.io.FileType.*
import static groovy.io.FileVisitResult.*
def headerFile = new File("/home/markus/Projects/olf_gpl3_license.txt")
def headerLines = headerFile.readLines()
def sourcebase = new File("/home/markus/Projects/OpenLabFramework")
sourcebase.traverse(
type : FILES,
nameFilter : ~/.*\.groovy/,
preDir : { if (it.name == '.svn' || it.name == '.idea' || it.name == '.git') return SKIP_SUBTREE }
) { f ->
def lines = f.readLines()
if (lines.size() < headerLines.size()) println "$f.name rejected: insufficient size"
for (int i in 0..<headerLines.size()) {
if (!(lines[i] ==~ headerLines[i])) {
println "Mismatch at line ${i+1} of $f.canonicalPath\n expect:${headerLines[i]}\n actual:${lines[i]}"
println "Adding file header..."
f.text = headerFile.text + f.text
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment