一段用于统计原代码行数的scala脚本
#!/bin/sh exec /opt/analysis/analysis "$0" "$@" !# import scalax.file._ import scalax.file.ImplicitConversions._ val dirs = if (args.size>0) args.toList else List(".") val exts = List( "scala","xml","drl","java","ksh","sh","sql","sbt","properties","conf" ) val excludes = List( "/examples/", "/target/").map(_.r) case class Result(source:Path, from:String) { lazy val lines = source.lines().size val ext = source.name.split("[.]").last } val sources:List[Result] = for { dir <- dirs found <- (dir ** "*.*").filter(_.isFile).toList if !excludes.exists(_.findFirstIn(found.path).isDefined) if exts.exists(ext => found.name.endsWith("."+ext)) } yield Result(found, dir) def showstat4(sources:List[Result], title:String) { println("----------------------------") println(title) val lines=sources.map(_.lines).sum println(s"global lines count : $lines (in ${sources.size} files)") for { (ext, sources4ext) <- sources.groupBy(_.ext) } { val count = sources4ext.map(_.lines).sum println(s"lines count for $ext : $count (in ${sources4ext.size} files)") } } showstat4(sources, "All directories") for {(dir, sources4dir) <- sources.groupBy(_.from) if dirs.size>1 } showstat4(sources4dir, s"For directory : $dir")