-
-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathfactory.lua
More file actions
77 lines (67 loc) · 2.29 KB
/
factory.lua
File metadata and controls
77 lines (67 loc) · 2.29 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
local system = require('java-core.utils.system')
local Unzip = require('pkgm.extractors.unzip')
local Tar = require('pkgm.extractors.tar')
local PowerShellExtractor = require('pkgm.extractors.powershell')
local Uncompressed = require('pkgm.extractors.uncompressed')
local log = require('java-core.utils.log2')
local err_util = require('java-core.utils.errors')
local M = {}
---Get appropriate extractor based on file extension
---@param opts table Extractor options (source, dest)
---@return table # Extractor instance
function M.get_extractor(opts)
local source = opts.source
local lower_source = source:lower()
local os = system.get_os()
log.debug('Getting extractor for:', source, 'on OS:', os)
-- Check for zip files
if lower_source:match('%.zip$') or lower_source:match('%.vsix$') then
log.debug('Detected zip file')
-- 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 extractor')
return PowerShellExtractor(opts)
end
end
-- Check for unzip on all platforms
if vim.fn.executable('unzip') == 1 then
log.debug('Using unzip extractor')
return Unzip(opts)
end
-- Fallback to PowerShell on Windows if available
if os == 'win' and (vim.fn.executable('pwsh') == 1 or vim.fn.executable('powershell') == 1) then
log.debug('Using PowerShell extractor (fallback)')
return PowerShellExtractor(opts)
end
local err = 'No zip extractor available (unzip or powershell not found)'
err_util.throw(err)
end
-- Check for tar files
if
lower_source:match('%.tar$')
or lower_source:match('%.tar%.gz$')
or lower_source:match('%.tgz$')
or lower_source:match('%.tar%.xz$')
or lower_source:match('%.tar%.bz2$')
then
log.debug('Detected tar file')
local tar_cmd = vim.fn.executable('gtar') == 1 and 'gtar' or 'tar'
if vim.fn.executable(tar_cmd) == 1 then
log.debug('Using tar extractor:', tar_cmd)
return Tar(opts)
else
local err = 'tar not available'
err_util.throw(err)
end
end
-- Check for jar files
if lower_source:match('%.jar$') then
log.debug('Detected jar file')
log.debug('Using uncompressed extractor')
return Uncompressed(opts)
end
local err = string.format('Unsupported archive format: %s', source)
err_util.throw(err)
end
return M