2012-08-14 11:56:20 -04:00
|
|
|
"============================================================================
|
|
|
|
"File: javac.vim
|
|
|
|
"Description: Syntax checking plugin for syntastic.vim
|
|
|
|
"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
|
|
|
"============================================================================
|
|
|
|
|
2013-02-21 10:50:41 -05:00
|
|
|
if exists("g:loaded_syntastic_java_javac_checker")
|
|
|
|
finish
|
|
|
|
endif
|
2014-01-04 13:31:55 -05:00
|
|
|
let g:loaded_syntastic_java_javac_checker = 1
|
2013-07-01 12:23:56 -04:00
|
|
|
let g:syntastic_java_javac_maven_pom_tags = ["build", "properties"]
|
|
|
|
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
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
" Global Options
|
|
|
|
if !exists("g:syntastic_java_javac_executable")
|
|
|
|
let g:syntastic_java_javac_executable = 'javac'
|
|
|
|
endif
|
|
|
|
|
2013-03-13 12:00:17 -04:00
|
|
|
if !exists("g:syntastic_java_maven_executable")
|
|
|
|
let g:syntastic_java_maven_executable = 'mvn'
|
|
|
|
endif
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
if !exists("g:syntastic_java_javac_options")
|
|
|
|
let g:syntastic_java_javac_options = '-Xlint'
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists("g:syntastic_java_javac_classpath")
|
|
|
|
let g:syntastic_java_javac_classpath = ''
|
|
|
|
endif
|
|
|
|
|
|
|
|
if !exists("g:syntastic_java_javac_delete_output")
|
|
|
|
let g:syntastic_java_javac_delete_output = 1
|
|
|
|
endif
|
|
|
|
|
2014-01-03 04:29:08 -05:00
|
|
|
let s:save_cpo = &cpo
|
|
|
|
set cpo&vim
|
|
|
|
|
2013-05-13 09:37:16 -04:00
|
|
|
function! s:CygwinPath(path)
|
2013-11-12 13:44:32 -05:00
|
|
|
return substitute(system("cygpath -m " . a:path), '\n', '', 'g')
|
2013-05-06 07:25:19 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-12-19 08:23:58 -05:00
|
|
|
if !exists("g:syntastic_java_javac_temp_dir")
|
|
|
|
if has('win32') || has('win64')
|
|
|
|
let g:syntastic_java_javac_temp_dir = $TEMP."\\vim-syntastic-javac"
|
2013-05-13 09:37:16 -04:00
|
|
|
elseif has('win32unix')
|
2013-05-14 12:36:20 -04:00
|
|
|
let g:syntastic_java_javac_temp_dir = s:CygwinPath('/tmp/vim-syntastic-javac')
|
2012-12-19 08:23:58 -05:00
|
|
|
else
|
|
|
|
let g:syntastic_java_javac_temp_dir = '/tmp/vim-syntastic-javac'
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
if !exists("g:syntastic_java_javac_autoload_maven_classpath")
|
|
|
|
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
|
|
|
|
|
2012-08-14 11:56:20 -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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2013-05-06 07:25:19 -04:00
|
|
|
function! s:RemoveCarriageReturn(line)
|
2013-05-13 09:37:16 -04:00
|
|
|
return substitute(a:line, '\r', '', 'g')
|
2013-05-06 07:25:19 -04:00
|
|
|
endfunction
|
|
|
|
|
2012-12-19 08:23:58 -05:00
|
|
|
" recursively remove directory and all it's sub-directories
|
|
|
|
function! s:RemoveDir(dir)
|
|
|
|
if isdirectory(a:dir)
|
2013-05-13 09:37:16 -04:00
|
|
|
for f in split(globpath(a:dir, '*'), "\n")
|
2012-12-19 08:23:58 -05:00
|
|
|
call s:RemoveDir(f)
|
|
|
|
endfor
|
2013-05-13 09:37:16 -04:00
|
|
|
silent! call system('rmdir ' . a:dir)
|
2012-12-19 08:23:58 -05:00
|
|
|
else
|
|
|
|
silent! call delete(a:dir)
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2014-01-26 02:10:26 -05:00
|
|
|
function! s:AddToClasspath(classpath, path)
|
2012-08-14 11:56:20 -04:00
|
|
|
if a:path == ''
|
|
|
|
return a:classpath
|
|
|
|
endif
|
|
|
|
if a:classpath != '' && a:path != ''
|
2013-04-28 09:32:12 -04:00
|
|
|
if has('win32') || has('win32unix') || has('win64')
|
2012-12-19 08:23:58 -05:00
|
|
|
return a:classpath . ";" . a:path
|
|
|
|
else
|
|
|
|
return a:classpath . ":" . a:path
|
|
|
|
endif
|
2012-08-14 11:56:20 -04:00
|
|
|
else
|
|
|
|
return a:path
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2014-01-04 13:31:55 -05:00
|
|
|
function! s:SplitClasspath(classpath)
|
|
|
|
if a:classpath == ''
|
|
|
|
return []
|
|
|
|
endif
|
|
|
|
if has('win32') || has('win32unix') || has('win64')
|
|
|
|
return split(a:classpath, ";")
|
2012-12-19 08:23:58 -05:00
|
|
|
else
|
2014-01-04 13:31:55 -05:00
|
|
|
return split(a:classpath, ":")
|
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:LoadConfigFile()
|
|
|
|
if filereadable(g:syntastic_java_javac_config_file)
|
|
|
|
exe 'source '.g:syntastic_java_javac_config_file
|
2012-12-19 08:23:58 -05:00
|
|
|
endif
|
|
|
|
endfunction
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
function! s:SaveClasspath()
|
2014-01-04 13:31:55 -05:00
|
|
|
" build classpath from lines
|
2012-08-14 11:56:20 -04:00
|
|
|
let path = ''
|
2013-05-13 09:37:16 -04:00
|
|
|
let lines = getline(1, line('$'))
|
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
|
2014-01-04 13:31:55 -05:00
|
|
|
if filereadable(g:syntastic_java_javac_config_file)
|
|
|
|
" load lines from config file
|
|
|
|
let lines = readfile(g:syntastic_java_javac_config_file)
|
|
|
|
" 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-01-04 13:31:55 -05:00
|
|
|
let i -= 1
|
|
|
|
endif
|
|
|
|
let i += 1
|
|
|
|
endwhile
|
|
|
|
else
|
|
|
|
let lines = []
|
|
|
|
endif
|
|
|
|
" add new g:syntastic_java_javac_classpath option to config
|
2014-01-26 02:10:26 -05:00
|
|
|
call add(lines, 'let g:syntastic_java_javac_classpath = "'.path.'"')
|
2014-01-04 13:31:55 -05:00
|
|
|
" save config file lines
|
2014-01-26 02:10:26 -05:00
|
|
|
call writefile(lines, g:syntastic_java_javac_config_file)
|
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
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:EditClasspath()
|
|
|
|
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
|
|
|
|
let path += s:SplitClasspath(p)
|
|
|
|
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
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:SaveConfig()
|
|
|
|
" get lines
|
|
|
|
let lines = getline(1, line('$'))
|
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
|
|
|
" save config file lines
|
2014-01-26 02:10:26 -05:00
|
|
|
call writefile(lines, g:syntastic_java_javac_config_file)
|
2014-01-04 13:31:55 -05:00
|
|
|
endif
|
|
|
|
let &modified = 0
|
|
|
|
endfunction
|
|
|
|
|
|
|
|
function! s:EditConfig()
|
|
|
|
let command = 'syntastic javac config'
|
|
|
|
let winnr = bufwinnr('^' . command . '$')
|
|
|
|
if winnr < 0
|
|
|
|
let lines = []
|
|
|
|
if filereadable(g:syntastic_java_javac_config_file)
|
|
|
|
let lines = readfile(g:syntastic_java_javac_config_file)
|
|
|
|
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
|
|
|
|
endfunction
|
2013-07-01 12:23:56 -04:00
|
|
|
|
|
|
|
function! s:GetMavenProperties()
|
|
|
|
let mvn_properties = {}
|
|
|
|
let pom = findfile("pom.xml", ".;")
|
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)
|
2013-10-28 11:30:25 -04:00
|
|
|
let mvn_cmd = expand(g:syntastic_java_maven_executable) . ' -f ' . pom
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_is_managed_tag = 1
|
|
|
|
let mvn_settings_output = split(system(mvn_cmd . ' help:effective-pom'), "\n")
|
|
|
|
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
|
2013-10-25 08:46:16 -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
|
|
|
|
endfunction
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
command! SyntasticJavacEditClasspath call s:EditClasspath()
|
|
|
|
|
2014-01-04 13:31:55 -05:00
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
|
|
|
command! SyntasticJavacEditConfig call s:EditConfig()
|
|
|
|
endif
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
function! s:GetMavenClasspath()
|
2013-07-01 12:23:56 -04:00
|
|
|
let pom = findfile("pom.xml", ".;")
|
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)
|
2013-10-28 11:30:25 -04:00
|
|
|
let mvn_cmd = expand(g:syntastic_java_maven_executable) . ' -f ' . pom
|
2013-07-01 12:23:56 -04:00
|
|
|
let mvn_classpath_output = split(system(mvn_cmd . ' dependency:build-classpath'), "\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()
|
|
|
|
|
|
|
|
let output_dir = 'target/classes'
|
|
|
|
if has_key(mvn_properties, 'project.build.outputDirectory')
|
|
|
|
let output_dir = mvn_properties['project.build.outputDirectory']
|
|
|
|
endif
|
|
|
|
let mvn_classpath = s:AddToClasspath(mvn_classpath, output_dir)
|
|
|
|
|
|
|
|
let test_output_dir = 'target/test-classes'
|
|
|
|
if has_key(mvn_properties, 'project.build.testOutputDirectory')
|
|
|
|
let test_output_dir = mvn_properties['project.build.testOutputDirectory']
|
|
|
|
endif
|
|
|
|
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 ''
|
|
|
|
endfunction
|
|
|
|
|
2013-10-28 11:30:25 -04:00
|
|
|
function! SyntaxCheckers_java_javac_IsAvailable() dict
|
|
|
|
let s:has_maven = executable(expand(g:syntastic_java_maven_executable))
|
|
|
|
return executable(expand(g:syntastic_java_javac_executable))
|
2013-01-27 15:08:30 -05:00
|
|
|
endfunction
|
|
|
|
|
2013-05-06 07:25:19 -04:00
|
|
|
function! s:MavenOutputDirectory()
|
2013-07-01 12:23:56 -04:00
|
|
|
let pom = findfile("pom.xml", ".;")
|
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()
|
2013-05-13 09:37:16 -04:00
|
|
|
let output_dir = getcwd()
|
2013-07-01 12:23:56 -04:00
|
|
|
if has_key(mvn_properties, 'project.properties.build.dir')
|
|
|
|
let output_dir = mvn_properties['project.properties.build.dir']
|
|
|
|
endif
|
2013-11-26 16:19:01 -05:00
|
|
|
if stridx(expand( '%:p:h' ), "src.main.java") >= 0
|
2013-05-13 09:37:16 -04:00
|
|
|
let output_dir .= '/target/classes'
|
2013-07-01 12:23:56 -04:00
|
|
|
if has_key(mvn_properties, 'project.build.outputDirectory')
|
|
|
|
let output_dir = mvn_properties['project.build.outputDirectory']
|
|
|
|
endif
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
2013-11-26 16:19:01 -05:00
|
|
|
if stridx(expand( '%:p:h' ), "src.test.java") >= 0
|
2013-05-13 09:37:16 -04:00
|
|
|
let output_dir .= '/target/test-classes'
|
2013-07-01 12:23:56 -04:00
|
|
|
if has_key(mvn_properties, 'project.build.testOutputDirectory')
|
2013-07-01 12:50:48 -04:00
|
|
|
let output_dir = mvn_properties['project.build.testOutputDirectory']
|
2013-07-01 12:23:56 -04:00
|
|
|
endif
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
|
|
|
|
|
|
|
if has('win32unix')
|
|
|
|
let output_dir=s:CygwinPath(output_dir)
|
|
|
|
endif
|
|
|
|
return output_dir
|
2013-05-06 07:25:19 -04:00
|
|
|
endif
|
2013-09-19 18:37:28 -04:00
|
|
|
return '.'
|
2013-05-06 07:25:19 -04:00
|
|
|
endfunction
|
|
|
|
|
2013-10-28 07:53:33 -04:00
|
|
|
function! SyntaxCheckers_java_javac_GetLocList() dict
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2013-05-13 09:37:16 -04:00
|
|
|
let javac_opts = g:syntastic_java_javac_options
|
2012-08-14 11:56:20 -04:00
|
|
|
|
2014-01-26 02:10:26 -05:00
|
|
|
let output_dir = ""
|
2012-08-14 11:56:20 -04:00
|
|
|
if g:syntastic_java_javac_delete_output
|
2013-05-13 09:37:16 -04:00
|
|
|
let output_dir = g:syntastic_java_javac_temp_dir
|
|
|
|
let javac_opts .= ' -d ' . output_dir
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2012-12-19 08:23:58 -05:00
|
|
|
" load classpath from config file
|
|
|
|
if g:syntastic_java_javac_config_file_enabled
|
2014-01-04 13:31:55 -05:00
|
|
|
call s:LoadConfigFile()
|
2012-12-19 08:23:58 -05:00
|
|
|
endif
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
let javac_classpath = ''
|
|
|
|
|
|
|
|
" add classpathes to javac_classpath
|
2014-01-27 15:52:24 -05:00
|
|
|
if has('win32') || has('win32unix') || has('win64')
|
|
|
|
let javac_classpath_split = ';'
|
|
|
|
else
|
|
|
|
let javac_classpath_split = ':'
|
|
|
|
endif
|
|
|
|
for path in split(g:syntastic_java_javac_classpath, javac_classpath_split)
|
2012-08-14 11:56:20 -04:00
|
|
|
if path != ''
|
2013-01-23 13:26:43 -05:00
|
|
|
try
|
2014-01-26 02:10:26 -05:00
|
|
|
let ps = glob(path, 0, 1)
|
2013-01-23 13:26:43 -05:00
|
|
|
catch
|
2014-01-26 02:10:26 -05:00
|
|
|
let ps = split(glob(path, 0), "\n")
|
2013-01-23 13:26:43 -05:00
|
|
|
endtry
|
2012-08-14 11:56:20 -04:00
|
|
|
if type(ps) == type([])
|
|
|
|
for p in ps
|
2014-01-26 02:10:26 -05:00
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, p)
|
2012-08-14 11:56:20 -04:00
|
|
|
endfor
|
|
|
|
else
|
2014-01-26 02:10:26 -05:00
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, ps)
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
endif
|
|
|
|
endfor
|
|
|
|
|
2013-09-19 18:37:28 -04:00
|
|
|
if s:has_maven && g:syntastic_java_javac_autoload_maven_classpath
|
2013-05-14 12:36:20 -04:00
|
|
|
if !g:syntastic_java_javac_delete_output
|
2013-09-19 18:37:28 -04:00
|
|
|
let javac_opts .= ' -d ' . s:MavenOutputDirectory()
|
2013-05-14 12:36:20 -04:00
|
|
|
endif
|
2013-09-19 18:37:28 -04:00
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, s:GetMavenClasspath())
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2014-01-04 14:09:18 -05:00
|
|
|
" load custom classpath
|
|
|
|
if g:syntastic_java_javac_custom_classpath_command != ''
|
|
|
|
let lines = system(g:syntastic_java_javac_custom_classpath_command)
|
|
|
|
if has('win32') || has('win32unix') || has('win64')
|
2014-01-26 02:10:26 -05:00
|
|
|
let lines = substitute(lines, "\r\n", "\n", 'g')
|
2014-01-04 14:09:18 -05:00
|
|
|
endif
|
|
|
|
for l in split(lines, "\n")
|
|
|
|
let javac_classpath = s:AddToClasspath(javac_classpath, l)
|
|
|
|
endfor
|
|
|
|
endif
|
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
if javac_classpath != ''
|
2013-04-28 09:32:12 -04:00
|
|
|
let javac_opts .= ' -cp "' . fnameescape(javac_classpath) . '"'
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
|
|
|
|
2012-12-19 08:43:08 -05:00
|
|
|
" path seperator
|
2013-04-28 09:32:12 -04:00
|
|
|
if has('win32') || has('win32unix') || has('win64')
|
2013-05-13 09:37:16 -04:00
|
|
|
let sep = "\\"
|
2012-12-19 08:43:08 -05:00
|
|
|
else
|
|
|
|
let sep = '/'
|
|
|
|
endif
|
|
|
|
|
2013-05-13 09:37:16 -04:00
|
|
|
let fname = fnameescape(expand ( '%:p:h' ) . sep . expand ( '%:t' ))
|
2013-04-28 09:32:12 -04:00
|
|
|
|
2013-05-13 09:37:16 -04:00
|
|
|
if has('win32unix')
|
2013-05-14 12:36:20 -04:00
|
|
|
let fname = s:CygwinPath(fname)
|
2013-05-13 09:37:16 -04:00
|
|
|
endif
|
2013-04-28 09:32:12 -04:00
|
|
|
|
2013-11-01 05:51:47 -04:00
|
|
|
let makeprg = self.makeprgBuild({
|
2013-05-13 09:37:16 -04:00
|
|
|
\ 'args': javac_opts,
|
|
|
|
\ 'fname': fname,
|
2013-11-01 05:51:47 -04:00
|
|
|
\ 'tail': '2>&1' })
|
2012-08-14 11:56:20 -04:00
|
|
|
|
|
|
|
" unashamedly stolen from *errorformat-javac* (quickfix.txt) and modified to include error types
|
2013-05-14 12:36:20 -04:00
|
|
|
let errorformat =
|
|
|
|
\ '%E%f:%l:\ error:\ %m,'.
|
|
|
|
\ '%W%f:%l:\ warning:\ %m,'.
|
|
|
|
\ '%A%f:%l:\ %m,'.
|
|
|
|
\ '%+Z%p^,'.
|
|
|
|
\ '%+C%.%#,'.
|
|
|
|
\ '%-G%.%#'
|
2012-08-14 11:56:20 -04:00
|
|
|
|
|
|
|
if g:syntastic_java_javac_delete_output
|
2014-01-26 02:10:26 -05:00
|
|
|
silent! call mkdir(output_dir, 'p')
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
2013-05-31 14:05:45 -04:00
|
|
|
let errors = SyntasticMake({
|
|
|
|
\ 'makeprg': makeprg,
|
|
|
|
\ 'errorformat': errorformat,
|
|
|
|
\ 'postprocess': ['cygwinRemoveCR'] })
|
2013-05-06 07:25:19 -04:00
|
|
|
|
2012-08-14 11:56:20 -04:00
|
|
|
if g:syntastic_java_javac_delete_output
|
2012-12-19 08:23:58 -05:00
|
|
|
call s:RemoveDir(output_dir)
|
2012-08-14 11:56:20 -04:00
|
|
|
endif
|
2013-05-06 07:25:19 -04:00
|
|
|
return errors
|
2012-08-14 11:56:20 -04:00
|
|
|
|
|
|
|
endfunction
|
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
|
|
|
|
|
|
|
|
" vim: set et sts=4 sw=4:
|