summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Lee <andrew.lambda@tuta.io>2019-06-03 12:30:18 -0700
committerw0rp <w0rp@users.noreply.github.com>2019-06-03 20:30:18 +0100
commitc6a5cbb3c737261bc46477733b3aa26203eb63d9 (patch)
tree1b2cc8bf9b6eefd280df998bbb48d209dcf82708
parenta76f056bd976a52d3d49f07726a067ac4dba2e6e (diff)
downloadale-c6a5cbb3c737261bc46477733b3aa26203eb63d9.zip
Feature/add ant support (#2539)
Use ant files to load Java settings too.
-rw-r--r--ale_linters/java/javac.vim5
-rw-r--r--autoload/ale/ant.vim41
-rw-r--r--autoload/ale/java.vim6
-rw-r--r--test/ant-test-files/ant-project/build.xml0
-rwxr-xr-xtest/ant-test-files/bin/ant0
-rwxr-xr-xtest/ant-test-files/bin/ant.exe0
-rw-r--r--test/test_ant_build_classpath_command.vader29
-rw-r--r--test/test_ant_find_project_root.vader35
8 files changed, 116 insertions, 0 deletions
diff --git a/ale_linters/java/javac.vim b/ale_linters/java/javac.vim
index 3883783b..8bb52c0b 100644
--- a/ale_linters/java/javac.vim
+++ b/ale_linters/java/javac.vim
@@ -21,6 +21,11 @@ function! ale_linters#java#javac#RunWithImportPaths(buffer) abort
let l:command = ale#gradle#BuildClasspathCommand(a:buffer)
endif
+ " Try to use Ant if Gradle and Maven aren't available
+ if empty(l:command)
+ let l:command = ale#ant#BuildClasspathCommand(a:buffer)
+ endif
+
if empty(l:command)
return ale_linters#java#javac#GetCommand(a:buffer, [], {})
endif
diff --git a/autoload/ale/ant.vim b/autoload/ale/ant.vim
new file mode 100644
index 00000000..689b444b
--- /dev/null
+++ b/autoload/ale/ant.vim
@@ -0,0 +1,41 @@
+" Author: Andrew Lee <andrewl@mbda.fun>.
+" Inspired by ale/gradle.vim by Michael Pardo <michael@michaelpardo.com>
+" Description: Functions for working with Ant projects.
+
+" Given a buffer number, find an Ant project root
+function! ale#ant#FindProjectRoot(buffer) abort
+ let l:build_xml_path = ale#path#FindNearestFile(a:buffer, 'build.xml')
+
+ if !empty(l:build_xml_path)
+ return fnamemodify(l:build_xml_path, ':h')
+ endif
+
+ return ''
+endfunction
+
+" Given a buffer number, find the path to the `ant` executable. Returns an empty
+" string if cannot find the executable.
+function! ale#ant#FindExecutable(buffer) abort
+ if executable('ant')
+ return 'ant'
+ 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#ant#BuildClasspathCommand(buffer) abort
+ let l:executable = ale#ant#FindExecutable(a:buffer)
+ let l:project_root = ale#ant#FindProjectRoot(a:buffer)
+
+ if !empty(l:executable) && !empty(l:project_root)
+ return ale#path#CdString(l:project_root)
+ \ . ale#Escape(l:executable)
+ \ . ' classpath'
+ \ . ' -S'
+ \ . ' -q'
+ endif
+
+ return ''
+endfunction
diff --git a/autoload/ale/java.vim b/autoload/ale/java.vim
index b7fd10bd..e641ac6c 100644
--- a/autoload/ale/java.vim
+++ b/autoload/ale/java.vim
@@ -16,5 +16,11 @@ function! ale#java#FindProjectRoot(buffer) abort
return fnamemodify(l:maven_pom_file, ':h')
endif
+ let l:ant_root = ale#ant#FindProjectRoot(a:buffer)
+
+ if !empty(l:ant_root)
+ return l:ant_root
+ endif
+
return ''
endfunction
diff --git a/test/ant-test-files/ant-project/build.xml b/test/ant-test-files/ant-project/build.xml
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/ant-test-files/ant-project/build.xml
diff --git a/test/ant-test-files/bin/ant b/test/ant-test-files/bin/ant
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/ant-test-files/bin/ant
diff --git a/test/ant-test-files/bin/ant.exe b/test/ant-test-files/bin/ant.exe
new file mode 100755
index 00000000..e69de29b
--- /dev/null
+++ b/test/ant-test-files/bin/ant.exe
diff --git a/test/test_ant_build_classpath_command.vader b/test/test_ant_build_classpath_command.vader
new file mode 100644
index 00000000..5542a9d8
--- /dev/null
+++ b/test/test_ant_build_classpath_command.vader
@@ -0,0 +1,29 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test')
+ runtime ale_linters/java/javac.vim
+
+ Save $PATH
+ let $PATH = ale#path#Simplify(g:dir . '/ant-test-files/bin')
+
+ let g:valid_project = 'ant-test-files/ant-project'
+ let g:invalid_project = 'ant-test-files/non-ant-project'
+ let g:command_tail = ' classpath' . ' -S' . ' -q'
+
+After:
+ Restore
+
+ unlet! g:command_tail
+ unlet! g:valid_project
+ unlet! g:invalid_project
+
+ call ale#test#RestoreDirectory()
+ call ale#linter#Reset()
+
+Execute(Should return `cd '[dir]' && 'ant' classpath -S -q`):
+ call ale#test#SetFilename(valid_project . '/Main.java')
+
+ AssertEqual
+ \ ale#path#CdString(ale#path#Simplify(g:dir . '/ant-test-files/ant-project'))
+ \ . ale#Escape('ant')
+ \ . g:command_tail,
+ \ ale#ant#BuildClasspathCommand(bufnr(''))
diff --git a/test/test_ant_find_project_root.vader b/test/test_ant_find_project_root.vader
new file mode 100644
index 00000000..bde33f00
--- /dev/null
+++ b/test/test_ant_find_project_root.vader
@@ -0,0 +1,35 @@
+Before:
+ call ale#test#SetDirectory('/testplugin/test')
+ runtime ale_linters/java/javac.vim
+
+After:
+ call ale#test#RestoreDirectory()
+ call ale#linter#Reset()
+
+Execute(Should return current directory if called on the project root):
+ call ale#test#SetFilename('ant-test-files/ant-project/Main.java')
+
+ AssertEqual
+ \ ale#path#Simplify(g:dir . '/ant-test-files/ant-project'),
+ \ ale#ant#FindProjectRoot(bufnr(''))
+
+Execute(Should return root directory if called on a deeply nested source file):
+ call ale#test#SetFilename('ant-test-files/ant-project/src/several/namespace/layers/A.java')
+
+ AssertEqual
+ \ ale#path#Simplify(g:dir . '/ant-test-files/ant-project'),
+ \ ale#ant#FindProjectRoot(bufnr(''))
+
+Execute(Should return empty string if called on a non-ant project):
+ call ale#test#SetFilename('ant-test-files/non-ant-project/Main.java')
+
+ AssertEqual
+ \ '',
+ \ ale#ant#FindProjectRoot(bufnr(''))
+
+Execute(Should return empty string if called on a file in a non-ant project):
+ call ale#test#SetFilename('ant-test-files/non-ant-project/several/namespace/layers/A.java')
+
+ AssertEqual
+ \ '',
+ \ ale#ant#FindProjectRoot(bufnr(''))