Class: LicenseFinder::Go15VendorExperiment
Instance Method Summary
collapse
#command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #prepare, #prepare_command, #project_root?, takes_priority_over
Constructor Details
Returns a new instance of Go15VendorExperiment.
7
8
9
10
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 7
def initialize(options = {})
super
@full_version = options[:go_full_version]
end
|
Instance Method Details
#active? ⇒ Boolean
12
13
14
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 12
def active?
super && go_files_exist?
end
|
#current_packages ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 33
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))}",
'Homepage' => repo_name(dep)
}, nil, true)
end
end
|
#go_files_exist? ⇒ Boolean
16
17
18
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 16
def go_files_exist?
!Dir[project_path.join('**/*.go')].empty? && !Dir[project_path.join('vendor/**/*.go')].empty?
end
|
#go_list ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 54
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
|
#package_management_command ⇒ Object
50
51
52
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 50
def package_management_command
'go'
end
|
#possible_package_paths ⇒ Object
20
21
22
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 20
def possible_package_paths
[project_path.join('vendor')]
end
|
#project_sha(path) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 24
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
|
#repo_name(name) ⇒ Object
46
47
48
|
# File 'lib/license_finder/package_managers/go_15vendorexperiment.rb', line 46
def repo_name(name)
name.split('/')[0..2].join('/')
end
|