Class: LicenseFinder::GoVendor
Class Method Summary
collapse
Instance Method Summary
collapse
#capture, command_exists?, current_packages, #current_packages_with_relations, installed?, package_managers
Constructor Details
#initialize(options = {}) ⇒ GoVendor
Returns a new instance of GoVendor.
6
7
8
9
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 6
def initialize(options={})
super
@full_version = options[:go_full_version]
end
|
Class Method Details
.package_management_command ⇒ Object
47
48
49
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 47
def self.package_management_command
'go'
end
|
Instance Method Details
#active? ⇒ Boolean
11
12
13
14
15
16
17
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 11
def active?
return false unless self.class.installed?(@logger)
(has_go_files? && package_path.exist?).tap do |is_active|
logger.active self.class, is_active
end
end
|
#current_packages ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 35
def current_packages
deps = go_list
vendored_deps = deps.select { |dep| package_path.join(dep).exist? }
vendored_deps.map do |dep|
GoPackage.from_dependency({
'ImportPath' => dep,
'InstallPath' => package_path.join(dep),
'Rev' => 'vendored-' + project_sha
}, nil, true)
end
end
|
#go_list ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 51
def go_list
Dir.chdir(project_path) do
ENV['GOPATH'] = nil
val = capture('go list -f \'{{join .Deps "\n"}}\' ./...')
return [] unless val.last
val.first.lines.map(&:strip).select { |l| l.split("/").length > 2 }.map { |l| l.split("/")[0..2].join("/") }.uniq
end
end
|
#has_go_files? ⇒ Boolean
19
20
21
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 19
def has_go_files?
!Dir[project_path.join("**/*.go")].empty?
end
|
#package_path ⇒ Object
23
24
25
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 23
def package_path
project_path.join("vendor")
end
|
#project_sha ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/license_finder/package_managers/go_vendor.rb', line 27
def project_sha
@project_sha ||= Dir.chdir(project_path) do
val = capture('git rev-list --max-count 1 HEAD')
raise 'git rev-list failed' unless val.last
val.first.strip
end
end
|