Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 0a75e9c4ba
Fetching contributors…

Cannot retrieve contributors at this time

file 94 lines (80 sloc) 2.53 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
apply plugin: "groovy"

def cloverConvention = new CloverPluginConvention(project)
project.convention.plugins.clover = cloverConvention

class CloverPluginConvention {
def classesBackupDir
def licenseFile

def clover(Closure close) {
close.delegate = this
close.run()
}

CloverPluginConvention(Project project) {
classesBackupDir = "${project.sourceSets.main.output.classesDir}-bak"
licenseFile = "clover.license"
}
}

dependencies {
testRuntime "com.cenqua.clover:clover:3.0.2"
}

test.doFirst {
if (project.hasProperty("withClover")) {
ant.taskdef(name: 'groovyc', classname:"org.codehaus.groovy.ant.Groovyc", classpath:configurations.testRuntime.asPath)
ant.taskdef(resource:"cloverlib.xml", classpath:configurations.testRuntime.asPath)
ant.property(name:"clover.license.path", value:cloverConvention.licenseFile)

ant."clover-clean"()

ant.'clover-setup'(initString: "${buildDir}/clover/clover.db", tmpDir: "${buildDir}/clover/tmp") {
["java", "groovy"].each { source ->
["main", "test"].each { type ->
sourceSets."$type"."$source".srcDirs.each {
if (it.exists()) {
ant.fileset(dir: it) {
include(name: "**/*.groovy")
include(name: "**/*.java")
}
}
}
}
}
}

//move original classes
ant.move(file:sourceSets.main.output.classesDir, tofile:cloverConvention.classesBackupDir)

//compile instrumented classes
sourceSets.main.output.classesDir.mkdirs()
ant.groovyc(
destdir:sourceSets.main.output.classesDir,
fork: true,
verbose: true
) {
classpath {
pathElement path:configurations.testCompile.asPath
}
javac(source:sourceCompatibility, target: targetCompatibility) {
classpath {
pathElement path:configurations.testRuntime.asPath
}
}

["java", "groovy"].each { source ->
sourceSets.main."$source".srcDirs.each {
if (it.exists()) {
src(path: it)
}
}
}
}

//copy resources
ant.copy(todir:sourceSets.main.output.classesDir) {
fileset(dir:cloverConvention.classesBackupDir, excludes:"**/*.class")
}
}
}

test.doLast {
if (project.hasProperty("withClover") && new File(cloverConvention.classesBackupDir).exists()) {
// restore original classes
ant.delete(file: sourceSets.main.output.classesDir)
ant.move(file:cloverConvention.classesBackupDir, tofile:sourceSets.main.output.classesDir)

ant."clover-report" {
current(outfile:"${reportsDir}/clover/clover.xml")
}
ant."clover-html-report"(outdir:"${reportsDir}/clover/html");
}
}
Something went wrong with that request. Please try again.