Sha256: c2cb7545f12ed553cb11d6abe477fe6e3c065976c029c82f5fb56e88a746cba0

Contents?: true

Size: 1.9 KB

Versions: 8

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

require 'license_finder/shared_helpers/common_path'
require 'json'

module LicenseFinder
  class Govendor < PackageManager
    def possible_package_paths
      [project_path.join('vendor', 'vendor.json')]
    end

    def current_packages
      file = File.read(detected_package_path)
      packages = packages_from_json(file)
      packages.map do |package|
        GoPackage.from_dependency({
                                    'ImportPath' => package[:path],
                                    'InstallPath' => project_path.join('vendor', package[:path]),
                                    'Rev' => package[:sha]
                                  }, nil, true)
      end
    end

    def self.takes_priority_over
      Go15VendorExperiment
    end

    def self.package_management_command
      'govendor'
    end

    def self.prepare_command
      'govendor sync'
    end

    private

    def packages_from_json(json_string)
      data = JSON.parse(json_string)
      packages = data['package']

      packages_by_sha = {}
      packages_with_no_sha = []

      packages.each do |package|
        package_path = package['path']
        package_revision = package['revision']

        if !package_is_versioned?(package)
          packages_with_no_sha << { sha: '', path: package_path }
        elsif packages_by_sha[package_revision].nil?
          packages_by_sha[package_revision] = [package_path]
        else
          packages_by_sha[package_revision] << package_path
        end
      end

      result = packages_with_no_sha
      packages_by_sha.each do |sha, paths|
        common_paths = CommonPathHelper.longest_common_paths(paths)
        common_paths.each { |cp| result << { sha: sha, path: cp } }
      end

      result
    end

    def package_is_versioned?(package)
      package_revision = package['revision']

      !package_revision.nil? && !package_revision.empty?
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
license_finder-5.7.1 lib/license_finder/package_managers/govendor.rb
license_finder-5.7.0 lib/license_finder/package_managers/govendor.rb
license_finder-5.6.2 lib/license_finder/package_managers/govendor.rb
license_finder-5.6.1 lib/license_finder/package_managers/govendor.rb
license_finder-5.6.0 lib/license_finder/package_managers/govendor.rb
license_finder-5.5.2 lib/license_finder/package_managers/govendor.rb
license_finder-5.5.1 lib/license_finder/package_managers/govendor.rb
license_finder-5.5.0 lib/license_finder/package_managers/govendor.rb