summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHoracio Sanson <hsanson@gmail.com>2020-05-19 22:51:42 +0900
committerGitHub <noreply@github.com>2020-05-19 22:51:42 +0900
commit7ff87a942b8a6c2cf50b7cf34f9b98421508f542 (patch)
tree350b47792f0ac8e12f495b8a5bbcda9becbab6f7
parent69d96aa9d9998a64ae7dacd700966ada6e30216f (diff)
parent0b5d72fecdbb50e9c6b72af7356a10f755e1a764 (diff)
downloadale-7ff87a942b8a6c2cf50b7cf34f9b98421508f542.zip
Merge pull request #3173 from nibocn/feat#javac-sourcepath
feat(javac): Add java_javac_sourcepath variable
-rw-r--r--ale_linters/java/javac.vim35
-rw-r--r--doc/ale-java.txt26
-rw-r--r--test/command_callback/java_paths/build/gen/main/java/com/something/dummy0
-rw-r--r--test/command_callback/java_paths/build/gen2/main/java/com/something/dummy0
-rw-r--r--test/command_callback/test_javac_command_callback.vader141
5 files changed, 196 insertions, 6 deletions
diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim
index 8bb52c0b..f866eb09 100644
--- a/ale_linters/java/javac.vim
+++ b/ale_linters/java/javac.vim
@@ -6,6 +6,7 @@ let s:classpath_sep = has('unix') ? ':' : ';'
call ale#Set('java_javac_executable', 'javac')
call ale#Set('java_javac_options', '')
call ale#Set('java_javac_classpath', '')
+call ale#Set('java_javac_sourcepath', '')
function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
let l:command = ''
@@ -40,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))
@@ -79,6 +85,27 @@ function! ale_linters#java#javac#GetCommand(buffer, import_paths, meta) abort
endif
endif
+ let l:source_paths = []
+ let l:source_path = ale#Var(a:buffer, 'java_javac_sourcepath')
+
+ if !empty(l:source_path) && type(l:source_path) is v:t_string
+ let l:source_paths = split(l:source_path, s:classpath_sep)
+ 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)
+ call add(l:sp_dirs, l:sp_path)
+ endif
+ endfor
+ endif
+
if !empty(l:sp_dirs)
let l:sp_option = '-sourcepath '
\ . ale#Escape(join(l:sp_dirs, s:classpath_sep))
diff --git a/doc/ale-java.txt b/doc/ale-java.txt
index 15e9e679..d2001ca7 100644
--- a/doc/ale-java.txt
+++ b/doc/ale-java.txt
@@ -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.
@@ -67,6 +67,30 @@ g:ale_java_javac_options *g:ale_java_javac_options*
This variable can be set to pass additional options to javac.
+g:ale_java_javac_sourcepath *g:ale_java_javac_sourcepath*
+ *b:ale_java_javac_sourcepath*
+ Type: |String| or |List|
+ Default: `''`
+
+This variable can set multiple source code paths, the source code path is a
+relative path (relative to the project root directory).
+
+Example:
+
+String type:
+Note that the unix system separator is a colon(`:`) window system
+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'
+ \ ]
+<
+
===============================================================================
google-java-format *ale-java-google-java-format*
diff --git a/test/command_callback/java_paths/build/gen/main/java/com/something/dummy b/test/command_callback/java_paths/build/gen/main/java/com/something/dummy
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/java_paths/build/gen/main/java/com/something/dummy
diff --git a/test/command_callback/java_paths/build/gen2/main/java/com/something/dummy b/test/command_callback/java_paths/build/gen2/main/java/com/something/dummy
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/command_callback/java_paths/build/gen2/main/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 42c64e54..d2eebf7a 100644
--- a/test/command_callback/test_javac_command_callback.vader
+++ b/test/command_callback/test_javac_command_callback.vader
@@ -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,137 @@ 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'
+
+ 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):
call ale#engine#Cleanup(bufnr(''))
noautocmd e! java_paths/src/main/java/com/something/dummy