1- *quickfix.txt* For Vim version 9.1. Last change: 2024 Nov 28
1+ *quickfix.txt* For Vim version 9.1. Last change: 2024 Dec 16
22
33
44 VIM REFERENCE MANUAL by Bram Moolenaar
@@ -1349,7 +1349,7 @@ It scans the Java bytecode of all classes in the currently open buffer.
13491349(Therefore, `:compiler! spotbugs` is not supported.)
13501350
13511351Commonly used compiler options can be added to 'makeprg' by setting the
1352- "b:" or "g:spotbugs_makeprg_params" variable. For example: >
1352+ "b:" or "g:spotbugs_makeprg_params" variable. For example: >vim
13531353
13541354 let b:spotbugs_makeprg_params = "-longBugCodes -effort:max -low"
13551355
@@ -1359,22 +1359,25 @@ By default, the class files are searched in the directory where the source
13591359files are placed. However, typical Java projects use distinct directories
13601360for source files and class files. To make both known to SpotBugs, assign
13611361their paths (distinct and relative to their common root directory) to the
1362- following properties (using the example of a common Maven project): >
1362+ following properties (using the example of a common Maven project): >vim
13631363
13641364 let g:spotbugs_properties = {
1365- \ 'sourceDirPath': 'src/main/java',
1366- \ 'classDirPath': 'target/classes',
1367- \ 'testSourceDirPath': 'src/test/java',
1368- \ 'testClassDirPath': 'target/test-classes',
1365+ \ 'sourceDirPath': [ 'src/main/java'] ,
1366+ \ 'classDirPath': [ 'target/classes'] ,
1367+ \ 'testSourceDirPath': [ 'src/test/java'] ,
1368+ \ 'testClassDirPath': [ 'target/test-classes'] ,
13691369 \ }
13701370
1371+ Note that source and class path entries are expected to come in pairs: define
1372+ both "sourceDirPath" and "classDirPath" when you are considering at least one,
1373+ and apply the same logic to "testSourceDirPath" and "testClassDirPath".
13711374Note that values for the path keys describe only for SpotBugs where to look
13721375for files; refer to the documentation for particular compiler plugins for more
13731376information.
13741377
13751378The default pre- and post-compiler actions are provided for Ant, Maven, and
13761379Javac compiler plugins and can be selected by assigning the name of a compiler
1377- plugin to the "compiler" key: >
1380+ plugin ( `ant` , `maven` , or `javac` ) to the "compiler" key: >vim
13781381
13791382 let g:spotbugs_properties = {
13801383 \ 'compiler' : 'maven' ,
@@ -1384,7 +1387,7 @@ This single setting is essentially equivalent to all the settings below, with
13841387the exception made for the "PreCompilerAction" and "PreCompilerTestAction"
13851388values: their listed | Funcref | s will obtain no-op implementations whereas the
13861389implicit Funcrefs of the "compiler" key will obtain the requested defaults if
1387- available. >
1390+ available. >vim
13881391
13891392 let g:spotbugs_properties = {
13901393 \ 'PreCompilerAction':
@@ -1393,34 +1396,53 @@ available. >
13931396 \ function('spotbugs#DefaultPreCompilerTestAction'),
13941397 \ 'PostCompilerAction':
13951398 \ function('spotbugs#DefaultPostCompilerAction'),
1396- \ 'sourceDirPath': 'src/main/java',
1397- \ 'classDirPath': 'target/classes',
1398- \ 'testSourceDirPath': 'src/test/java',
1399- \ 'testClassDirPath': 'target/test-classes',
1399+ \ 'sourceDirPath': [ 'src/main/java'] ,
1400+ \ 'classDirPath': [ 'target/classes'] ,
1401+ \ 'testSourceDirPath': [ 'src/test/java'] ,
1402+ \ 'testClassDirPath': [ 'target/test-classes'] ,
14001403 \ }
14011404
14021405With default actions, the compiler of choice will attempt to rebuild the class
14031406files for the buffer (and possibly for the whole project) as soon as a Java
14041407syntax file is loaded; then, `spotbugs` will attempt to analyze the quality of
14051408the compilation unit of the buffer.
14061409
1407- When default actions are not suited to a desired workflow, consider writing
1408- arbitrary functions yourself and matching their | Funcref | s to the supported
1410+ Vim commands proficient in 'makeprg' [0] can be composed with default actions.
1411+ Begin by considering which of the supported keys, "DefaultPreCompilerCommand",
1412+ "DefaultPreCompilerTestCommand", or "DefaultPostCompilerCommand", you need to
1413+ write an implementation for, observing that each of these keys corresponds to
1414+ a particular "*Action" key. Follow it by defining a new function that always
1415+ declares an only parameter of type string and puts to use a command equivalent
1416+ of | :make | , and assigning its | Funcref | to the selected key. For example:
1417+ >vim
1418+ function! GenericPostCompilerCommand(arguments) abort
1419+ execute 'make ' . a:arguments
1420+ endfunction
1421+
1422+ let g:spotbugs_properties = {
1423+ \ 'DefaultPostCompilerCommand':
1424+ \ function('GenericPostCompilerCommand'),
1425+ \ }
1426+
1427+ When default actions are not suited to a desired workflow, proceed by writing
1428+ arbitrary functions yourself and matching their Funcrefs to the supported
14091429keys: "PreCompilerAction", "PreCompilerTestAction", and "PostCompilerAction".
14101430
14111431The next example re-implements the default pre-compiler actions for a Maven
1412- project and requests other default Maven settings with the "compiler" entry: >
1413-
1432+ project and requests other default Maven settings with the "compiler" entry:
1433+ >vim
14141434 function! MavenPreCompilerAction() abort
14151435 call spotbugs#DeleteClassFiles()
14161436 compiler maven
14171437 make compile
1438+ cc
14181439 endfunction
14191440
14201441 function! MavenPreCompilerTestAction() abort
14211442 call spotbugs#DeleteClassFiles()
14221443 compiler maven
14231444 make test-compile
1445+ cc
14241446 endfunction
14251447
14261448 let g:spotbugs_properties = {
@@ -1433,14 +1455,46 @@ project and requests other default Maven settings with the "compiler" entry: >
14331455
14341456Note that all entered custom settings will take precedence over the matching
14351457default settings in "g:spotbugs_properties".
1458+ Note that it is necessary to notify the plugin of the result of a pre-compiler
1459+ action before further work can be undertaken. Using | :cc | after | :make | (or
1460+ | :ll | after | :lmake | ) as the last command of an action is the supported means
1461+ of such communication.
1462+
1463+ Two commands, "SpotBugsRemoveBufferAutocmd" and "SpotBugsDefineBufferAutocmd",
1464+ are provided to toggle actions for buffer-local autocommands. For example, to
1465+ also run actions on any | BufWritePost | and | SigUSR1 | event, add these lines to
1466+ `~/.vim/after/ftplugin/java.vim ` : >vim
1467+
1468+ if exists(':SpotBugsDefineBufferAutocmd') == 2
1469+ SpotBugsDefineBufferAutocmd BufWritePost SigUSR1
1470+ endif
1471+
1472+ Otherwise, you can turn to `:doautocmd java_spotbugs User` at any time.
14361473
14371474The "g:spotbugs_properties" variable is consulted by the Java filetype plugin
14381475(| ft-java-plugin | ) to arrange for the described automation, and, therefore, it
14391476must be defined before | FileType | events can take place for the buffers loaded
14401477with Java source files. It could, for example, be set in a project-local
1441- | vimrc | loaded by [0].
1478+ | vimrc | loaded by [1].
1479+
1480+ Both "g:spotbugs_properties" and "b:spotbugs_properties" are recognized and
1481+ must be modifiable (| :unlockvar | ). The "*Command" entries are always treated
1482+ as global functions to be shared among all Java buffers.
1483+
1484+ The SpotBugs Java library and, by extension, its distributed shell scripts do
1485+ not support in the `- textui` mode listed pathnames with directory filenames
1486+ that contain blank characters [2]. To work around this limitation, consider
1487+ making a symbolic link to such a directory from a directory that does not have
1488+ blank characters in its name and passing this information to SpotBugs: >vim
1489+
1490+ let g:spotbugs_alternative_path = {
1491+ \ 'fromPath': 'path/to/dir_without_blanks',
1492+ \ 'toPath': 'path/to/dir with blanks',
1493+ \ }
14421494
1443- [0] https://github.com/MarcWeber/vim-addon-local-vimrc/
1495+ [0] https://github.com/Konfekt/vim-compilers
1496+ [1] https://github.com/MarcWeber/vim-addon-local-vimrc
1497+ [2] https://github.com/spotbugs/spotbugs/issues/909
14441498
14451499GNU MAKE *compiler-make*
14461500
0 commit comments