This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathBuild.scala
264 lines (214 loc) · 10.7 KB
/
Build.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
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import java.text.SimpleDateFormat
import java.util.Date
import com.typesafe.sbt.SbtScalariform._
import sbt.Keys._
import sbt._
import sbtassembly.Plugin.AssemblyKeys._
import sbtassembly.Plugin._
import sbtbuildinfo.Plugin._
object Resolvers {
val codebragResolvers = Seq(
"Sonatype releases" at "http://oss.sonatype.org/content/repositories/releases/",
"Sonatype snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/",
"SotwareMill Public Releases" at "https://nexus.softwaremill.com/content/repositories/releases/",
"SotwareMill Public Snapshots" at "https://nexus.softwaremill.com/content/repositories/snapshots/",
"TorqueBox Releases" at "http://rubygems-proxy.torquebox.org/releases",
"RoundEights" at "http://maven.spikemark.net/roundeights"
)
}
object BuildSettings {
import Resolvers._
val buildSettings = Defaults.coreDefaultSettings ++ defaultScalariformSettings ++ Seq(
organization := "com.softwaremill",
version := "2.3.4",
scalaVersion := "2.10.4",
resolvers := codebragResolvers,
scalacOptions += "-unchecked",
classpathTypes ~= (_ + "orbit"),
libraryDependencies ++= Dependencies.testingDependencies,
libraryDependencies ++= Dependencies.logging,
libraryDependencies ++= Seq(Dependencies.guava, Dependencies.googleJsr305),
concurrentRestrictions in Global += Tags.limit(Tags.Test, 1) // no parallel execution of tests, because we are starting mongo in tests
)
}
object Dependencies {
val slf4jVersion = "1.7.2"
val logBackVersion = "1.0.9"
val scalatraVersion = "2.2.2"
val rogueVersion = "2.1.0"
val scalaLoggingVersion = "1.0.1"
val akkaVersion = "2.1.4"
val jettyVersion = "8.1.7.v20120910"
val slf4jApi = "org.slf4j" % "slf4j-api" % slf4jVersion
val logBackClassic = "ch.qos.logback" % "logback-classic" % logBackVersion
val log4jOverSlf4j = "org.slf4j" % "log4j-over-slf4j" % slf4jVersion
val scalaLogging = "com.typesafe" %% "scalalogging-slf4j" % scalaLoggingVersion
val logging = Seq(slf4jApi, logBackClassic, scalaLogging, log4jOverSlf4j)
val guava = "com.google.guava" % "guava" % "13.0.1"
val googleJsr305 = "com.google.code.findbugs" % "jsr305" % "2.0.1"
val scalatra = "org.scalatra" %% "scalatra" % scalatraVersion
val scalatraScalatest = "org.scalatra" %% "scalatra-scalatest" % scalatraVersion % "test"
val scalatraJson = "org.scalatra" %% "scalatra-json" % scalatraVersion
val json4s = "org.json4s" %% "json4s-jackson" % "3.2.10"
val json4sExt = "org.json4s" %% "json4s-ext" % "3.2.10"
val scalatraAuth = "org.scalatra" %% "scalatra-auth" % scalatraVersion exclude("commons-logging", "commons-logging")
val jodaTime = "joda-time" % "joda-time" % "2.0"
val jodaConvert = "org.joda" % "joda-convert" % "1.2"
val commonsValidator = "commons-validator" % "commons-validator" % "1.4.0" exclude("commons-logging", "commons-logging")
val commonsLang = "org.apache.commons" % "commons-lang3" % "3.1"
val commonsCodec = "commons-codec" % "commons-codec" % "1.8"
val jetty = "org.eclipse.jetty" % "jetty-webapp" % jettyVersion
val mockito = "org.mockito" % "mockito-all" % "1.9.5" % "test"
val scalatest = "org.scalatest" % "scalatest_2.10" % "1.9.1" % "test"
val jodaDependencies = Seq(jodaTime, jodaConvert)
val scalatraStack = Seq(scalatra, scalatraScalatest, scalatraJson, json4s, scalatraAuth, commonsLang)
val akka = "com.typesafe.akka" %% "akka-actor" % akkaVersion
val akkaSlf4j = "com.typesafe.akka" %% "akka-slf4j" % akkaVersion
val akkaTestkit = "com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test"
val typesafeConfig = "com.typesafe" % "config" % "1.0.1"
val testingDependencies = Seq(mockito, scalatest, akkaTestkit)
val javaxMail = "javax.mail" % "mail" % "1.4.5"
val scalate = "org.scalatra.scalate" %% "scalate-core" % "1.7.0"
val seleniumVer = "2.33.0"
val seleniumJava = "org.seleniumhq.selenium" % "selenium-java" % seleniumVer % "test"
val seleniumFirefox = "org.seleniumhq.selenium" % "selenium-firefox-driver" % seleniumVer % "test"
val fest = "org.easytesting" % "fest-assert" % "1.4" % "test"
val awaitility = "com.jayway.awaitility" % "awaitility-scala" % "1.3.5" % "test"
val selenium = Seq(seleniumJava, seleniumFirefox, fest)
// If the scope is provided;test, as in scalatra examples then gen-idea generates the incorrect scope (test).
// As provided implies test, so is enough here.
val servletApiProvided = "org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "provided" artifacts (Artifact("javax.servlet", "jar", "jar"))
val bson = "org.mongodb" % "bson" % "2.7.1"
val egitGithubApi = "org.eclipse.mylyn.github" % "org.eclipse.egit.github.core" % "2.1.3"
val jGit = "org.eclipse.jgit" % "org.eclipse.jgit" % "4.2.0.201601211800-r"
val jsch = "com.jcraft" % "jsch" % "0.1.53"
val dispatch = "net.databinder.dispatch" %% "dispatch-core" % "0.9.5"
val slick = "com.typesafe.slick" %% "slick" % "2.0.3"
val h2 = "com.h2database" % "h2" % "1.3.175"
val flyway = "com.googlecode.flyway" % "flyway-core" % "2.3"
val c3p0 = "com.mchange" % "c3p0" % "0.9.5-pre6"
val scalaval = "com.softwaremill.scalaval" %% "scalaval" % "0.1"
val httpClient = "net.databinder.dispatch" %% "dispatch-core" % "0.11.2"
val crypto = "com.roundeights" %% "hasher" % "1.0.0"
}
object SmlCodebragBuild extends Build {
import BuildSettings._
import Dependencies._
import com.earldouglas.xwp._
val buildWebClient = TaskKey[Unit](
"build-web-client",
"Builds browser client using Grunt.js"
)
val webClientBuildSettings = Seq[Setting[_]](buildWebClient <<= {
(scalaVersion, baseDirectory, projectID) map {
(sv, bd, pid) => {
val localGruntCommand = "./node_modules/.bin/grunt build"
def updateDeps(cwd: File) = Process("npm install", cwd)!
def runGrunt(cwd: File) = Process(localGruntCommand, cwd)!
def haltOnError(result: Int) {
if(result != 0) {
throw new Exception("Building web client failed")
}
}
println("Updating NPM dependencies")
haltOnError(updateDeps(bd))
println("Building with Grunt.js")
haltOnError(runGrunt(bd))
}
}
})
val runH2Console = TaskKey[Unit]("run-h2-console", "Runs the H2 console using the data file from the local config file")
val runH2ConsoleSettings = fullRunTask(runH2Console, Compile, "com.softwaremill.codebrag.dao.sql.H2BrowserConsole")
lazy val parent: Project = Project(
"codebrag-root",
file("."),
settings = buildSettings
) aggregate(common, domain, dao, service, rest, ui, dist)
lazy val common: Project = Project(
"codebrag-common",
file("codebrag-common"),
settings = buildSettings ++ Seq(libraryDependencies ++= Seq(bson) ++ jodaDependencies ++ Seq(commonsCodec, typesafeConfig, crypto)) ++ buildInfoSettings ++
Seq(
sourceGenerators in Compile <+= buildInfo,
buildInfoPackage := "com.softwaremill.codebrag.version",
buildInfoObject := "CodebragBuildInfo",
buildInfoKeys := Seq[BuildInfoKey](
version,
BuildInfoKey.action("buildDate")(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date())),
BuildInfoKey.action("buildSha")((Process("git rev-parse HEAD") !!).stripLineEnd)
)
)
)
lazy val domain: Project = Project(
"codebrag-domain",
file("codebrag-domain"),
settings = buildSettings ++ Seq(libraryDependencies ++= Seq(bson, json4s, json4sExt, commonsLang) ++ jodaDependencies) ++ assemblySettings ++ Seq(
assemblyOption in assembly ~= { _.copy(includeScala = false) },
excludedJars in assembly <<= (fullClasspath in assembly) map { cp =>
cp filter {_.data.getName == "config-1.0.1.jar"}
}
)
) dependsOn (common)
lazy val dao: Project = Project(
"codebrag-dao",
file("codebrag-dao"),
settings = buildSettings ++ Seq(libraryDependencies ++= Seq(bson, typesafeConfig, slick, h2, flyway, c3p0), runH2ConsoleSettings)
) dependsOn(domain % "test->test;compile->compile", common)
lazy val service: Project = Project(
"codebrag-service",
file("codebrag-service"),
settings = buildSettings ++ Seq(libraryDependencies ++= Seq(commonsValidator,
javaxMail, scalate, egitGithubApi, jGit, jsch, dispatch, json4s, json4sExt, commonsLang, scalaval, akka, akkaSlf4j))
) dependsOn(domain, common, dao % "test->test;compile->compile")
lazy val rest: Project = Project(
"codebrag-rest",
file("codebrag-rest"),
settings = buildSettings ++
XwpPlugin.jetty() ++
Seq(libraryDependencies ++= scalatraStack ++ jodaDependencies ++ Seq(servletApiProvided, typesafeConfig)) ++
Seq(
artifactName := { (config: ScalaVersion, module: ModuleID, artifact: Artifact) =>
"codebrag." + artifact.extension // produces nice war name -> http://stackoverflow.com/questions/8288859/how-do-you-remove-the-scala-version-postfix-from-artifacts-builtpublished-wi
}
) ++
Seq(javaOptions in XwpPlugin.container := Seq("-Dconfig.file=local.conf"))
) dependsOn(service % "test->test;compile->compile", domain, common)
lazy val dist = Project(
"codebrag-dist",
file("codebrag-dist"),
settings = buildSettings ++ assemblySettings ++ Seq(
libraryDependencies ++= Seq(jetty),
mainClass in assembly := Some("com.softwaremill.codebrag.Codebrag"),
// We need to include the whole webapp, hence replacing the resource directory
unmanagedResourceDirectories in Compile <<= baseDirectory { bd =>
List(bd.getParentFile() / rest.base.getName / "src" / "main", bd.getParentFile() / ui.base.getName / "dist")
},
mergeStrategy in assembly <<= (mergeStrategy in assembly) { (old) => {
// There are two of such files in jgit and javax.servlet - but we don't really care about them (I guess ... ;)
// Probably some OSGi stuff.
case "plugin.properties" => MergeStrategy.discard
case PathList("META-INF", "eclipse.inf") => MergeStrategy.discard
// Here we don't care for sure.
case "about.html" => MergeStrategy.discard
case x => old(x)
} }
)
) dependsOn (ui, rest)
lazy val ui = Project(
"codebrag-ui",
file("codebrag-ui"),
settings = buildSettings ++ webClientBuildSettings ++ Seq(
(compile in Compile) <<= (compile in Compile) dependsOn (buildWebClient)
)
)
lazy val uiTests = Project(
"codebrag-ui-tests",
file("codebrag-ui-tests"),
settings = buildSettings ++ Seq(
libraryDependencies ++= selenium ++ Seq(awaitility)
)
) dependsOn (dist)
// To run the embedded container, we need to provide the path to the configuration. To make things easier, we assume
// that the local conf is in the current dir in the local.conf file.
System.setProperty("config.file", "local.conf")
}