Class: LicenseFinder::Go15VendorExperiment
Class Method Summary
collapse
Instance Method Summary
collapse
command_exists?, #current_packages_with_relations, #detected_package_path, installed?, #prepare, prepare_command, takes_priority_over
Constructor Details
Returns a new instance of Go15VendorExperiment.
5
6
7
8
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 5
def initialize(options = {})
super
@full_version = options[:go_full_version]
end
|
Class Method Details
.package_management_command ⇒ Object
42
43
44
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 42
def self.package_management_command
'go'
end
|
Instance Method Details
#active? ⇒ Boolean
10
11
12
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 10
def active?
super && go_files_exist?
end
|
#current_packages ⇒ Object
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 30
def current_packages
deps = go_list
vendored_deps = deps.select { |dep| detected_package_path.join(dep).exist? }
vendored_deps.map do |dep|
GoPackage.from_dependency({
'ImportPath' => dep,
'InstallPath' => detected_package_path.join(dep),
'Rev' => 'vendored-' + project_sha(detected_package_path.join(dep))
}, nil, true)
end
end
|
#go_files_exist? ⇒ Boolean
14
15
16
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 14
def go_files_exist?
!Dir[project_path.join('**/*.go')].empty?
end
|
#go_list ⇒ Object
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
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 46
def go_list
Dir.chdir(project_path) do
orig_gopath = ENV['GOPATH']
ENV['GOPATH'] = nil
val, _stderr, status = Cmd.run('go list -f "{{join .Deps \"\n\"}}" ./...')
ENV['GOPATH'] = orig_gopath
return [] unless status.success?
deps = val.split("\n")
Cmd.run('go list std').first.split("\n").each do |std|
deps.delete_if do |dep|
dep =~ %r{(\/|^)#{std}(\/|$)}
end
end
deps.map do |d|
dep_parts = d.split('/')
if dep_parts.length > 2
dep_parts[0..2].join('/')
else
d
end
end
end
end
|
#possible_package_paths ⇒ Object
18
19
20
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 18
def possible_package_paths
[project_path.join('vendor')]
end
|
#project_sha(path) ⇒ Object
22
23
24
25
26
27
28
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 22
def project_sha(path)
Dir.chdir(path) do
stdout, _stderr, status = Cmd.run('git rev-list --max-count 1 HEAD')
raise 'git rev-list failed' unless status.success?
stdout.strip
end
end
|