ruby-changes:31269
From: drbrain <ko1@a...>
Date: Fri, 18 Oct 2013 10:57:06 +0900 (JST)
Subject: [ruby-changes:31269] drbrain:r43348 (trunk): Commit miss for r43347
drbrain 2013-10-18 10:57:00 +0900 (Fri, 18 Oct 2013) New Revision: 43348 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43348 Log: Commit miss for r43347 Added files: trunk/lib/rubygems/dependency_resolver/vendor_set.rb trunk/lib/rubygems/dependency_resolver/vendor_specification.rb trunk/lib/rubygems/source/vendor.rb trunk/test/rubygems/test_gem_dependency_resolver_vendor_set.rb trunk/test/rubygems/test_gem_dependency_resolver_vendor_specification.rb Index: lib/rubygems/dependency_resolver/vendor_specification.rb =================================================================== --- lib/rubygems/dependency_resolver/vendor_specification.rb (revision 0) +++ lib/rubygems/dependency_resolver/vendor_specification.rb (revision 43348) @@ -0,0 +1,44 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/dependency_resolver/vendor_specification.rb#L1 +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 + Property changes on: lib/rubygems/dependency_resolver/vendor_specification.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: lib/rubygems/dependency_resolver/vendor_set.rb =================================================================== --- lib/rubygems/dependency_resolver/vendor_set.rb (revision 0) +++ lib/rubygems/dependency_resolver/vendor_set.rb (revision 43348) @@ -0,0 +1,66 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/dependency_resolver/vendor_set.rb#L1 +## +# 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 + Property changes on: lib/rubygems/dependency_resolver/vendor_set.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: lib/rubygems/source/vendor.rb =================================================================== --- lib/rubygems/source/vendor.rb (revision 0) +++ lib/rubygems/source/vendor.rb (revision 43348) @@ -0,0 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/lib/rubygems/source/vendor.rb#L1 +## +# This represents a vendored source that is similar to an installed gem. + +class Gem::Source::Vendor < Gem::Source::Installed +end + Property changes on: lib/rubygems/source/vendor.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: test/rubygems/test_gem_dependency_resolver_vendor_set.rb =================================================================== --- test/rubygems/test_gem_dependency_resolver_vendor_set.rb (revision 0) +++ test/rubygems/test_gem_dependency_resolver_vendor_set.rb (revision 43348) @@ -0,0 +1,49 @@ https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_dependency_resolver_vendor_set.rb#L1 +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 + Property changes on: test/rubygems/test_gem_dependency_resolver_vendor_set.rb ___________________________________________________________________ Added: svn:eol-style + LF Index: test/rubygems/test_gem_dependency_resolver_vendor_specification.rb =================================================================== --- test/rubygems/test_gem_dependency_resolver_vendor_specification.rb (revision 0) +++ test/rubygems/test_gem_dependency_resolver_vendor_specification.rb (revision 43348) @@ -0,0 +1,87 @@ https://github.com/ruby/ruby/blob/trunk/test/rubygems/test_gem_dependency_resolver_vendor_specification.rb#L1 +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 + Property changes on: test/rubygems/test_gem_dependency_resolver_vendor_specification.rb ___________________________________________________________________ Added: svn:eol-style + LF -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/