emma.gradle 2.2 KB

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