Skip to content

Commit

Permalink
Merge pull request #52 from AndyHWChung/play-29-30
Browse files Browse the repository at this point in the history
add play 2.9+3.0 support
  • Loading branch information
ShaneTN authored Dec 11, 2023
2 parents 267fa9a + 592ab2d commit f55af4c
Show file tree
Hide file tree
Showing 48 changed files with 119 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ target

nohup.out
rebel.xml

.bsp
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ domain

Micro-library for typing and validating UK tax identifiers.

#### Change History
v9.0 - 05 Dec 23
- add support for Play 2.9 & Play 3.0, noting Play 2.8 is still supported
- update Scala 2.13 version
- update library dependencies
- add 'Change History' section to README

v8.3.0 - 23 May 22
- update broken sbt build

v8.1.0 - 06 May 22
- update library dependencies


#### Identifier Types

Types are provided for many common tax identifiers, such as:
Expand Down Expand Up @@ -48,13 +62,30 @@ taxIds.ctUtr // None

### Installing

#### Before version 9.x.x
Add the following to your SBT build:
```scala
libraryDependencies += "uk.gov.hmrc" %% "domain" % "[INSERT VERSION]-play-[INSERT VERSION]"
libraryDependencies += "uk.gov.hmrc" %% "domain" % "[LIB VERSION]-play-[PLAY VERSION]"
```
for example
```scala
libraryDependencies += "uk.gov.hmrc" %% "domain" % "8.3.0-play-28"
```

#### After version 9.x.x
Add the following to your SBT build:
```scala
libraryDependencies += "uk.gov.hmrc" %% "domain-play-[PLAY VERSION]" % "[LIB VERSION]"
```
for example
```scala
libraryDependencies += "uk.gov.hmrc" %% "domain-play-30" % "9.0.0"
```

## Version

Version 9.x.x add Play 2.9 and Play 3.0 support.

Version 8.x.x add Scala 2.13 support.

Version 7.x.x drop Play 2.6 and Play 2.7 support.
Expand Down
63 changes: 43 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,27 +1,50 @@
val scala2_12 = "2.12.15"
val scala2_13 = "2.13.8"
val scala2_13 = "2.13.12"

val silencerVersion = "1.7.8"
ThisBuild / scalaVersion := scala2_13
ThisBuild / majorVersion := 9
ThisBuild / isPublicArtefact := true
ThisBuild / scalacOptions += "-Wconf:src=src_managed/.*:s" // silence all warnings on autogenerated files

lazy val domain = (project in file("."))
.settings(publish / skip := true)
.aggregate(
play28,
play29,
play30
)

lazy val commonSettings =
ScalariformSettings() ++ ScoverageSettings()

lazy val play28 = Project("domain-play-28", file("play-28"))
.settings(
scalaVersion := scala2_12,
crossScalaVersions := Seq(scala2_12, scala2_13),
majorVersion := 8,
isPublicArtefact := true,
libraryDependencies ++= PlayCrossCompilation.dependencies(
shared = Seq(
"org.scalatest" %% "scalatest" % "3.2.11" % "test",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0" % "test",
"org.pegdown" % "pegdown" % "1.6.0" % "test",
"com.vladsch.flexmark" % "flexmark-all" % "0.62.2" % "test"
),
play28 = Seq(
"com.typesafe.play" %% "play-json" % "2.8.2"
)
)
libraryDependencies ++= LibDependencies.play28 ++ LibDependencies.test,
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always,
sharedSources
)
.settings(commonSettings)

lazy val play29 = Project("domain-play-29", file("play-29"))
.settings(
crossScalaVersions := Seq(scala2_13),
libraryDependencies ++= LibDependencies.play29 ++ LibDependencies.test,
sharedSources
)
.settings(PlayCrossCompilation.playCrossCompilationSettings)
.settings(ScalariformSettings())
.settings(ScoverageSettings())
.settings(SilencerSettings(silencerVersion))
.settings(commonSettings)

