emma.gradle 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. configurations{
  2. emma
  3. }
  4. dependencies{
  5. emma "emma:emma:2.0.5312"
  6. emma "emma:emma_ant:2.0.5312"
  7. }
  8. def emmaMetaDataFile = "${rootProject.buildDir}/emma/emma.em"
  9. def emmaCoverageFile = "${rootProject.buildDir}/emma/emma.ec"
  10. task emmaInstrument {
  11. dependsOn classes
  12. doFirst {
  13. ant.taskdef(resource:"emma_ant.properties", classpath: configurations.emma.asPath)
  14. ant.path(id: "emmarun.classpath") {
  15. pathelement(location: sourceSets.main.classesDir.absolutePath)
  16. }
  17. ant.emma(verbosity: "quiet") { // use "info, verbose, trace1, trace2, trace3 for more info"
  18. instr(merge: "true", destdir: "$buildDir/emma/classes", instrpathref: "emmarun.classpath", metadatafile: "$emmaMetaDataFile") {
  19. instrpath {
  20. fileset(dir: sourceSets.main.classesDir.absolutePath, includes: "*.class")
  21. }
  22. }
  23. }
  24. }
  25. }
  26. // Modify test tasks in the project to generate coverage data
  27. afterEvaluate {
  28. if (project.hasProperty('coverage') && ['on','true'].contains(project.properties.coverage)) {
  29. tasks.withType(Test.class).each { task ->
  30. task.dependsOn emmaInstrument
  31. task.configure() {
  32. jvmArgs '-Dsec.log.level=DEBUG', "-Demma.coverage.out.file=$emmaCoverageFile"
  33. jvmArgs '-Demma.verbosity.level=quiet'
  34. }
  35. task.doFirst {
  36. classpath = files("$buildDir/emma/classes") + configurations.emma + classpath
  37. }
  38. }
  39. }
  40. }
  41. if (rootProject.getTasksByName('coverageReport', false).isEmpty()) {
  42. rootProject.task('coverageReport') << {
  43. ant.taskdef(resource:"emma_ant.properties", classpath: configurations.emma.asPath)
  44. ant.path(id: "src.path") {
  45. coreModuleProjects.each {module->
  46. module.sourceSets.main.java.srcDirs.each {
  47. pathelement(location: it.absolutePath )
  48. }
  49. }
  50. }
  51. ant.emma(enabled: "true", verbosity: "info") {
  52. report(sourcepathref:"src.path") {
  53. fileset(dir: rootProject.buildDir) {
  54. include: '*.ec'
  55. include: '*.emma'
  56. }
  57. txt(outfile: "$rootProject.buildDir/emma/coverage.txt")
  58. html(outfile: "$rootProject.buildDir/emma/coverage.html")
  59. // xml(outfile: "$rootProject.buildDir/emma/coverage.xml")
  60. }
  61. }
  62. }
  63. }