runtime(compiler): include spotbugs Java linter

closes: #16001

Co-authored-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Konfekt <Konfekt@users.noreply.github.com>
Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
This commit is contained in:
Konfekt
2024-11-28 21:06:09 +01:00
committed by Christian Brabandt
parent 2cddf0e85a
commit 65311c6f47
7 changed files with 688 additions and 14 deletions

View File

@ -1,4 +1,4 @@
*quickfix.txt* For Vim version 9.1. Last change: 2024 Nov 12
*quickfix.txt* For Vim version 9.1. Last change: 2024 Nov 28
VIM REFERENCE MANUAL by Bram Moolenaar
@ -1331,10 +1331,117 @@ g:compiler_gcc_ignore_unmatched_lines
JAVAC *compiler-javac*
Commonly used compiler options can be added to 'makeprg' by setting the
g:javac_makeprg_params variable. For example: >
b/g:javac_makeprg_params variable. For example: >
let g:javac_makeprg_params = "-Xlint:all -encoding utf-8"
<
MAVEN *compiler-maven*
Commonly used compiler options can be added to 'makeprg' by setting the
b/g:maven_makeprg_params variable. For example: >
let g:maven_makeprg_params = "-DskipTests -U -X"
SPOTBUGS *compiler-spotbugs*
SpotBugs is a static analysis tool that can be used to find bugs in Java.
It scans the Java bytecode of all classes in the currently open buffer.
(Therefore, `:compiler! spotbugs` is not supported.)
Commonly used compiler options can be added to 'makeprg' by setting the
"b:" or "g:spotbugs_makeprg_params" variable. For example: >
let b:spotbugs_makeprg_params = "-longBugCodes -effort:max -low"
The global default is "-workHard -experimental".
By default, the class files are searched in the directory where the source
files are placed. However, typical Java projects use distinct directories
for source files and class files. To make both known to SpotBugs, assign
their paths (distinct and relative to their common root directory) to the
following properties (using the example of a common Maven project): >
let g:spotbugs_properties = {
\ 'sourceDirPath': 'src/main/java',
\ 'classDirPath': 'target/classes',
\ 'testSourceDirPath': 'src/test/java',
\ 'testClassDirPath': 'target/test-classes',
\ }
Note that values for the path keys describe only for SpotBugs where to look
for files; refer to the documentation for particular compiler plugins for more
information.
The default pre- and post-compiler actions are provided for Ant, Maven, and
Javac compiler plugins and can be selected by assigning the name of a compiler
plugin to the "compiler" key: >
let g:spotbugs_properties = {
\ 'compiler': 'maven',
\ }
This single setting is essentially equivalent to all the settings below, with
the exception made for the "PreCompilerAction" and "PreCompilerTestAction"
values: their listed |Funcref|s will obtain no-op implementations whereas the
implicit Funcrefs of the "compiler" key will obtain the requested defaults if
available. >
let g:spotbugs_properties = {
\ 'PreCompilerAction':
\ function('spotbugs#DefaultPreCompilerAction'),
\ 'PreCompilerTestAction':
\ function('spotbugs#DefaultPreCompilerTestAction'),
\ 'PostCompilerAction':
\ function('spotbugs#DefaultPostCompilerAction'),
\ 'sourceDirPath': 'src/main/java',
\ 'classDirPath': 'target/classes',
\ 'testSourceDirPath': 'src/test/java',
\ 'testClassDirPath': 'target/test-classes',
\ }
With default actions, the compiler of choice will attempt to rebuild the class
files for the buffer (and possibly for the whole project) as soon as a Java
syntax file is loaded; then, `spotbugs` will attempt to analyze the quality of
the compilation unit of the buffer.
When default actions are not suited to a desired workflow, consider writing
arbitrary functions yourself and matching their |Funcref|s to the supported
keys: "PreCompilerAction", "PreCompilerTestAction", and "PostCompilerAction".
The next example re-implements the default pre-compiler actions for a Maven
project and requests other default Maven settings with the "compiler" entry: >
function! MavenPreCompilerAction() abort
call spotbugs#DeleteClassFiles()
compiler maven
make compile
endfunction
function! MavenPreCompilerTestAction() abort
call spotbugs#DeleteClassFiles()
compiler maven
make test-compile
endfunction
let g:spotbugs_properties = {
\ 'compiler': 'maven',
\ 'PreCompilerAction':
\ function('MavenPreCompilerAction'),
\ 'PreCompilerTestAction':
\ function('MavenPreCompilerTestAction'),
\ }
Note that all entered custom settings will take precedence over the matching
default settings in "g:spotbugs_properties".
The "g:spotbugs_properties" variable is consulted by the Java filetype plugin
(|ft-java-plugin|) to arrange for the described automation, and, therefore, it
must be defined before |FileType| events can take place for the buffers loaded
with Java source files. It could, for example, be set in a project-local
|vimrc| loaded by [0].
[0] https://github.com/MarcWeber/vim-addon-local-vimrc/
GNU MAKE *compiler-make*
Since the default make program is "make", the compiler plugin for make,