Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package utils
- import java.io.File
- import com.google.common.base.Charsets
- import com.google.common.io.Files
- import scala.io.Source
- /**
- * main
- * Created by sjk on 1/24/17.
- */
- object StatisticUT {
- def main(args: Array[String]): Unit = {
- val dir = new File("/Users/sjk/g/flink/")
- val ret = listFiles(dir)
- showTestFiles(ret, dir)
- println(countLine(ret))
- }
- def showTestFiles(list: Set[File], home: File): Unit = {
- val abs = home.getAbsolutePath
- val test = list
- .filter(_.getAbsolutePath.contains("src/test"))
- .toArray
- .sortBy(_.getAbsolutePath)
- .map(f => {
- val p = f.getAbsolutePath.replace(abs + "/", "")
- p.substring(0, p.indexOf("/")) + " " + f.getAbsolutePath
- })
- val txt =
- s"""
- |total files: ${test.length}
- |${test.mkString("\n")}
- """.stripMargin
- println(txt)
- Files.write(txt, new File(home.getParent, "test_files.txt"), Charsets.UTF_8)
- }
- def countLine(list: Set[File]): Int = {
- list.map(f => Source.fromFile(f).getLines().length).sum
- }
- def listFiles(dir: File, suffix: Array[String] = Array("java", "scala")): Set[File] = {
- dir.isDirectory match {
- case false =>
- suffix.find(sf => dir.getName.toLowerCase.endsWith(sf)) match {
- case Some(_) => Set(dir)
- case None => Set.empty[File]
- }
- case true => dir.listFiles.flatMap(f => listFiles(f, suffix)).toSet
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement