Skip to content

Commit

Permalink
bump: Update case-app to 2.1.0-M14 and Scala to 2.13 (#493)
Browse files Browse the repository at this point in the history
* bump: Update case-app to 2.0.0

* Update case-app to  2.1.0-M10

* Update to case-app 2.1.0-M11

* Update case-app to 2.1.0-M14

* style: Run scalafmt

* bump: Update Scala to 2.13.13
  • Loading branch information
lolgab authored Mar 25, 2024
1 parent 9b03779 commit 161c45f
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ object CoverageReport {
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))
}(collection.breakOut))
})
}
implicit val coverageFileReportWrites: Writes[CoverageFileReport] = Json.writes[CoverageFileReport]
implicit val coverageReportWrites: Writes[CoverageReport] = Json.writes[CoverageReport]
Expand Down
4 changes: 3 additions & 1 deletion api-scala/src/main/scala/com/codacy/api/util/JsonOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.codacy.api.util

import play.api.libs.json.{JsError, JsPath, Json, JsonValidationError}

import scala.collection

object JsonOps {

def handleConversionFailure(error: Seq[(JsPath, Seq[JsonValidationError])]): String = {
def handleConversionFailure(error: collection.Seq[(JsPath, collection.Seq[JsonValidationError])]): String = {
val jsonError = Json.stringify(JsError.toJson(error.toList))
s"Json conversion error: $jsonError"
}
Expand Down
14 changes: 3 additions & 11 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
inThisBuild(
Seq(
scalaVersion := "2.12.18",
scalacOptions := Seq(
"-deprecation",
"-feature",
"-unchecked",
"-Ywarn-adapted-args",
"-Xlint",
"-Xfatal-warnings",
"-Ypartial-unification"
)
scalaVersion := "2.13.13",
scalacOptions := Seq("-deprecation", "-feature", "-unchecked", "-Xlint", "-Xfatal-warnings")
)
)

name := "codacy-coverage-reporter"

// Runtime dependencies
libraryDependencies ++= Seq(
"com.github.alexarchambault" %% "case-app" % "1.2.0",
"com.github.alexarchambault" %% "case-app" % "2.1.0-M14",
"org.wvlet.airframe" %% "airframe-log" % "22.3.0",
"com.lihaoyi" %% "ujson" % "1.5.0"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
} yield {
val cleanFilename = TextUtils.sanitiseFilename(filename).stripPrefix(projectRootStr).stripPrefix("/")
lineCoverage(cleanFilename, classes)
})(collection.breakOut)
}).toList

CoverageReport(fileReports)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ object JacocoParser extends CoverageParser with XmlReportParser {
}

private def lineCoverage(filename: String, fileNode: Node): CoverageFileReport = {
val lineHitMap: Map[Int, Int] = (fileNode \\ "line")
val lineHitMap: Map[Int, Int] = (fileNode \\ "line").view
.map { line =>
(line \@ "nr").toInt -> LineCoverage((line \@ "mi").toInt, (line \@ "ci").toInt)
}
.collect {
case (key, lineCoverage) if lineCoverage.missedInstructions + lineCoverage.coveredInstructions > 0 =>
key -> (if (lineCoverage.coveredInstructions > 0) 1 else 0)
}(collection.breakOut)
}
.toMap

