changeset 132:8a7c3673dee9

CM-133: add fullCoverageReport task for consolidated coverage report
author smith@nwoca.org
date Thu, 06 Jun 2013 18:54:27 +0100
parents ca34c067b178
children 0d8681ff046b
files metrics.gradle
diffstat 1 files changed, 56 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/metrics.gradle	Wed Jun 05 22:45:58 2013 +0100
+++ b/metrics.gradle	Thu Jun 06 18:54:27 2013 +0100
@@ -27,16 +27,57 @@
     }
 }
 
-//gradle.rootProject.afterEvaluate { project ->
-//
-//    project.jacocoTestReport {
-//
-//
-//    }
-//
-//}
+if (gradle.environment.coverage) {
+
+    configurations {
+        jacocoAntRoot
+    }
+    dependencies {
+        jacocoAntRoot 'org.jacoco:org.jacoco.ant:0.6.2.201302030002'
+    }
+
+    task fullCoverageReport << {
+        ant {
+            taskdef(name:'jacocoreport', classname: 'org.jacoco.ant.ReportTask', classpath: configurations.jacocoAntRoot.asPath)
+
+            mkdir dir: "${buildDir.path}/reports/coverage"
+
+            jacocoreport {
+                executiondata {
+                    fileset(dir: "${buildDir.path}/coverage-results") {
+                        include name: '*.jacoco.exec'
+                    }
+                }
+
+                structure(name: project.name) {
 
+                    classfiles {
+                        subprojects.each { project ->
+                            fileset dir: project.sourceSets.main.output.classesDir
+                        }
+                    }
+                    sourcefiles(encoding: 'CP1252') {
+                        subprojects.each { project ->
+                            project.sourceSets.main.allGroovy.srcDirs.findAll { file(it).exists() } each {
+                                fileset dir: "$it"
+                            }
+                        }
+                    }
+                }
 
+                xml  destfile: "${buildDir.path}/reports/coverage/jacoco.xml"
+                html destdir:  "${buildDir.path}/reports/coverage"
+            }
+        }
+    }
+
+    fullCoverageReport.dependsOn {
+        subprojects.collect { project ->
+            project.copyCoverageData.path
+        }
+    }
+
+}
 
 subprojects {
     afterEvaluate { project ->
@@ -73,6 +114,13 @@
                 dependsOn jacocoTestReport
             }
 
+            task copyCoverageData(dependsOn: test, type: Copy) {
+                from project.test.jacoco.destPath
+                into "${rootProject.buildDir.path}/coverage-results"
+                include 'test.exec'
+                rename 'test.exec', "${project.name}.jacoco.exec"
+            }
+
         }
 
         sonarRunner {