Skip to content

Commit 2951613

Browse files
authored
fix: trying to load jar that's not a jdtls extension (#56)
1 parent 4ab0b6c commit 2951613

File tree

2 files changed

+38
-59
lines changed

2 files changed

+38
-59
lines changed
Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,43 @@
11
local mason = require('java-core.utils.mason')
2-
local path = require('java-core.utils.path')
32
local file = require('java-core.utils.file')
43

54
local List = require('java-core.utils.list')
65

76
local M = {}
87

9-
local plugin_to_jar_path_map = {
10-
['java-test'] = '*.jar',
11-
['java-debug-adapter'] = '*.jar',
8+
local plug_jar_map = {
9+
['java-test'] = {
10+
'junit-jupiter-api_*.jar',
11+
'junit-jupiter-engine_*.jar',
12+
'junit-jupiter-migrationsupport_*.jar',
13+
'junit-jupiter-params_*.jar',
14+
'junit-platform-commons_*.jar',
15+
'junit-platform-engine_*.jar',
16+
'junit-platform-launcher_*.jar',
17+
'junit-platform-runner_*.jar',
18+
'junit-platform-suite-api_*.jar',
19+
'junit-platform-suite-commons_*.jar',
20+
'junit-platform-suite-engine_*.jar',
21+
'junit-vintage-engine_*.jar',
22+
'org.apiguardian.api_*.jar',
23+
'org.eclipse.jdt.junit4.runtime_*.jar',
24+
'org.eclipse.jdt.junit5.runtime_*.jar',
25+
'org.opentest4j_*.jar',
26+
'com.microsoft.java.test.plugin-*.jar',
27+
},
28+
['java-debug-adapter'] = { '*.jar' },
1229
}
1330

1431
---Returns a list of .jar file paths for given list of jdtls plugins
15-
---@param plugins string[]
32+
---@param plugin_names string[]
1633
---@return string[] # list of .jar file paths
17-
function M.get_plugin_paths(plugins)
18-
local plugin_paths = List:new()
19-
20-
for _, plugin in ipairs(plugins) do
21-
local relative_path = plugin_to_jar_path_map[plugin]
22-
local plugin_shared_path = mason.get_shared_path(plugin)
23-
local full_path = path.join(plugin_shared_path, relative_path)
24-
local resolved_paths = file.get_file_list(full_path)
25-
26-
plugin_paths:push(resolved_paths)
27-
end
28-
29-
return plugin_paths:flatten()
34+
function M.get_plugin_paths(plugin_names)
35+
return List:new(plugin_names)
36+
:map(function(plugin_name)
37+
local root = mason.get_shared_path(plugin_name)
38+
return file.resolve_paths(root, plug_jar_map[plugin_name])
39+
end)
40+
:flatten()
3041
end
3142

3243
return M

lua/java-core/utils/file.lua

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,15 @@
1-
local M = {}
2-
3-
---Return true if the given path is a directory
4-
---@param path string
5-
---@return boolean
6-
function M.is_dir(path)
7-
return vim.fn.isdirectory(path) == 1
8-
end
1+
local path = require('java-core.utils.path')
92

10-
---Returns true if the given path is a file
11-
---@param path string
12-
---@return boolean
13-
function M.is_file(path)
14-
return vim.fn.filereadable(path) == 1
15-
end
16-
17-
---Returns true if the given path is an executable
18-
---@param path string
19-
---@return boolean
20-
function M.is_exec(path)
21-
return vim.fn.executable(path) == 1
22-
end
3+
local List = require('java-core.utils.list')
234

24-
---Returns a list of files from a path with wildcards
25-
---@param path string path with the wildcards
26-
---@return string[]
27-
function M.get_file_list(path)
28-
return vim.fn.glob(path, true, true)
29-
end
30-
31-
---Creates a directory in the given path
32-
---@param path string
33-
---@param opts JavaDirCreateFlags
34-
function M.mkdir(path, opts)
35-
local flags = ''
36-
37-
if opts.create_intermediate then
38-
flags = flags .. 'p'
39-
end
5+
local M = {}
406

41-
vim.fn.mkdir(path, flags)
7+
function M.resolve_paths(root, paths)
8+
return List:new(paths)
9+
:map(function(path_pattern)
10+
return vim.fn.glob(path.join(root, path_pattern), true, true)
11+
end)
12+
:flatten()
4213
end
4314

4415
return M
45-
46-
---@class JavaDirCreateFlags
47-
---@field create_intermediate boolean whether the intermediate directories should be created in the process

0 commit comments

Comments
 (0)