Class: LicenseFinder::GoWorkspace

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

Defined Under Namespace

Classes: Submodule

Constant Summary collapse

ENVRC_REGEXP =
/GOPATH|GO15VENDOREXPERIMENT/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PackageManager

#command_exists?, #current_packages_with_relations, #detected_package_path, id, #installed?, #prepare, #prepare_command, #project_root?

Constructor Details

#initialize(options = {}) ⇒ GoWorkspace

Returns a new instance of GoWorkspace.



13
14
15
16
17
# File 'lib/license_finder/package_managers/go_workspace.rb', line 13

def initialize(options = {})
  super
  @full_version = options[:go_full_version]
  @strict_matching = options[:strict_matching]
end

Class Method Details

.takes_priority_overObject



43
44
45
# File 'lib/license_finder/package_managers/go_workspace.rb', line 43

def self.takes_priority_over
  Go15VendorExperiment
end

Instance Method Details

#active?Boolean

Returns:

  • (Boolean)


51
52
53
54
55
56
57
58
59
60
# File 'lib/license_finder/package_managers/go_workspace.rb', line 51

def active?
  return false if @strict_matching

  # Dep has been deprecated since 2020
  godep = LicenseFinder::GoDep.new(project_path: Pathname(project_path))
  # go workspace is only active if GoDep wasn't. There are some projects
  # that will use the .envrc and have a Godep folder as well.
  # !!(!godep.active? && !dep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
  !!(!godep.active? && envrc_path && ENVRC_REGEXP.match(IO.read(envrc_path)))
end

#current_packagesObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/license_finder/package_managers/go_workspace.rb', line 23

def current_packages
  go_list_packages = go_list
  git_modules.map do |submodule|
    # We are filtering the non-standard packages because the word "net"
    # seems to be common that can give false positive when filtering the git submodules
    import_path = go_list_packages.find do |gp|
      submodule.install_path =~ /#{repo_name(gp)}$/
    end
    next unless import_path

    dependency_info = {
      'ImportPath' => repo_name(import_path),
      'Homepage' => repo_name(import_path),
      'InstallPath' => submodule.install_path,
      'Rev' => submodule.revision
    }
    GoPackage.from_dependency(dependency_info, nil, @full_version)
  end.compact
end

#package_management_commandObject



19
20
21
# File 'lib/license_finder/package_managers/go_workspace.rb', line 19

def package_management_command
  'go'
end

#possible_package_pathsObject



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

def possible_package_paths
  [envrc_path.dirname]
end