CoverageFileReport(filename, lineHitMap)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,22 @@ object PhpUnitXmlParser extends CoverageParser with XmlReportParser {
reportRootPath: String
): Either[String, Seq[CoverageFileReport]] = {
val builder = Seq.newBuilder[CoverageFileReport]
for (f <- fileNodes) {
var error = Option.empty[String]
for (f <- fileNodes if error.isEmpty) {
val reportFileName = f \@ "href"
val fileName = getSourceFileName(projectRootPath, codeDirectory, reportFileName)
getLineCoverage(reportRootPath, reportFileName) match {
case Right(lineCoverage) =>
builder += CoverageFileReport(fileName, lineCoverage)
case Left(message) => return Left(message)
case Left(message) => error = Some(message)
}
}
Right(builder.result())
error match {
case Some(value) =>
Left(value)
case None =>
Right(builder.result())
}
}

private def getLineCoverage(reportRootPath: String, filename: String) = {
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ addSbtPlugin("com.codacy" % "codacy-sbt-plugin" % "25.1.1")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.1.4")

// Coverage
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.9")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")

libraryDependencySchemes ++= Seq("org.scala-lang.modules" %% "scala-xml" % VersionScheme.Always)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package com.codacy.configuration.parser

import java.io.File
import caseapp._
import caseapp.core.ArgParser
import caseapp.core.Error
import caseapp.core.app._
import caseapp.core.argparser.ArgParser
import com.codacy.api.OrganizationProvider
import com.codacy.configuration.parser.ConfigArgumentParsers._
import com.codacy.parsers.CoverageParser
Expand Down Expand Up @@ -108,7 +110,10 @@ case class BaseCommandConfig(

object ConfigArgumentParsers {

implicit val fileParser: ArgParser[File] = ArgParser.instance("file")(a => Right(new File(a)))
implicit val fileParser: ArgParser[File] = new ArgParser[File] {
def apply(current: Option[File], index: Int, span: Int, value: String) = Right(new File(value))
def description = "file"
}

val parsersMap = Map(
"cobertura" -> CoberturaParser,
Expand All @@ -121,27 +126,38 @@ object ConfigArgumentParsers {
"go" -> GoParser
)

implicit val coverageParser: ArgParser[CoverageParser] = ArgParser.instance("parser") { v =>
val value = v.trim.toLowerCase
parsersMap.get(value) match {
case Some(parser) => Right(parser)
case _ =>
Left(
s"${value} is an unsupported/unrecognized coverage parser. (Available patterns are: ${parsersMap.keys.mkString(",")})"
)
implicit val coverageParser: ArgParser[CoverageParser] = new ArgParser[CoverageParser] {

def apply(current: Option[CoverageParser], index: Int, span: Int, v: String) = {
val value = v.trim.toLowerCase
parsersMap.get(value) match {
case Some(parser) => Right(parser)
case _ =>
Left(
Error.Other(
s"${value} is an unsupported/unrecognized coverage parser. (Available patterns are: ${parsersMap.keys.mkString(",")})"
)
)
}
}
def description = "parser"
}

implicit val organizationProvider: ArgParser[OrganizationProvider.Value] =
ArgParser.instance("organizationProvider") { v =>
implicit val organizationProvider: ArgParser[OrganizationProvider.Value] = new ArgParser[OrganizationProvider.Value] {

def apply(current: Option[OrganizationProvider.Value], index: Int, span: Int, v: String) = {
val value = v.trim.toLowerCase
OrganizationProvider.values.find(_.toString == value) match {
case Some(provider) => Right(provider)
case _ =>
Left(
s"${value} is an unsupported/unrecognized organization provider. (Available organization provider are: ${OrganizationProvider.values
.mkString(",")})"
Error.Other(
s"${value} is an unsupported/unrecognized organization provider. (Available organization provider are: ${OrganizationProvider.values
.mkString(",")})"
)
)
}
}
def description = "organizationProvider"
}
}
4 changes: 2 additions & 2 deletions src/main/scala/com/codacy/rules/ConfigurationRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ class ConfigurationRules(cmdConfig: CommandConfiguration, envVars: Map[String, S
*/
private[rules] def validateReportFiles(filesOpt: Option[List[File]]): Either[String, List[File]] = {
filesOpt match {
case Some(value) if value.isEmpty =>
case Some(Nil) =>
Left("Invalid report list. Try passing a report file with -r")
case Some(value) if value.nonEmpty =>
case Some(value) =>
Right(value)
case None =>
Right(List.empty[File])
Expand Down
6 changes: 3 additions & 3 deletions src/main/scala/com/codacy/rules/ReportRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ class ReportRules(coverageServices: => CoverageServices, gitFileFetcher: GitFile
val reportLanguages = getReportLanguages(report).distinct
reportLanguages.headOption match {
case None => Left("Can't guess the report language")
case Some(language) =>
case Some(l) =>
if (reportLanguages.size > 1) {
logger.warn(
s"""
|Multiple languages detected in $reportFilePath (${reportLanguages.mkString(",")}).
| This run will only upload coverage for the $language language.
| This run will only upload coverage for the $l language.
| To make sure that you upload coverage for all languages in the report,
| see https://docs.codacy.com/coverage-reporter/uploading-coverage-in-advanced-scenarios/#multiple-languages""".stripMargin
)
}
Right(language)
Right(l)
}
}
}
Expand Down

0 comments on commit 161c45f

Please sign in to comment.