Skip to content

Instantly share code, notes, and snippets.

@llibra
Last active December 17, 2015 12:39
Show Gist options
  • Save llibra/5611751 to your computer and use it in GitHub Desktop.
Save llibra/5611751 to your computer and use it in GitHub Desktop.
ファイル先頭のコピーライト表記をチェックするために書いた書き捨て系スクリプト
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