Skip to content

Commit

Permalink
breaking: Update to Scala 3.3.3 (#507)
Browse files Browse the repository at this point in the history
* breaking: Update to Scala `3.3.3`

Scala 3 case-app doesn't depend on shapeless anymore, which
should reduce the binary size
This also updates dependencies to their Scala 3 compatible counterpart
- case-app is updated to `2.1.0-M28`
- airframe-log is updated to `24.6.0`
- airframe-log is updated to `24.6.0`
- `mockito` is replaced with `scalamock` which supports scala 3
- `scalatest` is updated to `3.2.18`
- `play-json` is updated to `2.10.5`
- `codacy-plugins-api` is updated to `8.1.4`
- `scala-xml` is updated to `2.3.0`

* fix: Add `= None` to optional configs as required by case-app on Scala 3

* fix: Revert circle changes

* fix: Use LazyList to keep lazy semantics
  • Loading branch information
lolgab authored Jun 14, 2024
1 parent 5cad31b commit 9642dc1
Show file tree
Hide file tree
Showing 26 changed files with 244 additions and 241 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ case class CoverageFileReport(filename: String, coverage: Map[Int, Int])
case class CoverageReport(fileReports: Seq[CoverageFileReport])

object CoverageReport {
implicit val mapWrites: Writes[Map[Int, Int]] = Writes[Map[Int, Int]] { map: Map[Int, Int] =>
implicit val mapWrites: Writes[Map[Int, Int]] = Writes[Map[Int, Int]] { (map: Map[Int, Int]) =>
JsObject(map.map {
case (key, value) => (key.toString, JsNumber(value))
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.eclipse.jgit.lib.{Repository, RepositoryBuilder}
import org.eclipse.jgit.revwalk.RevWalk
import org.eclipse.jgit.treewalk.TreeWalk

import scala.collection.JavaConverters._
import scala.jdk.CollectionConverters._
import scala.util.Try

case class CommitInfo(uuid: String, authorName: String, authorEmail: String, date: Date)
Expand Down Expand Up @@ -53,7 +53,7 @@ class GitClient(workDirectory: File) {

val result: Seq[String] =
if (treeWalk.next) {
Stream
LazyList
.continually(treeWalk.getPathString)
.takeWhile(_ => treeWalk.next)
} else Seq.empty
Expand Down
7 changes: 4 additions & 3 deletions api-scala/src/test/scala/com/codacy/api/GitClientTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.codacy.api

import com.codacy.api.helpers.vcs.GitClient
import java.nio.file.Paths
import org.scalatest.{FlatSpec, Matchers}
import org.scalatest.matchers.should.Matchers
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.OptionValues._

class GitClientTest extends FlatSpec with Matchers {
class GitClientTest extends AnyFlatSpec with Matchers {

"GitClient" should "latestCommitUuid" in {

Expand All @@ -15,7 +16,7 @@ class GitClientTest extends FlatSpec with Matchers {

latest shouldNot be(None)

latest.value shouldNot be('empty)
latest.value shouldNot be(Symbol("empty"))
}

}
43 changes: 22 additions & 21 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
inThisBuild(
Seq(
scalaVersion := "2.13.13",
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Xlint", "-Xfatal-warnings")
)
)
inThisBuild(Seq(scalaVersion := "3.3.3"))

def commonSettings =
Seq(scalacOptions := {
val toFilter = Set("-deprecation:false")
scalacOptions.value.filterNot(toFilter) ++ Seq("-deprecation")
})

name := "codacy-coverage-reporter"

// Runtime dependencies
libraryDependencies ++= Seq(
"com.github.alexarchambault" %% "case-app" % "2.1.0-M26",
"org.wvlet.airframe" %% "airframe-log" % "22.3.0"
"com.github.alexarchambault" %% "case-app" % "2.1.0-M28",
"org.wvlet.airframe" %% "airframe-log" % "24.6.0"
)

// Test dependencies
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % "3.0.8" % "it,test",
"org.mockito" %% "mockito-scala-scalatest" % "1.7.1" % Test
)
libraryDependencies ++= Seq(scalatest % "it,test", "org.scalamock" %% "scalamock" % "6.0.0" % Test)

assembly / mainClass := Some("com.codacy.CodacyCoverageReporter")
assembly / assemblyMergeStrategy := {
Expand Down Expand Up @@ -72,24 +70,30 @@ nativeImageOptions := Seq(

dependsOn(coverageParser)

commonSettings

val scalatest = "org.scalatest" %% "scalatest" % "3.2.18"

lazy val apiScala = project
.in(file("api-scala"))
.settings(
commonSettings,
libraryDependencies ++= Seq(
"com.typesafe.play" %% "play-json" % "2.8.2",
"org.scalaj" %% "scalaj-http" % "2.4.2",
"com.typesafe.play" %% "play-json" % "2.10.5",
("org.scalaj" %% "scalaj-http" % "2.4.2").cross(CrossVersion.for3Use2_13),
"org.eclipse.jgit" % "org.eclipse.jgit" % "4.11.9.201909030838-r",
"org.scalatest" %% "scalatest" % "3.0.8" % Test
scalatest % Test
)
)

lazy val coverageParser = project
.in(file("coverage-parser"))
.settings(
commonSettings,
libraryDependencies ++= Seq(
"com.codacy" %% "codacy-plugins-api" % "5.2.0",
"org.scala-lang.modules" %% "scala-xml" % "1.2.0",
"org.scalatest" %% "scalatest" % "3.0.8" % Test
"com.codacy" %% "codacy-plugins-api" % "8.1.4",
"org.scala-lang.modules" %% "scala-xml" % "2.3.0",
scalatest % Test
)
)
.dependsOn(apiScala)
Expand All @@ -102,6 +106,3 @@ ThisBuild / assemblyMergeStrategy := {
val oldStrategy = (ThisBuild / assemblyMergeStrategy).value
oldStrategy(x)
}

// required to upgrade org.scoverage.sbt-scoverage.2.0.6
ThisBuild / libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ object CloverParser extends CoverageParser with XmlReportParser {
val coverageFiles = (report \\ "file").foldLeft[Either[String, Seq[CoverageFileReport]]](Right(List())) {
case (Right(accumulatedFileReports), fileTag) =>
val fileReport = getCoverageFileReport(rootPath, fileTag)
fileReport.right.map(_ +: accumulatedFileReports)
fileReport.map(_ +: accumulatedFileReports)

case (Left(errorMessage), _) => Left(errorMessage)
}
Expand Down Expand Up @@ -76,7 +76,7 @@ object CloverParser extends CoverageParser with XmlReportParser {
lineNumber <- getFirstNonEmptyValueAsInt(Seq(line), "num")
countOfExecutions <- getFirstNonEmptyValueAsInt(Seq(line), "count")
} yield (lineNumber, countOfExecutions)
lineCoverage.right.map(lines + _)
lineCoverage.map(lines + _)

case (accumulated, _) => accumulated
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.codacy.parsers
import java.io.File

import com.codacy.parsers.implementation.CloverParser
import org.scalatest.{EitherValues, Matchers, WordSpec}
import org.scalatest.EitherValues
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class CloverParserTest extends WordSpec with Matchers with EitherValues {
class CloverParserTest extends AnyWordSpec with Matchers with EitherValues {

"parse" should {

Expand Down Expand Up @@ -46,7 +48,7 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {
val parseResult = CloverParser.parse(new File("."), new File(cloverReportPath))

// Assert
parseResult shouldBe 'right
parseResult shouldBe Symbol("right")
}

"the report does not have packages" in {
Expand All @@ -55,7 +57,7 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {
.parse(new File("/home/codacy-php/"), new File(cloverWithoutPackagesFilePath))

// Assert
parseResult shouldBe 'right
parseResult shouldBe Symbol("right")
}

}
Expand All @@ -70,7 +72,6 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {
val parsedReportFilePaths =
CloverParser
.parse(new File("/Users/username/workspace/repository"), cloverWithPaths)
.right
.value
.fileReports
.map(_.filename)
Expand Down Expand Up @@ -98,7 +99,7 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {

// Act
val fileReports =
CloverParser.parse(new File("/home/codacy-php/"), new File(cloverReportPath)).right.value.fileReports
CloverParser.parse(new File("/home/codacy-php/"), new File(cloverReportPath)).value.fileReports

// Assert
fileReports should have length expectedNumberOfFiles
Expand All @@ -118,7 +119,6 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {
val parsedReportFilePaths =
CloverParser
.parse(new File("/home/codacy-php/"), new File(cloverReportPath))
.right
.value
.fileReports
.map(_.filename)
Expand All @@ -135,7 +135,6 @@ class CloverParserTest extends WordSpec with Matchers with EitherValues {
val fileLineCoverage =
CloverParser
.parse(new File("/home/codacy-php/"), new File(cloverReportPath))
.right
.value
.fileReports
.find(_.filename == filePath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import java.io.File

import com.codacy.api.{CoverageFileReport, CoverageReport}
import com.codacy.parsers.implementation.CoberturaParser
import org.scalatest.{BeforeAndAfterAll, EitherValues, Matchers, WordSpec}
import org.scalatest.{BeforeAndAfterAll, EitherValues}
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers with EitherValues {
class CoberturaParserTest extends AnyWordSpec with BeforeAndAfterAll with Matchers with EitherValues {

"CoberturaParser" should {

Expand Down Expand Up @@ -35,7 +37,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
)
)

reader.right.value should equal(testReport)
reader.value should equal(testReport)
}

"not crash on thousands separators" in {
Expand All @@ -52,7 +54,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
)
)

reader.right.value should equal(testReport)
reader.value should equal(testReport)
}

"return a valid report with windows file path separator" in {
Expand All @@ -69,7 +71,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
)
)

reader.right.value should equal(testReport)
reader.value should equal(testReport)
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.codacy.parsers
import java.io.File

import com.codacy.api.{CoverageFileReport, CoverageReport}
import org.scalatest.{BeforeAndAfterAll, Matchers, WordSpec}
import org.scalatest.{BeforeAndAfterAll}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers

class CoverageParserFactoryTest extends WordSpec with BeforeAndAfterAll with Matchers {
class CoverageParserFactoryTest extends AnyWordSpec with BeforeAndAfterAll with Matchers {

"CoverageParserFactory" should {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package com.codacy.parsers
import java.io.File
import com.codacy.parsers.implementation._

import org.scalatest.{BeforeAndAfterAll, EitherValues, Matchers, WordSpec}
import org.scalatest.{BeforeAndAfterAll, EitherValues}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers

class CoverageParserTest extends WordSpec with BeforeAndAfterAll with Matchers with EitherValues {
class CoverageParserTest extends AnyWordSpec with BeforeAndAfterAll with Matchers with EitherValues {
private val coberturaReportPath = "coverage-parser/src/test/resources/test_cobertura.xml"
private val cloverReportPath = "coverage-parser/src/test/resources/test_clover.xml"

Expand All @@ -14,25 +16,25 @@ class CoverageParserTest extends WordSpec with BeforeAndAfterAll with Matchers w
"the file cannot be parsed with a specific parser" in {
val reader = CoverageParser.parse(new File("."), new File(coberturaReportPath), Some(CloverParser))

reader shouldBe 'left
reader shouldBe Symbol("left")
}
"the file cannot be parsed with another specific parser" in {
val reader = CoverageParser.parse(new File("."), new File(coberturaReportPath), Some(LCOVParser))

reader shouldBe 'left
reader shouldBe Symbol("left")
}
}
"return a valid result" when {
"file and format are matching cobertura" in {
val reader =
CoverageParser.parse(new File("."), new File(coberturaReportPath), Some(CoberturaParser))

reader shouldBe 'right
reader shouldBe Symbol("right")
}
"file and format are matching clover" in {
val reader = CoverageParser.parse(new File("."), new File(cloverReportPath), Some(CloverParser))

reader shouldBe 'right
reader shouldBe Symbol("right")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import java.io.File

import com.codacy.api.{CoverageFileReport, CoverageReport}
import com.codacy.parsers.implementation.DotcoverParser
import org.scalatest.{BeforeAndAfterAll, EitherValues, Matchers, WordSpec}
import org.scalatest.{BeforeAndAfterAll, EitherValues}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers

class DotCoverParserTest extends WordSpec with BeforeAndAfterAll with Matchers with EitherValues {
class DotCoverParserTest extends AnyWordSpec with BeforeAndAfterAll with Matchers with EitherValues {
private val nonExistentFile = "coverage-parser/src/test/resources/non-existent.xml"
private val dotCoverReport = "coverage-parser/src/test/resources/test_dotcover.xml"
private val differentFormatReport = "coverage-parser/src/test/resources/test_cobertura.xml"
Expand All @@ -15,25 +17,25 @@ class DotCoverParserTest extends WordSpec with BeforeAndAfterAll with Matchers w
"report file does not exist" in {
val reader = DotcoverParser.parse(new File("."), new File(nonExistentFile))

reader shouldBe 'left
reader shouldBe Symbol("left")
}

"report file has a different format" in {
val reader = DotcoverParser.parse(new File("."), new File(differentFormatReport))

reader shouldBe 'left
reader shouldBe Symbol("left")
}
}

"return a valid report" in {
val reader = DotcoverParser.parse(new File("."), new File(dotCoverReport))

reader shouldBe 'right
reader shouldBe Symbol("right")
}

"return the expected files" in {
val reader = DotcoverParser.parse(new File("."), new File(dotCoverReport))
reader.right.value.fileReports.map(_.filename).sorted shouldBe Seq(
reader.value.fileReports.map(_.filename).sorted shouldBe Seq(
"src/Coverage/FooBar.cs",
"src/Tests/FooBarTests.cs",
"src/Coverage/Program.cs",
Expand All @@ -45,7 +47,7 @@ class DotCoverParserTest extends WordSpec with BeforeAndAfterAll with Matchers w
"return the expected coverage report" in {
val reader = DotcoverParser.parse(new File("."), new File(dotCoverReport))

reader.right.value shouldBe CoverageReport(
reader.value shouldBe CoverageReport(
List(
CoverageFileReport(
"src/Coverage/FooBar.cs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import java.io.File
import com.codacy.api._

import com.codacy.parsers.implementation.GoParser
import org.scalatest.{EitherValues, Matchers, WordSpec}
import org.scalatest.{EitherValues}
import org.scalatest.wordspec.AnyWordSpec
import org.scalatest.matchers.should.Matchers

class GoParserTest extends WordSpec with Matchers with EitherValues {
class GoParserTest extends AnyWordSpec with Matchers with EitherValues {

"parse" should {

Expand Down Expand Up @@ -37,7 +39,7 @@ class GoParserTest extends WordSpec with Matchers with EitherValues {
)
)

reader.right.value should equal(testReport)
reader.value should equal(testReport)
}

"return consistent values" in {
Expand All @@ -46,7 +48,7 @@ class GoParserTest extends WordSpec with Matchers with EitherValues {
val reader1 =
GoParser.parse(new File("."), new File("coverage-parser/src/test/resources/go/changed_package_name.out"))

reader.right.value.fileReports(0).coverage should equal(reader1.right.value.fileReports(0).coverage)
reader.value.fileReports(0).coverage should equal(reader1.value.fileReports(0).coverage)
}
}
}
Loading

0 comments on commit 9642dc1

Please sign in to comment.