14 files changed
@@ -16,4 +16,9 @@ read_globals = { | |||
| 16 | 16 | ignore = { | |
| 17 | 17 | '212/self', | |
| 18 | 18 | } | |
| 19 | + files['tests/specs/pkgm_resolve_spec.lua'] = { | ||
| 20 | + globals = { | ||
| 21 | + 'vim.notify', | ||
| 22 | + }, | ||
| 23 | + } | ||
| 19 | 24 | max_line_length = false | |
@@ -336,33 +336,44 @@ require('java').setup({ | |||
| 336 | 336 | -- JDTLS configuration | |
| 337 | 337 | jdtls = { | |
| 338 | 338 | version = '1.43.0', | |
| 339 | + path = nil, | ||
| 340 | + auto_install = true, | ||
| 339 | 341 | }, | |
| 340 | 342 | ||
| 341 | 343 | -- Extensions | |
| 342 | 344 | lombok = { | |
| 343 | 345 | enable = true, | |
| 344 | 346 | version = '1.18.40', | |
| 347 | + path = nil, | ||
| 348 | + auto_install = true, | ||
| 345 | 349 | }, | |
| 346 | 350 | ||
| 347 | 351 | java_test = { | |
| 348 | 352 | enable = true, | |
| 349 | 353 | version = '0.40.1', | |
| 354 | + path = nil, | ||
| 355 | + auto_install = true, | ||
| 350 | 356 | }, | |
| 351 | 357 | ||
| 352 | 358 | java_debug_adapter = { | |
| 353 | 359 | enable = true, | |
| 354 | 360 | version = '0.58.2', | |
| 361 | + path = nil, | ||
| 362 | + auto_install = true, | ||
| 355 | 363 | }, | |
| 356 | 364 | ||
| 357 | 365 | spring_boot_tools = { | |
| 358 | 366 | enable = true, | |
| 359 | 367 | version = '1.55.1', | |
| 368 | + path = nil, | ||
| 369 | + auto_install = true, | ||
| 360 | 370 | }, | |
| 361 | 371 | ||
| 362 | 372 | -- JDK installation | |
| 363 | 373 | jdk = { | |
| 364 | 374 | auto_install = true, | |
| 365 | 375 | version = '17', | |
| 376 | + path = nil, | ||
| 366 | 377 | }, | |
| 367 | 378 | ||
| 368 | 379 | -- Logging | |
@@ -377,6 +388,21 @@ require('java').setup({ | |||
| 377 | 388 | }) | |
| 378 | 389 | ``` | |
| 379 | 390 | ||
| 391 | + Set `path` when a tool is managed externally. When `path` is set, nvim-java | ||
| 392 | + uses that path and does not install the tool. Set | ||
| 393 | + `auto_install = false` on a tool to fail instead of downloading when no path is | ||
| 394 | + configured. Note: `path` has no effect when the tool is disabled | ||
| 395 | + (`enable = false`) — the tool is simply not loaded. | ||
| 396 | + | ||
| 397 | + Path meanings: | ||
| 398 | + | ||
| 399 | + - `jdtls.path`: directory containing `plugins/` and platform `config_*` | ||
| 400 | + directories | ||
| 401 | + - `lombok.path`: path to `lombok.jar` | ||
| 402 | + - `java_test.path`, `java_debug_adapter.path`, `spring_boot_tools.path`: VS Code | ||
| 403 | + extension root containing `package.json` | ||
| 404 | + - `jdk.path`: JDK home containing `bin/java` | ||
| 405 | + | ||
| 380 | 406 | </details> | |
| 381 | 407 | ||
| 382 | 408 | ## :golf: Architecture | |
@@ -349,33 +349,44 @@ want, following options are available: | |||
| 349 | 349 | -- JDTLS configuration | |
| 350 | 350 | jdtls = { | |
| 351 | 351 | version = '1.43.0', | |
| 352 | + path = nil, | ||
| 353 | + auto_install = true, | ||
| 352 | 354 | }, | |
| 353 | 355 | ||
| 354 | 356 | -- Extensions | |
| 355 | 357 | lombok = { | |
| 356 | 358 | enable = true, | |
| 357 | 359 | version = '1.18.40', | |
| 360 | + path = nil, | ||
| 361 | + auto_install = true, | ||
| 358 | 362 | }, | |
| 359 | 363 | ||
| 360 | 364 | java_test = { | |
| 361 | 365 | enable = true, | |
| 362 | 366 | version = '0.40.1', | |
| 367 | + path = nil, | ||
| 368 | + auto_install = true, | ||
| 363 | 369 | }, | |
| 364 | 370 | ||
| 365 | 371 | java_debug_adapter = { | |
| 366 | 372 | enable = true, | |
| 367 | 373 | version = '0.58.2', | |
| 374 | + path = nil, | ||
| 375 | + auto_install = true, | ||
| 368 | 376 | }, | |
| 369 | 377 | ||
| 370 | 378 | spring_boot_tools = { | |
| 371 | 379 | enable = true, | |
| 372 | 380 | version = '1.55.1', | |
| 381 | + path = nil, | ||
| 382 | + auto_install = true, | ||
| 373 | 383 | }, | |
| 374 | 384 | ||
| 375 | 385 | -- JDK installation | |
| 376 | 386 | jdk = { | |
| 377 | 387 | auto_install = true, | |
| 378 | 388 | version = '17', | |
| 389 | + path = nil, | ||
| 379 | 390 | }, | |
| 380 | 391 | ||
| 381 | 392 | -- Logging | |
@@ -390,6 +401,21 @@ want, following options are available: | |||
| 390 | 401 | }) | |
| 391 | 402 | < | |
| 392 | 403 | ||
| 404 | + Set `path` when a tool is managed externally. When `path` is set, nvim-java | ||
| 405 | + uses that path and does not install the tool. Set | ||
| 406 | + `auto_install = false` on a tool to fail instead of downloading when no path is | ||
| 407 | + configured. Note: `path` has no effect when the tool is disabled | ||
| 408 | + (`enable = false`) — the tool is simply not loaded. | ||
| 409 | + | ||
| 410 | + Path meanings: | ||
| 411 | + | ||
| 412 | + - `jdtls.path`: directory containing `plugins/` and platform `config_*` | ||
| 413 | + directories | ||
| 414 | + - `lombok.path`: path to `lombok.jar` | ||
| 415 | + - `java_test.path`, `java_debug_adapter.path`, `spring_boot_tools.path`: VS Code | ||
| 416 | + extension root containing `package.json` | ||
| 417 | + - `jdk.path`: JDK home containing `bin/java` | ||
| 418 | + | ||
| 393 | 419 | ||
| 394 | 420 | ARCHITECTURE *nvim-java-architecture* | |
| 395 | 421 | ||
@@ -1,12 +1,12 @@ | |||
| 1 | 1 | local List = require('java-core.utils.list') | |
| 2 | 2 | local path = require('java-core.utils.path') | |
| 3 | - local Manager = require('pkgm.manager') | ||
| 4 | 3 | local system = require('java-core.utils.system') | |
| 5 | 4 | local log = require('java-core.utils.log2') | |
| 6 | 5 | local err = require('java-core.utils.errors') | |
| 7 | 6 | local java_version_map = require('java-core.constants.java_version') | |
| 8 | 7 | local lsp_utils = require('java-core.utils.lsp') | |
| 9 | 8 | local str = require('java-core.utils.str') | |
| 9 | + local resolver = require('pkgm.resolve') | ||
| 10 | 10 | ||
| 11 | 11 | local M = {} | |
| 12 | 12 | ||
@@ -23,7 +23,7 @@ function M.get_cmd(config) | |||
| 23 | 23 | -- system java. So as a workaround, we use the absolute path to java instead | |
| 24 | 24 | -- So following check is not needed when we have auto_install set to true | |
| 25 | 25 | -- @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 | ||
| 27 | 27 | M.validate_java_version(config, lsp_config.cmd_env) | |
| 28 | 28 | end | |
| 29 | 29 | ||
@@ -44,23 +44,16 @@ end | |||
| 44 | 44 | ---@return java-core.List | |
| 45 | 45 | function M.get_jvm_args(config) | |
| 46 | 46 | 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) | ||
| 49 | 49 | ||
| 50 | 50 | local java_exe = 'java' | |
| 51 | 51 | ||
| 52 | 52 | -- NOTE: eventhough we are setting the PATH env var, due to a bug, it's not | |
| 53 | 53 | -- working on Windows. So we are using the absolute path to java instead | |
| 54 | 54 | -- @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) | ||
| 64 | 57 | java_exe = path.join(java_home, 'bin', 'java') | |
| 65 | 58 | end | |
| 66 | 59 | ||
@@ -85,20 +78,37 @@ function M.get_jvm_args(config) | |||
| 85 | 78 | ||
| 86 | 79 | -- Adding lombok | |
| 87 | 80 | 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)) | ||
| 91 | 82 | end | |
| 92 | 83 | ||
| 93 | 84 | return jvm_args | |
| 94 | 85 | end | |
| 95 | 86 | ||
| 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 | + | ||
| 96 | 106 | ---@private | |
| 97 | 107 | ---@param config java.Config | |
| 98 | 108 | ---@param cwd? string | |
| 99 | 109 | ---@return java-core.List | |
| 100 | 110 | function 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) | ||
| 102 | 112 | cwd = cwd or vim.fn.getcwd() | |
| 103 | 113 | ||
| 104 | 114 | local launcher_reg = path.join(jdtls_root, 'plugins', 'org.eclipse.equinox.launcher_*.jar') | |
@@ -115,7 +125,7 @@ function M.get_jar_args(config, cwd) | |||
| 115 | 125 | equinox_launcher, | |
| 116 | 126 | ||
| 117 | 127 | '-configuration', | |
| 118 | - lsp_utils.get_jdtls_cache_conf_path(), | ||
| 128 | + lsp_utils.get_jdtls_cache_conf_path(jdtls_root), | ||
| 119 | 129 | ||
| 120 | 130 | '-data', | |
| 121 | 131 | lsp_utils.get_jdtls_cache_data_path(cwd), | |
@@ -1,26 +1,18 @@ | |||
| 1 | 1 | local path = require('java-core.utils.path') | |
| 2 | - local Manager = require('pkgm.manager') | ||
| 3 | 2 | local log = require('java-core.utils.log2') | |
| 4 | 3 | local system = require('java-core.utils.system') | |
| 4 | + local resolver = require('pkgm.resolve') | ||
| 5 | 5 | ||
| 6 | 6 | local M = {} | |
| 7 | 7 | ||
| 8 | 8 | --- @param config java.Config | |
| 9 | 9 | function M.get_env(config) | |
| 10 | - if not config.jdk.auto_install then | ||
| 11 | - log.debug('config.jdk.auto_install disabled, returning empty env') | ||
| 10 | + if not config.jdk.auto_install and not config.jdk.path then | ||
| 11 | + log.debug('config.jdk.auto_install disabled and config.jdk.path unset, returning empty env') | ||
| 12 | 12 | return {} | |
| 13 | 13 | end | |
| 14 | 14 | ||
| 15 | - local jdk_root = Manager:get_install_dir('openjdk', config.jdk.version) | ||
| 16 | - | ||
| 17 | - local java_home | ||
| 18 | - | ||
| 19 | - if system.get_os() == 'mac' then | ||
| 20 | - java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*', 'Contents', 'Home')) | ||
| 21 | - else | ||
| 22 | - java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*')) | ||
| 23 | - end | ||
| 15 | + local java_home = resolver.get_jdk_home(config) | ||
| 24 | 16 | ||
| 25 | 17 | local java_bin = path.join(java_home, 'bin') | |
| 26 | 18 | ||
@@ -1,10 +1,10 @@ | |||
| 1 | 1 | local M = {} | |
| 2 | 2 | ||
| 3 | - function M.get_plugin_version_map(config) | ||
| 3 | + function M.get_plugin_config_map(config) | ||
| 4 | 4 | return { | |
| 5 | - ['java-test'] = config.java_test.version, | ||
| 6 | - ['java-debug'] = config.java_debug_adapter.version, | ||
| 7 | - ['spring-boot-tools'] = config.spring_boot_tools.version, | ||
| 5 | + ['java-test'] = config.java_test, | ||
| 6 | + ['java-debug'] = config.java_debug_adapter, | ||
| 7 | + ['spring-boot-tools'] = config.spring_boot_tools, | ||
| 8 | 8 | } | |
| 9 | 9 | end | |
| 10 | 10 | ||
@@ -15,19 +15,18 @@ end | |||
| 15 | 15 | function M.get_plugins(config, plugins) | |
| 16 | 16 | local file = require('java-core.utils.file') | |
| 17 | 17 | local List = require('java-core.utils.list') | |
| 18 | - local Manager = require('pkgm.manager') | ||
| 19 | 18 | local path = require('java-core.utils.path') | |
| 20 | 19 | local err = require('java-core.utils.errors') | |
| 21 | 20 | local str = require('java-core.utils.str') | |
| 21 | + local resolver = require('pkgm.resolve') | ||
| 22 | 22 | ||
| 23 | - local plugin_version_map = M.get_plugin_version_map(config) | ||
| 23 | + local plugin_config_map = M.get_plugin_config_map(config) | ||
| 24 | 24 | ||
| 25 | 25 | return List:new(plugins) | |
| 26 | 26 | :map(function(plugin_name) | |
| 27 | - local version = plugin_version_map[plugin_name] | ||
| 27 | + local plugin_config = plugin_config_map[plugin_name] | ||
| 28 | 28 | ||
| 29 | - local pkg_path = Manager:get_install_dir(plugin_name, version) | ||
| 30 | - local plugin_root = path.join(pkg_path, 'extension') | ||
| 29 | + local plugin_root = resolver.get_extension_root(plugin_name, plugin_config) | ||
| 31 | 30 | local package_json_str = vim.fn.readfile(path.join(plugin_root, 'package.json')) | |
| 32 | 31 | local package_json = vim.json.decode(table.concat(package_json_str, '\n')) | |
| 33 | 32 | local java_extensions = package_json.contributes.javaExtensions | |
@@ -23,12 +23,23 @@ function M.get_jdtls_cache_root_path() | |||
| 23 | 23 | return cache_root | |
| 24 | 24 | end | |
| 25 | 25 | ||
| 26 | + local function get_cache_key(value) | ||
| 27 | + if value == nil or value == '' then | ||
| 28 | + return nil | ||
| 29 | + end | ||
| 30 | + | ||
| 31 | + return vim.fn.sha256(value) | ||
| 32 | + end | ||
| 33 | + | ||
| 26 | 34 | --- Returns the path to the jdtls config file | |
| 35 | + ---@param jdtls_root? string | ||
| 27 | 36 | ---@return string | |
| 28 | - function M.get_jdtls_cache_conf_path() | ||
| 37 | + function M.get_jdtls_cache_conf_path(jdtls_root) | ||
| 29 | 38 | local path = require('java-core.utils.path') | |
| 30 | 39 | local cache_root = M.get_jdtls_cache_root_path() | |
| 31 | - local conf_path = path.join(cache_root, 'config') | ||
| 40 | + local cache_key = get_cache_key(jdtls_root) | ||
| 41 | + local conf_dir_name = cache_key and ('config_' .. cache_key) or 'config' | ||
| 42 | + local conf_path = path.join(cache_root, conf_dir_name) | ||
| 32 | 43 | return conf_path | |
| 33 | 44 | end | |
| 34 | 45 | ||
@@ -28,16 +28,15 @@ function M.setup(custom_config) | |||
| 28 | 28 | ---------------------------------------------------------------------- | |
| 29 | 29 | -- package installation -- | |
| 30 | 30 | ---------------------------------------------------------------------- | |
| 31 | - local Manager = require('pkgm.manager') | ||
| 32 | - local pkgm = Manager() | ||
| 31 | + local pkgm = require('pkgm.resolve') | ||
| 33 | 32 | ||
| 34 | - pkgm:install('jdtls', config.jdtls.version) | ||
| 33 | + pkgm.install('jdtls', config.jdtls) | ||
| 35 | 34 | ||
| 36 | 35 | if config.java_test.enable then | |
| 37 | 36 | ---------------------------------------------------------------------- | |
| 38 | 37 | -- test -- | |
| 39 | 38 | ---------------------------------------------------------------------- | |
| 40 | - pkgm:install('java-test', config.java_test.version) | ||
| 39 | + pkgm.install('java-test', config.java_test) | ||
| 41 | 40 | ||
| 42 | 41 | M.test = { | |
| 43 | 42 | run_current_class = test_api.run_current_class, | |
@@ -54,7 +53,7 @@ function M.setup(custom_config) | |||
| 54 | 53 | ---------------------------------------------------------------------- | |
| 55 | 54 | -- debugger -- | |
| 56 | 55 | ---------------------------------------------------------------------- | |
| 57 | - pkgm:install('java-debug', config.java_debug_adapter.version) | ||
| 56 | + pkgm.install('java-debug', config.java_debug_adapter) | ||
| 58 | 57 | require('java-dap').setup() | |
| 59 | 58 | ||
| 60 | 59 | M.dap = { | |
@@ -65,15 +64,15 @@ function M.setup(custom_config) | |||
| 65 | 64 | end | |
| 66 | 65 | ||
| 67 | 66 | if config.spring_boot_tools.enable then | |
| 68 | - pkgm:install('spring-boot-tools', config.spring_boot_tools.version) | ||
| 67 | + pkgm.install('spring-boot-tools', config.spring_boot_tools) | ||
| 69 | 68 | end | |
| 70 | 69 | ||
| 71 | 70 | if config.lombok.enable then | |
| 72 | - pkgm:install('lombok', config.lombok.version) | ||
| 71 | + pkgm.install('lombok', config.lombok) | ||
| 73 | 72 | end | |
| 74 | 73 | ||
| 75 | 74 | if config.jdk.auto_install then | |
| 76 | - pkgm:install('openjdk', config.jdk.version) | ||
| 75 | + pkgm.install('openjdk', config.jdk) | ||
| 77 | 76 | end | |
| 78 | 77 | ||
| 79 | 78 | ---------------------------------------------------------------------- | |
0 commit comments