summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ale_linters/java/javac.vim15
-rw-r--r--doc/ale-java.txt8
-rw-r--r--test/command_callback/test_javac_command_callback.vader24
3 files changed, 38 insertions, 9 deletions
diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim
index 73e84147..b1f74a6d 100644
--- a/ale_linters/java/javac.vim
+++ b/ale_linters/java/javac.vim
@@ -3,8 +3,9 @@
let s:classpath_sep = has('unix') ? ':' : ';'
-let g:ale_java_javac_options = get(g:, 'ale_java_javac_options', '')
-let g:ale_java_javac_classpath = get(g:, 'ale_java_javac_classpath', '')
+call ale#Set('java_javac_executable', 'javac')
+call ale#Set('java_javac_options', '')
+call ale#Set('java_javac_classpath', '')
function! ale_linters#java#javac#GetImportPaths(buffer) abort
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
@@ -35,6 +36,10 @@ function! s:BuildClassPathOption(buffer, import_paths) abort
\ : ''
endfunction
+function! ale_linters#java#javac#GetExecutable(buffer) abort
+ return ale#Var(a:buffer, 'java_javac_executable')
+endfunction
+
function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
let l:cp_option = s:BuildClassPathOption(a:buffer, a:import_paths)
let l:sp_option = ''
@@ -72,11 +77,13 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths) abort
" Create .class files in a temporary directory, which we will delete later.
let l:class_file_directory = ale#engine#CreateDirectory(a:buffer)
+ let l:executable = ale_linters#java#javac#GetExecutable(a:buffer)
" Always run javac from the directory the file is in, so we can resolve
" relative paths correctly.
return ale#path#BufferCdString(a:buffer)
- \ . 'javac -Xlint'
+ \ . ale#Escape(l:executable)
+ \ . ' -Xlint'
\ . ' ' . l:cp_option
\ . ' ' . l:sp_option
\ . ' -d ' . ale#Escape(l:class_file_directory)
@@ -119,7 +126,7 @@ endfunction
call ale#linter#Define('java', {
\ 'name': 'javac',
-\ 'executable': 'javac',
+\ 'executable_callback': 'ale_linters#java#javac#GetExecutable',
\ 'command_chain': [
\ {'callback': 'ale_linters#java#javac#GetImportPaths', 'output_stream': 'stdout'},
\ {'callback': 'ale_linters#java#javac#GetCommand', 'output_stream': 'stderr'},
diff --git a/doc/ale-java.txt b/doc/ale-java.txt
index 0d2011f8..3837f6c6 100644
--- a/doc/ale-java.txt
+++ b/doc/ale-java.txt
@@ -25,6 +25,14 @@ g:ale_java_javac_classpath *g:ale_java_javac_classpath*
This variable can be set to change the global classpath for Java.
+g:ale_java_javac_executable *g:ale_java_javac_executable*
+ *b:ale_java_javac_executable*
+ Type: |String|
+ Default: `'javac'`
+
+ This variable can be set to change the executable path used for javac.
+
+
g:ale_java_javac_options *g:ale_java_javac_options*
*b:ale_java_javac_options*
Type: |String|
diff --git a/test/command_callback/test_javac_command_callback.vader b/test/command_callback/test_javac_command_callback.vader
index 7823d030..b0d0e7c7 100644
--- a/test/command_callback/test_javac_command_callback.vader
+++ b/test/command_callback/test_javac_command_callback.vader
@@ -1,9 +1,11 @@
Before:
call ale#test#SetDirectory('/testplugin/test/command_callback')
+ Save g:ale_java_javac_executable
Save g:ale_java_javac_options
Save g:ale_java_javac_classpath
+ unlet! g:ale_java_javac_executable
unlet! g:ale_java_javac_options
unlet! g:ale_java_javac_classpath
@@ -28,7 +30,8 @@ Before:
call ale#test#SetFilename('dummy.java')
- let g:prefix = 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
+ let g:prefix = 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
+ \ . ale#Escape('javac') . ' -Xlint'
After:
call ale#test#RestoreDirectory()
@@ -57,6 +60,17 @@ Execute(The javac callback should use g:ale_java_javac_classpath correctly):
\ . ' -d TEMP %t',
\ GetCommand([])
+Execute(The executable should be configurable):
+ let g:ale_java_javac_executable = 'foobar'
+
+ AssertEqual 'foobar', ale_linters#java#javac#GetExecutable(bufnr(''))
+
+ AssertEqual
+ \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && '
+ \ . ale#Escape('foobar') . ' -Xlint'
+ \ . ' -d TEMP %t',
+ \ GetCommand([])
+
Execute(The javac callback should include discovered classpaths):
AssertEqual
\ g:prefix
@@ -120,7 +134,7 @@ Execute(The javac callback should detect source directories):
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
- \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
+ \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/')
\ )
@@ -133,7 +147,7 @@ Execute(The javac callback should combine detected source directories and classp
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
- \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
+ \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
\ . ' -cp ' . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep))
\ . ' -sourcepath ' . ale#Escape(
\ ale#path#Simplify(g:dir . '/java_paths/src/main/java/')
@@ -164,7 +178,7 @@ Execute(The javac callback should include src/test/java for test paths):
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
- \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
+ \ 'cd ' . ale#Escape(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/src/test/java/'),
@@ -178,7 +192,7 @@ Execute(The javac callback should include src/main/jaxb when available):
call ale#engine#InitBufferInfo(bufnr(''))
AssertEqual
- \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && javac -Xlint'
+ \ 'cd ' . ale#Escape(expand('%:p:h')) . ' && ' . ale#Escape('javac') . ' -Xlint'
\ . ' -sourcepath ' . ale#Escape(join([
\ ale#path#Simplify(g:dir . '/java_paths_with_jaxb/src/main/java/'),
\ ale#path#Simplify(g:dir . '/java_paths_with_jaxb/src/main/jaxb/'),