-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathenv.lua
More file actions
39 lines (28 loc) · 956 Bytes
/
env.lua
File metadata and controls
39 lines (28 loc) · 956 Bytes
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
local path = require('java-core.utils.path')
local Manager = require('pkgm.manager')
local log = require('java-core.utils.log2')
local system = require('java-core.utils.system')
local M = {}
--- @param config java.Config
function M.get_env(config)
if not config.jdk.auto_install then
log.debug('config.jdk.auto_install disabled, returning empty env')
return {}
end
local jdk_root = Manager:get_install_dir('openjdk', config.jdk.version)
local java_home
if system.get_os() == 'mac' then
java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*', 'Contents', 'Home'))
else
java_home = vim.fn.glob(path.join(jdk_root, 'jdk-*'))
end
local java_bin = path.join(java_home, 'bin')
local separator = system.get_os() == 'win' and ';' or ':'
local env = {
['PATH'] = java_bin .. separator .. vim.fn.getenv('PATH'),
['JAVA_HOME'] = java_home,
}
log.debug('env set - JAVA_HOME:', env.JAVA_HOME, 'PATH:', env.PATH)
return env
end
return M