Created
May 8, 2013 08:06
-
-
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
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
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