lazy val play30 = Project("domain-play-30", file("play-30"))
.settings(
crossScalaVersions := Seq(scala2_13),
libraryDependencies ++= LibDependencies.play30 ++ LibDependencies.test,
sharedSources
)
.settings(commonSettings)

def sharedSources = Seq(
Compile / unmanagedSourceDirectories += baseDirectory.value / "../shared/src/main/scala",
Compile / unmanagedResourceDirectories += baseDirectory.value / "../shared/src/main/resources",
Test / unmanagedSourceDirectories += baseDirectory.value / "../shared/src/test/scala",
Test / unmanagedResourceDirectories += baseDirectory.value / "../shared/src/test/resources"
)
22 changes: 22 additions & 0 deletions project/LibDependencies.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import sbt._

object LibDependencies {
val play28 = Seq(
"com.typesafe.play" %% "play" % "2.8.21"
)

val play29 = Seq(
"com.typesafe.play" %% s"play" % "2.9.0"
)

val play30 = Seq(
"org.playframework" %% s"play" % "3.0.0"
)

val test = Seq(
"org.scalatest" %% "scalatest" % "3.2.11",
"org.scalatestplus" %% "scalacheck-1-15" % "3.2.11.0",
"org.pegdown" % "pegdown" % "1.6.0",
"com.vladsch.flexmark" % "flexmark-all" % "0.62.2"
).map(_ % Test)
}
4 changes: 0 additions & 4 deletions project/PlayCrossCompilation.scala

This file was deleted.

2 changes: 1 addition & 1 deletion project/ScoverageSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ object ScoverageSettings {
ScoverageKeys.coverageMinimumStmtTotal := 81,
ScoverageKeys.coverageFailOnMinimum := true,
ScoverageKeys.coverageHighlighting := true,
parallelExecution in Test := false
(Test / parallelExecution) := false
)
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.5.8
sbt.version=1.9.7
9 changes: 3 additions & 6 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
resolvers += MavenRepository("HMRC-open-artefacts-maven2", "https://open.artefacts.tax.service.gov.uk/maven2")
resolvers += Resolver.url("HMRC-open-artefacts-ivy2", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)

addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.6.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.15.0")

addSbtPlugin("uk.gov.hmrc" % "sbt-play-cross-compilation" % "2.3.0")

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.9.3")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.3" exclude("org.scala-lang.modules", "scala-xml_2.12"))
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ case class TaxCode(code: String) {
}

