-
-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathfactory.lua
More file actions
40 lines (33 loc) · 1.22 KB
/
factory.lua
File metadata and controls
40 lines (33 loc) · 1.22 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
local system = require('java-core.utils.system')
local Wget = require('pkgm.downloaders.wget')
local PowerShell = require('pkgm.downloaders.powershell')
local log = require('java-core.utils.log2')
local err_util = require('java-core.utils.errors')
local M = {}
---Get appropriate downloader based on platform and binary availability
---@param opts table Downloader options (url, dest, retry_count, timeout)
---@return table # Downloader instance
function M.get_downloader(opts)
local os = system.get_os()
log.debug('Getting downloader for OS:', os)
-- On Windows, prefer PowerShell
if os == 'win' then
if vim.fn.executable('pwsh') == 1 or vim.fn.executable('powershell') == 1 then
log.debug('Using PowerShell downloader')
return PowerShell(opts)
end
end
-- Check for wget on all platforms
if vim.fn.executable('wget') == 1 then
log.debug('Using wget downloader')
return Wget(opts)
end
-- On Windows, fallback to PowerShell if available
if os == 'win' and (vim.fn.executable('pwsh') == 1 or vim.fn.executable('powershell') == 1) then
log.debug('Using PowerShell downloader (fallback)')
return PowerShell(opts)
end
local err = 'No downloader available (wget or powershell not found)'
err_util.throw(err)
end
return M