Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active December 20, 2015 07:38
Show Gist options
  • Save dacr/6094303 to your computer and use it in GitHub Desktop.
Save dacr/6094303 to your computer and use it in GitHub Desktop.
A scala script that counts the number of lines in source code files
#!/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")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment