-
-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathenv.lua
More file actions
43 lines (31 loc) · 1.05 KB
/
env.lua
File metadata and controls
43 lines (31 loc) · 1.05 KB
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
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')
--- @TODO: importing stuff from java main package feels wrong.
--- We should fix this in the future
local config = require('java.config')
local M = {}
--- @param opts { use_jdk: boolean }
function M.get_env(opts)
if not opts.use_jdk then
log.debug('use_jdk 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