Skip to content
Open
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
5 changes: 5 additions & 0 deletions .stylua.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
indent_width = 2
column_width = 120
line_endings = "Unix"
indent_type = "Tabs"
quote_style = "AutoPreferDouble"
78 changes: 44 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

<section align="center">

<h1>neotest-java</h1>
Expand Down Expand Up @@ -36,38 +35,38 @@
<details>
<summary><a href="https://github.com/folke/lazy.nvim">lazy.nvim</a> plugin manager example</summary>

```lua
return {
{
"rcasia/neotest-java",
ft = "java",
dependencies = {
"mfussenegger/nvim-jdtls",
"mfussenegger/nvim-dap", -- for the debugger
"rcarriga/nvim-dap-ui", -- recommended
"theHamsta/nvim-dap-virtual-text", -- recommended
},
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
```lua
return {
{
"rcasia/neotest-java",
ft = "java",
dependencies = {
"mfussenegger/nvim-jdtls",
"mfussenegger/nvim-dap", -- for the debugger
"rcarriga/nvim-dap-ui", -- recommended
"theHamsta/nvim-dap-virtual-text", -- recommended
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-java")({
-- config here
}),
},
})
end,
}
}
```
},
{
"nvim-neotest/neotest",
dependencies = {
"nvim-neotest/nvim-nio",
"nvim-lua/plenary.nvim",
"antoinemadec/FixCursorHold.nvim",
"nvim-treesitter/nvim-treesitter",
},
config = function()
require("neotest").setup({
adapters = {
require("neotest-java")({
-- config here
}),
},
})
end,
}
}
```

</details>

Expand All @@ -81,8 +80,19 @@

```lua
{
junit_jar = nil, -- default: stdpath("data") .. /nvim/neotest-java/junit-platform-console-standalone-[version].jar
incremental_build = true
junit_jar = nil, -- default: stdpath("data") .. /nvim/neotest-java/junit-platform-console-standalone-[version].jar
incremental_build = true, -- default: true, avoid doing a full rebuild by default of projects or the entire workspace
target_type = "project", -- default: project, build and compile processes will target projects not the entire workspace
java_runtimes = {
-- There are no runtimes defined by default, if you wish to have
-- neotest-java resolve them based on your environment define them here,
-- one could also define environment variables with the same key/names
-- i.e. `JAVA_HOME_8` or `JAVA_HOME_11` or `JAVA_HOME_17` etc in your
-- zshenv or equivalent.
["JAVA_HOME_8"] = "/absolute/path/to/jdk8/home/directory",
["JAVA_HOME_11"] = "/absolute/path/to/jdk11/home/directory",
["JAVA_HOME_17"] = "/absolute/path/to/jdk17/home/directory",
},
}
```

Expand Down
3 changes: 2 additions & 1 deletion lua/neotest-java/build_tool/gradle.lua
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ end

