forked from jdegoes/blueeyes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.scala
130 lines (115 loc) · 6.41 KB
/
compile.scala
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import scala.annotation.tailrec
import java.io._
import scala.collection.JavaConversions._
val ivy = System.getProperty("user.home") + "/.ivy2/cache"
val scalaz = ivy + "/org.scalaz/scalaz-core_2.9.1/jars/scalaz-core_2.9.1-7.0-SNAPSHOT.jar"
val specialScalaz = ivy + "/org.specs2/specs2-scalaz-core_2.9.1/jars/specs2-scalaz-core_2.9.1-6.0.1.jar"
val joda = ivy + "/joda-time/joda-time/jars/joda-time-1.6.2.jar"
val scalacheck = ivy + "/org.scala-tools.testing/scalacheck_2.9.1/jars/scalacheck_2.9.1-1.9.jar"
val conhashmp = ivy + "/com.googlecode.concurrentlinkedhashmap/concurrentlinkedhashmap-lru/jars/concurrentlinkedhashmap-lru-1.1.jar"
val codec = ivy + "/commons-codec/commons-codec/jars/commons-codec-1.5.jar"
val netty = ivy + "/org.jboss.netty/netty/bundles/netty-3.2.6.Final.jar"
val xlightweb = ivy + "/org.xlightweb/xlightweb/jars/xlightweb-2.13.2.jar"
val xsocket = ivy + "/org.xsocket/xSocket/jars/xSocket-2.8.15.jar"
val javolution = ivy + "/javolution/javolution/bundles/javolution-5.5.1.jar"
val akka = ivy + "/com.typesafe.akka/akka-actor/jars/akka-actor-2.0.2.jar"
val streum = ivy + "/org.streum/configrity_2.9.1/jars/configrity_2.9.1-0.9.0.jar"
val slf4j = ivy + "/org.slf4j/slf4j-api/jars/slf4j-api-1.6.1.jar"
val slf4s = ivy + "/com.weiglewilczek.slf4s/slf4s_2.9.1/jars/slf4s_2.9.1-1.0.7.jar"
val specs2 = ivy + "/org.specs2/specs2_2.9.1/jars/specs2_2.9.1-1.8.jar"
val mockito = ivy + "/org.mockito/mockito-all/jars/mockito-all-1.9.0.jar"
val testing = ivy + "/org.scala-tools.testing/scalacheck_2.9.1/jars/scalacheck_2.9.1-1.9.jar"
val servlet = ivy + "/javax.servlet/javax.servlet-api/jars/javax.servlet-api-3.0.1.jar"
val jettyServer = ivy + "/org.eclipse.jetty/jetty-server/jars/jetty-server-8.1.3.v20120416.jar"
val jettyServlet = ivy + "/org.eclipse.jetty/jetty-servlet/jars/jetty-servlet-8.1.3.v20120416.jar"
val jettySecurity = ivy + "/org.eclipse.jetty/jetty-security/jars/jetty-security-8.1.3.v20120416.jar"
val jettyUtil = ivy + "/org.eclipse.jetty/jetty-util/jars/jetty-util-8.1.3.v20120416.jar"
val jettyHttp = ivy + "/org.eclipse.jetty/jetty-http/jars/jetty-http-8.1.3.v20120416.jar"
val jettyIO = ivy + "/org.eclipse.jetty/jetty-io/jars/jetty-io-8.1.3.v20120416.jar"
val scalatest = ivy + "/org.scalatest/scalatest_2.9.1/jars/scalatest_2.9.1-2.0.M2.jar"
val mongodb = ivy + "/org.mongodb/mongo-java-driver/jars/mongo-java-driver-2.7.3.jar"
val rhino = ivy + "/rhino/js/jars/js-1.7R2.jar"
val targetClasses = new File("target/classes")
targetClasses.delete()
targetClasses.mkdir()
val targetTestClasses = new File("target/test_classes")
targetTestClasses.delete()
targetTestClasses.mkdir()
def getScalaSourceFiles(srcDir: File) = {
@tailrec
def getScalaSourceFilesAcc(dirList: Array[File], accList: List[String]): List[String] = {
val (files, subDirs) = dirList.partition(_.isFile)
val newAccList = accList ++ files.filter(_.getName.endsWith(".scala")).map { f => f.getAbsolutePath }
if (subDirs.isEmpty)
newAccList
else
getScalaSourceFilesAcc(subDirs.flatMap(d => d.listFiles), newAccList)
}
getScalaSourceFilesAcc(srcDir.listFiles, List.empty)
}
val mainClasspathList = List(scalaz,
specialScalaz,
joda,
scalacheck,
conhashmp,
codec,
netty,
xlightweb,
xsocket,
javolution,
akka,
streum,
slf4j,
slf4s,
testing,
servlet,
specs2,
scalatest,
mongodb,
rhino,
"target/classes") // needs to be here so that when compiling core, it can find compiled json classes
val testClasspathList = mainClasspathList ++
List(mockito,
jettyServer,
jettyServlet,
jettySecurity,
jettyUtil,
jettyHttp,
jettyIO,
"target/test_classes")
val mainClasspath = mainClasspathList.mkString(":")
val testClasspath = testClasspathList.mkString(":")
def compile(name: String, srcDir: String, classpath: String, targetDir: String) {
val sourceFiles = getScalaSourceFiles(new File(srcDir)).toList
val command = List("scalac", "-classpath", classpath, "-d", targetDir) ++ sourceFiles
val builder = new ProcessBuilder(command)
builder.redirectErrorStream(true)
val process = builder.start()
val stdout = new BufferedReader(new InputStreamReader(process.getInputStream))
var line = "Starting compilation of " + name + "..."
while (line != null) {
println (line)
line = stdout.readLine
}
}
def copy(srcFilePath: String, destDirPath: String) {
val srcFile = new File(srcFilePath)
val destDir = new File(destDirPath)
val destFile = new File(destDir, srcFile.getName)
new FileOutputStream(destFile) getChannel() transferFrom(
new FileInputStream(srcFile) getChannel(), 0, Long.MaxValue)
}
val start = System.currentTimeMillis
compile("json/main", "json/src/main/scala", mainClasspath, targetClasses.getAbsolutePath)
compile("json/test", "json/src/test/scala", testClasspath, targetTestClasses.getAbsolutePath)
compile("core/main", "core/src/main/scala", mainClasspath, targetClasses.getAbsolutePath)
compile("core/test", "core/src/test/scala", testClasspath, targetTestClasses.getAbsolutePath)
compile("mongo/main", "mongo/src/main/scala", mainClasspath, targetClasses.getAbsolutePath)
compile("mongo/test", "mongo/src/test/scala", testClasspath, targetTestClasses.getAbsolutePath)
val end = System.currentTimeMillis
copy("json/src/test/resources/diff-example-expected-additions.json", targetTestClasses.getAbsolutePath)
copy("json/src/test/resources/diff-example-expected-changes.json", targetTestClasses.getAbsolutePath)
copy("json/src/test/resources/diff-example-expected-deletions.json", targetTestClasses.getAbsolutePath)
copy("json/src/test/resources/diff-example-json1.json", targetTestClasses.getAbsolutePath)
copy("json/src/test/resources/diff-example-json2.json", targetTestClasses.getAbsolutePath)
println("Total compilation time: " + (end - start) + " millis.")