11local List = require (' java-core.utils.list' )
22local path = require (' java-core.utils.path' )
3- local Manager = require (' pkgm.manager' )
43local system = require (' java-core.utils.system' )
54local log = require (' java-core.utils.log2' )
65local err = require (' java-core.utils.errors' )
76local java_version_map = require (' java-core.constants.java_version' )
87local lsp_utils = require (' java-core.utils.lsp' )
98local str = require (' java-core.utils.str' )
9+ local resolver = require (' pkgm.resolve' )
1010
1111local M = {}
1212
@@ -23,7 +23,7 @@ function M.get_cmd(config)
2323 -- system java. So as a workaround, we use the absolute path to java instead
2424 -- So following check is not needed when we have auto_install set to true
2525 -- @see https://github.com/neovim/neovim/issues/36818
26- if not config .jdk .auto_install then
26+ if not config .jdk .auto_install and not config . jdk . path then
2727 M .validate_java_version (config , lsp_config .cmd_env )
2828 end
2929
4444--- @return java-core.List
4545function M .get_jvm_args (config )
4646 local use_lombok = config .lombok .enable
47- local jdtls_root = Manager : get_install_dir ( ' jdtls ' , config . jdtls . version )
48- local jdtls_config = path . join (jdtls_root , system . get_config_suffix () )
47+ local jdtls_root = resolver . get_jdtls_root ( config )
48+ local jdtls_config = M . get_jdtls_config_path (jdtls_root )
4949
5050 local java_exe = ' java'
5151
5252 -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not
5353 -- working on Windows. So we are using the absolute path to java instead
5454 -- @see https://github.com/neovim/neovim/issues/36818
55- if config .jdk .auto_install then
56- local jdk_root = Manager :get_install_dir (' openjdk' , config .jdk .version )
57- local java_home
58- if system .get_os () == ' mac' then
59- java_home = vim .fn .glob (path .join (jdk_root , ' jdk-*' , ' Contents' , ' Home' ))
60- else
61- java_home = vim .fn .glob (path .join (jdk_root , ' jdk-*' ))
62- end
63-
55+ if config .jdk .auto_install or config .jdk .path then
56+ local java_home = resolver .get_jdk_home (config )
6457 java_exe = path .join (java_home , ' bin' , ' java' )
6558 end
6659
@@ -85,20 +78,37 @@ function M.get_jvm_args(config)
8578
8679 -- Adding lombok
8780 if use_lombok then
88- local lombok_root = Manager :get_install_dir (' lombok' , config .lombok .version )
89- local lombok_path = vim .fn .glob (path .join (lombok_root , ' lombok*.jar' ))
90- jvm_args :push (' -javaagent:' .. lombok_path )
81+ jvm_args :push (' -javaagent:' .. resolver .get_lombok_path (config ))
9182 end
9283
9384 return jvm_args
9485end
9586
87+ --- @private
88+ --- @param jdtls_root string
89+ --- @return string
90+ function M .get_jdtls_config_path (jdtls_root )
91+ local config_path = path .join (jdtls_root , system .get_config_suffix ())
92+
93+ if vim .fn .isdirectory (config_path ) == 1 then
94+ return config_path
95+ end
96+
97+ local os_config_path = path .join (jdtls_root , ' config_' .. system .get_os ())
98+
99+ if vim .fn .isdirectory (os_config_path ) == 1 then
100+ return os_config_path
101+ end
102+
103+ err .throw ((' nvim-java: jdtls config directory not found at %s or %s' ):format (config_path , os_config_path ))
104+ end
105+
96106--- @private
97107--- @param config java.Config
98108--- @param cwd ? string
99109--- @return java-core.List
100110function M .get_jar_args (config , cwd )
101- local jdtls_root = Manager : get_install_dir ( ' jdtls ' , config . jdtls . version )
111+ local jdtls_root = resolver . get_jdtls_root ( config )
102112 cwd = cwd or vim .fn .getcwd ()
103113
104114 local launcher_reg = path .join (jdtls_root , ' plugins' , ' org.eclipse.equinox.launcher_*.jar' )
@@ -115,7 +125,7 @@ function M.get_jar_args(config, cwd)
115125 equinox_launcher ,
116126
117127 ' -configuration' ,
118- lsp_utils .get_jdtls_cache_conf_path (),
128+ lsp_utils .get_jdtls_cache_conf_path (jdtls_root ),
119129
120130 ' -data' ,
121131 lsp_utils .get_jdtls_cache_data_path (cwd ),
0 commit comments