Class: LicenseFinder::Sbt

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

Instance Method Summary collapse

Methods inherited from PackageManager

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

Constructor Details

#initialize(options = {}) ⇒ Sbt

Returns a new instance of Sbt.



8
9
10
11
# File 'lib/license_finder/package_managers/sbt.rb', line 8

def initialize(options = {})
  super
  @include_groups = options[:sbt_include_groups]
end

Instance Method Details

#current_packagesObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/license_finder/package_managers/sbt.rb', line 13

def current_packages
  command = "#{package_management_command} dumpLicenseReport"
  _stdout, stderr, status = Dir.chdir(project_path) { Cmd.run(command) }
  raise "Command '#{command}' failed to execute: #{stderr}" unless status.success?

  dependencies = SbtDependencyFinder.new(project_path).dependencies
  packages = dependencies.flat_map do |text|
    contents = CSV.parse(text, headers: true)
    contents.map do |row|
      group_id, name, version = row['Dependency'].split('#').map(&:strip)
      spec = {
        'artifactId' => name,
        'groupId' => group_id,
        'version' => version,
        'licenses' => [{ 'name' => row['License'] }]
      }

      path = File.join("#{Dir.home}/.ivy2/cache", "#{spec['groupId']}/#{spec['artifactId']}")
      SbtPackage.new(spec, logger: logger, include_groups: @include_groups, install_path: path)
    end
  end

  packages.uniq
end

#package_management_commandObject



38
39
40
# File 'lib/license_finder/package_managers/sbt.rb', line 38

def package_management_command
  'sbt'
end

#possible_package_pathsObject



42
43
44
# File 'lib/license_finder/package_managers/sbt.rb', line 42

def possible_package_paths
  [project_path.join('build.sbt')]
end