Sha256: 7bf4254ceb3156cbf5ce0832182052ac9cb60503c1d663d4d481899bf352b130

Contents?: true

Size: 1.28 KB

Versions: 21

Compression:

Stored size: 1.28 KB

Contents

# frozen_string_literal: true

require 'csv'
require 'license_finder/package_utils/sbt_dependency_finder'

module LicenseFinder
  class Sbt < PackageManager
    def initialize(options = {})
      super
      @include_groups = options[:sbt_include_groups]
    end

    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|
        options = {
          headers: true
        }

        contents = CSV.parse(text, options)
        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'] }]
          }
          SbtPackage.new(spec, logger: logger, include_groups: @include_groups)
        end
      end

      packages.uniq
    end

    def package_management_command
      'sbt'
    end

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

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
license_finder-6.2.0 lib/license_finder/package_managers/sbt.rb
license_finder-6.1.2 lib/license_finder/package_managers/sbt.rb
license_finder-6.1.0 lib/license_finder/package_managers/sbt.rb
license_finder-6.0.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.11.1 lib/license_finder/package_managers/sbt.rb
license_finder-5.11.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.10.2 lib/license_finder/package_managers/sbt.rb
license_finder-5.10.1 lib/license_finder/package_managers/sbt.rb
license_finder-5.10.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.9.2 lib/license_finder/package_managers/sbt.rb
license_finder-5.9.1 lib/license_finder/package_managers/sbt.rb
license_finder-5.9.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.8.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.7.1 lib/license_finder/package_managers/sbt.rb
license_finder-5.7.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.6.2 lib/license_finder/package_managers/sbt.rb
license_finder-5.6.1 lib/license_finder/package_managers/sbt.rb
license_finder-5.6.0 lib/license_finder/package_managers/sbt.rb
license_finder-5.5.2 lib/license_finder/package_managers/sbt.rb
license_finder-5.5.1 lib/license_finder/package_managers/sbt.rb