81 lines
2.1 KiB
Lua
81 lines
2.1 KiB
Lua
function IsFileExist(filename)
|
|
local f = io.open(filename)
|
|
if f ~= nil then
|
|
io.close(f)
|
|
return true
|
|
else
|
|
return false
|
|
end
|
|
end
|
|
|
|
function IsWindows()
|
|
local delimeter = package.config:sub(1, 1)
|
|
if delimeter == "/" then
|
|
return false
|
|
end
|
|
return true
|
|
end
|
|
|
|
function Path2Windows(path)
|
|
return (string.gsub(path, "/", "\\"))
|
|
end
|
|
|
|
function IsDirectoryExist(dirname)
|
|
return os.rename(dirname, dirname) and true or false
|
|
end
|
|
|
|
local homepage = os.getenv("HOME")
|
|
if IsWindows() then
|
|
homepage = os.getenv("USERPROFILE")
|
|
end
|
|
|
|
local jdtlspath = homepage .. "/.jdtls"
|
|
local jdtls_bin = jdtlspath .. "/bin/jdtls"
|
|
local lombok_jar = jdtlspath .. "/bin/lombok.jar"
|
|
local temp_download = os.getenv("TEMP")
|
|
|
|
if IsWindows() then
|
|
jdtlspath = Path2Windows(jdtlspath)
|
|
jdtls_bin = Path2Windows(jdtls_bin)
|
|
lombok_jar = Path2Windows(lombok_jar)
|
|
end
|
|
|
|
-- 创建目录
|
|
if not IsDirectoryExist(jdtlspath) then
|
|
os.execute("mkdir " .. jdtlspath)
|
|
end
|
|
|
|
-- 检测文件存在否
|
|
if not IsDirectoryExist(jdtls_bin) then
|
|
print("download jdtls binary")
|
|
local download_ret = os.execute(
|
|
"curl --create-dirs -O --output-dir "
|
|
.. temp_download
|
|
.. " https://download.eclipse.org/jdtls/milestones/1.23.0/jdt-language-server-1.23.0-202304271346.tar.gz"
|
|
)
|
|
if download_ret ~= 0 then
|
|
vim.notify("download jdtls binary failed")
|
|
return
|
|
end
|
|
vim.notify("download jdtls success")
|
|
local tar_ret =
|
|
os.execute("tar xvzf " .. temp_download .. "/jdt-language-server-1.23.0-202304271346.tar.gz -C " .. jdtlspath)
|
|
if tar_ret ~= 0 then
|
|
vim.notify("extract jdtls file failed")
|
|
return
|
|
end
|
|
vim.notify("install jdtls success")
|
|
end
|
|
|
|
-- 下载lombok
|
|
if not IsFileExist(lombok_jar) then
|
|
vim.notify("download lombok.jar")
|
|
local download_ret = os.execute(
|
|
"curl --create-dirs -O --output-dir " .. jdtlspath .. "/bin https://projectlombok.org/downloads/lombok.jar"
|
|
)
|
|
if download_ret ~= 0 then
|
|
vim.notify("download lombok failed")
|
|
end
|
|
vim.notify("download lombok.jar success")
|
|
end
|