Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

non-working clover integration

  • Loading branch information...
commit eda971b71d800e8afefc11b4eba733c122883995 1 parent 93500fd
graemerocher graemerocher authored

Showing 3 changed files with 164 additions and 0 deletions. Show diff stats Hide diff stats

  1. +65 0 build.gradle
  2. +94 0 clover.gradle
  3. +5 0 clover.license
65 build.gradle
@@ -23,6 +23,7 @@ subprojects {
23 23 apply plugin: 'groovy'
24 24 apply plugin: 'eclipse'
25 25 apply plugin: 'maven'
  26 + apply from: "file:${rootDir}/clover.gradle"
26 27 }
27 28
28 29 def isGormDatasource = project.name.startsWith("grails-datastore-gorm-") && !project.name.endsWith("tck")
@@ -38,6 +39,7 @@ subprojects {
38 39 dependencies {
39 40 if(isStandardGroovyMavenProject) {
40 41 groovy group: 'org.codehaus.groovy', name: 'groovy-all', version: '1.7.4'
  42 +
41 43 testCompile 'junit:junit:4.8.1'
42 44 testCompile spockDependency
43 45 }
@@ -164,4 +166,67 @@ subprojects {
164 166 }
165 167
166 168 }
  169 +}
  170 +
  171 +configurations {
  172 + build
  173 +}
  174 +
  175 +repositories {
  176 + mavenCentral()
  177 +}
  178 +
  179 +dependencies {
  180 + build "com.cenqua.clover:clover:3.0.2"
  181 + build "org.apache.ant:ant-junit:1.8.1"
  182 + build "org.apache.ant:ant-nodeps:1.8.1"
  183 +}
  184 +
  185 +task test(dependsOn: getTasksByName("test", true)) << {
  186 + def reportsDir = "${buildDir}/reports"
  187 +
  188 + // Aggregate the test results
  189 + ant.taskdef(
  190 + name: 'junitreport2',
  191 + classname: "org.apache.tools.ant.taskdefs.optional.junit.XMLResultAggregator",
  192 + classpath: configurations.build.asPath
  193 + )
  194 +
  195 + def testReportsDir = new File("${reportsDir}/tests")
  196 + if (testReportsDir.exists()) {
  197 + testReportsDir.deleteDir()
  198 + }
  199 + testReportsDir.mkdirs()
  200 +
  201 + ant.junitreport2(todir: testReportsDir) {
  202 + subprojects.each {
  203 + def testResultsDir = "${it.buildDir}/test-results"
  204 + if (new File(testResultsDir).exists()) {
  205 + fileset(dir: testResultsDir) {
  206 + include(name: "TEST-*.xml")
  207 + }
  208 + }
  209 + }
  210 + report(todir: testReportsDir)
  211 + }
  212 +
  213 + // Aggregate the coverage results
  214 + if (project.hasProperty("withClover")) {
  215 + def db = "clover/clover.db"
  216 + def mergedDb = "${buildDir}/${db}"
  217 + def cloverReportsDir = "${reportsDir}/clover"
  218 + ant.taskdef(resource: "cloverlib.xml", classpath: configurations.build.asPath)
  219 + ant."clover-merge"(initstring: mergedDb) {
  220 + subprojects.each {
  221 + def projectCloverDb = "${it.buildDir}/${db}"
  222 + if (new File(projectCloverDb).exists()) {
  223 + cloverdb(initstring: projectCloverDb)
  224 + }
  225 + }
  226 + }
  227 + ant."clover-report"(initstring: mergedDb) {
  228 + current(outfile:"${cloverReportsDir}/clover.xml")
  229 + }
  230 + ant."clover-html-report"(initstring: mergedDb, outdir:"${cloverReportsDir}/html")
  231 + }
167 232 }
94 clover.gradle
... ... @@ -0,0 +1,94 @@
  1 +apply plugin: "groovy"
  2 +
  3 +def cloverConvention = new CloverPluginConvention(project)
  4 +project.convention.plugins.clover = cloverConvention
  5 +
  6 +class CloverPluginConvention {
  7 + def classesBackupDir
  8 + def licenseFile
  9 +
  10 + def clover(Closure close) {
  11 + close.delegate = this
  12 + close.run()
  13 + }
  14 +
  15 + CloverPluginConvention(Project project) {
  16 + classesBackupDir = "${project.sourceSets.main.classesDir}-bak"
  17 + licenseFile = "/Developer/grails-dev/core/inconsequential/clover.license"
  18 + }
  19 +}
  20 +
  21 +dependencies {
  22 + testRuntime "com.cenqua.clover:clover:3.0.2"
  23 +}
  24 +
  25 +test.doFirst {
  26 + if (project.hasProperty("withClover")) {
  27 + ant.taskdef(name: 'groovyc', classname:"org.codehaus.groovy.ant.Groovyc", classpath:configurations.testRuntime.asPath)
  28 + ant.taskdef(resource:"cloverlib.xml", classpath:configurations.testRuntime.asPath)
  29 + ant.property(name:"clover.license.path", value:cloverConvention.licenseFile)
  30 +
  31 + ant."clover-clean"()
  32 +
  33 + ant.'clover-setup'(initString: "${buildDir}/clover/clover.db", tmpDir: "${buildDir}/clover/tmp") {
  34 + ["java", "groovy"].each { source ->
  35 + ["main", "test"].each { type ->
  36 + sourceSets."$type"."$source".srcDirs.each {
  37 + if (it.exists()) {
  38 + ant.fileset(dir: it) {
  39 + include(name: "**/*.groovy")
  40 + include(name: "**/*.java")
  41 + }
  42 + }
  43 + }
  44 + }
  45 + }
  46 + }
  47 +
  48 + //move original classes
  49 + ant.move(file:sourceSets.main.classesDir, tofile:cloverConvention.classesBackupDir)
  50 +
  51 + //compile instrumented classes
  52 + sourceSets.main.classesDir.mkdirs()
  53 + ant.groovyc(
  54 + destdir:sourceSets.main.classesDir,
  55 + fork: true,
  56 + verbose: true
  57 + ) {
  58 + classpath {
  59 + pathElement path:configurations.testCompile.asPath
  60 + }
  61 + javac(source:sourceCompatibility, target: targetCompatibility) {
  62 + classpath {
  63 + pathElement path:configurations.testRuntime.asPath
  64 + }
  65 + }
  66 +
  67 + ["java", "groovy"].each { source ->
  68 + sourceSets.main."$source".srcDirs.each {
  69 + if (it.exists()) {
  70 + src(path: it)
  71 + }
  72 + }
  73 + }
  74 + }
  75 +
  76 + //copy resources
  77 + ant.copy(todir:sourceSets.main.classesDir) {
  78 + fileset(dir:cloverConvention.classesBackupDir, excludes:"**/*.class")
  79 + }
  80 + }
  81 +}
  82 +
  83 +test.doLast {
  84 + if (project.hasProperty("withClover") && new File(cloverConvention.classesBackupDir).exists()) {
  85 + // restore original classes
  86 + ant.delete(file: sourceSets.main.classesDir)
  87 + ant.move(file:cloverConvention.classesBackupDir, tofile:sourceSets.main.classesDir)
  88 +
  89 + ant."clover-report" {
  90 + current(outfile:"${reportsDir}/clover/clover.xml")
  91 + }
  92 + ant."clover-html-report"(outdir:"${reportsDir}/clover/html");
  93 + }
  94 +}
5 clover.license
... ... @@ -0,0 +1,5 @@
  1 +pmqOPPevJRxewUAoSwGTXaKrPNwRSFgqNRUUNwpFTlvnMC
  2 +mi2KC0BWSj8iuzoLZUtK<49L2K70p6Dqxa0wTtoVPIQuB2
  3 +rqRoTuoqpmNOnopnoOpTUOmonooOQQRnoRUUTvSwvxuvPP
  4 +nmQnmqmUUnottnouummmmmUUnottnouummmmmUU7oXfipU
  5 +Unmmmm

0 comments on commit eda971b

Please sign in to comment.
Something went wrong with that request. Please try again.