--- @param roots string[]
function gradle.get_spring_property_filepaths(roots)
local base_dirs = vim.iter(roots)
local base_dirs = vim
.iter(roots)
:map(function(root)
return {
gradle.get_output_dir(root) .. "/main",
Expand Down
3 changes: 2 additions & 1 deletion lua/neotest-java/build_tool/maven.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ end

--- @param roots string[]
function maven.get_spring_property_filepaths(roots)
local base_dirs = vim.iter(roots)
local base_dirs = vim
.iter(roots)
:map(function(root)
return {
maven.get_output_dir(root) .. "/classes",
Expand Down
14 changes: 7 additions & 7 deletions lua/neotest-java/command/binaries.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
local jdtls = require("neotest-java.command.jdtls")
local compatible_path = require("neotest-java.util.compatible_path")
local runtime = require("neotest-java.command.runtime")
local logger = require("neotest-java.logger")

local binaries = {

java = function()
local ok, jdtls_java_home = pcall(jdtls.get_java_home)
java = function(...)
local ok, jdtls_java_home = pcall(runtime.get_java_runtime, ...)

if ok then
return compatible_path(jdtls_java_home .. "/bin/java")
end

logger.warn("JAVA_HOME setting not found in jdtls. Using defualt binary: java")
logger.warn("Unable to detect JAVA_HOME. Using defualt binary in path: java")
return "java"
end,

javac = function()
local ok, jdtls_java_home = pcall(jdtls.get_java_home)
javac = function(...)
local ok, jdtls_java_home = pcall(runtime.get_java_runtime, ...)

if ok then
return compatible_path(jdtls_java_home .. "/bin/javac")
end

logger.warn("JAVA_HOME setting not found in jdtls. Using default: javac")
logger.warn("Unable to detect JAVA_HOME. Using defualt binary in path: javac")
return "javac"
end,
}
Expand Down
59 changes: 59 additions & 0 deletions lua/neotest-java/command/classpath.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
local nio = require("nio")
local lsp = require("neotest-java.lsp")
local logger = require("neotest-java.logger")

local M = {}

---@param additional_classpath_entries string[]
---@param dir string
M.get_classpaths = function(additional_classpath_entries, dir)
additional_classpath_entries = additional_classpath_entries or {}

local bufnr = nio.api.nvim_get_current_buf()
local uri = vim.uri_from_fname(dir)

local results = { ["runtime"] = {}, ["test"] = {} }
for scope, _ in pairs(results) do
local options = vim.json.encode({ scope = scope })
local args = {
command = "java.project.getClasspaths",
arguments = { uri, options },
}
local err, result = lsp.execute_command("workspace/executeCommand", args, bufnr)
assert(not err, vim.inspect(err))

-- Note:
-- 1) module paths are not duplicated on the classpath,
-- 2) the classpath and modulepath generated by the eclipse jdtls, do
-- not include the target/test-classes directory, for maven projects
-- using the Java Platform Module System.

if next(result.modulepaths) ~= nil then
logger.error(
"Java Platform Module System not supported. Temporarily remove "
.. "module-info.java for the test duration. modulepath="
.. vim.inspect(result.modulepaths)
)
end
results[scope] = result.classpaths
end

local runtime_classpaths = results.runtime
local test_classpaths = results.test

local classpaths = {}
for _, v in ipairs(additional_classpath_entries) do
classpaths[#classpaths + 1] = v
end
for _, v in ipairs(runtime_classpaths) do
classpaths[#classpaths + 1] = v
end
for _, v in ipairs(test_classpaths) do
classpaths[#classpaths + 1] = v
end

logger.debug(("classpath entries: %d"):format(#classpaths))
return classpaths
end

return M
113 changes: 0 additions & 113 deletions lua/neotest-java/command/jdtls.lua

This file was deleted.

7 changes: 4 additions & 3 deletions lua/neotest-java/command/junit_command_builder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ local CommandBuilder = {
assert(self._spring_property_filepaths, "_spring_property_filepaths cannot be nil")

local selectors = {}
-- FIX: use concat and more performant and robust string concatenation please !
for _, v in ipairs(self._test_references) do
if v.type == "test" then
local class_name = v.qualified_name:match("^(.-)#") or v.qualified_name
table.insert(selectors, "--select-class='" .. class_name .. "'")
table.insert(selectors, "--select-class=" .. class_name .. "")
if v.method_name then
table.insert(selectors, "--select-method='" .. v.method_name .. "'")
table.insert(selectors, "--select-method=" .. v.method_name .. "")
end
elseif v.type == "file" then
table.insert(selectors, "-c=" .. v.qualified_name)
Expand All @@ -113,7 +114,7 @@ local CommandBuilder = {
assert(#selectors ~= 0, "junit command has to have a selector")

local junit_command = {
command = java(),
command = java(self._basedir),
args = {
"-Dspring.config.additional-location=" .. table.concat(self._spring_property_filepaths, ","),
"-jar",
Expand Down
Loading
Loading