Last active
December 17, 2015 12:39
-
-
Save llibra/5611751 to your computer and use it in GitHub Desktop.
ファイル先頭のコピーライト表記をチェックするために書いた書き捨て系スクリプト
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 scala.io.Source | |
import java.io.File | |
def isJavaSource (f: File) : Boolean = { | |
val r = "\\.java$".r | |
r.findFirstIn(f.getName) match { | |
case Some(_) => true | |
case None => false | |
} | |
} | |
def isCopyrighted (f: File) : Boolean = { | |
val src = Source.fromFile(f, "UTF-8") | |
try { | |
val lines = src.getLines | |
val r = "^/\\*\\*".r | |
r.findFirstIn(lines.next) match { | |
case Some(_) => true | |
case None => false | |
} | |
} | |
finally { | |
src.close | |
} | |
} | |
def rec(file: File, fn: File => Unit) { | |
file.listFiles.foreach { f => | |
if (f.isDirectory) { | |
rec(f, fn) | |
} else { | |
fn(f) | |
} | |
} | |
} | |
val root = new File(args.apply(0)) | |
rec(root, { f => | |
if (isJavaSource(f) && !isCopyrighted(f)) { | |
println(f.getPath) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment