Class: LicenseFinder::Gvt

Inherits:
PackageManager show all
Defined in:
lib/license_finder/package_managers/gvt.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PackageManager

#active?, command_exists?, #current_packages_with_relations, #detected_package_path, #initialize, installed?, #prepare

Constructor Details

This class inherits a constructor from LicenseFinder::PackageManager

Class Method Details

.package_management_commandObject



12
13
14
# File 'lib/license_finder/package_managers/gvt.rb', line 12

def self.package_management_command
  'gvt'
end

.prepare_commandObject



16
17
18
# File 'lib/license_finder/package_managers/gvt.rb', line 16

def self.prepare_command
  'gvt restore'
end

.takes_priority_overObject



47
48
49
# File 'lib/license_finder/package_managers/gvt.rb', line 47

def self.takes_priority_over
  Go15VendorExperiment
end

Instance Method Details

#current_packagesObject



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
# File 'lib/license_finder/package_managers/gvt.rb', line 20

def current_packages
  split_project_path = project_path.to_s.split('/')
  project_root_depth = split_project_path.length - 1

  split_package_path = detected_package_path.to_s.split('/')
  vendor_dir_depth = split_package_path.index('vendor')
  return [] if vendor_dir_depth.nil?

  vendor_dir_parent_depth = vendor_dir_depth - 1

  is_project_root_parent_of_vendor_dir = project_root_depth == vendor_dir_parent_depth

  if is_project_root_parent_of_vendor_dir
    shell_command = 'gvt list -f "{{.Importpath}} {{.Revision}} {{.Repository}}"'
    path = project_path.join('vendor')
  else
    vendor_dir_parent = split_package_path[vendor_dir_parent_depth]
    shell_command = "cd #{vendor_dir_parent} && gvt list -f \"{{.Importpath}} {{.Revision}} {{.Repository}}\""
    path = project_path.join(vendor_dir_parent, 'vendor')
  end

  stdout, _stderr, status = Cmd.run(shell_command)
  return [] unless status.success?

  packages_from_output(stdout, path)
end

#possible_package_pathsObject



6
7
8
9
10
# File 'lib/license_finder/package_managers/gvt.rb', line 6

def possible_package_paths
  potential_path_list = Dir.glob project_path.join('*', 'vendor', 'manifest')
  potential_path_list << project_path.join('vendor', 'manifest')
  potential_path_list.map { |path| Pathname path }
end