-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
240 lines (200 loc) · 8.07 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
233
234
235
236
237
238
239
import java.time.{LocalDateTime, ZoneOffset}
import java.time.format.DateTimeFormatter
import com.typesafe.sbt.packager.linux.LinuxPackageMapping
import sbt.Keys.{libraryDependencies, organization}
import sbt.classpath.ClasspathUtilities
import sbtassembly.AssemblyKeys.assemblyMergeStrategy
import sbtassembly.MergeStrategy
val major = "0"
val minor = "0"
val patch = "0"
val preReleaseWithPrefix = ""
val jarVersion = "0.1"
val akka = "2.5.18"
val akka_http = "10.1.5"
val scala_test = "3.0.3"
val jackson = "2.8.8"
val dispatchVersion = "0.13.1"
lazy val allConfFiles = Set("application.conf")
lazy val commonSettings = Seq(
version := jarVersion,
organization := "com.evernym",
scalaVersion := "2.12.2",
scalacOptions := Seq("-unchecked", "-deprecation", "-encoding", "utf8", "-Xmax-classfile-name", "128"),
resolvers += "Lib-indy" at "https://repo.evernym.com/artifactory/libindy-maven-local",
resolvers += "Velvia maven" at "http://dl.bintray.com/velvia/maven",
resolvers += Resolver.bintrayRepo("bfil", "maven"),
parallelExecution in Test := false,
parallelExecution in Global := false,
assemblyMergeStrategy in assembly := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
case s if allConfFiles.contains(s) => MergeStrategy.discard
case s => MergeStrategy.defaultMergeStrategy(s)
},
//test in assembly := {},
PB.targets in Compile := Seq(
scalapb.gen(flatPackage = true) -> (sourceManaged in Compile).value
)
)
def commonTestSettings(projectName: String) = Seq (
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-h", s"target/test-reports/$projectName"),
PB.targets in Test := Seq(
scalapb.gen(flatPackage = true) -> (sourceManaged in Test).value
),
PB.protoSources in Test := Seq(file("core-agent/src/test/protobuf"))
)
lazy val apiLibraryDependencies = {
val akkaGrp = "com.typesafe.akka"
//akka related
val coreDeps = Seq.apply(
akkaGrp %% "akka-actor" % akka,
akkaGrp %% "akka-stream" % akka,
akkaGrp %% "akka-http" % akka_http
)
coreDeps
}
lazy val coreAgentLibraryDependencies = {
val akkaGrp = "com.typesafe.akka"
//akka related
val coreDeps = Seq.apply(
akkaGrp %% "akka-persistence" % akka,
akkaGrp %% "akka-http-spray-json" % akka_http,
//indy java wrapper
"org.hyperledger" % "indy" % "1.6.8",
//logging deps
"com.typesafe.scala-logging" %% "scala-logging" % "3.9.0",
"ch.qos.logback" % "logback-classic" % "1.2.3",
"com.typesafe.akka" %% "akka-slf4j" % akka,
//persistence dependencies
"com.typesafe.akka" %% "akka-persistence-cassandra" % "0.91",
"org.iq80.leveldb" % "leveldb" % "0.10",
//sms (TODO: need to finalize dependencies mentioned in this section)
"com.twilio.sdk" % "twilio-java-sdk" % "6.3.0",
"javax.ws.rs" % "javax.ws.rs-api" % "2.0",
"com.fasterxml.jackson.jaxrs" % "jackson-jaxrs-json-provider" % jackson,
"org.glassfish.jersey.core" % "jersey-client" % "2.25",
//others
"com.thesamet.scalapb" %% "scalapb-runtime" % scalapb.compiler.Version.scalapbVersion % "protobuf",
"info.faljse" % "SDNotify" % "1.1",
"org.velvia" %% "msgpack4s" % "0.6.0"
)
//test dependencies
val testDeps = Seq(
//persistence for tests
"org.iq80.leveldb" % "leveldb" % "0.7", //to be used in E2E tests
"org.scalatest" % "scalatest_2.12" % scala_test,
"org.pegdown" % "pegdown" % "1.6.0",
"org.mockito" % "mockito-all" % "1.9.5",
"org.abstractj.kalium" % "kalium" % "0.8.0", // java binding for nacl
akkaGrp %% "akka-testkit" % akka ,
akkaGrp %% "akka-http-testkit" % akka_http
).map(_ % "test")
coreDeps ++ testDeps
}
//mapping of "jarname to be searched" with "target jar file name"
lazy val nonAssemblyJarsToBePutIntoPackage: Map[String, String] = Map.empty
def addDeps(deps:Seq[ModuleID], modifyDepTagForDeps:Seq[String], tags:String )={
deps.map { dep =>
if(modifyDepTagForDeps contains dep.name){
dep.organization % dep.name % dep.revision % tags
} else {
dep
}
}
}
def getBuildMetadataWithPrefix(commitDate:String, commitHash:String) : String = {
val secondsFromEpoch = (LocalDateTime.parse(commitDate,
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ssZ"))
.atZone(ZoneOffset.UTC).toInstant.toEpochMilli / 1000) - 1500000000
val trimmedHash = commitHash.substring(0, 7)
s"+$secondsFromEpoch.$trimmedHash"
}
def getVersion(commitDate:String, commitHash:String) : String = {
val buildMetadataWithPrefix = getBuildMetadataWithPrefix(commitDate, commitHash)
//s"$major.$minor.$patch$preReleaseWithPrefix$buildMetadataWithPrefix"
s"$major.$minor.$patch"
}
def buildPackageMappings(
sourceDir: String, targetDir: String,
includeFiles: Set[String] = Set.empty,
excludeFiles: Set[String] = Set.empty,
replaceFilesIfExists: Boolean = false): LinuxPackageMapping = {
val d = new File(sourceDir)
val fms = if (d.exists) {
val files = d.listFiles.filter { f =>
f.isFile &&
(includeFiles.isEmpty || includeFiles.contains(f.name)) &&
(excludeFiles.isEmpty || ! excludeFiles.contains(f.name))
}.toSeq
files.map { f =>
(file(s"$sourceDir/${f.name}"), s"$targetDir/${f.name}")
}
} else Seq.empty
val r = packageMapping(fms: _*)
if (replaceFilesIfExists) r else r.withConfig("noreplace")
}
lazy val dprDirPath = "deb-package-resources"
lazy val targetDirPathPrefix = "/usr/share/agent"
lazy val publishDeb = taskKey[Unit]("Publish deb package")
def getNonAssemblyJarFileMapping(pName: String, dependencies: Keys.Classpath):Map[File, String] = {
val depLibs = dependencies.map(_.data).filter(ClasspathUtilities.isArchive)
val nonAssemblyJarsToBePutIntoDebPckg = nonAssemblyJarsToBePutIntoPackage.map { djn =>
depLibs.find(_.getName.contains(djn._1)).get -> djn._2
}
nonAssemblyJarsToBePutIntoDebPckg.map { djn =>
(djn._1, s"/usr/lib/$pName/${djn._2}")
}
}
def commonPackageSettings(targetRootPath: String) = Seq (
maintainer := "Evernym Inc <[email protected]>",
packageName := name.value,
version := getVersion(git.gitHeadCommitDate.value.get, git.gitHeadCommit.value.get),
linuxPackageMappings += {
val pName = name.value
val basePackageMapping = Seq(
(assembly.value, s"/usr/lib/$pName/$pName-assembly.jar"),
(baseDirectory.value / "src" / "main" / "resources" / "systemd" / "systemd.service",
s"/usr/lib/systemd/system/${packageName.value}.service")
)
val dependencies = (externalDependencyClasspath in assembly).value
val extraJarDepMapping = getNonAssemblyJarFileMapping(pName, dependencies)
packageMapping(basePackageMapping ++ extraJarDepMapping: _*)
},
linuxPackageMappings += {
buildPackageMappings(s"core-agent/src/main/resources/$dprDirPath",
s"$targetRootPath/${packageName.value}",
includeFiles = allConfFiles, replaceFilesIfExists = true)
},
publishDeb := {
val artifact = target.value + "/" + name.value + "_" + version.value + "_all.deb"
val code = ("sh upload_deb.sh " + artifact !)
code match {
case 0 => println("Successful Upload!!")
case n => sys.error(s"Error in Upload Script, exit code: $n")
}
}
)
lazy val api = (project in file("api")).
enablePlugins(DebianPlugin).
settings(
name := "api",
packageSummary := "api",
libraryDependencies ++= apiLibraryDependencies,
commonSettings,
commonPackageSettings(s"$targetDirPathPrefix")
)
lazy val coreAgent = (project in file("core-agent")).
enablePlugins(DebianPlugin).
settings(
name := "core-agent",
packageSummary := "core-agent",
packageDescription := "Scala and Akka package to run core agent",
libraryDependencies ++= coreAgentLibraryDependencies,
commonTestSettings("core-agent"),
commonSettings,
commonPackageSettings(s"$targetDirPathPrefix"),
//libindy provides libindy.so
debianPackageDependencies in Debian ++= Seq("default-jre", "libindy(>= 1.6.8)")
).dependsOn(api % "test->test; compile->compile")
lazy val agent = project.in(file(".")).aggregate(api, coreAgent)
Revolver.settings