aboutsummaryrefslogtreecommitdiffstats
path: root/lua/mason-registry/index/jdtls/init.lua
blob: 714cb3e65a0f2469df847b31a6a43d56bc3ec160 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
local Pkg = require "mason-core.package"
local _ = require "mason-core.functional"
local fetch = require "mason-core.fetch"
local github = require "mason-core.managers.github"
local installer = require "mason-core.installer"
local path = require "mason-core.path"
local platform = require "mason-core.platform"
local std = require "mason-core.managers.std"

---@async
local function download_jdtls()
    local source = github.tag { repo = "eclipse/eclipse.jdt.ls" }
    source.with_receipt()

    local version = _.gsub("^v", "", source.tag)
    local response =
        fetch(("https://download.eclipse.org/jdtls/milestones/%s/latest.txt"):format(version)):get_or_throw "Failed to fetch latest release from eclipse.org."
    local release_file = _.head(_.split("\n", response))

    std.download_file(
        ("https://download.eclipse.org/jdtls/milestones/%s/%s"):format(version, release_file),
        "archive.tar.gz"
    )
    std.untar "archive.tar.gz"
end

---@async
local function download_lombok()
    std.download_file("https://projectlombok.org/downloads/lombok.jar", "lombok.jar")
end

return Pkg.new {
    name = "jdtls",
    desc = [[Java language server]],
    homepage = "https://github.com/eclipse/eclipse.jdt.ls",
    languages = { Pkg.Lang.Java },
    categories = { Pkg.Cat.LSP },
    ---@async
    ---@param ctx InstallContext
    install = function(ctx)
        installer.run_concurrently { download_jdtls, download_lombok }
        platform.when {
            unix = function()
                ctx:link_bin("jdtls", path.concat { "bin", "jdtls" })
            end,
            win = function()
                ctx:link_bin(
                    "jdtls",
                    ctx:write_shell_exec_wrapper(
                        path.concat { "bin", "jdtls-win" },
                        ("python %q"):format(path.concat {
                            ctx.package:get_install_path(),
                            "bin",
                            "jdtls.py",
                        })
                    )
                )
            end,
        }
    end,
}