1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Commit miss for r43347

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43348 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
drbrain 2013-10-18 01:57:00 +00:00
parent 05ca2faba2
commit 0751fd43ac
5 changed files with 252 additions and 0 deletions

View file

@ -0,0 +1,66 @@
##
# 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:
#
# set = Gem::DependencyResolver::VendorSet.new
#
# 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).
class Gem::DependencyResolver::VendorSet
def initialize
@specs = {}
end
##
# Adds a specification to the set with the given +name+ which has been
# unpacked into the given +directory+.
def add_vendor_gem name, directory
gemspec = File.join directory, "#{name}.gemspec"
spec = Gem::Specification.load gemspec
key = "#{spec.name}-#{spec.version}-#{spec.platform}"
@specs[key] = spec
end
##
# Returns an Array of VendorSpecification objects matching the
# DependencyRequest +req+.
def find_all req
@specs.values.select do |spec|
req.matches_spec? spec
end.map do |spec|
Gem::DependencyResolver::VendorSpecification.new self, spec, nil
end
end
##
# Loads a spec with the given +name+, +version+ and +platform+. Since the
# +source+ is defined when the specification was added to index it is not
# used.
def load_spec name, version, platform, source
key = "#{name}-#{version}-#{platform}"
@specs.fetch key
end
##
# No prefetch is needed as the index is loaded at creation time.
def prefetch gems
end
end

View file

@ -0,0 +1,44 @@
class Gem::DependencyResolver::VendorSpecification
attr_reader :spec
attr_reader :set
def initialize set, spec, source=nil
@set = set
@source = source
@spec = spec
end
def == other # :nodoc:
self.class === other and
@set == other.set and
@spec == other.spec
end
def dependencies
@spec.dependencies
end
def full_name
"#{@spec.name}-#{@spec.version}"
end
def name
@spec.name
end
def platform
@spec.platform
end
def source
@source ||= Gem::Source::Vendor.new
end
def version
@spec.version
end
end

View file

@ -0,0 +1,6 @@
##
# This represents a vendored source that is similar to an installed gem.
class Gem::Source::Vendor < Gem::Source::Installed
end

View file

@ -0,0 +1,49 @@
require 'rubygems/test_case'
require 'rubygems/dependency_resolver'
class TestGemDependencyResolverVendorSet < Gem::TestCase
def setup
super
@set = Gem::DependencyResolver::VendorSet.new
end
def test_add_vendor_gem
name, version, directory = vendor_gem
@set.add_vendor_gem name, directory
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
assert_equal "#{name}-#{version}", spec.full_name
end
def test_find_all
name, version, directory = vendor_gem
@set.add_vendor_gem name, directory
dependency = dep 'a', '~> 1'
req = Gem::DependencyResolver::DependencyRequest.new dependency, nil
found = @set.find_all req
spec = @set.load_spec name, version, Gem::Platform::RUBY, nil
expected = [
Gem::DependencyResolver::VendorSpecification.new(@set, spec, nil)
]
assert_equal expected, found
end
def test_load_spec
assert_raises KeyError do
@set.load_spec 'a', v(1), Gem::Platform::RUBY, nil
end
end
end

View file

@ -0,0 +1,87 @@
require 'rubygems/test_case'
require 'rubygems/dependency_resolver'
class TestGemDependencyResolverVendorSpecification < Gem::TestCase
def setup
super
@set = Gem::DependencyResolver::VendorSet.new
@spec = Gem::Specification.new 'a', 1
end
def test_initialize
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal 'a', v_spec.name
assert_equal v(1), v_spec.version
assert_equal Gem::Platform::RUBY, v_spec.platform
assert_equal Gem::Source::Vendor.new, v_spec.source
end
def test_equals2
v_spec_a = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal v_spec_a, v_spec_a
spec_b = Gem::Specification.new 'b', 1
v_spec_b = Gem::DependencyResolver::VendorSpecification.new @set, spec_b
refute_equal v_spec_a, v_spec_b
v_set = Gem::DependencyResolver::VendorSet.new
v_spec_s = Gem::DependencyResolver::VendorSpecification.new v_set, @spec
refute_equal v_spec_a, v_spec_s
i_set = Gem::DependencyResolver::IndexSet.new
source = Gem::Source.new @gem_repo
i_spec = Gem::DependencyResolver::IndexSpecification.new(
i_set, 'a', v(1), source, Gem::Platform::RUBY)
refute_equal v_spec_a, i_spec
end
def test_dependencies
@spec.add_dependency 'b'
@spec.add_dependency 'c'
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal [dep('b'), dep('c')], v_spec.dependencies
end
def test_full_name
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal 'a-1', v_spec.full_name
end
def test_name
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal 'a', v_spec.name
end
def test_platform
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal Gem::Platform::RUBY, v_spec.platform
end
def test_source
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, @spec
assert_equal Gem::Source::Vendor.new, v_spec.source
end
def test_version
spec = Gem::Specification.new 'a', 1
v_spec = Gem::DependencyResolver::VendorSpecification.new @set, spec
assert_equal v(1), spec.version
end
end