csantanapr closed pull request #3249: #3243 - Use gradle scoverage to collect 
test coverage stats
URL: https://github.com/apache/incubator-openwhisk/pull/3249
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/build.gradle b/build.gradle
index b91005e8e3..3e8d9a3438 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 4a7a82e7fa..683e2010d6 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 8a50af38b9..70d855e5f8 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 aad64a7af0..2e91e4d78e 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 d3f56e2b6b..587f7c5b28 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 264e3b384e..e50751b2c0 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 765bd253c4..60df1dae62 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)


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to