From b47611446108e236125364c6afc019dbb503523f Mon Sep 17 00:00:00 2001 From: troydm Date: Wed, 19 Dec 2012 17:23:58 +0400 Subject: [PATCH] added config file support for javac checker and windows os support --- syntax_checkers/java/javac.vim | 67 ++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/syntax_checkers/java/javac.vim b/syntax_checkers/java/javac.vim index d65baa7a..2fab5386 100644 --- a/syntax_checkers/java/javac.vim +++ b/syntax_checkers/java/javac.vim @@ -28,10 +28,26 @@ if !exists("g:syntastic_java_javac_delete_output") let g:syntastic_java_javac_delete_output = 1 endif +if !exists("g:syntastic_java_javac_temp_dir") + if has('win32') || has('win64') + let g:syntastic_java_javac_temp_dir = $TEMP."\\vim-syntastic-javac" + else + let g:syntastic_java_javac_temp_dir = '/tmp/vim-syntastic-javac' + endif +endif + if !exists("g:syntastic_java_javac_autoload_maven_classpath") let g:syntastic_java_javac_autoload_maven_classpath = 1 endif +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 + " Internal variables, do not ovveride those if !exists("g:syntastic_java_javac_maven_pom_cwd") let g:syntastic_java_javac_maven_pom_cwd = '' @@ -45,20 +61,55 @@ if !exists("g:syntastic_java_javac_maven_pom_classpath") let g:syntastic_java_javac_maven_pom_classpath = '' endif +" recursively remove directory and all it's sub-directories +function! s:RemoveDir(dir) + if isdirectory(a:dir) + for f in split(globpath(a:dir,'*'),"\n") + call s:RemoveDir(f) + endfor + silent! call system('rmdir '.a:dir) + else + silent! call delete(a:dir) + endif +endfunction + function! s:AddToClasspath(classpath,path) if a:path == '' return a:classpath endif if a:classpath != '' && a:path != '' - return a:classpath . ":" . a:path + if has('win32') || has('win64') + return a:classpath . ";" . a:path + else + return a:classpath . ":" . a:path + endif else return a:path endif endfunction +function! s:LoadClasspathFromConfigFile() + if filereadable(g:syntastic_java_javac_config_file) + let path = '' + let lines = readfile(g:syntastic_java_javac_config_file) + for l in lines + if l != '' + let path .= l."\n" + endif + endfor + return path + else + return '' + endif +endfunction + function! s:SaveClasspath() let path = '' let lines = getline(1,line('$')) + " save classpath to config file + if g:syntastic_java_javac_config_file_enabled + call writefile(lines,g:syntastic_java_javac_config_file) + endif for l in lines if l != '' let path .= l."\n" @@ -112,10 +163,18 @@ function! SyntaxCheckers_java_GetLocList() let javac_opts = g:syntastic_java_javac_options if g:syntastic_java_javac_delete_output - let output_dir = '/tmp/vim-syntastic' + let output_dir = g:syntastic_java_javac_temp_dir let javac_opts .= ' -d ' .output_dir endif + " load classpath from config file + if g:syntastic_java_javac_config_file_enabled + let loaded_classpath = s:LoadClasspathFromConfigFile() + if loaded_classpath != '' + let g:syntastic_java_javac_classpath = loaded_classpath + endif + endif + let javac_classpath = '' " add classpathes to javac_classpath @@ -149,11 +208,11 @@ function! SyntaxCheckers_java_GetLocList() let errorformat = '%E%f:%l:\ error:\ %m,%W%f:%l:\ warning:\ %m,%A%f:%l:\ %m,%+Z%p^,%+C%.%#,%-G%.%#' if g:syntastic_java_javac_delete_output - call system('mkdir -p ' . output_dir) + silent! call mkdir(output_dir,'p') endif let r = SyntasticMake({ 'makeprg': makeprg, 'errorformat': errorformat }) if g:syntastic_java_javac_delete_output - call system('rm -rf ' . output_dir) + call s:RemoveDir(output_dir) endif return r