-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sbt
232 lines (193 loc) · 7.94 KB
/
build.sbt
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
import com.typesafe.config.{Config, ConfigFactory}
import org.jacoco.core.tools.{ExecDumpClient, ExecFileLoader}
import org.jdom2.input.SAXBuilder
import org.jdom2.input.sax.XMLReaders
import sbt.Keys.{scalaVersion, version}
import sbt.complete.DefaultParsers.spaceDelimited
import scala.sys.process._
import Path.rebase
import scala.collection.JavaConverters._
name := "equella-autotests"
libraryDependencies += "org.jacoco" % "org.jacoco.agent" % "0.7.9" classifier "runtime"
scalaVersion in ThisBuild := "2.12.6"
version in ThisBuild := "1.0"
lazy val config = (project in file("config")).settings(resourceDirectory in Compile := baseDirectory.value / "resources")
lazy val IntegTester = project in file("IntegTester")
lazy val Tests = project in file("Tests")
lazy val OldTests = (project in file("OldTests")).dependsOn(Tests, config)
buildConfig in ThisBuild := {
val defaultConfig = ConfigFactory.parseFile(file("project/build-defaults.conf"))
val configFile = file(sys.props.getOrElse("config.file", {
val envConfig = sys.env.get("AUTOTEST_CONFIG")
envConfig.foreach { cf => sys.props.update("config.file", cf); ConfigFactory.invalidateCaches() }
envConfig.getOrElse("config/resources/application.conf")
}))
sLog.value.info(s"Loading config from: ${configFile.absolutePath}")
ConfigFactory.load(ConfigFactory.parseFile(configFile).withFallback(defaultConfig))
}
lazy val installConfig = Def.setting[Config] {
buildConfig.value.getConfig("install")
}
installDir := optPath(installConfig.value, "basedir").getOrElse(baseDirectory.value / "equella-install")
installOptions := {
val ic = installConfig.value
val jacocoJar = coverageJar.value
val jacoco = Option(ic.getString("jacoco")).filter(_.nonEmpty).map(o => JacocoAgent(jacocoJar, o))
val db = ic.getConfig("db")
InstallOptions(
installDir.value, file(sys.props("java.home")),
url = ic.getString("url"), hostname = ic.getString("hostname"), port = ic.getInt("port"),
jacoco = jacoco, dbtype = db.getString("type"), dbname = db.getString("name"),
dbport = db.getInt("port"), dbhost = db.getString("host"), dbuser = db.getString("user"),
dbpassword = db.getString("password"))
}
def optPath(bc: Config, p: String) = if (bc.hasPath(p)) Some(file(bc.getString(p))) else None
installerZip := {
val bc = buildConfig.value
optPath(bc, "install.zip").orElse(optPath(bc, "install.dir").map(d => (d * "equella-installer-*.zip").get.head))
}
sourceZip := optPath(buildConfig.value, "install.sourcezip")
lazy val relevantClasses: Seq[String] => Boolean = {
case Seq("com", "tle", "admin", _*) => false
case Seq("com", "dytech", "edge", "admin", _*) => false
case Seq("com", "dytech", "gui", _*) => false
case Seq("com", "blackboard", _*) => false
case Seq("com", "tle", "core", "connectors", "blackboard", "webservice", _*) => false
case _ => true
}
coverageJar := {
update.value.select(
configurationFilter(AllPassFilter),
moduleFilter("org.jacoco", "org.jacoco.agent"),
artifactFilter(classifier = "runtime")
).head
}
dumpCoverage := {
val f = target.value / "jacoco.exec"
sLog.value.info(s"Dumping coverage data to ${f.absolutePath}")
coverageLoader.value.save(f, false)
f
}
coverageLoader := {
val log = sLog.value
val cc = buildConfig.value.getConfig("coverage")
val l = new ExecFileLoader()
optPath(cc, "file").filter(_.canRead).foreach { f =>
log.info(s"Loading coverage data from ${f.absolutePath}")
l.load(f)
}
cc.getStringList("hosts").asScala.foreach { h =>
val ind = h.indexOf(':')
val (hname, port) = if (ind == -1) (h, 6300) else (h.substring(0, ind), h.substring(ind + 1).toInt)
log.info(s"Collecting coverage from $h")
CoverageReporter.dumpCoverage(l, hname, port)
}
l
}
val saxBuilder = {
val sb = new SAXBuilder(XMLReaders.NONVALIDATING)
sb.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
sb.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
sb
}
sourceDirectory in coverageReport := target.value / "all_srcs"
target in coverageReport := {
val cc = buildConfig.value.getConfig("coverage")
optPath(cc, "reportdir").getOrElse(target.value / "coverage-report")
}
coverageReport := {
val log = sLog.value
val io = installOptions.value
val execLoader = coverageLoader.value
val allClasses = target.value / "all_classes"
IO.delete(allClasses)
val classFilter = new NameFilter {
def accept(name: String): Boolean = if (name.startsWith("classes/"))
relevantClasses.apply(name.substring("classes/".length).split("/"))
else name == "plugin-jpf.xml"
}
val allPlugins = (io.installDir / "plugins" ** "*.jar").get.flatMap { jar =>
val clzDir = allClasses / jar.getName
val files = IO.unzip(jar, clzDir, filter = classFilter)
val jpf = saxBuilder.build(clzDir / "plugin-jpf.xml")
val pluginId = jpf.getRootElement.getAttributeValue("id")
if (files.size > 2)
Some((jar.getParentFile.getName, CoveragePlugin(clzDir, pluginId)))
else None
}
val srcZip = sourceZip.value
val allSrcs = (sourceDirectory in coverageReport).value
srcZip.foreach(z => IO.unzip(z, allSrcs))
val coverageDir = (target in coverageReport).value
log.info(s"Creating coverage report at ${coverageDir.absolutePath}")
CoverageReporter.createReport(execLoader, allPlugins.groupBy(_._1).mapValues(_.map(_._2)).toSeq, coverageDir, allSrcs)
}
installEquella := {
val opts = installOptions.value
val zipFile = installerZip.value
val log = sLog.value
val installSettings = target.value / "installsettings.xml"
zipFile.fold(sys.error("Must have install.zip set")) { z =>
val installFiles = target.value / "installer_files"
log.info(s"Unzipping $z")
IO.delete(installFiles)
IO.unzip(z, installFiles)
val baseInstaller = (installFiles * "*").get.head
val installerJar = baseInstaller / "enterprise-install.jar"
opts.writeXML(installSettings, baseInstaller)
val o = ForkOptions().withRunJVMOptions(Vector("-jar", installerJar.absolutePath))
val args = Seq("--unsupported", installSettings.absolutePath)
Fork.java(o, args)
baseInstaller
}
}
def serviceCommand(opts: InstallOptions, cmd: String): Unit = {
val serverScript = opts.installDir / "manager/equellaserver"
List(serverScript.absolutePath, cmd) !
}
startEquella := serviceCommand(installOptions.value, "start")
stopEquella := serviceCommand(installOptions.value, "stop")
val TestPrj = LocalProject("Tests")
setupForTests := {
val run = (runner in (TestPrj,Test)).value
val log = sLog.value
run.run("equellatests.SetupForTests", (fullClasspath in (TestPrj, Test)).value.files, spaceDelimited("<arg>").parsed, log)
}
configureInstall := {
val run = (runner in (TestPrj, Test)).value
run.run("equellatests.InstallFirstTime", (fullClasspath in (TestPrj, Test)).value.files, Seq(), sLog.value)
}
aggregate in test := false
collectArtifacts := {
val results = target.value / "test-artifacts.zip"
def allFiles(files: Seq[File]): Traversable[(File, String)] = {
files.flatMap(f => (f ** "*").pair(rebase(f, f.getName)))
}
val logsDir = installDir.value / "logs"
val scReportDir = (target in LocalProject("Tests")).value / "test-reports"
val oldReportDir = file((testNGOutputDirectory in OldTests).value)
sLog.value.info(s"Collecting test artifacts into ${results.absolutePath}")
IO.zip(allFiles(Seq(logsDir, scReportDir, oldReportDir, (target in coverageReport).value)), results)
results
}
concurrentRestrictions in Global := {
val testConfig = buildConfig.value.getConfig("tests")
if (testConfig.hasPath("maxthreads"))
{
Seq(
Tags.limit(Tags.Test, testConfig.getInt("maxthreads"))
)
}
else {
Seq()
}
}
/*
Steps to clusterize install
Change freetext path to local dir - mandatory config
Change logs path in learningedge-log4j.properties
Set LOGS_HOME in equellaserver-config.sh
Set EQUELLASERVER_HOME in equellaserver-config.sh
Remove java.io.tmpdir property from equellaserver-config.sh
Make sure LOGS_HOME dir exists
*/