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

This commit is contained in:
NiBo 2020-05-18 17:35:16 +08:00
parent 3635285c02
commit ff6bfc3d37
5 changed files with 117 additions and 13 deletions

View file

@ -80,11 +80,20 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths, meta) abort
endif endif
endif endif
let l:sourcepath_item = ale#Var(a:buffer, 'java_javac_sourcepath') let l:source_paths = []
let l:source_path = ale#Var(a:buffer, 'java_javac_sourcepath')
if !empty(l:sourcepath_item) if !empty(l:source_path) && type(l:source_path) is v:t_string
for l:sourcepath in l:sourcepath_item let l:source_paths = split(l:source_path, s:classpath_sep)
let l:sp_path = ale#path#FindNearestDirectory(a:buffer, l:sourcepath) endif
if !empty(l:source_path) && type(l:source_path) is v:t_list
let l:source_paths = l:source_path
endif
if !empty(l:source_paths)
for l:path in l:source_paths
let l:sp_path = ale#path#FindNearestDirectory(a:buffer, l:path)
if !empty(l:sp_path) if !empty(l:sp_path)
call add(l:sp_dirs, l:sp_path) call add(l:sp_dirs, l:sp_path)

View file

@ -69,18 +69,27 @@ g:ale_java_javac_options *g:ale_java_javac_options*
g:ale_java_javac_sourcepath *g:ale_java_javac_sourcepath* g:ale_java_javac_sourcepath *g:ale_java_javac_sourcepath*
*b:ale_java_javac_sourcepath* *b:ale_java_javac_sourcepath*
Type: |List| Type: |String| or |List|
Default: `[]` Default: `[]`
This variable can set multiple source code paths, the source code path is a This variable can set multiple source code paths, the source code path is a
relative path (relative to the project root directory). relative path (relative to the project root directory).
Example: Example:
>
let g:ale_java_javac_sourcepath = [ String type:
\ 'build/generated/source/querydsl/main', Note that the unix system separator is a colon(`:`) window system
\ 'target/generated-sources/source/querydsl/main' is a semicolon(`;`).
\ ] >
let g:ale_java_javac_sourcepath = 'build/gen/source/xx/main:build/gen/source'
<
List type:
>
let g:ale_java_javac_sourcepath = [
\ 'build/generated/source/querydsl/main',
\ 'target/generated-sources/source/querydsl/main'
\ ]
<
=============================================================================== ===============================================================================

View file

@ -108,6 +108,92 @@ Execute(The javac callback should combine discovered classpaths and manual ones)
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t', \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g') \ 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'
AssertLinter 'javac',
\ g:prefix
\ . ' -sourcepath ' . ale#Escape(
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/')
\ )
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The javac callback should use list type g:ale_java_javac_sourcepath correctly):
let g:ale_java_javac_sourcepath = ['java_paths/build/gen/main']
AssertLinter 'javac',
\ g:prefix
\ . ' -sourcepath ' . ale#Escape(
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/')
\ )
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The javac callback shouldn't add -sourcepath when g:ale_java_javac_sourcepath variable path doesn't exist):
let g:ale_java_javac_sourcepath = 'java_paths/build/gen3/main'
AssertLinter 'javac',
\ g:prefix
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
Execute(The javac callback should combine discovered sourcepath and manual ones):
call ale#engine#Cleanup(bufnr(''))
call ale#test#SetFilename('java_paths/src/main/java/com/something/dummy.java')
call ale#engine#InitBufferInfo(bufnr(''))
let g:ale_java_javac_sourcepath = 'java_paths/build/gen/main'
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [], {})
AssertEqual
\ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/'),
\ ], g:cp_sep))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
let g:ale_java_javac_sourcepath = 'java_paths/build/gen/main'
\ . g:cp_sep . 'java_paths/build/gen2/main'
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [], {})
AssertEqual
\ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen2/main/')
\ ], g:cp_sep))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
let g:ale_java_javac_sourcepath = ['java_paths/build/gen/main']
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [], {})
AssertEqual
\ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/')
\ ], g:cp_sep))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
let g:ale_java_javac_sourcepath = [
\ 'java_paths/build/gen/main',
\ 'java_paths/build/gen2/main'
\ ]
let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [], {})
AssertEqual
\ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen/main/'),
\ ale#path#Simplify(g:dir . '/java_paths/build/gen2/main/')
\ ], g:cp_sep))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t',
\ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g')
Execute(The javac callback should detect source directories): Execute(The javac callback should detect source directories):
call ale#engine#Cleanup(bufnr('')) call ale#engine#Cleanup(bufnr(''))
noautocmd e! java_paths/src/main/java/com/something/dummy noautocmd e! java_paths/src/main/java/com/something/dummy