Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

breaking: Update to Scala 3.3.3 #507

Merged
merged 4 commits into from
Jun 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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))
})
Original file line number Diff line number Diff line change
@@ -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)
@@ -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
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
@@ -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 {

@@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here and why do we need it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There were two issues that were failing compilation because of -Xfatal-warnings and couldn't be seen because of the -deprecation:false setting in codacy-sbt. Maybe we need to revisit scalacOptions in codacy-sbt but until that day this removes that option and adds -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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙃

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷‍♂️

"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 := {
@@ -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),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the ideia here? That lib is not available for Scala3, and with this we are relying on the one from 2.13? (It also seems deprecated, so I guess we will want to swap at some point)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly!
I tried to swap with sttp once and I created an outage, but I will give another try with a newer and better maintained library. Fortunately Sbt can check for incompatibilities with the mix of _2.13 and _3 dependencies, so we are totally safe here.

"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)
@@ -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
@@ -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)
}
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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 {

@@ -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 {
@@ -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")
}

}
@@ -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)
@@ -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
@@ -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)
@@ -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)
Original file line number Diff line number Diff line change
@@ -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 {

@@ -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 {
@@ -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 {
@@ -69,7 +71,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
)
)

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

}
Original file line number Diff line number Diff line change
@@ -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 {

Original file line number Diff line number Diff line change
@@ -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"

@@ -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")
}
}
}
Original file line number Diff line number Diff line change
@@ -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"
@@ -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",
@@ -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",
Original file line number Diff line number Diff line change
@@ -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 {

@@ -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 {
@@ -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