]> git.madduck.net Git - etc/vim.git/blob - autoload/ale/gradle.vim

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/ale/' content from commit 22185c4c
[etc/vim.git] / autoload / ale / gradle.vim
1 " Author: Michael Pardo <michael@michaelpardo.com>
2 " Description: Functions for working with Gradle projects.
3
4 let s:script_path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
5 let s:init_path = has('win32')
6 \   ? s:script_path . '\gradle\init.gradle'
7 \   : s:script_path . '/gradle/init.gradle'
8
9 function! ale#gradle#GetInitPath() abort
10     return s:init_path
11 endfunction
12
13 " Given a buffer number, find a Gradle project root.
14 function! ale#gradle#FindProjectRoot(buffer) abort
15     let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew')
16
17     if !empty(l:gradlew_path)
18         return fnamemodify(l:gradlew_path, ':h')
19     endif
20
21     let l:settings_path = ale#path#FindNearestFile(a:buffer, 'settings.gradle')
22
23     if !empty(l:settings_path)
24         return fnamemodify(l:settings_path, ':h')
25     endif
26
27     let l:build_path = ale#path#FindNearestFile(a:buffer, 'build.gradle')
28
29     if !empty(l:build_path)
30         return fnamemodify(l:build_path, ':h')
31     endif
32
33     return ''
34 endfunction
35
36 " Given a buffer number, find the path to the executable.
37 " First search on the path for 'gradlew', if nothing is found, try the global
38 " command. Returns an empty string if cannot find the executable.
39 function! ale#gradle#FindExecutable(buffer) abort
40     let l:gradlew_path = ale#path#FindNearestFile(a:buffer, 'gradlew')
41
42     if !empty(l:gradlew_path)
43         return l:gradlew_path
44     endif
45
46     if executable('gradle')
47         return 'gradle'
48     endif
49
50     return ''
51 endfunction
52
53 " Given a buffer number, get a working directory and command to print the
54 " classpath of the root project.
55 "
56 " Returns an empty string for the command if Gradle is not detected.
57 function! ale#gradle#BuildClasspathCommand(buffer) abort
58     let l:executable = ale#gradle#FindExecutable(a:buffer)
59
60     if !empty(l:executable)
61         let l:project_root = ale#gradle#FindProjectRoot(a:buffer)
62
63         if !empty(l:project_root)
64             return [
65             \   l:project_root,
66             \   ale#Escape(l:executable)
67             \   . ' -I ' . ale#Escape(s:init_path)
68             \   . ' -q printClasspath'
69             \]
70         endif
71     endif
72
73     return ['', '']
74 endfunction