Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 84 lines (72 sloc) 2.887 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
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 = "/Users/eric/clover.license"
    }
}

dependencies {
    testRuntime group: 'com.cenqua.clover', name: 'clover', version: '3.0.2'
    testRuntime group: 'org.apache.ant', name: 'ant-junit', version: '1.8.1'
    testRuntime group: 'org.apache.ant', name: 'ant-nodeps', version: '1.8.1'
}

test.doFirst {
    if (project.hasProperty("withClover") && sourceSets.main.classesDir.exists()) {
        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"()

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

        //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.testRuntime.asPath
            }
            sourceSets.main.groovy.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)

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