From d1655f065f7c5537a3b12f77281748689a253a87 Mon Sep 17 00:00:00 2001 From: AB024LL Date: Mon, 21 Nov 2022 10:37:00 +0100 Subject: [PATCH] #532 - Add code coverage support - Jacoco - added new plugin dependency - extended readme.md file with how to get code coverage report - extended build logic to add JaCoCo non-default settings --- README.md | 19 +++++++++++++++++++ build.sbt | 22 ++++++++++++++++++++++ project/plugins.sbt | 1 + 3 files changed, 42 insertions(+) diff --git a/README.md b/README.md index 8bb5cf790..6608048a8 100644 --- a/README.md +++ b/README.md @@ -125,6 +125,15 @@ of that project for the detailed guide how to run the examples locally and on a When running `mvn clean package` in `examples/spark-cobol-app` an uber jar will be created. It can be used to run jobs via `spark-submit` or `spark-shell`. +## How to generate Code coverage report +```sbt +sbt ++{scala_version} jacoco +``` +Code coverage will be generated on path: +``` +{project-root}/cobrix/{module}/target/scala-{scala_version}/jacoco/report/html +``` + ### Reading Cobol binary files from HDFS/local and querying them 1. Create a Spark ```SQLContext``` @@ -1423,6 +1432,16 @@ For multisegment variable lengths tests: ![](performance/images/exp3_multiseg_wide_time.svg) ![](performance/images/exp3_multiseg_wide_efficiency.svg) ![](performance/images/exp3_multiseg_wide_records_throughput.svg) ![](performance/images/exp3_multiseg_wide_mb_throughput.svg) + +### How to generate Code coverage report +```sbt +sbt jacoco +``` +Code coverage will be generated on path: +``` +{local-path}\fixed-width\target\scala-2.XY\jacoco\report\html +``` + ## FAQ This is a new section where we are going to post common questions and workarounds from GitHub issues raised by our users. diff --git a/build.sbt b/build.sbt index 647bb079e..3ba6a64ec 100644 --- a/build.sbt +++ b/build.sbt @@ -17,6 +17,7 @@ import Dependencies._ import BuildInfoTemplateSettings._ import ScalacOptions._ +import com.github.sbt.jacoco.report.JacocoReportSettings lazy val scala211 = "2.11.12" lazy val scala212 = "2.12.17" @@ -38,6 +39,15 @@ ThisBuild / autoScalaLibrary := false lazy val printSparkVersion = taskKey[Unit]("Print Spark version spark-cobol is building against.") +lazy val commonJacocoReportSettings: JacocoReportSettings = JacocoReportSettings( + formats = Seq(JacocoReportFormats.HTML, JacocoReportFormats.XML) +) + +lazy val commonJacocoExcludes: Seq[String] = Seq( +// "za.co.absa.cobrix.spark.cobol.reader.FixedLenTextReader*", // class and related objects +// "za.co.absa.cobrix.spark.cobol.reader.RowHandler" // class only +) + lazy val cobrix = (project in file(".")) .disablePlugins(sbtassembly.AssemblyPlugin) .settings( @@ -56,6 +66,10 @@ lazy val cobolParser = (project in file("cobol-parser")) libraryDependencies ++= CobolParserDependencies :+ getScalaDependency(scalaVersion.value), releasePublishArtifactsAction := PgpKeys.publishSigned.value, assemblySettings + ) + .settings( + jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:cobol-parser Jacoco Report"), + jacocoExcludes := commonJacocoExcludes ).enablePlugins(AutomateHeaderPlugin) lazy val cobolConverters = (project in file("cobol-converters")) @@ -64,6 +78,10 @@ lazy val cobolConverters = (project in file("cobol-converters")) name := "cobol-converters", libraryDependencies ++= CobolConvertersDependencies :+ getScalaDependency(scalaVersion.value), releasePublishArtifactsAction := PgpKeys.publishSigned.value + ) + .settings( + jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:cobol-converters Jacoco Report"), + jacocoExcludes := commonJacocoExcludes ).dependsOn(cobolParser) .enablePlugins(AutomateHeaderPlugin) @@ -83,6 +101,10 @@ lazy val sparkCobol = (project in file("spark-cobol")) releasePublishArtifactsAction := PgpKeys.publishSigned.value, assemblySettings ) + .settings( + jacocoReportSettings := commonJacocoReportSettings.withTitle("cobrix:spark-cobol Jacoco Report"), + jacocoExcludes := commonJacocoExcludes + ) .dependsOn(cobolParser) .enablePlugins(AutomateHeaderPlugin) diff --git a/project/plugins.sbt b/project/plugins.sbt index 3990830be..dcd570e5d 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -3,3 +3,4 @@ addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.0") addSbtPlugin("de.heikoseeberger" % "sbt-header" % "5.2.0") addSbtPlugin("com.github.sbt" % "sbt-release" % "1.1.0") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0") +addSbtPlugin("com.github.sbt" % "sbt-jacoco" % "3.4.0")