forked from waves-enterprise/we-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
672 lines (591 loc) · 27.2 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
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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
import com.lightbend.sbt.SbtProguard.autoImport._
import com.typesafe.sbt.SbtGit.GitKeys.gitUncommittedChanges
import com.typesafe.sbt.git.JGit
import org.eclipse.jgit.submodule.SubmoduleWalk.IgnoreSubmoduleMode
import sbt.Keys.{credentials, sourceGenerators, _}
import sbt.internal.inc.ReflectUtilities
import sbt.librarymanagement.ivy.IvyDependencyResolution
import sbt.{Compile, Credentials, Def, Path, _}
import sbtassembly.MergeStrategy
import java.io.File
import scala.sys.process.{Process, ProcessLogger}
excludeDependencies ++= Seq(
// workaround for https://github.com/sbt/sbt/issues/3618
// include "jakarta.ws.rs" % "jakarta.ws.rs-api" instead
ExclusionRule("javax.ws.rs", "javax.ws.rs-api")
)
libraryDependencies += "jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.5"
enablePlugins(JavaServerAppPackaging, SystemdPlugin, GitVersioning)
scalafmtOnCompile in ThisBuild := true
Global / cancelable := true
Global / onChangedBuildSource := ReloadOnSourceChanges
fork in run := true
connectInput in run := true
name := "waves-enterprise"
/**
* You have to put your credentials in a local file ~/.sbt/.credentials
* File structure:
*
* realm=Sonatype Nexus Repository Manager
* host=artifacts.wavesenterprise.com
* username={YOUR_LDAP_USERNAME}
* password={YOUR_LDAP_PASSWORD}
*/
credentials += {
val envUsernameOpt = sys.env.get("nexusUser")
val envPasswordOpt = sys.env.get("nexusPassword")
(envUsernameOpt, envPasswordOpt) match {
case (Some(username), Some(password)) =>
println("Using credentials from environment for artifacts.wavesenterprise.com")
Credentials("Sonatype Nexus Repository Manager", "artifacts.wavesenterprise.com", username, password)
case _ =>
val localCredentialsFile = Path.userHome / ".sbt" / ".credentials"
println(s"Going to use ${localCredentialsFile.getAbsolutePath} as credentials for artifacts.wavesenterprise.com")
Credentials(localCredentialsFile)
}
}
lazy val nodeJarName = settingKey[String]("Name for assembled node jar")
nodeJarName := s"waves-enterprise-all-${version.value}.jar"
lazy val generatorJarName = settingKey[String]("Name for generator jar")
generatorJarName := s"generators-${version.value}.jar"
val nodeVersionSource = Def.task {
// WARNING!!!
// Please, update the fallback version every major and minor releases.
// This version is used then building from sources without Git repository
// In case of not updating the version nodes build from headless sources will fail to connect to newer versions
val FallbackVersion = (1, 0, 0)
val nodeVersionFile: File = (sourceManaged in Compile).value / "com" / "wavesenterprise" / "Version.scala"
val versionExtractor = """(\d+)\.(\d+)\.(\d+).*""".r
val (major, minor, patch) = version.value match {
case versionExtractor(ma, mi, pa) => (ma.toInt, mi.toInt, pa.toInt)
case _ => FallbackVersion
}
IO.write(
nodeVersionFile,
s"""package com.wavesenterprise
|
|object Version {
| val VersionString = "${version.value}"
| val VersionTuple = ($major, $minor, $patch)
|}
|""".stripMargin
)
Seq(nodeVersionFile)
}
normalizedName := s"${name.value}"
gitUncommittedChanges in ThisBuild := JGit(baseDirectory.value).porcelain
.status()
.setIgnoreSubmodules(IgnoreSubmoduleMode.ALL)
.call()
.hasUncommittedChanges
version in ThisBuild := {
val suffix = git.makeUncommittedSignifierSuffix(git.gitUncommittedChanges.value, Some("DIRTY"))
val releaseVersion = git.releaseVersion(git.gitCurrentTags.value, git.gitTagToVersionNumber.value, suffix)
lazy val describedExtended = git.gitDescribedVersion.value.map { described =>
val commitHashLength = 7
val (tagVersionWithoutCommitHash, commitHash) = described.splitAt(described.length - commitHashLength)
val tagVersionWithCommitsAhead = tagVersionWithoutCommitHash.dropRight(2)
s"$tagVersionWithCommitsAhead-$commitHash" + suffix
}
releaseVersion.orElse(describedExtended).getOrElse(git.formattedDateVersion.value)
}
publishArtifact in (Compile, packageDoc) := false
publishArtifact in (Compile, packageSrc) := false
mainClass in Compile := Some("com.wavesenterprise.Application")
scalacOptions ++= Seq(
"-feature",
"-deprecation",
"-language:higherKinds",
"-language:implicitConversions",
"-Ywarn-unused:-implicits",
"-Xlint",
"-Yresolve-term-conflict:object",
"-Ypartial-unification",
"-language:postfixOps"
)
logBuffered := false
inThisBuild(
Seq(
scalaVersion := "2.12.10",
organization := "com.wavesenterprise",
crossPaths := false,
scalacOptions ++= Seq("-feature",
"-deprecation",
"-language:higherKinds",
"-language:implicitConversions",
"-Ywarn-unused:-implicits",
"-Xlint",
"-Ypartial-unification")
))
scalaModuleInfo ~= (_.map(_.withOverrideScalaVersion(true)))
// for sbt plugins sources resolving
updateSbtClassifiers / dependencyResolution := IvyDependencyResolution((updateSbtClassifiers / ivyConfiguration).value)
resolvers ++= Seq(
"WE Nexus" at "https://artifacts.wavesenterprise.com/repository/we-public",
Resolver.sbtPluginRepo("releases")
)
javaOptions in run ++= Seq(
"-XX:+IgnoreUnrecognizedVMOptions"
)
Test / fork := true
Test / javaOptions ++= Seq(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED",
"-Dnode.waves-crypto=true"
)
Test / parallelExecution := true
val aopMerge: MergeStrategy = new MergeStrategy {
val name = "aopMerge"
import scala.xml._
import scala.xml.dtd._
def apply(tempDir: File, path: String, files: Seq[File]): Either[String, Seq[(File, String)]] = {
val dt = DocType("aspectj", PublicID("-//AspectJ//DTD//EN", "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"), Nil)
val file = MergeStrategy.createMergeTarget(tempDir, path)
val xmls: Seq[Elem] = files.map(XML.loadFile)
val aspectsChildren: Seq[Node] = xmls.flatMap(_ \\ "aspectj" \ "aspects" \ "_")
val weaverChildren: Seq[Node] = xmls.flatMap(_ \\ "aspectj" \ "weaver" \ "_")
val options: String = xmls.map(x => (x \\ "aspectj" \ "weaver" \ "@options").text).mkString(" ").trim
val weaverAttr = if (options.isEmpty) Null else new UnprefixedAttribute("options", options, Null)
val aspects = new Elem(null, "aspects", Null, TopScope, false, aspectsChildren: _*)
val weaver = new Elem(null, "weaver", weaverAttr, TopScope, false, weaverChildren: _*)
val aspectj = new Elem(null, "aspectj", Null, TopScope, false, aspects, weaver)
XML.save(file.toString, aspectj, "UTF-8", xmlDecl = false, dt)
IO.append(file, IO.Newline.getBytes(IO.defaultCharset))
Right(Seq(file -> path))
}
}
inTask(assembly)(
Seq(
test := {},
assemblyJarName := nodeJarName.value,
assemblyMergeStrategy := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
case PathList("META-INF", "aop.xml") => aopMerge
case PathList("com", "google", "thirdparty", xs @ _*) => MergeStrategy.first
case PathList("com", "kenai", xs @ _*) => MergeStrategy.first
case PathList("javax", "ws", xs @ _*) => MergeStrategy.first
case PathList("jersey", "repackaged", xs @ _*) => MergeStrategy.first
case PathList("jnr", xs @ _*) => MergeStrategy.first
case PathList("org", "aopalliance", xs @ _*) => MergeStrategy.first
case PathList("org", "jvnet", xs @ _*) => MergeStrategy.first
case PathList("com", "sun", "activation", xs @ _*) => MergeStrategy.last
case PathList("javax", "activation", xs @ _*) => MergeStrategy.last
case PathList("jakarta", "activation", xs @ _*) => MergeStrategy.last
case path if path.endsWith("module-info.class") => MergeStrategy.discard
case "META-INF/maven/com.kohlschutter.junixsocket/junixsocket-native-common/pom.properties" => MergeStrategy.first
case PathList("com", "google", "protobuf", xs @ _*) => MergeStrategy.first
case other => (assemblyMergeStrategy in assembly).value(other)
}
))
inConfig(Compile)(
Seq(
mainClass := Some("com.wavesenterprise.Application"),
publishArtifact in packageDoc := false,
publishArtifact in packageSrc := false,
sourceGenerators += nodeVersionSource
))
inConfig(Test)(
Seq(
logBuffered := false,
parallelExecution := true,
testListeners := Seq.empty,
testOptions += Tests.Argument("-oIDOF", "-u", "target/test-reports"),
testOptions += Tests.Setup({ _ =>
sys.props("sbt-testing") = "true"
})
))
// The bash scripts classpath only needs the fat jar
scriptClasspath := Seq((assemblyJarName in assembly).value)
commands += Command.command("packageAll") { state =>
"clean" ::
"assembly" ::
state
}
bashScriptExtraDefines += s"""addJava "-Dnode.directory=/var/lib/${normalizedName.value}""""
val linuxScriptPattern = "bin/(.+)".r
val batScriptPattern = "bin/([^.]+)\\.bat".r
inConfig(Universal)(
Seq(
mappings += (baseDirectory.value / s"node-example.conf" -> "doc/we.conf.sample"),
mappings := {
val fatJar = (assembly in Compile).value
val universalMappings = mappings.value.map {
case (file, batScriptPattern(script)) =>
(file, s"bin/$script.bat")
case (file, linuxScriptPattern(script)) =>
(file, s"bin/$script")
case other => other
}
// Filter all jar dependencies because they already exists in the fat jar
val filtered = universalMappings filter {
case (_, name) => !name.endsWith(".jar")
}
filtered :+ (fatJar -> ("lib/" + fatJar.getName))
},
javaOptions ++= Seq(
// -J prefix is required by the bash script
"-J-server",
// JVM memory tuning for 2g ram
"-J-Xms128m",
"-J-Xmx2g",
"-J-XX:+ExitOnOutOfMemoryError",
// Java 9 support
"-J-XX:+IgnoreUnrecognizedVMOptions",
// from https://groups.google.com/d/msg/akka-user/9s4Yl7aEz3E/zfxmdc0cGQAJ
"-J-XX:+UseG1GC",
"-J-XX:+UseNUMA",
"-J-XX:+AlwaysPreTouch",
// probably can't use these with jstack and others tools
"-J-XX:+PerfDisableSharedMem",
"-J-XX:+ParallelRefProcEnabled",
"-J-XX:+UseStringDeduplication"
)
))
// https://stackoverflow.com/a/48592704/4050580
def allProjects: List[ProjectReference] = ReflectUtilities.allVals[Project](this).values.toList map { p =>
p: ProjectReference
}
addCommandAlias(
name = "compileAll",
value = "; cleanAll; " +
"compile; test:compile; " +
"generator/compile; generator/test:compile; " +
"transactionsSigner/compile; transactionsSigner/test:compile"
)
val scalafmtTestAllCommand = "scalafmtTestAll"
addCommandAlias(
name = scalafmtTestAllCommand,
value = "scalafmt::test; test:scalafmt::test; " +
"generator/ scalafmt::test; generator / test:scalafmt::test; " +
"transactionsSigner/ scalafmt::test; transactionsSigner / test:scalafmt::test; "
)
addCommandAlias(
name = "compileAllCI",
value = "; cleanAll; " +
s"$scalafmtTestAllCommand; " +
"compile; test:compile; " +
"generator/compile; generator/test:compile; " +
"transactionsSigner/compile; transactionsSigner/test:compile"
)
val weReleasesRepo = Some("Sonatype Nexus Repository Manager" at "https://artifacts.wavesenterprise.com/repository/we-releases")
lazy val node = project
.in(file("."))
.settings(
addCompilerPlugin(Dependencies.kindProjector),
libraryDependencies ++=
Dependencies.weCore ++
Dependencies.network ++
Dependencies.db ++
Dependencies.http ++
Dependencies.serialization ++
Dependencies.testKit.map(_ % "test") ++
Dependencies.logging ++
Dependencies.metrics ++
Dependencies.fp ++
Dependencies.meta ++
Dependencies.ficus ++
Dependencies.scorex ++
Dependencies.commonsNet ++
Dependencies.commonsLang ++
Dependencies.monix.value ++
Dependencies.docker ++
Dependencies.enumeratum ++
Dependencies.dbDependencies ++
Dependencies.awsDependencies ++
Dependencies.javaplot ++
Dependencies.pureConfig,
dependencyOverrides ++= Seq(
Dependencies.AkkaHTTP
) ++ Dependencies.fastparse.value
)
.settings(
credentials += Credentials(Path.userHome / ".sbt" / ".credentials"),
publishTo := weReleasesRepo,
publishArtifact in (Compile, packageSrc) := false,
publishArtifact in (Compile, packageBin) := false,
publishArtifact in (Compile, packageDoc) := false,
addArtifact(artifact in (Compile, assembly), assembly),
publish := (publish dependsOn (assembly in Compile)).value
)
lazy val javaHomeProguardOption = Def.task[String] {
(for {
versionStr <- sys.props.get("java.version").toRight("failed to get system property java.version")
javaHome <- sys.props.get("java.home").toRight("failed to get system property java.home")
version <- "^(\\d+).*".r.findFirstMatchIn(versionStr).map(_.group(1)).toRight(s"java.version system property has wrong format: '$versionStr'")
} yield {
if (version.toInt > 8)
s"-libraryjars $javaHome/jmods/java.base.jmod"
else ""
}) match {
case Right(path) => path
case Left(error) => sys.error(error)
}
}
lazy val extLibrariesProguardExclusions = Def.task[Seq[String]] {
libraryDependencies.value
.map(_.organization.toLowerCase)
.distinct
.filterNot(org => org.startsWith("com.wavesenterprise") && org.startsWith("com.wavesplatform"))
.flatMap { org =>
Seq(
s"-keep class $org.** { *; }",
s"-keep interface $org.** { *; }",
s"-keep enum $org.** { *; }"
)
}
}
lazy val generator = project
.dependsOn(node)
.dependsOn(node % "test->test; compile->compile")
.enablePlugins(SbtProguard)
.settings(
Global / cancelable := true,
fork in run := true,
fork in Test := true,
connectInput in run := true,
libraryDependencies += "com.github.scopt" %% "scopt" % "3.6.0",
assemblyJarName in assembly := s"generators-${version.value}.jar",
mainClass in assembly := Some("com.wavesenterprise.generator.GeneratorLauncher"),
testOptions in Test += Tests.Argument("-oIDOF", "-u", "target/generator/test-reports"),
javaOptions in Test ++= Seq(
"-XX:+IgnoreUnrecognizedVMOptions",
"--add-exports=java.base/jdk.internal.ref=ALL-UNNAMED",
"-Dnode.waves-crypto=true"
),
assemblyMergeStrategy in assembly := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
case PathList("META-INF", "aop.xml") => MergeStrategy.discard
case sign if sign.endsWith(".CP") => MergeStrategy.discard
case PathList("com", "google", "thirdparty", xs @ _*) => MergeStrategy.discard
case PathList("com", "kenai", xs @ _*) => MergeStrategy.discard
case PathList("javax", "ws", xs @ _*) => MergeStrategy.discard
case PathList("jersey", "repackaged", xs @ _*) => MergeStrategy.discard
case PathList("jnr", xs @ _*) => MergeStrategy.discard
case PathList("org", "aopalliance", xs @ _*) => MergeStrategy.discard
case PathList("org", "jvnet", xs @ _*) => MergeStrategy.discard
case PathList("com", "sun", "activation", xs @ _*) => MergeStrategy.discard
case PathList("javax", "activation", xs @ _*) => MergeStrategy.discard
case PathList("jakarta", "activation", xs @ _*) => MergeStrategy.discard
case "application.conf" => MergeStrategy.concat
case path if path.endsWith("module-info.class") => MergeStrategy.discard
case PathList("com", "google", "protobuf", xs @ _*) => MergeStrategy.first
case other => (assemblyMergeStrategy in assembly).value(other)
},
proguardInputs in Proguard := Seq((assemblyOutputPath in assembly).value),
proguardOutputs in Proguard := Seq((proguardDirectory in Proguard).value / (assemblyJarName in assembly).value),
proguardOptions in Proguard ++= Seq(
"-dontnote",
"-dontwarn",
"-dontoptimize",
"-dontusemixedcaseclassnames",
javaHomeProguardOption.value,
// to keep logback
"-keep public class org.slf4j.** { *; }",
"-keep public class ch.** { *; }",
"-keep class org.bouncycastle.** { *; }",
"-keep class scala.** { *; }",
"-keep interface scala.** { *; }",
"-keep enum scala.** { *; }",
"-keep class akka.actor.** { *; }",
"-keep interface akka.actor.** { *; }",
"-keep enum akka.actor.** { *; }",
"""-keepnames public class * {
|public static ** classTag();
|}""".stripMargin,
"""-keepclasseswithmembers public class * {
| public static void main(java.lang.String[]);
|}""".stripMargin,
"""-keepclassmembers class * {
|** MODULE$;
|}""".stripMargin,
"""-keepclasseswithmembernames,includedescriptorclasses class * {
|native <methods>;
|}""".stripMargin,
"""-keepclassmembers,allowoptimization enum * {
|public static **[] values();
|public static ** valueOf(java.lang.String);
|}""".stripMargin,
"-keepattributes SourceFile,LineNumberTable"
) ++ extLibrariesProguardExclusions.value,
javaOptions in (Proguard, proguard) := Seq("-Xmx2G"),
proguardOptions in Proguard += ProguardOptions.keepMain("com.wavesenterprise.generator.GeneratorLauncher"),
proguardInputFilter in Proguard := { file =>
None
},
proguardVersion in Proguard := "6.2.2",
(proguard in Proguard) := ((proguard in Proguard) dependsOn assembly).value
)
.settings(
credentials += Credentials(Path.userHome / ".sbt" / ".credentials"),
publishTo := weReleasesRepo,
publishArtifact in (Compile, packageSrc) := false,
publishArtifact in (Compile, packageBin) := false,
publishArtifact in (Compile, packageDoc) := false,
publishArtifact in (Proguard, proguard) := false,
addArtifact(artifact in (Compile, assembly), assembly)
)
lazy val transactionsSigner = (project in file("transactions-signer"))
.dependsOn(node)
.settings(
name := "transactions-signer",
mainClass := Some("com.wavesenterprise.TxSignerApplication"),
libraryDependencies ++= Dependencies.console,
testOptions in Test += Tests.Argument("-oIDOF", "-u", "target/transactions-signer/test-reports")
)
.settings(
assemblyMergeStrategy in assembly := {
case PathList("META-INF", "io.netty.versions.properties") => MergeStrategy.concat
case PathList("META-INF", "aop.xml") => MergeStrategy.discard
case PathList("META-INF", "mailcap.default") => MergeStrategy.discard
case PathList("META-INF", "mimetypes.default") => MergeStrategy.discard
case sign if sign.endsWith(".CP") => MergeStrategy.discard
case PathList("com", "google", "thirdparty", xs @ _*) => MergeStrategy.discard
case PathList("com", "kenai", xs @ _*) => MergeStrategy.discard
case PathList("javax", "ws", xs @ _*) => MergeStrategy.discard
case PathList("jersey", "repackaged", xs @ _*) => MergeStrategy.discard
case PathList("jnr", xs @ _*) => MergeStrategy.discard
case PathList("org", "aopalliance", xs @ _*) => MergeStrategy.discard
case PathList("org", "jvnet", xs @ _*) => MergeStrategy.discard
case PathList("javax", "activation", xs @ _*) => MergeStrategy.discard
case PathList("com", "sun", "activation", xs @ _*) => MergeStrategy.discard
case "application.conf" => MergeStrategy.concat
case path if path.endsWith("module-info.class") => MergeStrategy.discard
case "META-INF/maven/com.kohlschutter.junixsocket/junixsocket-native-common/pom.properties" => MergeStrategy.first
case PathList("com", "google", "protobuf", xs @ _*) => MergeStrategy.first
case other => (assemblyMergeStrategy in assembly).value(other)
}
)
.settings(
credentials += Credentials(Path.userHome / ".sbt" / ".credentials"),
publishTo := weReleasesRepo,
publishArtifact in (Compile, packageSrc) := false,
publishArtifact in (Compile, packageBin) := false,
publishArtifact in (Compile, packageDoc) := false,
addArtifact(artifact in (Compile, assembly), assembly)
)
def printMessage(msg: String): Unit = {
println(" " + ">" * 3 + " " + msg)
}
def printMessageTask(msg: String) = Def.task {
printMessage(msg)
}
/* ********************************************************* */
/**
* Some convenient assembly machinery:
* task "prepareJars": compiles and assembles node and generator, puts resulting fat jars to cleaned 'jars' dir
* task "cleanJars": deletes 'jars' directory
*/
lazy val jarsDir = settingKey[File]("Jars output directory")
jarsDir := (baseDirectory in (node, Compile)).value / "jars"
lazy val movePrepareJarsArtifacts = Def.task[Unit] {
val nodeJarName = (assemblyJarName in (node, assembly)).value
val nodeJar = (target in (node, Compile)).value / nodeJarName
val generatorJarName = (assemblyJarName in (generator, assembly)).value
val generatorJar = (target in (generator, Compile)).value / generatorJarName
val generatorConfigs = (resourceDirectory in (generator, Compile)).value.listFiles().filter(_.getName.endsWith(".conf"))
IO.delete(jarsDir.value)
IO.createDirectory(jarsDir.value)
generatorConfigs.foreach { configFile =>
val fileName = configFile.getName.split(File.separator).last
IO.copyFile(configFile, jarsDir.value / (fileName + ".sample"))
}
IO.copyFile(nodeJar, jarsDir.value / nodeJarName)
IO.copyFile(generatorJar, jarsDir.value / generatorJarName)
}
/* ********************************************************* */
lazy val cleanJars = taskKey[Unit]("Delete jars directory")
cleanJars := IO.delete(jarsDir.value)
/* ********************************************************* */
lazy val prepareJars = taskKey[Unit]("Package everything")
prepareJars := Def
.sequential(
printMessageTask("Stage 1: compile node"),
compile in (node, Compile),
printMessageTask("Stage 2: compile generator"),
compile in (generator, Compile),
printMessageTask("Stage 3: assembly node jar"),
assembly in (node, assembly),
printMessageTask("Stage 4: assembly generator jar"),
assembly in (generator, assembly),
printMessageTask("Stage 5: create jars dir and move assembled jars there"),
movePrepareJarsArtifacts,
printMessageTask("All done!")
)
.value
/* ********************************************************* */
lazy val buildAllDir = settingKey[File]("Directory for artifacts, generated with 'buildAll' task")
buildAllDir := (baseDirectory in (node, Compile)).value / "artifacts"
lazy val moveNodeFatJar = Def.task[Unit] {
val nodeJar = (target in (node, Compile)).value / nodeJarName.value
IO.copyFile(nodeJar, buildAllDir.value / nodeJarName.value)
}
lazy val moveGeneratorFatJar = Def.task[Unit] {
val generatorJar = (target in (generator, Compile)).value / generatorJarName.value
IO.copyFile(generatorJar, buildAllDir.value / generatorJarName.value)
}
lazy val moveGeneratorObfuscatedJar = Def.task[Unit] {
val obfuscatedJar = (proguardOutputs in (generator, Proguard)).value.head
IO.copyFile(obfuscatedJar, buildAllDir.value / generatorJarName.value)
}
lazy val recreateBuildAllDir = Def.task[Unit] {
IO.delete(buildAllDir.value)
IO.createDirectory(buildAllDir.value)
}
/* ********************************************************* */
/**
* More machinery:
* * cleanAll - cleans all sub-projects;
* * buildAll - builds node and generator (to fat jars)
*/
lazy val cleanAll = taskKey[Unit]("Clean all sub-projects")
cleanAll := Def
.sequential(
printMessageTask("Clean node"),
clean in node,
printMessageTask("Clean generator"),
clean in generator,
printMessageTask("Clean transactionsSigner"),
clean in transactionsSigner
)
.value
lazy val buildAll = taskKey[Unit]("Build node and generator (jars)")
buildAll := Def
.sequential(
printMessageTask("Recreate /artifacts dir"),
recreateBuildAllDir,
printMessageTask("Assembly node (fat jar)"),
assembly,
printMessageTask("Move node fat jar to /artifacts"),
moveNodeFatJar,
printMessageTask("Assembly generator (fat jar)"),
assembly in generator,
printMessageTask("Move generator fat jar to /artifacts"),
moveGeneratorFatJar
)
.value
/* ********************************************************* */
lazy val errLogger = ProcessLogger(_ => (), err => sys.error(err))
lazy val dockerBuild = taskKey[Unit]("Runs Docker build")
dockerBuild := Def.task(Process(s"docker build -t wavesenterprise/node:v${version.value} .").!(errLogger))
lazy val dockerLifeCheck = taskKey[Unit]("Checks if Docker is running")
dockerLifeCheck := Def.task { Process("docker info").!(errLogger) }
lazy val release = taskKey[Unit]("Prepares artifacts for release. Since 1.1.1, it assembles and obfuscates generator jar")
release := Def
.sequential(
printMessageTask("Checking is Docker running"),
dockerLifeCheck,
printMessageTask("Recreating /artifacts dir"),
recreateBuildAllDir,
printMessageTask("Assembling fat jar"),
assembly,
printMessageTask("Building Docker image"),
dockerBuild,
printMessageTask("Assembling generator"),
assembly in generator,
printMessageTask("Obfuscating assembled generator"),
proguard in (generator, Proguard),
printMessageTask("Moving obfuscated generator jar to /artifacts"),
moveGeneratorObfuscatedJar,
printMessageTask("Done")
)
.value