2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-10-17 21:57:00 -04:00
|
|
|
##
|
|
|
|
# A VendorSet represents gems that have been unpacked into a specific
|
|
|
|
# directory that contains a gemspec.
|
|
|
|
#
|
|
|
|
# This is used for gem dependency file support.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
2013-11-18 19:34:13 -05:00
|
|
|
# set = Gem::Resolver::VendorSet.new
|
2013-10-17 21:57:00 -04:00
|
|
|
#
|
|
|
|
# set.add_vendor_gem 'rake', 'vendor/rake'
|
|
|
|
#
|
|
|
|
# The directory vendor/rake must contain an unpacked rake gem along with a
|
|
|
|
# rake.gemspec (watching the given name).
|
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class Gem::Resolver::VendorSet < Gem::Resolver::Set
|
2013-10-17 21:57:00 -04:00
|
|
|
|
2013-12-08 14:32:07 -05:00
|
|
|
##
|
|
|
|
# The specifications for this set.
|
|
|
|
|
|
|
|
attr_reader :specs # :nodoc:
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def initialize # :nodoc:
|
2014-02-03 19:48:31 -05:00
|
|
|
super()
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
@directories = {}
|
|
|
|
@specs = {}
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Adds a specification to the set with the given +name+ which has been
|
|
|
|
# unpacked into the given +directory+.
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def add_vendor_gem name, directory # :nodoc:
|
2013-10-17 21:57:00 -04:00
|
|
|
gemspec = File.join directory, "#{name}.gemspec"
|
|
|
|
|
|
|
|
spec = Gem::Specification.load gemspec
|
|
|
|
|
2013-10-19 20:31:12 -04:00
|
|
|
raise Gem::GemNotFoundException,
|
|
|
|
"unable to find #{gemspec} for gem #{name}" unless spec
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
spec.full_gem_path = File.expand_path directory
|
|
|
|
|
2013-12-08 14:32:07 -05:00
|
|
|
@specs[spec.name] = spec
|
2013-11-10 12:51:40 -05:00
|
|
|
@directories[spec] = directory
|
2014-09-13 23:30:02 -04:00
|
|
|
|
|
|
|
spec
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Returns an Array of VendorSpecification objects matching the
|
|
|
|
# DependencyRequest +req+.
|
|
|
|
|
|
|
|
def find_all req
|
|
|
|
@specs.values.select do |spec|
|
2014-09-13 23:30:02 -04:00
|
|
|
req.match? spec
|
2013-10-17 21:57:00 -04:00
|
|
|
end.map do |spec|
|
2013-11-10 12:51:40 -05:00
|
|
|
source = Gem::Source::Vendor.new @directories[spec]
|
2013-11-18 19:34:13 -05:00
|
|
|
Gem::Resolver::VendorSpecification.new self, spec, source
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2013-12-08 14:32:07 -05:00
|
|
|
# Loads a spec with the given +name+. +version+, +platform+ and +source+ are
|
|
|
|
# ignored.
|
2013-10-17 21:57:00 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
def load_spec name, version, platform, source # :nodoc:
|
2013-12-08 14:32:07 -05:00
|
|
|
@specs.fetch name
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|
2013-11-30 18:27:52 -05:00
|
|
|
def pretty_print q # :nodoc:
|
|
|
|
q.group 2, '[VendorSet', ']' do
|
|
|
|
next if @directories.empty?
|
|
|
|
q.breakable
|
|
|
|
|
|
|
|
dirs = @directories.map do |spec, directory|
|
|
|
|
"#{spec.full_name}: #{directory}"
|
|
|
|
end
|
|
|
|
|
|
|
|
q.seplist dirs do |dir|
|
|
|
|
q.text dir
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-17 21:57:00 -04:00
|
|
|
end
|
|
|
|
|