Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 29 additions & 18 deletions lua/java-core/ls/servers/jdtls/plugins.lua
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
local mason = require('java-core.utils.mason')
local path = require('java-core.utils.path')
local file = require('java-core.utils.file')

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

local M = {}

local plugin_to_jar_path_map = {
['java-test'] = '*.jar',
['java-debug-adapter'] = '*.jar',
local plug_jar_map = {
['java-test'] = {
'junit-jupiter-api_*.jar',
'junit-jupiter-engine_*.jar',
'junit-jupiter-migrationsupport_*.jar',
'junit-jupiter-params_*.jar',
'junit-platform-commons_*.jar',
'junit-platform-engine_*.jar',
'junit-platform-launcher_*.jar',
'junit-platform-runner_*.jar',
'junit-platform-suite-api_*.jar',
'junit-platform-suite-commons_*.jar',
'junit-platform-suite-engine_*.jar',
'junit-vintage-engine_*.jar',
'org.apiguardian.api_*.jar',
'org.eclipse.jdt.junit4.runtime_*.jar',
'org.eclipse.jdt.junit5.runtime_*.jar',
'org.opentest4j_*.jar',
'com.microsoft.java.test.plugin-*.jar',
},
['java-debug-adapter'] = { '*.jar' },
}

---Returns a list of .jar file paths for given list of jdtls plugins
---@param plugins string[]
---@param plugin_names string[]
---@return string[] # list of .jar file paths
function M.get_plugin_paths(plugins)
local plugin_paths = List:new()

for _, plugin in ipairs(plugins) do
local relative_path = plugin_to_jar_path_map[plugin]
local plugin_shared_path = mason.get_shared_path(plugin)
local full_path = path.join(plugin_shared_path, relative_path)
local resolved_paths = file.get_file_list(full_path)

plugin_paths:push(resolved_paths)
end

return plugin_paths:flatten()
function M.get_plugin_paths(plugin_names)
return List:new(plugin_names)
:map(function(plugin_name)
local root = mason.get_shared_path(plugin_name)
return file.resolve_paths(root, plug_jar_map[plugin_name])
end)
:flatten()
end

return M
50 changes: 9 additions & 41 deletions lua/java-core/utils/file.lua
Original file line number Diff line number Diff line change
@@ -1,47 +1,15 @@
local M = {}

---Return true if the given path is a directory
---@param path string
---@return boolean
function M.is_dir(path)
return vim.fn.isdirectory(path) == 1
end
local path = require('java-core.utils.path')

---Returns true if the given path is a file
---@param path string
---@return boolean
function M.is_file(path)
return vim.fn.filereadable(path) == 1
end

---Returns true if the given path is an executable
---@param path string
---@return boolean
function M.is_exec(path)
return vim.fn.executable(path) == 1
end
local List = require('java-core.utils.list')

---Returns a list of files from a path with wildcards
---@param path string path with the wildcards
---@return string[]
function M.get_file_list(path)
return vim.fn.glob(path, true, true)
end

---Creates a directory in the given path
---@param path string
---@param opts JavaDirCreateFlags
function M.mkdir(path, opts)
local flags = ''

if opts.create_intermediate then
flags = flags .. 'p'
end
local M = {}

vim.fn.mkdir(path, flags)
function M.resolve_paths(root, paths)
return List:new(paths)
:map(function(path_pattern)
return vim.fn.glob(path.join(root, path_pattern), true, true)
end)
:flatten()
end

return M

---@class JavaDirCreateFlags
---@field create_intermediate boolean whether the intermediate directories should be created in the process