-
-
Save kyonmm/e9085a7e277bcf0e306c to your computer and use it in GitHub Desktop.
Emma for Gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apply plugin:'java' | |
configurations{ | |
emma | |
} | |
def emmaConvention = new EmmaPluginConvention(project) | |
project.convention.plugins.emma = emmaConvention | |
class EmmaPluginConvention{ | |
def verbosityLevel = "info" | |
def reportPath; | |
def coverageFileName; | |
def tmpDir; | |
def instrDir; | |
def metaDataFilePath; | |
def emma(Closure close){ | |
close.delegate = this; | |
close.run() | |
} | |
EmmaPluginConvention(Project project){ | |
reportPath = "${project.reportsDir.absolutePath}/emma" | |
coverageFileName = "coverage" | |
tmpDir = "${project.buildDir}/tmp/emma" | |
instrDir = "${tmpDir}/instr" | |
metaDataFilePath = "${tmpDir}/metadata.emma" | |
} | |
} | |
test{ | |
jvmArgs "-Demma.coverage.out.file=${emmaConvention.metaDataFilePath}", "-Demma.coverage.out.merge=true" | |
doFirst{ | |
ant.taskdef( resource:"emma_ant.properties", classpath: configurations.emma.asPath) | |
ant.path(id:"run.classpath"){ | |
pathelement(location:sourceSets.main.classesDir.absolutePath ) | |
} | |
ant.emma(verbosity:"${emmaConvention.verbosityLevel}"){ | |
instr(merge:"true", destdir:"${emmaConvention.instrDir}", instrpathref:"run.classpath", metadatafile:"${emmaConvention.metaDataFilePath}"){ | |
instrpath{ | |
fileset(dir:sourceSets.main.classesDir.absolutePath, includes:"*.class") | |
} | |
} | |
} | |
setClasspath(files("${emmaConvention.instrDir}") + configurations.emma + getClasspath()) | |
} | |
doLast{ | |
ant.path(id:"src.path"){ | |
sourceSets.main.java.srcDirs.each{ | |
pathelement(location:it.absolutePath ) | |
} | |
} | |
ant.emma(enabled:"true"){ | |
report(sourcepathref:"src.path"){ | |
fileset(dir:"${emmaConvention.tmpDir}"){ | |
include(name:"*.emma") | |
} | |
txt(outfile:"${emmaConvention.reportPath}/coverage.txt") | |
html(outfile:"${emmaConvention.reportPath}/coverage.html") | |
xml(outfile:"${emmaConvention.reportPath}/coverage.xml") | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment