You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by cs...@apache.org on 2018/04/26 14:26:01 UTC

[incubator-openwhisk] branch master updated: #3243 - Use gradle scoverage to collect test coverage stats (#3249)

This is an automated email from the ASF dual-hosted git repository.

csantanapr pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 6a306f3  #3243 - Use gradle scoverage to collect test coverage stats (#3249)
6a306f3 is described below

commit 6a306f33e6e725b0bb2976d18115b19190d41974
Author: Chetan Mehrotra <ch...@apache.org>
AuthorDate: Thu Apr 26 19:55:58 2018 +0530

    #3243 - Use gradle scoverage to collect test coverage stats (#3249)
---
 build.gradle                 |  1 +
 common/scala/build.gradle    |  2 ++
 core/controller/build.gradle |  2 ++
 core/invoker/build.gradle    |  2 ++
 settings.gradle              |  7 ++++
 tests/build.gradle           | 79 ++++++++++++++++++++++++++++++++++++++++----
 tools/travis/build.sh        |  4 ++-
 7 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/build.gradle b/build.gradle
index b91005e..3e8d9a3 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,6 +4,7 @@ buildscript {
     }
     dependencies {
         classpath "cz.alenkacz:gradle-scalafmt:${gradle.scalafmt.version}"
+        classpath 'org.scoverage:gradle-scoverage:2.1.0'
     }
 }
 
diff --git a/common/scala/build.gradle b/common/scala/build.gradle
index 4a7a82e..683e201 100644
--- a/common/scala/build.gradle
+++ b/common/scala/build.gradle
@@ -1,6 +1,7 @@
 apply plugin: 'scala'
 apply plugin: 'eclipse'
 apply plugin: 'maven'
+apply plugin: 'org.scoverage'
 
 ext.dockerImageName = 'scala'
 apply from: '../../gradle/docker.gradle'
