Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package utils
  2.  
  3. import java.io.File
  4.  
  5. import com.google.common.base.Charsets
  6. import com.google.common.io.Files
  7.  
  8. import scala.io.Source
  9.  
  10. /**
  11. * main
  12. * Created by sjk on 1/24/17.
  13. */
  14. object StatisticUT {
  15. def main(args: Array[String]): Unit = {
  16. val dir = new File("/Users/sjk/g/flink/")
  17. val ret = listFiles(dir)
  18.  
  19. showTestFiles(ret, dir)
  20. println(countLine(ret))
  21. }
  22.  
  23. def showTestFiles(list: Set[File], home: File): Unit = {
  24. val abs = home.getAbsolutePath
  25. val test = list
  26. .filter(_.getAbsolutePath.contains("src/test"))
  27. .toArray
  28. .sortBy(_.getAbsolutePath)
  29. .map(f => {
  30. val p = f.getAbsolutePath.replace(abs + "/", "")
  31. p.substring(0, p.indexOf("/")) + " " + f.getAbsolutePath
  32. })
  33. val txt =
  34. s"""
  35. |total files: ${test.length}
  36. |${test.mkString("\n")}
  37. """.stripMargin
  38. println(txt)
  39. Files.write(txt, new File(home.getParent, "test_files.txt"), Charsets.UTF_8)
  40. }
  41.  
  42. def countLine(list: Set[File]): Int = {
  43. list.map(f => Source.fromFile(f).getLines().length).sum
  44. }
  45.  
  46. def listFiles(dir: File, suffix: Array[String] = Array("java", "scala")): Set[File] = {
  47. dir.isDirectory match {
  48. case false =>
  49. suffix.find(sf => dir.getName.toLowerCase.endsWith(sf)) match {
  50. case Some(_) => Set(dir)
  51. case None => Set.empty[File]
  52. }
  53. case true => dir.listFiles.flatMap(f => listFiles(f, suffix)).toSet
  54. }
  55. }
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement