checkstyle.vim 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. "============================================================================
  2. "File: checkstyle.vim
  3. "Description: Syntax checking plugin for syntastic.vim
  4. "Maintainer: Dmitry Geurkov <d.geurkov at gmail dot com>
  5. "License: This program is free software. It comes without any warranty,
  6. " to the extent permitted by applicable law. You can redistribute
  7. " it and/or modify it under the terms of the Do What The Fuck You
  8. " Want To Public License, Version 2, as published by Sam Hocevar.
  9. " See http://sam.zoy.org/wtfpl/COPYING for more details.
  10. "
  11. " Tested with checkstyle 5.5
  12. "============================================================================
  13. if exists('g:loaded_syntastic_java_checkstyle_checker')
  14. finish
  15. endif
  16. let g:loaded_syntastic_java_checkstyle_checker = 1
  17. if !exists('g:syntastic_java_checkstyle_classpath')
  18. let g:syntastic_java_checkstyle_classpath = 'checkstyle-6.10.1-all.jar'
  19. endif
  20. if !exists('g:syntastic_java_checkstyle_conf_file')
  21. let g:syntastic_java_checkstyle_conf_file = 'sun_checks.xml'
  22. endif
  23. let s:save_cpo = &cpo
  24. set cpo&vim
  25. function! SyntaxCheckers_java_checkstyle_IsAvailable() dict
  26. if !executable(self.getExec())
  27. return 0
  28. endif
  29. let conf_file = expand(g:syntastic_java_checkstyle_conf_file, 1)
  30. call self.log('filereadable(' . string(conf_file) . ') = ' . filereadable(conf_file))
  31. return filereadable(conf_file)
  32. endfunction
  33. function! SyntaxCheckers_java_checkstyle_GetLocList() dict
  34. " classpath
  35. if !exists('s:sep')
  36. let s:sep = syntastic#util#isRunningWindows() || has('win32unix') ? ';' : ':'
  37. endif
  38. let classpath = join(map( split(g:syntastic_java_checkstyle_classpath, s:sep, 1), 'expand(v:val, 1)' ), s:sep)
  39. call self.log('classpath =', classpath)
  40. " forced options
  41. let opts = []
  42. if classpath !=# ''
  43. call extend(opts, ['-cp', classpath])
  44. endif
  45. call extend(opts, [
  46. \ 'com.puppycrawl.tools.checkstyle.Main',
  47. \ '-c', expand(g:syntastic_java_checkstyle_conf_file, 1),
  48. \ '-f', 'xml' ])
  49. " filename
  50. let fname = syntastic#util#shescape( expand('%:p:h', 1) . syntastic#util#Slash() . expand('%:t', 1) )
  51. if has('win32unix')
  52. let fname = substitute(syntastic#util#system('cygpath -m ' . fname), '\m\%x00', '', 'g')
  53. endif
  54. let makeprg = self.makeprgBuild({ 'args_after': opts, 'fname': fname })
  55. let errorformat = '%f:%t:%l:%c:%m'
  56. return SyntasticMake({
  57. \ 'makeprg': makeprg,
  58. \ 'errorformat': errorformat,
  59. \ 'preprocess': 'checkstyle',
  60. \ 'subtype': 'Style' })
  61. endfunction
  62. call g:SyntasticRegistry.CreateAndRegisterChecker({
  63. \ 'filetype': 'java',
  64. \ 'name': 'checkstyle',
  65. \ 'exec': 'java'})
  66. let &cpo = s:save_cpo
  67. unlet s:save_cpo
  68. " vim: set sw=4 sts=4 et fdm=marker: