summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Campbell <campbellr@gmail.com>2018-12-20 15:37:31 -0700
committerRyan Campbell <campbellr@gmail.com>2019-03-03 14:43:21 -0700
commit4fc27f099bfe89be284f64838884d0357956420f (patch)
tree6403ec0cc77de0b080a0ecce55c3da3403ed984b
parentfefc093e707716da755ca2c326f852495f1b56fb (diff)
downloadale-4fc27f099bfe89be284f64838884d0357956420f.zip
javac: Don't assume src/main/java always exists
Some projects I have only have src/test/java (no /src/main/java), which seemed to break some incorrect assumptions the linter had.
-rw-r--r--ale_linters/java/javac.vim13
-rw-r--r--test/command_callback/java_paths_no_main/src/test/java/com/something/dummy0
-rw-r--r--test/command_callback/test_javac_command_callback.vader12
3 files changed, 18 insertions, 7 deletions
diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim
index 2aa01b4f..18a26b77 100644
--- a/ale_linters/java/javac.vim
+++ b/ale_linters/java/javac.vim
@@ -55,15 +55,14 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
if isdirectory(l:jaxb_dir)
call add(l:sp_dirs, l:jaxb_dir)
endif
+ 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/')
+ " Automatically include the test directory, but only for test code.
+ if expand('#' . a:buffer . ':p') =~? '\vsrc[/\\]test[/\\]java'
+ let l:test_dir = ale#path#FindNearestDirectory(a:buffer, 'src/test/java')
- if isdirectory(l:test_dir)
- call add(l:sp_dirs, l:test_dir)
- endif
+ if isdirectory(l:test_dir)
+ call add(l:sp_dirs, l:test_dir)
endif
endif
diff --git a/test/command_callback/java_paths_no_main/src/test/java/com/something/dummy b/test/command_callback/java_paths_no_main/src/test/java/com/something/dummy
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/java_paths_no_main/src/test/java/com/something/dummy
diff --git a/test/command_callback/test_javac_command_callback.vader b/test/command_callback/test_javac_command_callback.vader
index 2dcb6a1b..a7a928e4 100644
--- a/test/command_callback/test_javac_command_callback.vader
+++ b/test/command_callback/test_javac_command_callback.vader
@@ -166,3 +166,15 @@ Execute(The javac callback should include src/main/jaxb when available):
\ ale#path#Simplify(g:dir . '/java_paths_with_jaxb/src/main/jaxb/'),
\ ], g:cp_sep))
\ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'
+
+Execute(The javac callback should add -sourcepath even if src/java/main doesn't exist):
+ call ale#engine#Cleanup(bufnr(''))
+ call ale#test#SetFilename('java_paths_no_main/src/test/java/com/something/dummy.java')
+ call ale#engine#InitBufferInfo(bufnr(''))
+
+ AssertLinter 'javac',
+ \ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint'
+ \ . ' -sourcepath ' . ale#Escape(join([
+ \ ale#path#Simplify(g:dir . '/java_paths_no_main/src/test/java/'),
+ \ ], g:cp_sep))
+ \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t'