-
Notifications
You must be signed in to change notification settings - Fork 4
/
jgs-demo
executable file
·78 lines (68 loc) · 3 KB
/
jgs-demo
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
71
72
73
74
75
76
77
78
#!/usr/bin/env scala
import sys.process._
object JgsDemo {
def printUsage(): Unit = {
println("usage: jgs-demo [--secdomain project] [--demo project] [--only-dynamic] [--create-jimple] class-to-run")
}
def nextOption(args : List[String]) : Map[Symbol, String] = {
args match {
case "--secdomain" :: path :: rest => nextOption(rest) + ('secdomain -> path)
case "--demo" :: path :: rest => nextOption(rest) + ('demo -> path)
case "--only-dynamic" :: rest => nextOption(rest) + ('only_dynamic -> "-onlydynamic")
case "--create-jimple" :: rest => nextOption(rest) + ('create_jimple -> "-j")
case "--force-monomorphic-methods" :: rest => nextOption(rest) + ('force_monomorphic_methods -> "-forcemonomorphic")
case s :: rest if !s.startsWith("-") => nextOption(rest) + ('class -> s)
case s :: rest => println("Unkown option" + s); printUsage; sys.exit(-1)
case Nil => Map()
}
}
def run(p: ProcessBuilder) : Unit = {
if (p.! != 0) {
println("A command failed. Exiting")
sys.exit(-1)
}
}
def main(args : Array[String]) : Unit = {
val options = nextOption(args.toList)
val secdomainProject = options.getOrElse('secdomain, "LMHSecurityDomain")
val secdomainCP = secdomainProject + "/target/scala-2.11/classes"
val secdomainJar = secdomainProject + "/target/scala-2.11/lmhsecuritydomain_2.11-0.1-SNAPSHOT.jar"
val demoProject = options.getOrElse('demo, "DemoTestclasses")
val classpathCompile = List(
"JGSTestclasses/Demo/target/scala-2.11/classes",
"JGSTestclasses/Scratch/target/scala-2.11/classes",
"JGSSupport/target/scala-2.11/classes",
secdomainCP,
"DynamicAnalyzer/target/scala-2.11/classes"
).mkString(":")
val classpathRun = List(
secdomainCP,
"DynamicAnalyzer/target/scala-2.11/classes",
"GradualConstraints/InstrumentationSupport/target/scala-2.11/classes",
"lib/commons-collections4-4.0.jar",
"JGSSupport/target/scala-2.11/classes"
).mkString(":")
val outputDir = "out-instrumented"
val outputJimple = "out-original"
val classToRun = options.getOrElse('class, {printUsage() ; throw new IllegalArgumentException("No class-to-run specified ") })
val sbtJgsRunCommand : String = (List(
"runMain", "de.unifreiburg.cs.proglang.jgs.Main", "-m", classToRun, "-cp", classpathCompile, "-o", outputDir
) ++
options.get('only_dynamic).toList ++
options.get('create_jimple).toList ++
options.get('force_monomorphic_methods)
).mkString(" ")
println(s"Compiling: ${secdomainProject}, ${demoProject}")
val sbtCompileProcess =
Process(Seq("sbt", s"; ${secdomainProject}/package ; ${demoProject}/compile"))
run(sbtCompileProcess)
println("Running sbt with: " + sbtJgsRunCommand)
val sbtRunProcess = Process(
(Seq("sbt", s"${sbtJgsRunCommand}")),
None,
"JGS_SECDOMAIN_JARS" -> secdomainJar
)
run(sbtRunProcess)
Seq("java", "-cp", s"${outputDir}:${classpathRun}", classToRun).!
}
}