-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.sbt
131 lines (108 loc) · 5.37 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
import AppDependencies._
import com.typesafe.sbt.web.PathMapping
import com.typesafe.sbt.web.pipeline.Pipeline
import play.sbt.PlayImport.PlayKeys.playDefaultPort
import sbt.Keys._
import sbt.Tests.{Group, SubProcess}
import sbt._
import uk.gov.hmrc.DefaultBuildSettings.{addTestReportOption, targetJvm}
import uk.gov.hmrc.gitstamp.GitStampPlugin._
import uk.gov.hmrc.sbtdistributables.SbtDistributablesPlugin
import java.text.SimpleDateFormat
import java.util.Calendar
import scala.language.postfixOps
name := "customs-declarations"
scalaVersion := "2.13.14"
lazy val CdsIntegrationComponentTest = config("it") extend Test
val testConfig = Seq(CdsIntegrationComponentTest, Test)
def forkedJvmPerTestConfig(tests: Seq[TestDefinition], packages: String*): Seq[Group] =
tests.groupBy(_.name.takeWhile(_ != '.')).filter(packageAndTests => packages contains packageAndTests._1) map {
case (packg, theTests) =>
Group(packg, theTests, SubProcess(ForkOptions()))
} toSeq
lazy val testAll = TaskKey[Unit]("test-all")
lazy val allTest = Seq(testAll := (CdsIntegrationComponentTest / test).dependsOn(Test / test).value)
lazy val microservice = (project in file("."))
.enablePlugins(PlayScala)
.enablePlugins(SbtDistributablesPlugin)
.disablePlugins(sbt.plugins.JUnitXmlReportPlugin)
.configs(testConfig: _*)
.settings(
commonSettings,
unitTestSettings,
integrationComponentTestSettings,
allTest,
scoverageSettings
)
.settings(majorVersion := 0)
.settings(playDefaultPort := 9820)
def onPackageName(rootPackage: String): String => Boolean = {
testName => testName startsWith rootPackage
}
lazy val unitTestSettings =
inConfig(Test)(Defaults.testTasks) ++
Seq(
Test / testOptions := Seq(Tests.Filter(onPackageName("unit"))),
Test / testOptions += Tests.Argument(TestFrameworks.ScalaTest, "-oD"),
Test / unmanagedSourceDirectories := Seq((Test / baseDirectory).value / "test"),
addTestReportOption(Test, "test-reports")
)
lazy val integrationComponentTestSettings =
inConfig(CdsIntegrationComponentTest)(Defaults.testTasks) ++
Seq(
CdsIntegrationComponentTest / testOptions := Seq(Tests.Filter(integrationComponentTestFilter)),
CdsIntegrationComponentTest / parallelExecution := false,
addTestReportOption(CdsIntegrationComponentTest, "int-comp-test-reports"),
CdsIntegrationComponentTest / testGrouping := forkedJvmPerTestConfig((Test / definedTests).value, "integration", "component")
)
lazy val commonSettings: Seq[Setting[_]] = gitStampSettings
lazy val scoverageSettings: Seq[Setting[_]] = Seq(
coverageExcludedPackages := List(
"<empty>"
,"uk\\.gov\\.hmrc\\.customs\\.declaration\\.model\\..*"
,"uk\\.gov\\.hmrc\\.customs\\.declaration\\.views\\..*"
,".*(Reverse|AuthService|BuildInfo|Routes).*"
).mkString(";"),
coverageMinimumStmtTotal := 96,
coverageFailOnMinimum := true,
coverageHighlighting := true,
Test / parallelExecution := false
)
def integrationComponentTestFilter(name: String): Boolean = (name startsWith "integration") || (name startsWith "component")
def unitTestFilter(name: String): Boolean = name startsWith "unit"
scalastyleConfig := baseDirectory.value / "project" / "scalastyle-config.xml"
val compileDependencies = Seq(hmrcMongo, bootstrapBackendPlay30, cats)
val testDependencies = Seq(scalamock, hmrcMongoTest, bootstrapBackendTestPlay30)
Compile / unmanagedResourceDirectories += baseDirectory.value / "public"
(Runtime / managedClasspath) += (Assets / packageBin).value
libraryDependencies ++= compileDependencies ++ testDependencies
// Task to create a ZIP file containing all WCO XSDs for each version, under the version directory
val zipWcoXsds = taskKey[Pipeline.Stage]("Zips up all WCO declaration XSDs and example messages")
zipWcoXsds := { mappings: Seq[PathMapping] =>
val targetDir = WebKeys.webTarget.value / "zip"
val zipFiles: Iterable[java.io.File] =
((Assets / resourceDirectory ).value / "api" / "conf")
.listFiles
.filter(_.isDirectory)
.map { dir =>
val xsdPaths = Path.allSubpaths(dir / "schemas")
val exampleMessagesFilter = new SimpleFileFilter(_.getPath.contains("/annotated_XML_samples/"))
val exampleMessagesPaths = Path.selectSubpaths(dir / "examples", exampleMessagesFilter)
val zipFile = targetDir / "api" / "conf" / dir.getName / "wco-declaration-schemas.zip"
IO.zip(xsdPaths ++ exampleMessagesPaths, zipFile, None)
val sizeInMb = (BigDecimal(zipFile.length) / BigDecimal(1024 * 1024)).setScale(1, BigDecimal.RoundingMode.UP)
println(s"Created zip $zipFile")
val today = Calendar.getInstance().getTime()
val dateFormat = new SimpleDateFormat("dd/MM/YYYY")
val lastUpdated = dateFormat.format(today)
println(s"Update the file size in ${dir.getParent}/${dir.getName}/docs/schemasAndExamples.md to be [ZIP, ${sizeInMb}MB last updated $lastUpdated]")
println(s"Check the yaml renders correctly file://${dir.getParent}/${dir.getName}/application.yaml")
println("")
zipFile
}
zipFiles.pair(Path.relativeTo(targetDir)) ++ mappings
}
pipelineStages := Seq(zipWcoXsds)
// To resolve a bug with version 2.x.x of the scoverage plugin - https://github.com/sbt/sbt/issues/6997
// Try to remove when sbt 1.8.0+ and scoverage is 2.0.7+
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always