2012-08-14 11:56:20 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: javac.vim
|
2017-09-15 14:04:16 -04:00
|
|
|
"Description: Syntax checking plugin for syntastic
|
2012-08-14 11:56:20 -04:00
|
|
|
"Maintainer: Jochen Keil <jochen.keil at gmail dot com>
|
|
|
|
" Dmitry Geurkov <d.geurkov at gmail dot com>
|
|
|
|
"License: This program is free software. It comes without any warranty,
|
|
|
|
" to the extent permitted by applicable law. You can redistribute
|
|
|
|
" it and/or modify it under the terms of the Do What The Fuck You
|
|
|
|
" Want To Public License, Version 2, as published by Sam Hocevar.
|
2014-01-26 02:10:26 -05:00
|
|
|
" See http://sam.zoy.org/wtfpl/COPYING for more details.
|
2012-08-14 11:56:20 -04:00
|
|
|
"============================================================================
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if exists('g:loaded_syntastic_java_javac_checker')
|
2013-02-21 10:50:41 -05:00
|
|
|
finish
|
|
|
|
endif
|
2014-01-04 13:31:55 -05:00
|
|
|
let g:loaded_syntastic_java_javac_checker = 1
|
2014-04-19 03:03:53 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_tags = ['build', 'properties']
|
2013-07-01 12:23:56 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_properties = {}
|
2013-09-19 18:37:28 -04:00
|
|
|
let s:has_maven = 0
|
2013-02-21 10:50:41 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
|
|
|
" Checker options {{{1
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_executable')
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_executable = 'javac'
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_maven_executable')
|
2013-03-13 12:00:17 -04:00
|
|
|
let g:syntastic_java_maven_executable = 'mvn'
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_options')
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_options = '-Xlint'
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:14:05 -04:00
|
|
|
if !exists('g:syntastic_java_maven_options')
|
|
|
|
let g:syntastic_java_maven_options = ''
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_classpath')
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_classpath = ''
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_delete_output')
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_delete_output = 1
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_autoload_maven_classpath')
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_autoload_maven_classpath = 1
|
|
|
|
endif
|
|
|
|
|
2012-12-19 08:23:58 -05:00
|
|
|
if !exists('g:syntastic_java_javac_config_file_enabled')
|
|
|
|
let g:syntastic_java_javac_config_file_enabled = 0
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists('g:syntastic_java_javac_config_file')
|
|
|
|
let g:syntastic_java_javac_config_file = '.syntastic_javac_config'
|
|
|
|
endif
|
|
|
|
|
2014-01-04 14:09:18 -05:00
|
|
|
if !exists('g:syntastic_java_javac_custom_classpath_command')
|
|
|
|
let g:syntastic_java_javac_custom_classpath_command = ''
|
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_maven_pom_ftime')
|
2013-07-01 12:23:56 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_ftime = {}
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2014-04-19 03:03:53 -04:00
|
|
|
if !exists('g:syntastic_java_javac_maven_pom_classpath')
|
2013-07-01 12:23:56 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_classpath = {}
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" }}}1
|
|
|
|
|
2015-06-26 00:01:05 -04:00
|
|
|
" Constants {{{1
|
|
|
|
|
|
|
|
let s:_FILE_SHORTCUTS = {
|
|
|
|
\ '%FILE_PATH%': '%:p',
|
|
|
|
\ '%FILE_NAME%': '%:t',
|
|
|
|
\ '%FILE_DIR%': '%:p:h',
|
|
|
|
\ }
|
|
|
|
lockvar! s:_FILE_SHORTCUTS
|
|
|
|
|
|
|
|
" }}}1
|
|
|
|
|
2015-09-06 12:39:17 -04:00
|
|
|
" Commands {{{1
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
command! SyntasticJavacEditClasspath call s:EditClasspath()
|
2015-09-06 12:39:17 -04:00
|
|
|
command! SyntasticJavacEditConfig call s:EditConfig()
|
2015-01-04 05:46:54 -05:00
|
|
|
|
2015-09-06 12:39:17 -04:00
|
|
|
" }}}1
|
2015-01-04 05:46:54 -05:00
|
|
|
|
|
|
|
function! SyntaxCheckers_java_javac_IsAvailable() dict " {{{1
|
|
|
|
let s:has_maven = executable(expand(g:syntastic_java_maven_executable, 1))
|
|
|
|
return executable(expand(g:syntastic_java_javac_executable, 1))
|
|
|
|
endfunction " }}}1
|
|
|
|
|
|
|
|
function! SyntaxCheckers_java_javac_GetLocList() dict " {{{1
|
|
|
|
let javac_opts = g:syntastic_java_javac_options
|
|
|
|
|
|
|
|
let output_dir = ''
|
|
|
|
if g:syntastic_java_javac_delete_output
|
2015-01-17 07:26:24 -05:00
|
|
|
let output_dir = syntastic#util#tmpdir()
|
2015-01-04 05:46:54 -05:00
|
|
|
let javac_opts .= ' -d ' . syntastic#util#shescape(output_dir)
|
|
|
|
endif
|
|
|
|
|
|
|
|
" load classpath from config file
|
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
|
|
|
call s:LoadConfigFile()
|
|
|
|
endif
|
|
|
|
|
|
|
|
|
|
|
|
" add classpathes to javac_classpath {{{2
|
|
|
|
let javac_classpath = ''
|
|
|
|
|
|
|
|
for path in split(g:syntastic_java_javac_classpath, s:ClassSep())
|
2015-03-25 12:44:34 -04:00
|
|
|
if path !=# ''
|
2015-01-04 05:46:54 -05:00
|
|
|
try
|
|
|
|
let ps = glob(path, 1, 1)
|
|
|
|
catch
|
|
|
|
let ps = split(glob(path, 1), "\n")
|
|
|
|
endtry
|
|
|
|
if type(ps) == type([])
|
|
|
|
for p in ps
|
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, p)
|
|
|
|
endfor
|
|
|
|
else
|
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, ps)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
|
|
|
if s:has_maven && g:syntastic_java_javac_autoload_maven_classpath
|
2015-11-05 13:21:42 -05:00
|
|
|
if !g:syntastic_java_javac_delete_output
|
|
|
|
let javac_opts .= ' -d ' . syntastic#util#shescape(s:MavenOutputDirectory())
|
2015-01-04 05:46:54 -05:00
|
|
|
endif
|
2015-11-05 13:21:42 -05:00
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, s:GetMavenClasspath())
|
2015-01-04 05:46:54 -05:00
|
|
|
endif
|
|
|
|
" }}}2
|
|
|
|
|
|
|
|
" load custom classpath {{{2
|
2015-03-25 12:44:34 -04:00
|
|
|
if g:syntastic_java_javac_custom_classpath_command !=# ''
|
2015-06-24 21:12:30 -04:00
|
|
|
" Pre-process the classpath command string a little.
|
|
|
|
let classpath_command = g:syntastic_java_javac_custom_classpath_command
|
2015-06-26 00:01:05 -04:00
|
|
|
for [key, val] in items(s:_FILE_SHORTCUTS)
|
|
|
|
let classpath_command = substitute(classpath_command, '\V' . key, syntastic#util#shexpand(val), 'g')
|
2015-06-24 21:12:30 -04:00
|
|
|
endfor
|
2015-06-25 09:27:58 -04:00
|
|
|
let lines = syntastic#util#system(classpath_command)
|
2015-01-04 05:46:54 -05:00
|
|
|
if syntastic#util#isRunningWindows() || has('win32unix')
|
|
|
|
let lines = substitute(lines, "\r\n", "\n", 'g')
|
|
|
|
endif
|
|
|
|
for l in split(lines, "\n")
|
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, l)
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
2015-03-25 12:44:34 -04:00
|
|
|
if javac_classpath !=# ''
|
2015-01-04 05:46:54 -05:00
|
|
|
let javac_opts .= ' -cp ' . syntastic#util#shexpand(javac_classpath)
|
|
|
|
endif
|
|
|
|
" }}}2
|
|
|
|
|
|
|
|
let fname = expand('%:p:h', 1) . syntastic#util#Slash() . expand ('%:t', 1)
|
|
|
|
|
|
|
|
if has('win32unix')
|
2015-02-23 09:40:53 -05:00
|
|
|
let fname = syntastic#util#CygwinPath(fname)
|
2015-01-04 05:46:54 -05:00
|
|
|
endif
|
|
|
|
|
|
|
|
let makeprg = self.makeprgBuild({
|
|
|
|
\ 'args': javac_opts,
|
|
|
|
\ 'fname': syntastic#util#shescape(fname) })
|
|
|
|
|
|
|
|
" unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types
|
|
|
|
let errorformat =
|
2015-02-13 04:56:09 -05:00
|
|
|
\ '%E%f:%l: error: %m,'.
|
|
|
|
\ '%W%f:%l: warning: %m,'.
|
2015-08-06 11:23:05 -04:00
|
|
|
\ '%E%f:%l: %m,'.
|
|
|
|
\ '%Z%p^,'.
|
2015-01-04 05:46:54 -05:00
|
|
|
\ '%-G%.%#'
|
|
|
|
|
2015-03-25 12:44:34 -04:00
|
|
|
if output_dir !=# ''
|
2015-01-04 05:46:54 -05:00
|
|
|
silent! call mkdir(output_dir, 'p')
|
|
|
|
endif
|
|
|
|
let errors = SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
|
|
|
\ 'postprocess': ['cygwinRemoveCR'] })
|
|
|
|
|
2015-03-25 12:44:34 -04:00
|
|
|
if output_dir !=# ''
|
2015-01-04 05:46:54 -05:00
|
|
|
call syntastic#util#rmrf(output_dir)
|
|
|
|
endif
|
|
|
|
return errors
|
|
|
|
|
|
|
|
endfunction " }}}1
|
|
|
|
|
|
|
|
" Utilities {{{1
|
|
|
|
|
|
|
|
function! s:RemoveCarriageReturn(line) " {{{2
|
2014-04-19 03:03:53 -04:00
|
|
|
return substitute(a:line, "\r", '', 'g')
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2013-05-06 07:25:19 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:ClassSep() " {{{2
|
2014-04-19 03:03:53 -04:00
|
|
|
return (syntastic#util#isRunningWindows() || has('win32unix')) ? ';' : ':'
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2014-04-19 03:03:53 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:AddToClasspath(classpath, path) " {{{2
|
2015-03-25 12:44:34 -04:00
|
|
|
if a:path ==# ''
|
2012-08-14 11:56:20 -04:00
|
|
|
return a:classpath
|
|
|
|
endif
|
2015-03-25 12:44:34 -04:00
|
|
|
return (a:classpath !=# '') ? a:classpath . s:ClassSep() . a:path : a:path
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:SplitClasspath(classpath) " {{{2
|
2014-04-19 03:03:53 -04:00
|
|
|
return split(a:classpath, s:ClassSep())
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2014-01-04 13:31:55 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:LoadConfigFile() " {{{2
|
2015-01-04 02:01:55 -05:00
|
|
|
if filereadable(expand(g:syntastic_java_javac_config_file, 1))
|
2015-01-27 03:05:58 -05:00
|
|
|
execute 'source ' . fnameescape(expand(g:syntastic_java_javac_config_file, 1))
|
2012-12-19 08:23:58 -05:00
|
|
|
endif
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2012-12-19 08:23:58 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:SaveClasspath() " {{{2
|
2014-01-04 13:31:55 -05:00
|
|
|
" build classpath from lines
|
2012-08-14 11:56:20 -04:00
|
|
|
let path = ''
|
2017-02-15 01:48:45 -05:00
|
|
|
let lines = getline(1, '$')
|
2014-01-04 13:31:55 -05:00
|
|
|
for l in lines
|
2014-01-26 02:10:26 -05:00
|
|
|
let path = s:AddToClasspath(path, l)
|
2014-01-04 13:31:55 -05:00
|
|
|
endfor
|
2012-12-19 08:23:58 -05:00
|
|
|
" save classpath to config file
|
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
2015-01-04 02:01:55 -05:00
|
|
|
if filereadable(expand(g:syntastic_java_javac_config_file, 1))
|
2014-01-04 13:31:55 -05:00
|
|
|
" load lines from config file
|
2015-01-04 02:01:55 -05:00
|
|
|
let lines = readfile(expand(g:syntastic_java_javac_config_file, 1))
|
2014-01-04 13:31:55 -05:00
|
|
|
" strip g:syntastic_java_javac_classpath options from config file lines
|
|
|
|
let i = 0
|
|
|
|
while i < len(lines)
|
|
|
|
if match(lines[i], 'g:syntastic_java_javac_classpath') != -1
|
2014-01-26 02:10:26 -05:00
|
|
|
call remove(lines, i)
|
2014-04-19 03:03:53 -04:00
|
|
|
else
|
|
|
|
let i += 1
|
2014-01-04 13:31:55 -05:00
|
|
|
endif
|
|
|
|
endwhile
|
|
|
|
else
|
|
|
|
let lines = []
|
|
|
|
endif
|
|
|
|
" add new g:syntastic_java_javac_classpath option to config
|
2014-04-19 03:03:53 -04:00
|
|
|
call add(lines, 'let g:syntastic_java_javac_classpath = ' . string(path))
|
2014-01-04 13:31:55 -05:00
|
|
|
" save config file lines
|
2015-01-04 02:01:55 -05:00
|
|
|
call writefile(lines, expand(g:syntastic_java_javac_config_file, 1))
|
2012-12-19 08:23:58 -05:00
|
|
|
endif
|
2014-01-04 13:31:55 -05:00
|
|
|
" set new classpath
|
2012-08-14 11:56:20 -04:00
|
|
|
let g:syntastic_java_javac_classpath = path
|
|
|
|
let &modified = 0
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:EditClasspath() " {{{2
|
2012-08-14 11:56:20 -04:00
|
|
|
let command = 'syntastic javac classpath'
|
|
|
|
let winnr = bufwinnr('^' . command . '$')
|
|
|
|
if winnr < 0
|
2014-01-04 13:31:55 -05:00
|
|
|
let path = []
|
2014-01-26 02:10:26 -05:00
|
|
|
let pathlines = split(g:syntastic_java_javac_classpath, "\n")
|
2014-01-04 13:31:55 -05:00
|
|
|
for p in pathlines
|
2014-04-19 03:03:53 -04:00
|
|
|
call extend(path, s:SplitClasspath(p))
|
2014-01-04 13:31:55 -05:00
|
|
|
endfor
|
|
|
|
execute (len(path) + 5) . 'sp ' . fnameescape(command)
|
2013-05-13 09:37:16 -04:00
|
|
|
|
|
|
|
augroup syntastic
|
|
|
|
autocmd BufWriteCmd <buffer> call s:SaveClasspath() | bwipeout
|
|
|
|
augroup END
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
setlocal buftype=acwrite bufhidden=wipe nobuflisted noswapfile nowrap number
|
2014-01-04 13:31:55 -05:00
|
|
|
for p in path
|
2013-05-13 09:37:16 -04:00
|
|
|
call append(line('$') - 1, p)
|
|
|
|
endfor
|
2014-01-04 13:31:55 -05:00
|
|
|
let &modified = 0
|
|
|
|
else
|
|
|
|
execute winnr . 'wincmd w'
|
|
|
|
endif
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2014-01-04 13:31:55 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:SaveConfig() " {{{2
|
2014-01-04 13:31:55 -05:00
|
|
|
" get lines
|
2017-02-15 01:48:45 -05:00
|
|
|
let lines = getline(1, '$')
|
2014-01-04 13:31:55 -05:00
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
|
|
|
" save config file lines
|
2015-01-04 02:01:55 -05:00
|
|
|
call writefile(lines, expand(g:syntastic_java_javac_config_file, 1))
|
2014-01-04 13:31:55 -05:00
|
|
|
endif
|
|
|
|
let &modified = 0
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2014-01-04 13:31:55 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:EditConfig() " {{{2
|
2015-09-06 12:39:17 -04:00
|
|
|
if !g:syntastic_java_javac_config_file_enabled
|
|
|
|
return
|
|
|
|
endif
|
|
|
|
|
2014-01-04 13:31:55 -05:00
|
|
|
let command = 'syntastic javac config'
|
|
|
|
let winnr = bufwinnr('^' . command . '$')
|
|
|
|
if winnr < 0
|
|
|
|
let lines = []
|
2015-01-04 02:01:55 -05:00
|
|
|
if filereadable(expand(g:syntastic_java_javac_config_file, 1))
|
|
|
|
let lines = readfile(expand(g:syntastic_java_javac_config_file, 1))
|
2014-01-04 13:31:55 -05:00
|
|
|
endif
|
|
|
|
execute (len(lines) + 5) . 'sp ' . fnameescape(command)
|
|
|
|
|
|
|
|
augroup syntastic
|
|
|
|
autocmd BufWriteCmd <buffer> call s:SaveConfig() | bwipeout
|
|
|
|
augroup END
|
|
|
|
|
|
|
|
setlocal ft=vim buftype=acwrite bufhidden=wipe nobuflisted noswapfile nowrap number
|
|
|
|
for l in lines
|
|
|
|
call append(line('$') - 1, l)
|
|
|
|
endfor
|
|
|
|
let &modified = 0
|
2012-08-14 11:56:20 -04:00
|
|
|
else
|
|
|
|
execute winnr . 'wincmd w'
|
|
|
|
endif
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2013-07-01 12:23:56 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:GetMavenProperties() " {{{2
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_properties = {}
|
2015-06-26 00:28:50 -04:00
|
|
|
let pom = syntastic#util#findFileInParent('pom.xml', expand('%:p:h', 1))
|
2013-09-19 18:37:28 -04:00
|
|
|
if s:has_maven && filereadable(pom)
|
2013-07-01 12:23:56 -04:00
|
|
|
if !has_key(g:syntastic_java_javac_maven_pom_properties, pom)
|
2014-04-19 03:14:05 -04:00
|
|
|
let mvn_cmd = syntastic#util#shexpand(g:syntastic_java_maven_executable) .
|
|
|
|
\ ' -f ' . syntastic#util#shescape(pom) .
|
|
|
|
\ ' ' . g:syntastic_java_maven_options
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_is_managed_tag = 1
|
2015-03-12 13:20:06 -04:00
|
|
|
let mvn_settings_output = split(syntastic#util#system(mvn_cmd . ' help:effective-pom'), "\n")
|
2013-07-01 12:23:56 -04:00
|
|
|
let current_path = 'project'
|
|
|
|
for line in mvn_settings_output
|
2013-10-25 08:46:16 -04:00
|
|
|
let matches = matchlist(line, '\m^\s*<\([a-zA-Z0-9\-\.]\+\)>\s*$')
|
2013-07-01 12:23:56 -04:00
|
|
|
if mvn_is_managed_tag && !empty(matches)
|
|
|
|
let mvn_is_managed_tag = index(g:syntastic_java_javac_maven_pom_tags, matches[1]) >= 0
|
|
|
|
let current_path .= '.' . matches[1]
|
|
|
|
else
|
2013-10-25 08:46:16 -04:00
|
|
|
let matches = matchlist(line, '\m^\s*</\([a-zA-Z0-9\-\.]\+\)>\s*$')
|
2013-07-01 12:23:56 -04:00
|
|
|
if !empty(matches)
|
|
|
|
let mvn_is_managed_tag = index(g:syntastic_java_javac_maven_pom_tags, matches[1]) < 0
|
2014-04-19 03:03:53 -04:00
|
|
|
let current_path = substitute(current_path, '\m\.' . matches[1] . '$', '', '')
|
2013-07-01 12:23:56 -04:00
|
|
|
else
|
2013-10-25 08:46:16 -04:00
|
|
|
let matches = matchlist(line, '\m^\s*<\([a-zA-Z0-9\-\.]\+\)>\(.\+\)</[a-zA-Z0-9\-\.]\+>\s*$')
|
2013-07-01 12:23:56 -04:00
|
|
|
if mvn_is_managed_tag && !empty(matches)
|
|
|
|
let mvn_properties[current_path . '.' . matches[1]] = matches[2]
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
let g:syntastic_java_javac_maven_pom_properties[pom] = mvn_properties
|
|
|
|
endif
|
|
|
|
return g:syntastic_java_javac_maven_pom_properties[pom]
|
|
|
|
endif
|
|
|
|
return mvn_properties
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2014-01-04 13:31:55 -05:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:GetMavenClasspath() " {{{2
|
2015-06-26 00:28:50 -04:00
|
|
|
let pom = syntastic#util#findFileInParent('pom.xml', expand('%:p:h', 1))
|
2013-09-19 18:37:28 -04:00
|
|
|
if s:has_maven && filereadable(pom)
|
2013-07-01 12:57:21 -04:00
|
|
|
if !has_key(g:syntastic_java_javac_maven_pom_ftime, pom) || g:syntastic_java_javac_maven_pom_ftime[pom] != getftime(pom)
|
2014-04-19 03:14:05 -04:00
|
|
|
let mvn_cmd = syntastic#util#shexpand(g:syntastic_java_maven_executable) .
|
|
|
|
\ ' -f ' . syntastic#util#shescape(pom) .
|
|
|
|
\ ' ' . g:syntastic_java_maven_options
|
2015-11-28 05:49:16 -05:00
|
|
|
let mvn_classpath_output = split(syntastic#util#system(mvn_cmd . ' dependency:build-classpath -DincludeScope=test'), "\n")
|
2013-09-19 18:27:28 -04:00
|
|
|
let mvn_classpath = ''
|
2012-08-14 11:56:20 -04:00
|
|
|
let class_path_next = 0
|
2013-05-13 09:37:16 -04:00
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
for line in mvn_classpath_output
|
|
|
|
if class_path_next == 1
|
2013-05-06 07:25:19 -04:00
|
|
|
let mvn_classpath = s:RemoveCarriageReturn(line)
|
2012-08-14 11:56:20 -04:00
|
|
|
break
|
|
|
|
endif
|
2014-01-26 02:10:26 -05:00
|
|
|
if stridx(line, 'Dependencies classpath:') >= 0
|
2012-08-14 11:56:20 -04:00
|
|
|
let class_path_next = 1
|
|
|
|
endif
|
|
|
|
endfor
|
2013-05-13 09:37:16 -04:00
|
|
|
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_properties = s:GetMavenProperties()
|
|
|
|
|
2015-02-20 09:15:44 -05:00
|
|
|
let sep = syntastic#util#Slash()
|
2015-11-26 04:37:44 -05:00
|
|
|
let output_dir = get(mvn_properties, 'project.build.outputDirectory', join(['target', 'classes'], sep))
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_classpath = s:AddToClasspath(mvn_classpath, output_dir)
|
|
|
|
|
2015-11-26 04:37:44 -05:00
|
|
|
let test_output_dir = get(mvn_properties, 'project.build.testOutputDirectory', join(['target', 'test-classes'], sep))
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_classpath = s:AddToClasspath(mvn_classpath, test_output_dir)
|
2013-05-13 09:37:16 -04:00
|
|
|
|
2013-07-01 12:23:56 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_ftime[pom] = getftime(pom)
|
|
|
|
let g:syntastic_java_javac_maven_pom_classpath[pom] = mvn_classpath
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
2013-07-01 12:23:56 -04:00
|
|
|
return g:syntastic_java_javac_maven_pom_classpath[pom]
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
return ''
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
function! s:MavenOutputDirectory() " {{{2
|
2015-06-26 00:28:50 -04:00
|
|
|
let pom = syntastic#util#findFileInParent('pom.xml', expand('%:p:h', 1))
|
2013-09-19 18:37:28 -04:00
|
|
|
if s:has_maven && filereadable(pom)
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_properties = s:GetMavenProperties()
|
2015-11-26 04:37:44 -05:00
|
|
|
let output_dir = get(mvn_properties, 'project.properties.build.dir', getcwd())
|
2015-02-20 02:47:43 -05:00
|
|
|
|
2015-11-26 04:37:44 -05:00
|
|
|
let sep = syntastic#util#Slash()
|
|
|
|
let src_main_dir = get(mvn_properties, 'project.build.sourceDirectory', join(['src', 'main', 'java'], sep))
|
|
|
|
let src_test_dir = get(mvn_properties, 'project.build.testsourceDirectory', join(['src', 'test', 'java'], sep))
|
|
|
|
if stridx(expand('%:p:h', 1), src_main_dir) >= 0
|
|
|
|
let output_dir = get(mvn_properties, 'project.build.outputDirectory', join ([output_dir, 'target', 'classes'], sep))
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
2015-11-26 04:37:44 -05:00
|
|
|
if stridx(expand('%:p:h', 1), src_test_dir) >= 0
|
|
|
|
let output_dir = get(mvn_properties, 'project.build.testOutputDirectory', join([output_dir, 'target', 'test-classes'], sep))
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has('win32unix')
|
2015-02-23 09:40:53 -05:00
|
|
|
let output_dir = syntastic#util#CygwinPath(output_dir)
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
|
|
|
return output_dir
|
2013-05-06 07:25:19 -04:00
|
|
|
endif
|
2013-09-19 18:37:28 -04:00
|
|
|
return '.'
|
2015-01-04 05:46:54 -05:00
|
|
|
endfunction " }}}2
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" }}}1
|
2013-01-27 15:08:30 -05:00
|
|
|
|
|
|
|
call g:SyntasticRegistry.CreateAndRegisterChecker({
|
|
|
|
\ 'filetype': 'java',
|
|
|
|
\ 'name': 'javac'})
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let &cpo = s:save_cpo
|
|
|
|
unlet s:save_cpo
|
|
|
|
|
2015-01-04 05:46:54 -05:00
|
|
|
" vim: set sw=4 sts=4 et fdm=marker:
|