Skip to content

Commit

Permalink
breaking: Update to Scala 3.3.3
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
lolgab committed Jun 14, 2024
1 parent 5cad31b commit 0bc8d1d
Show file tree
Hide file tree
Showing 26 changed files with 241 additions and 237 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ references:

commands:
run_coverage_reporting:
description: "Runs the coverage reporting using the mock-server as API"
description: "Runs the coverage reporting using the stub-server as API"
parameters:
executor:
type: string
Expand Down Expand Up @@ -125,8 +125,8 @@ jobs:
name: wait for mockserver
command: wget --retry-connrefused --method=PUT http://localhost:1080/mockserver/status
- run:
name: configure mock server
command: wget --method=PUT --body-data="$(cat integration-tests/mock-server-config.json)" http://localhost:1080/mockserver/expectation
name: configure stub server
command: wget --method=PUT --body-data="$(cat integration-tests/stub-server-config.json)" http://localhost:1080/mockserver/expectation
- run_coverage_reporting:
executor: sh
error_code: 0
Expand All @@ -148,7 +148,7 @@ jobs:
name: wait for mockserver
command: timeout 60 bash -c 'while [[ "$(curl -X PUT -o /dev/null -w ''%{http_code}'' localhost:1080/mockserver/status)" != "200" ]]; do sleep 2; done' || false
- run:
name: configure mock server
name: configure stub server
command: curl -v -X PUT localhost:1080/mockserver/expectation -d "$(cat << parameters.config_path >>)"
- run_coverage_reporting:
executor: bash
Expand All @@ -174,7 +174,7 @@ jobs:
echo "Start and provision the mockserver"
nohup mockserver -logLevel INFO -serverPort 1080 &
gtimeout 60 bash -c 'while [[ "$(curl -X PUT -o /dev/null -w ''%{http_code}'' localhost:1080/mockserver/status)" != "200" ]]; do sleep 2; done' || false
curl -X PUT -d "$(cat integration-tests/mock-server-config.json)" http://localhost:1080/mockserver/expectation
curl -X PUT -d "$(cat integration-tests/stub-server-config.json)" http://localhost:1080/mockserver/expectation
echo "Run the test"
set +e
Expand Down Expand Up @@ -288,13 +288,13 @@ workflows:
- it_coverage_script_ubuntu:
name: it_coverage_script_ubuntu_success
error_code: 0
config_path: integration-tests/mock-server-config.json
config_path: integration-tests/stub-server-config.json
requires:
- package_artifacts
- it_coverage_script_ubuntu:
name: it_coverage_script_ubuntu_failure
error_code: 1
config_path: integration-tests/mock-server-error-config.json
config_path: integration-tests/stub-server-error-config.json
requires:
- package_artifacts
- codacy/shell:
Expand Down
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,9 +53,10 @@ class GitClient(workDirectory: File) {

val result: Seq[String] =
if (treeWalk.next) {
Stream
Iterator
.continually(treeWalk.getPathString)
.takeWhile(_ => treeWalk.next)
.toSeq
} else Seq.empty

result
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
Loading

0 comments on commit 0bc8d1d

Please sign in to comment.