Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. checkstyle {
  2. toolVersion = "7.0"
  3. ignoreFailures = true
  4. configFile rootProject.file("checkstyle/checkstyle.xml")
  5. configProperties = [ "checkstyleFilterFile" : file('checkstyle/filter.xml')]
  6. }
  7.  
  8. task checkstyleChanged(type: Checkstyle) {
  9. source 'changedfiles'
  10. include '**/*.java'
  11. classpath = files()
  12. ignoreFailures = true
  13. showViolations = true
  14.  
  15. copyChangedFilesForCheckstyle()
  16.  
  17. reports {
  18. html {
  19. destination "${project.rootDir}/build/reports/checkstyle/checkstyle_changed.html"
  20. }
  21. xml {
  22. destination "${project.rootDir}/build/reports/checkstyle/checkstyle_changed.xml"
  23. }
  24. }
  25. }
  26.  
  27. /**
  28. * Compares the current set of changed files to HEAD and copies them to a temporary
  29. * folder. This is a prerequisite to run checkstyle on changed files only.
  30. */
  31. def copyChangedFilesForCheckstyle() {
  32. ByteArrayOutputStream systemOutStream = new ByteArrayOutputStream()
  33. ("git diff --name-status HEAD~1").execute().waitForProcessOutput(systemOutStream, System.err)
  34. def allFiles = systemOutStream.toString().trim().split('\n')
  35. systemOutStream.close()
  36.  
  37. Pattern statusPattern = Pattern.compile("([^D])\\t+(.+)")
  38. // Contains all files that are not deleted
  39. ArrayList<String> files = new ArrayList<>()
  40. for (file in allFiles) {
  41. Matcher matcher = statusPattern.matcher(file)
  42. if (matcher.find()) {
  43. files.add(matcher.group(2))
  44. }
  45. }
  46.  
  47. String dst = "./changedfiles/"
  48. String rootDir = "./"
  49. new File(dst).deleteDir()
  50. mkdir(dst)
  51.  
  52. for (file in files) {
  53. File srcFile = new File(rootDir + file)
  54. if (!srcFile.exists()) {
  55. continue
  56. }
  57. String dstFileName = dst + file
  58. String dstDirOnly = dstFileName.substring(0, dstFileName.lastIndexOf("/"))
  59. File dstDir = new File(dstDirOnly)
  60. File dstFile = new File(dstFileName)
  61. dstDir.mkdirs()
  62. Files.copy(srcFile.toPath(), dstFile.toPath())
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement