mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-18 02:05:56 +08:00
Add maven helper file; use maven wrapper if available instead of global 'mvn' executable
This commit is contained in:
@@ -9,13 +9,7 @@ call ale#Set('java_javac_classpath', '')
|
|||||||
call ale#Set('java_javac_sourcepath', '')
|
call ale#Set('java_javac_sourcepath', '')
|
||||||
|
|
||||||
function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
|
function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
|
||||||
let l:command = ''
|
let l:command = ale#maven#BuildClasspathCommand(a:buffer)
|
||||||
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
|
|
||||||
|
|
||||||
if !empty(l:pom_path) && executable('mvn')
|
|
||||||
let l:command = ale#path#CdString(fnamemodify(l:pom_path, ':h'))
|
|
||||||
\ . 'mvn dependency:build-classpath'
|
|
||||||
endif
|
|
||||||
|
|
||||||
" Try to use Gradle if Maven isn't available.
|
" Try to use Gradle if Maven isn't available.
|
||||||
if empty(l:command)
|
if empty(l:command)
|
||||||
|
|||||||
51
autoload/ale/maven.vim
Normal file
51
autoload/ale/maven.vim
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
" Description: Functions for working with Maven projects.
|
||||||
|
"
|
||||||
|
" Given a buffer number, find a Maven project root.
|
||||||
|
function! ale#maven#FindProjectRoot(buffer) abort
|
||||||
|
let l:wrapper_path = ale#path#FindNearestFile(a:buffer, 'mvnw')
|
||||||
|
|
||||||
|
if !empty(l:wrapper_path)
|
||||||
|
return fnamemodify(l:wrapper_path, ':h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
let l:pom_path = ale#path#FindNearestFile(a:buffer, 'pom.xml')
|
||||||
|
|
||||||
|
if !empty(l:pom_path)
|
||||||
|
return fnamemodify(l:pom_path, ':h')
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
|
||||||
|
" Given a buffer number, find the path to the executable.
|
||||||
|
" First search on the path for 'mvnw' (mvnw.cmd on Windows), if nothing is found,
|
||||||
|
" try the global command. Returns an empty string if cannot find the executable.
|
||||||
|
function! ale#maven#FindExecutable(buffer) abort
|
||||||
|
let l:wrapper_cmd = has('unix') ? 'mvnw' : 'mvnw.cmd'
|
||||||
|
let l:wrapper_path = ale#path#FindNearestFile(a:buffer, l:wrapper_cmd)
|
||||||
|
|
||||||
|
if executable(l:wrapper_path)
|
||||||
|
return l:wrapper_path
|
||||||
|
endif
|
||||||
|
|
||||||
|
if executable('mvn')
|
||||||
|
return 'mvn'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
|
|
||||||
|
" Given a buffer number, build a command to print the classpath of the root
|
||||||
|
" project. Returns an empty string if cannot build the command.
|
||||||
|
function! ale#maven#BuildClasspathCommand(buffer) abort
|
||||||
|
let l:executable = ale#maven#FindExecutable(a:buffer)
|
||||||
|
let l:project_root = ale#maven#FindProjectRoot(a:buffer)
|
||||||
|
|
||||||
|
if !empty(l:executable) && !empty(l:project_root)
|
||||||
|
return ale#path#CdString(l:project_root)
|
||||||
|
\ . l:executable . ' dependency:build-classpath'
|
||||||
|
endif
|
||||||
|
|
||||||
|
return ''
|
||||||
|
endfunction
|
||||||
Reference in New Issue
Block a user