Sha256: 45cee8d586af1cd11473c9708d4bc9a419251bb541b40d63bb6e3325b456576a

Contents?: true

Size: 1.89 KB

Versions: 13

Compression:

Stored size: 1.89 KB

Contents

# frozen_string_literal: true

require 'json'

module LicenseFinder
  class GoDep < PackageManager
    def initialize(options = {})
      super
      @full_version = options[:go_full_version]
    end

    def current_packages
      packages_from_json(detected_package_path.read)
      # godep includes subpackages as a seperate dependency, we can de-dup that
    end

    def self.takes_priority_over
      Go15VendorExperiment
    end

    def possible_package_paths
      [project_path.join('Godeps/Godeps.json')]
    end

    def package_management_command
      'godep'
    end

    private

    def install_prefix
      go_path = if workspace_dir.directory?
                  workspace_dir
                else
                  Pathname(ENV['GOPATH'] || ENV['HOME'] + '/go')
                end
      go_path.join('src')
    end

    def workspace_dir
      project_path.join('Godeps/_workspace')
    end

    def packages_from_json(json_string)
      all_packages = JSON.parse(json_string)['Deps']

      return [] unless all_packages

      packages_grouped_by_revision = all_packages.group_by { |package| package['Rev'] }
      result = []

      packages_grouped_by_revision.each do |_sha, packages_in_group|
        all_paths_in_group = packages_in_group.map { |p| p['ImportPath'] }
        common_paths = CommonPathHelper.longest_common_paths(all_paths_in_group)
        package_info = packages_in_group.first

        common_paths.each do |common_path|
          dependency_info_hash = {
            'Homepage' => common_path,
            'ImportPath' => common_path,
            'InstallPath' => package_info['InstallPath'],
            'Rev' => package_info['Rev']
          }

          result << GoPackage.from_dependency(dependency_info_hash,
                                              install_prefix,
                                              @full_version)
        end
      end
      result
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
license_finder-6.8.2 lib/license_finder/package_managers/go_dep.rb
license_finder-6.8.1 lib/license_finder/package_managers/go_dep.rb
license_finder-6.8.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.7.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.6.2 lib/license_finder/package_managers/go_dep.rb
license_finder-6.6.1 lib/license_finder/package_managers/go_dep.rb
license_finder-6.6.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.5.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.4.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.3.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.2.0 lib/license_finder/package_managers/go_dep.rb
license_finder-6.1.2 lib/license_finder/package_managers/go_dep.rb
license_finder-6.1.0 lib/license_finder/package_managers/go_dep.rb