Module: Bundler::Sbom::SpecLicenseFinder

Defined in:
lib/bundler/sbom/spec_license_finder.rb

Class Method Summary collapse

Class Method Details

.find_licenses(spec) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/bundler/sbom/spec_license_finder.rb', line 4

def self.find_licenses(spec)
  gemspec = begin
    mat = spec.materialize_for_installation if spec.respond_to?(:materialize_for_installation)
    mat if mat.respond_to?(:licenses)
  rescue Bundler::GemspecError
    nil
  end

  begin
    gemspec ||= spec.__materialize__ if spec.respond_to?(:__materialize__)
  rescue Bundler::GemspecError
    # ignore
  end

  begin
    gemspec ||= Gem::Specification.find_by_name(spec.name, spec.version)
  rescue Gem::LoadError
    Bundler.ui.warn("Warning: Could not find license information for #{spec.name} (#{spec.version})")
  end

  if gemspec && gemspec.respond_to?(:licenses) && gemspec.licenses && !gemspec.licenses.empty?
    gemspec.licenses
  else
    []
  end
end