object TaxCodeFormats {
implicit val taxCodeReads = new TaxCodeReads
implicit val taxCodeWrites = new TaxCodeWrites
implicit val taxCodeReads: TaxCodeReads = new TaxCodeReads
implicit val taxCodeWrites: TaxCodeWrites = new TaxCodeWrites

class TaxCodeReads extends Reads[TaxCode] {
override def reads(json: JsValue): JsResult[TaxCode] = {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,23 @@ package uk.gov.hmrc.domain
import org.scalatest.LoneElement
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec
import play.api.libs.json.{JsError, Json}
import play.api.libs.json.{Format, JsError, Json}

class TaxIdsSpec extends AnyWordSpec with Matchers with LoneElement {

val nino = Nino("NM439088A")
val saUtr = SaUtr("some-sa-utr")
implicit val format = TaxIds.format(TaxIds.defaultSerialisableIds: _*)
implicit val format: Format[TaxIds] = TaxIds.format(TaxIds.defaultSerialisableIds: _*)

"TaxIds constructor" should {
"fail to create a TaxIds object with duplicate tax identifiers" in {
val ex = the[IllegalArgumentException] thrownBy TaxIds(nino, nino)
ex should have('message("requirement failed: TaxIds cannot have TaxIdentifers with the same name"))
ex should have(Symbol("message")("requirement failed: TaxIds cannot have TaxIdentifers with the same name"))
}

"fail to create a TaxIds object with no tax identifiers" in {
val ex = the[IllegalArgumentException] thrownBy TaxIds()
ex should have('message("requirement failed: TaxIds must have at least one TaxIdentifier"))
ex should have(Symbol("message")("requirement failed: TaxIds must have at least one TaxIdentifier"))
}
}

Expand All @@ -46,7 +46,7 @@ class TaxIdsSpec extends AnyWordSpec with Matchers with LoneElement {
"""{
|"nino": "NM439088A"
}""".stripMargin
Json.parse(input).as[TaxIds] should have('nino(Some(nino)))
Json.parse(input).as[TaxIds] should have(Symbol("nino")(Some(nino)))
}

"succeed to build a TaxIds object with two TaxIdentifiers of type Nino and SaUtr" in {
Expand All @@ -55,15 +55,15 @@ class TaxIdsSpec extends AnyWordSpec with Matchers with LoneElement {
|"nino": "NM439088A",
|"sautr": "some-sa-utr"
}""".stripMargin
Json.parse(input).as[TaxIds] should (have('nino(Some(nino))) and have('saUtr(Some(saUtr))))
Json.parse(input).as[TaxIds] should (have(Symbol("nino")(Some(nino))) and have(Symbol("saUtr")(Some(saUtr))))
}

"succeed to build a TaxIds object with a TaxIdentifier of type SaUtr" in {
val input =
"""{
|"sautr": "some-sa-utr"
}""".stripMargin
Json.parse(input).as[TaxIds] should have('saUtr(Some(saUtr)))
Json.parse(input).as[TaxIds] should have(Symbol("saUtr")(Some(saUtr)))
}

"fail to build a TaxIds object with more than one TaxIdentifier of the same type" ignore {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ class ModulusCheckerSpec extends AnyWordSpecLike with Matchers with ScalaCheckDr
val remainderLookupTable = List(2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1)

forAll(checkSum) { (ints: Seq[Int]) =>
val remainder = (ints, weights).zipped.map {
val remainder = ints.zip(weights).map {
case (s, i) => s * i
}.sum % 11
val firstNumber: Int = remainderLookupTable(remainder)
SelfAssessmentReferenceChecker.isValid(firstNumber + ints.mkString + "K") shouldBe true
SelfAssessmentReferenceChecker.isValid(s"$firstNumber${ints.mkString}K") shouldBe true
}
}

Expand All @@ -72,11 +72,11 @@ class ModulusCheckerSpec extends AnyWordSpecLike with Matchers with ScalaCheckDr
val remainderLookupTable = List(2, 1, 9, 8, 7, 6, 5, 4, 3, 2, 1)

forAll(checkSum) { (ints: Seq[Int]) =>
val remainder = (ints, weights).zipped.map {
val remainder = ints.zip(weights).map {
case (s, i) => s * i
}.sum % 11
val firstNumber: Int = remainderLookupTable(remainder)
CorporationTaxReferenceChecker.isValid(firstNumber + ints.mkString) should be (true)
CorporationTaxReferenceChecker.isValid(s"$firstNumber${ints.mkString}") should be (true)
}
}

Expand All @@ -102,7 +102,7 @@ class ModulusCheckerSpec extends AnyWordSpecLike with Matchers with ScalaCheckDr

forAll(checkSum) { (ints: Seq[Int]) =>
whenever(ints.size == 7) {
var sums = (ints, vatWeights).zipped.map {
var sums = ints.zip(vatWeights).map {
case (s, i) => s * i
}.sum

Expand All @@ -119,7 +119,7 @@ class ModulusCheckerSpec extends AnyWordSpecLike with Matchers with ScalaCheckDr

forAll(checkSum) { (ints: Seq[Int]) =>
whenever(ints.size == 7) {
var sums = (ints, vatWeights).zipped.map {
var sums = ints.zip(vatWeights).map {
case (s, i) => s * i
}.sum + 55

Expand Down

0 comments on commit f55af4c

Please sign in to comment.