Fix #859 Include test and jaxb Java source paths when available

This commit is contained in:
w0rp 2017-11-20 16:42:43 +00:00
parent f20e5a4cf0
commit c9e203e620
5 changed files with 56 additions and 2 deletions

View File

@ -41,9 +41,33 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
" Find the src directory, for files in this project.
let l:src_dir = ale#path#FindNearestDirectory(a:buffer, 'src/main/java')
let l:sp_dirs = []
if !empty(l:src_dir)
let l:sp_option = '-sourcepath ' . ale#Escape(l:src_dir)
call add(l:sp_dirs, l:src_dir)
" Automatically include the jaxb directory too, if it's there.
let l:jaxb_dir = fnamemodify(l:src_dir, ':h:h')
\ . (has('win32') ? '\jaxb\' : '/jaxb/')
if isdirectory(l:jaxb_dir)
call add(l:sp_dirs, l:jaxb_dir)
endif
" Automatically include the test directory, but only for test code.
if expand('#' . a:buffer . ':p') =~? '\vsrc[/\\]test[/\\]java'
let l:test_dir = fnamemodify(l:src_dir, ':h:h:h')
\ . (has('win32') ? '\test\java\' : '/test/java/')
if isdirectory(l:test_dir)
call add(l:sp_dirs, l:test_dir)
endif
endif
endif
if !empty(l:sp_dirs)
let l:sp_option = '-sourcepath '
\ . ale#Escape(join(l:sp_dirs, s:classpath_sep))
endif
" Create .class files in a temporary directory, which we will delete later.

View File

@ -116,7 +116,7 @@ Execute(The javac callback should combine discovered classpaths and manual ones)
Execute(The javac callback should detect source directories):
call ale#engine#Cleanup(bufnr(''))
:e! java_paths/src/main/java/com/something/dummy
noautocmd e! java_paths/src/main/java/com/something/dummy
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
@ -155,3 +155,33 @@ Execute(The javac callback should use g:ale_java_javac_options correctly):
\ g:prefix
\ . ' -d TEMP --anything --else %t',
\ GetCommand([])
Execute(The javac callback should include src/test/java for test paths):
call ale#engine#Cleanup(bufnr(''))
" The test path is only included for test files.
" Regular Java files shouldn't import from tests.
noautocmd e! java_paths/src/test/java/com/something/dummy
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Winify(g:dir . '/java_paths/src/main/java/'),
\ ale#path#Winify(g:dir . '/java_paths/src/test/java/'),
\ ], g:cp_sep))
\ . ' -d TEMP %t',
\ GetCommand([])
Execute(The javac callback should include src/main/jaxb when available):
call ale#engine#Cleanup(bufnr(''))
noautocmd e! java_paths_with_jaxb/src/main/java/com/something/dummy
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
\ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Winify(g:dir . '/java_paths_with_jaxb/src/main/java/'),
\ ale#path#Winify(g:dir . '/java_paths_with_jaxb/src/main/jaxb/'),
\ ], g:cp_sep))
\ . ' -d TEMP %t',
\ GetCommand([])