emma.gradle 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. if (!rootProject.buildDir.exists()) {
  52. throw new GradleException("No coverage data. Run gradle with -Pcoverage=on if using coverageRepor");
  53. }
  54. ant.emma(enabled: "true", verbosity: "info") {
  55. report(sourcepathref:"src.path") {
  56. fileset(dir: rootProject.buildDir) {
  57. include: '*.ec'
  58. include: '*.emma'
  59. }
  60. txt(outfile: "$rootProject.buildDir/emma/coverage.txt")
  61. html(outfile: "$rootProject.buildDir/emma/coverage.html")
  62. // xml(outfile: "$rootProject.buildDir/emma/coverage.xml")
  63. }
  64. }
  65. }
  66. }