-
Notifications
You must be signed in to change notification settings - Fork 333
/
go_modules.rb
55 lines (44 loc) · 1.26 KB
/
go_modules.rb
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
# frozen_string_literal: true
require 'license_finder/packages/go_package'
module LicenseFinder
class GoModules < PackageManager
PACKAGES_FILE = 'go.sum'
class << self
def takes_priority_over
Go15VendorExperiment
end
def prepare_command
'GO111MODULE=on go mod tidy && GO111MODULE=on go mod vendor'
end
end
def active?
sum_files?
end
def current_packages
info_output, _stderr, _status = Cmd.run("GO111MODULE=on go list -m -mod=vendor -f '{{.Path}},{{.Version}},{{.Dir}}' all")
packages_info = info_output.split("\n")
packages = packages_info.map do |package|
name, version, install_path = package.split(',')
read_package(install_path, name, version)
end
packages.reject do |package|
Pathname(package.install_path).cleanpath == Pathname(project_path).cleanpath
end
end
private
def sum_files?
sum_file_paths.any?
end
def sum_file_paths
Dir[project_path.join(PACKAGES_FILE)]
end
def read_package(install_path, name, version)
info = {
'ImportPath' => name,
'InstallPath' => install_path,
'Rev' => version
}
GoPackage.from_dependency(info, nil, true)
end
end
end