You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

codacy.gradle 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright (c) 2006-2017 DMDirc Developers
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
  5. * documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
  6. * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
  7. * permit persons to whom the Software is furnished to do so, subject to the following conditions:
  8. *
  9. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
  10. * Software.
  11. *
  12. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  13. * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
  14. * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  15. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  16. */
  17. def javaProjects() {
  18. allprojects.findAll { project -> project.plugins.hasPlugin('java') }
  19. }
  20. FileTree getJacocoClassDirs(Set<Project> projects) {
  21. def classDirs = fileTree(dir: "${buildDir}/classes/main")
  22. projects.each {
  23. classDirs += fileTree(dir: "${it.buildDir}/classes/main")
  24. }
  25. return classDirs
  26. }
  27. FileCollection getJacocoSrcDirs(Set<Project> projects) {
  28. Set srcDirs = sourceSets.main.java.srcDirs
  29. projects.each {
  30. srcDirs.add(it.sourceSets.main.java.srcDirs)
  31. }
  32. return files(srcDirs)
  33. }
  34. subprojects.each { evaluationDependsOn it.path }
  35. afterEvaluate {
  36. task tests(dependsOn: javaProjects()*.test)
  37. task jacocoMerge(type: JacocoMerge) {
  38. javaProjects().each {
  39. subproject -> executionData subproject.test
  40. }
  41. }
  42. task jacocoCombinedTestReport(type: JacocoReport, dependsOn: jacocoMerge) {
  43. classDirectories = getJacocoClassDirs(javaProjects())
  44. sourceDirectories = getJacocoSrcDirs(javaProjects())
  45. executionData = files("${buildDir}/jacoco/jacocoMerge.exec")
  46. reports {
  47. xml.enabled = true // coveralls plugin depends on xml format report
  48. html.enabled = true
  49. }
  50. }
  51. task sendCoverageToCodacy(type: JavaExec, dependsOn: jacocoCombinedTestReport) {
  52. main = "com.codacy.CodacyCoverageReporter"
  53. classpath = configurations.codacy
  54. args = [
  55. "-l",
  56. "Java",
  57. "-r",
  58. "${buildDir}/reports/jacoco/jacocoCombinedTestReport/jacocoCombinedTestReport.xml"
  59. ]
  60. }
  61. }