forked from scalatron/scalatron
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.sbt
214 lines (183 loc) · 6.85 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
organization := "Scalatron"
name := "Scalatron"
version := "1.4.0"
enablePlugins(sbtdocker.DockerPlugin)
lazy val targetJvm =
SettingKey[String]("jvm-version", "The version of the JVM the build targets")
lazy val commonSettings = Seq( //Defaults.defaultSettings ++ src ++ Seq(
scalaSource in Compile := baseDirectory.value / "src",
scalaSource in Test := baseDirectory.value / "test",
resourceDirectory in Test := baseDirectory.value / "test/resources",
scalaVersion := "2.12.1",
crossPaths := false,
targetJvm := "1.8",
publishMavenStyle := false,
parallelExecution in Test := false,
scalacOptions ++= Seq("-target:jvm-" + targetJvm.value,
"-feature",
"-deprecation",
"-unchecked",
"-Xlint",
"-Xfatal-warnings"),
javacOptions ++= Seq("-source", targetJvm.value, "-target", targetJvm.value),
externalResolvers := Seq(Resolver.jcenterRepo),
assemblyMergeStrategy in assembly := {
case "plugin.properties" => MergeStrategy.first
case "about.html" => MergeStrategy.first
case x =>
val oldStrategy = (assemblyMergeStrategy in assembly).value
oldStrategy(x)
})
lazy val lintingSettings = Seq(
addCompilerPlugin("org.psywerx.hairyfotr" %% "linter" % "0.1.17"),
scalacOptions += "-P:linter:disable:UnusedParameter"
)
lazy val all = project
.in(file("."))
.settings(commonSettings)
.aggregate(Scalatron, ScalatronCLI, ScalaMarkdown, referenceBot, tagTeamBot)
lazy val ScalatronCore = project
.in(file("ScalatronCore"))
.settings(
commonSettings,
lintingSettings,
libraryDependencies ++= Dependencies.core,
assemblyJarName in assembly := "ScalatronCore.jar"
)
lazy val BotWar = project
.in(file("BotWar"))
.dependsOn(ScalatronCore)
.settings(
commonSettings,
lintingSettings,
libraryDependencies ++= Dependencies.botWar,
assemblyJarName in assembly := "BotWar.jar"
)
lazy val Scalatron = project
.in(file("Scalatron"))
.dependsOn(ScalatronCore, BotWar)
.settings(
commonSettings,
lintingSettings,
libraryDependencies ++= Dependencies.scalatron(scalaVersion.value),
assemblyJarName in assembly := "Scalatron.jar" // , logLevel in assembly := Level.Debug
)
lazy val ScalatronCLI = project
.in(file("ScalatronCLI"))
.settings(
commonSettings,
lintingSettings,
libraryDependencies ++= Dependencies.cli,
assemblyJarName in assembly := "ScalatronCLI.jar"
)
lazy val ScalaMarkdown = project
.in(file("ScalaMarkdown"))
.settings(
commonSettings,
libraryDependencies ++= Dependencies.markdown,
assemblyJarName in assembly := "ScalaMarkdown.jar"
)
lazy val samples = IO
.listFiles(file("Scalatron") / "samples")
.filter(!_.isFile)
.map { sample: File =>
sample.getName -> Project(
sample.getName.replace(" ", ""),
sample,
settings = commonSettings ++ Seq(
artifactName in packageBin := ((_, _, _) => "ScalatronBot.jar"),
libraryDependencies ++= Dependencies.samples
))
}.toMap
lazy val referenceBot = samples("Example Bot 01 - Reference")
lazy val tagTeamBot = samples("Example Bot 02 - TagTeam")
lazy val dist = taskKey[File]("Makes the distribution zip file")
dist := {
(assembly in ScalatronCore).value
(assembly in BotWar).value
(assembly in Scalatron).value
(assembly in ScalatronCLI).value
(assembly in ScalaMarkdown).value
(packageBin in Compile in referenceBot).value
(packageBin in Compile in tagTeamBot).value
println("Beginning distribution generation...")
val distDir = file("dist")
// clean distribution directory
println("Deleting /dist directory...")
IO delete distDir
// create new distribution directory
println("Creating /dist directory...")
IO createDirectory distDir
val scalatronDir = file("Scalatron")
println("Copying Readme.txt and License.txt...")
for (fileToCopy <- List("Readme.txt", "License.txt")) {
IO.copyFile(scalatronDir / fileToCopy, distDir / fileToCopy)
}
for (dirToCopy <- List("webui", "doc/pdf")) {
println("Copying " + dirToCopy)
IO.copyDirectory(scalatronDir / dirToCopy, distDir / dirToCopy)
}
val distSamples = distDir / "samples"
def sampleJar(sample: Project) = sample.base / "target/ScalatronBot.jar"
for (sample <- samples.values; if sampleJar(sample).exists) {
println("Copying " + sample.base)
IO.copyDirectory(sample.base / "src", distSamples / sample.base.getName / "src")
IO.copyFile(sampleJar(sample), distSamples / sample.base.getName / "ScalatronBot.jar")
}
println("Copying Reference bot to /bots directory...")
IO.copyFile(sampleJar(referenceBot), distDir / "bots" / "Reference" / "ScalatronBot.jar")
def runmarkdown(docDir: File, htmlDir: File) = {
Seq("java",
"-Xmx1G",
"-jar",
"ScalaMarkdown/target/ScalaMarkdown.jar",
docDir.getPath,
htmlDir.getPath).!
}
// generate HTML from Markdown, for /doc and /devdoc
println("Generating /dist/doc/html from /doc/markdown...")
runmarkdown(scalatronDir / "doc/markdown", distDir / "doc/html")
println("Generating /webui/tutorial from /dev/tutorial...")
runmarkdown(scalatronDir / "doc/tutorial", distDir / "webui/tutorial")
for (jar <- Seq("Scalatron", "ScalatronCLI", "ScalatronCore", "BotWar")) {
IO.copyFile(file(jar) / "target" / (jar + ".jar"), distDir / "bin" / (jar + ".jar"))
}
// This is ridiculous, there has to be be an easier way to zip up a directory
val zipFileName = s"scalatron-${version.value}.zip"
println("Zipping up /dist into " + zipFileName + "...")
def zip(srcDir: File, destFile: File, prepend: String) = {
val allDistFiles = (srcDir ** "*").get.filter(_.isFile).map { f =>
(f, prepend + IO.relativize(distDir, f).get)
}
IO.zip(allDistFiles, destFile)
}
val zipFile = file(s"./$zipFileName")
zip(distDir, zipFile, "Scalatron/")
zipFile
}
// scalafmt is this not working fine yet in this project, due to some bug with scala 2.12.1
// this seems to be related: https://github.com/olafurpg/scalafmt/issues/485
//scalafmtConfig := Some(file(".scalafmt.conf"))
dockerfile in docker := {
new Dockerfile {
val artifact = dist.value
stageFile(artifact, artifact)
from("registry.opensource.zalan.do/stups/openjdk:8-53")
runShell("apt-get", "update", "&&", "apt-get", "install", "-y", "unzip")
workDir("/opt")
copyRaw(s"/$artifact", "/opt/")
run("unzip", s"/opt/$artifact")
volume("/opt/Scalatron/bots")
expose(8080)
cmd("java", "-jar", "/opt/Scalatron/bin/Scalatron.jar", "-headless", "yes")
}
}
imageNames in docker := Seq(
// repository name must be lowercase
ImageName(s"${organization.value.toLowerCase}/${name.value.toLowerCase}:latest"),
ImageName(
namespace = Some(organization.value.toLowerCase),
repository = name.value.toLowerCase,
tag = Some("v" + version.value)
)
)