refactor(javac): ale_java_javac_classpath variable supports String and List types

This commit is contained in:
NiBo 2020-05-19 10:43:16 +08:00
parent ff6bfc3d37
commit e61e1147b0
3 changed files with 64 additions and 6 deletions

View file

@ -41,10 +41,15 @@ endfunction
function! s:BuildClassPathOption(buffer, import_paths) abort
" Filter out lines like [INFO], etc.
let l:class_paths = filter(a:import_paths[:], 'v:val !~# ''[''')
call extend(
\ l:class_paths,
\ split(ale#Var(a:buffer, 'java_javac_classpath'), s:classpath_sep),
\)
let l:cls_path = ale#Var(a:buffer, 'java_javac_classpath')
if !empty(l:cls_path) && type(l:cls_path) is v:t_string
call extend(l:class_paths, split(l:cls_path, s:classpath_sep))
endif
if !empty(l:cls_path) && type(l:cls_path) is v:t_list
call extend(l:class_paths, l:cls_path)
endif
return !empty(l:class_paths)
\ ? '-cp ' . ale#Escape(join(l:class_paths, s:classpath_sep))

View file

@ -46,7 +46,7 @@ javac *ale-java-javac*
g:ale_java_javac_classpath *g:ale_java_javac_classpath*
*b:ale_java_javac_classpath*
Type: |String|
Type: |String| or |List|
Default: `''`
This variable can be set to change the global classpath for Java.

View file

@ -31,7 +31,7 @@ After:
Execute(The javac callback should return the correct default value):
AssertLinter 'javac', g:prefix . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The javac callback should use g:ale_java_javac_classpath correctly):
Execute(The javac callback should use string type g:ale_java_javac_classpath correctly):
let g:ale_java_javac_classpath = 'foo.jar'
AssertLinter 'javac',
@ -39,6 +39,14 @@ Execute(The javac callback should use g:ale_java_javac_classpath correctly):
\ . ' -cp ' . ale#Escape('foo.jar')
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The javac callback should use list type g:ale_java_javac_classpath correctly):
let g:ale_java_javac_classpath = ['foo.jar']
AssertLinter 'javac',
\ g:prefix
\ . ' -cp ' . ale#Escape('foo.jar')
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The executable should be configurable):
let g:ale_java_javac_executable = 'foobar'
@ -108,6 +116,51 @@ Execute(The javac callback should combine discovered classpaths and manual ones)
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
let g:ale_java_javac_classpath = ['configured.jar']
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [
\ '[DEBUG] Ignore this.',
\ '[INFO] Something we should ignore.',
\ '/foo/bar.jar',
\ '/xyz/abc.jar',
\], {})
AssertEqual
\ g:prefix
\ . ' -cp '
\ . ale#Escape(join(
\ [
\ '/foo/bar.jar',
\ '/xyz/abc.jar',
\ 'configured.jar',
\ ],
\ g:cp_sep
\ ))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
let g:ale_java_javac_classpath = ['configured.jar', 'configured2.jar']
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [
\ '[DEBUG] Ignore this.',
\ '[INFO] Something we should ignore.',
\ '/foo/bar.jar',
\ '/xyz/abc.jar',
\], {})
AssertEqual
\ g:prefix
\ . ' -cp '
\ . ale#Escape(join(
\ [
\ '/foo/bar.jar',
\ '/xyz/abc.jar',
\ 'configured.jar',
\ 'configured2.jar',
\ ],
\ g:cp_sep
\ ))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
Execute(The javac callback should use string type g:ale_java_javac_sourcepath correctly):
let g:ale_java_javac_sourcepath = 'java_paths/build/gen/main'