@@ -46,6 +47,7 @@ dependencies {
     compile 'io.kamon:kamon-statsd_2.11:0.6.7'
     //for mesos
     compile 'com.adobe.api.platform.runtime:mesos-actor:0.0.7'
+    scoverage gradle.scoverage.deps
 }
 
 tasks.withType(ScalaCompile) {
diff --git a/core/controller/build.gradle b/core/controller/build.gradle
index 8a50af3..70d855e 100644
--- a/core/controller/build.gradle
+++ b/core/controller/build.gradle
@@ -2,6 +2,7 @@ apply plugin: 'scala'
 apply plugin: 'application'
 apply plugin: 'eclipse'
 apply plugin: 'maven'
+apply plugin: 'org.scoverage'
 
 ext.dockerImageName = 'controller'
 apply from: '../../gradle/docker.gradle'
@@ -19,6 +20,7 @@ dependencies {
     compile 'com.lightbend.akka.discovery:akka-discovery-kubernetes-api_2.11:0.11.0'
     compile 'com.lightbend.akka.discovery:akka-discovery-marathon-api_2.11:0.11.0'
     compile project(':common:scala')
+    scoverage gradle.scoverage.deps
 }
 
 tasks.withType(ScalaCompile) {
diff --git a/core/invoker/build.gradle b/core/invoker/build.gradle
index aad64a7..2e91e4d 100644
--- a/core/invoker/build.gradle
+++ b/core/invoker/build.gradle
@@ -2,6 +2,7 @@ apply plugin: 'scala'
 apply plugin: 'application'
 apply plugin: 'eclipse'
 apply plugin: 'maven'
+apply plugin: 'org.scoverage'
 
 ext.dockerImageName = 'invoker'
 apply from: '../../gradle/docker.gradle'
@@ -23,6 +24,7 @@ dependencies {
         exclude group: 'log4j'
         exclude group: 'jline'
     }
+    scoverage gradle.scoverage.deps
 }
 
 tasks.withType(ScalaCompile) {
diff --git a/settings.gradle b/settings.gradle
index d3f56e2..587f7c5 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -30,3 +30,10 @@ gradle.ext.scalafmt = [
     version: '1.5.0',
     config: new File(rootProject.projectDir, '.scalafmt.conf')
 ]
+
+gradle.ext.scoverage = [
+    deps: [
+        'org.scoverage:scalac-scoverage-plugin_2.11:1.3.1',
+        'org.scoverage:scalac-scoverage-runtime_2.11:1.3.1'
+    ]
+]
diff --git a/tests/build.gradle b/tests/build.gradle
index 264e3b3..e50751b 100644
--- a/tests/build.gradle
+++ b/tests/build.gradle
@@ -1,6 +1,9 @@
+import org.scoverage.ScoverageReport
+
 apply plugin: 'scala'
 apply plugin: 'eclipse'
 apply plugin: 'maven'
+apply plugin: 'org.scoverage'
 compileTestScala.options.encoding = 'UTF-8'
 
 repositories {
@@ -20,14 +23,18 @@ tasks.withType(Test) {
     outputs.upToDateWhen { false } // force tests to run every time
 }
 
+def leanExcludes = [
+    '**/*Swift*',
+    '**/*Python*',
+    '**/*Java*',
+    '**/*ThrottleTests*',
+    '**/MaxActionDurationTests*',
+    '**/*ApiGwRestBasicTests*',
+    '**/*WskCli*'
+]
+
 task testLean(type: Test) {
-    exclude '**/*Swift*'
-    exclude '**/*Python*'
-    exclude '**/*Java*'
-    exclude '**/*ThrottleTests*'
-    exclude '**/MaxActionDurationTests*'
-    exclude '**/*ApiGwRestBasicTests*'
-    exclude '**/*WskCli*'
+    exclude leanExcludes
 }
 
 task testLeanCli(type: Test) {
@@ -71,6 +78,8 @@ dependencies {
     compile project(':common:scala')
     compile project(':core:controller')
     compile project(':core:invoker')
+
+    scoverage gradle.scoverage.deps
 }
 
 tasks.withType(ScalaCompile) {
@@ -92,7 +101,63 @@ task createKeystore(dependsOn: deleteKeystore) {
 }
 
 afterEvaluate {
+    task testCoverageLean(type:Test) {
+        classpath = getScoverageClasspath(project)
+        exclude leanExcludes
+    }
+
+    task testCoverage(type:Test) {
+        classpath = getScoverageClasspath(project)
+    }
     tasks.withType(Test) {
         dependsOn createKeystore
     }
 }
+
+/**
+ * Task to generate coverage xml report. Requires the
+ * tests to be executed prior to its invocation
+ */
+task reportCoverage(type: ScoverageReport) {
+    dependsOn([
+        ':common:scala:reportScoverage',
+        ':core:controller:reportScoverage',
+        ':core:invoker:reportScoverage'
+    ])
+}
+
+/**
+ * Aggregates the scoverage xml reports from various modules into a
+ * single report
+ */
+task aggregateCoverage(type: JavaExec, dependsOn: reportCoverage) {
+    //Taken from ScoverageAggregate
+    main = 'org.scoverage.AggregateReportApp'
+    classpath = project.extensions.scoverage.pluginClasspath
+    args = [
+        project.rootProject.projectDir, //Use the root project path so as to "see" all source paths
+        new File(project.buildDir, 'scoverage-aggregate'),
+        false, //Clean scoverage report post process
+        true,  //coverageOutputCobertura
+        true,  //coverageOutputXML
+        true,  //coverageOutputHTML
+        false  //coverageDebug
+    ]
+}
+
+/**
+ * Prepares the classpath which refer to scoverage instrumented classes from
+ * dependent projects "before" the non instrumented classes
+ */
+def getScoverageClasspath(Project project) {
+    def projectNames = [
+        ':common:scala',
+        ':core:controller',
+        ':core:invoker'
+    ]
+    def combinedClasspath = projectNames.inject(project.files([])){result, name ->
+        result + project.project(name).sourceSets.scoverage.runtimeClasspath
+    }
+
+    combinedClasspath + sourceSets.test.runtimeClasspath
+}
diff --git a/tools/travis/build.sh b/tools/travis/build.sh
index 765bd25..60df1da 100755
--- a/tools/travis/build.sh
+++ b/tools/travis/build.sh
@@ -63,10 +63,12 @@ $ANSIBLE_CMD openwhisk.yml
 
 cd $ROOTDIR
 cat whisk.properties
-TERM=dumb ./gradlew :tests:testLean $GRADLE_PROJS_SKIP
+TERM=dumb ./gradlew :tests:testCoverageLean :tests:reportCoverage
 
 cd $ROOTDIR/ansible
 $ANSIBLE_CMD logs.yml
 
 cd $ROOTDIR
 tools/build/checkLogs.py logs
+
+bash <(curl -s https://codecov.io/bash)

-- 
To stop receiving notification emails like this one, please contact
csantanapr@apache.org.