-
Notifications
You must be signed in to change notification settings - Fork 5
/
Eff.sc
70 lines (52 loc) · 1.67 KB
/
Eff.sc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import scala.io.Source
import scala.util._
import sys.process._
import java.io.File
val mavenCommand = "mvn"
val mvn = Try(Process(Seq(mavenCommand,"-version")).!) match{
case Success(_) =>
"mvn"
case Failure(th) =>
"mvn.bat"
}
println(s"Maven command is: $mvn")
if (args.length == 0) {
println( """Call "scala Eff.sc <rootDir1> [<rootDir2>]" """)
sys.exit(-1)
} else {
println( s"""You are called "scala Eff ${args.mkString(" ")}" """)
}
val parseModuleName = """<module>(.*)</module>""".r
def callEffectivePom(dir: File) {
val effectivePom = "effective-pom.xml"
val result = Process(Seq(mvn, "-N", "help:effective-pom", s"-Doutput=$effectivePom"), dir).!
wrongResult(result, new File(dir, effectivePom))
val pom = Source.fromFile(new File(dir, "pom.xml")).mkString
(parseModuleName findAllIn pom).map {
case parseModuleName(inside) => inside
}.foreach {
f =>
val child = new File(dir, f)
if (child.exists()) {
callEffectivePom(child)
}
}
}
args.foreach { root =>
val rootDir = new File(root)
val dependencyTree = new File(rootDir, "dependencyTree.txt")
println(s"Creating $dependencyTree.")
val result = (Process(Seq(mvn, "dependency:tree"), rootDir) #> dependencyTree).!
wrongResult(result, dependencyTree)
println(s"$dependencyTree created")
callEffectivePom(rootDir)
}
def wrongResult(result: Int, output: File) {
if (result != 0) {
println(s"See $output for errors, content below:\n\n\n\n")
println("==================ERROR MESSAGE==========")
scala.io.Source.fromFile(output).getLines().foreach(println)
println("==================ERROR MESSAGE==========")
sys.exit(result)
}
}