Permalink
Fetching contributors…
Cannot retrieve contributors at this time
94 lines (80 sloc) 2.46 KB
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.classesDir}-bak"
licenseFile = "/Developer/grails-dev/core/inconsequential/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.classesDir, tofile:cloverConvention.classesBackupDir)
//compile instrumented classes
sourceSets.main.classesDir.mkdirs()
ant.groovyc(
destdir:sourceSets.main.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.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.classesDir)
ant.move(file:cloverConvention.classesBackupDir, tofile:sourceSets.main.classesDir)
ant."clover-report" {
current(outfile:"${reportsDir}/clover/clover.xml")
}
ant."clover-html-report"(outdir:"${reportsDir}/clover/html");
}
}