Class: LicenseScout::DependencyManager::Gomod

Inherits:
Base
  • Object
show all
Defined in:
lib/license_scout/dependency_manager/gomod.rb

Instance Attribute Summary

Attributes inherited from Base

#directory

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from LicenseScout::DependencyManager::Base

Instance Method Details

#dependenciesObject


44
45
46
47
48
49
50
51
52
53
54
# File 'lib/license_scout/dependency_manager/gomod.rb', line 44

def dependencies
  go_modules.map do |mod|
    next if mod["Main"] == true

    dep_name = mod["Path"]
    dep_version = mod["Version"]
    dep_path = mod["Dir"]

    new_dependency(dep_name, dep_version, dep_path)
  end.compact
end

#detected?Boolean

Returns:

  • (Boolean)

40
41
42
# File 'lib/license_scout/dependency_manager/gomod.rb', line 40

def detected?
  File.exist?(go_sum_file)
end

#go_modulesObject


68
69
70
71
72
73
74
# File 'lib/license_scout/dependency_manager/gomod.rb', line 68

def go_modules
  if vendor_mode
    GoModulesTxtParser.parse(File.read(modules_txt_file), vendor_dir)
  else
    FFI_Yajl::Parser.parse(go_modules_json)
  end
end

#go_modules_jsonObject


83
84
85
86
87
88
# File 'lib/license_scout/dependency_manager/gomod.rb', line 83

def go_modules_json
  s = Mixlib::ShellOut.new("go list -m -json all", cwd: directory, environment: LicenseScout::Config.environment)
  s.run_command
  s.error!
  "[" + s.stdout.gsub("}\n{", "},\n{") + "]"
end

#go_sum_fileObject


56
57
58
# File 'lib/license_scout/dependency_manager/gomod.rb', line 56

def go_sum_file
  File.join(directory, "go.sum")
end

#install_commandObject


36
37
38
# File 'lib/license_scout/dependency_manager/gomod.rb', line 36

def install_command
  "go mod download"
end

#modules_txt_fileObject


64
65
66
# File 'lib/license_scout/dependency_manager/gomod.rb', line 64

def modules_txt_file
  File.join(vendor_dir, "modules.txt")
end

#nameObject


24
25
26
# File 'lib/license_scout/dependency_manager/gomod.rb', line 24

def name
  "golang_modules"
end

#signatureObject


32
33
34
# File 'lib/license_scout/dependency_manager/gomod.rb', line 32

def signature
  "go.sum file"
end

#typeObject


28
29
30
# File 'lib/license_scout/dependency_manager/gomod.rb', line 28

def type
  "golang"
end

#vendor_dirObject


60
61
62
# File 'lib/license_scout/dependency_manager/gomod.rb', line 60

def vendor_dir
  File.join(directory, "vendor")
end

#vendor_modeObject


76
77
78
79
80
81
# File 'lib/license_scout/dependency_manager/gomod.rb', line 76

def vendor_mode
  if @vendor_mode.nil?
    @vendor_mode = File.directory?(vendor_dir)
  end
  @vendor_mode
end