forked from wycats/bundler
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yehuda Katz + Carl Lerche
committed
Jul 7, 2009
1 parent
eedced0
commit 325ace5
Showing
12 changed files
with
175 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,5 @@ | ||
require "bundler/faster_source_index" | ||
require "bundler/fetcher" | ||
require "rubygems/remote_fetcher" | ||
require "bundler/finder" | ||
require "bundler/gem_specification" | ||
|
||
# require "rubygems" | ||
# require "rubygems/remote_fetcher" | ||
# require "pp" | ||
# | ||
# index = nil | ||
# File.open("dumped", "r") do |f| | ||
# index = Marshal.load(f.read) | ||
# end | ||
# | ||
# index = FasterSourceIndex.new(index) | ||
# | ||
# t = Time.now | ||
# | ||
# # ENV["GEM_RESOLVER_DEBUG"] = "true" | ||
# | ||
# list = { | ||
# "rails" => ">= 0" | ||
# # "merb-core" => ">= 0", | ||
# # "merb-haml" => ">= 0", | ||
# # "merb_datamapper" => ">= 0" | ||
# }.map {|k,v| Gem::Dependency.new(k, v)} | ||
# | ||
# require File.expand_path(File.join(File.dirname(__FILE__), "..", "gem_resolver", "lib", "gem_resolver")) | ||
# pp GemResolver.resolve(list, index).all_specs.map {|x| x.full_name } | ||
# | ||
# puts "TOTAL: #{Time.now - t}" | ||
# | ||
# # deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{Gem.sources.first}/Marshal.4.8.Z"); nil | ||
# # inflated = Gem.inflate deflated; nil | ||
# # index = Marshal.load(inflated); nil | ||
# # File.open("dumped", "w") do |f| | ||
# # f.puts inflated | ||
# # end | ||
require File.expand_path(File.join(File.dirname(__FILE__), "..", "gem_resolver", "lib", "gem_resolver")) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Bundler | ||
class Finder | ||
def initialize(*sources) | ||
@results = {} | ||
@index = Hash.new { |h,k| h[k] = {} } | ||
|
||
sources.each { |source| fetch(source) } | ||
end | ||
|
||
def resolve(*dependencies) | ||
resolved = GemResolver.resolve(dependencies, self) | ||
resolved && resolved.all_specs | ||
end | ||
|
||
def fetch(source) | ||
deflated = Gem::RemoteFetcher.fetcher.fetch_path("#{source}/Marshal.4.8.Z") | ||
inflated = Gem.inflate deflated | ||
|
||
append(Marshal.load(inflated), source) | ||
rescue Gem::RemoteFetcher::FetchError => e | ||
raise ArgumentError, "#{source} is not a valid source: #{e.message}" | ||
end | ||
|
||
def append(index, source) | ||
index.gems.values.each do |spec| | ||
spec.source = source | ||
@index[spec.name][spec.version] ||= spec | ||
end | ||
self | ||
end | ||
|
||
def search(dependency) | ||
@results[dependency.hash] ||= begin | ||
possibilities = @index[dependency.name].values | ||
possibilities.select do |spec| | ||
dependency =~ spec | ||
end.sort_by {|s| s.version } | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
module Gem | ||
class Specification | ||
attribute :source | ||
|
||
def source=(source) | ||
@source = source.is_a?(URI) ? source : URI.parse(source) | ||
raise ArgumentError, "The source must be an absolute URI" unless @source.absolute? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,44 @@ | ||
require File.join(File.dirname(__FILE__), "spec_helper") | ||
|
||
describe "Fetcher" do | ||
it "gets the remote index and returns a source index" do | ||
index = Bundler::Fetcher.fetch("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures") | ||
index.should be_kind_of(FasterSourceIndex) | ||
before(:each) do | ||
@source = URI.parse("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures") | ||
@other = URI.parse("file://#{File.expand_path(File.dirname(__FILE__))}/fixtures2") | ||
@finder = Bundler::Finder.new(@source, @other) | ||
end | ||
|
||
it "stashes the source in the returned gem specification" do | ||
@finder.search(Gem::Dependency.new("abstract", ">= 0")).first.source.should == @source | ||
end | ||
|
||
it "uses the first source that was passed in if multiple sources have the same gem" do | ||
@finder.search(build_dep("activerecord", "= 2.3.2")).first.source.should == @source | ||
end | ||
|
||
it "raises if the source is invalid" do | ||
lambda { Bundler::Fetcher.fetch("file://not/a/gem/source") }.should raise_error(ArgumentError) | ||
lambda { Bundler::Fetcher.fetch("http://localhost") }.should raise_error(ArgumentError) | ||
lambda { Bundler::Fetcher.fetch("http://google.com/not/a/gem/location") }.should raise_error(ArgumentError) | ||
lambda { Bundler::Finder.new.fetch("file://not/a/gem/source") }.should raise_error(ArgumentError) | ||
lambda { Bundler::Finder.new.fetch("http://localhost") }.should raise_error(ArgumentError) | ||
lambda { Bundler::Finder.new.fetch("http://google.com/not/a/gem/location") }.should raise_error(ArgumentError) | ||
end | ||
|
||
it "accepts multiple source indexes" do | ||
@finder.search(Gem::Dependency.new("abstract", ">= 0")).size.should == 1 | ||
@finder.search(Gem::Dependency.new("merb-core", ">= 0")).size.should == 2 | ||
end | ||
|
||
it "resolves rails" do | ||
specs = @finder.resolve(build_dep('rails', '>= 0')) | ||
specs.should match_gems( | ||
"rails" => ["2.3.2"], | ||
"actionpack" => ["2.3.2"], | ||
"actionmailer" => ["2.3.2"], | ||
"activerecord" => ["2.3.2"], | ||
"activeresource" => ["2.3.2"], | ||
"activesupport" => ["2.3.2"], | ||
"rake" => ["0.8.7"] | ||
) | ||
|
||
specs.select { |spec| spec.name == "activeresource" && spec.source == @other }.should have(1).item | ||
specs.select { |spec| spec.name == "activerecord" && spec.source == @source }.should have(1).item | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.expand_path(File.dirname(__FILE__) + '/spec_helper') | ||
|
||
describe "Gem::Specification" do | ||
|
||
it "is able to store the source URI of the gem as a URI" do | ||
spec = Gem::Specification.new do |s| | ||
s.name = 'greeter' | ||
s.version = '1.0' | ||
s.source = 'http://gems.rubyforge.org' | ||
end | ||
|
||
spec.source.should == URI.parse("http://gems.rubyforge.org") | ||
end | ||
|
||
it "does not consider two gem specs with different sources to be the same" do | ||
spec1 = Gem::Specification.new do |s| | ||
s.name = 'greeter' | ||
s.version = '1.0' | ||
s.source = 'http://gems.rubyforge.org' | ||
end | ||
|
||
spec2 = spec1.dup | ||
spec2.source = "http://gems.github.com" | ||
|
||
spec1.should_not == spec2 | ||
end | ||
|
||
it "can set a source that is already a URI" do | ||
source = URI.parse("http://foo") | ||
spec = Gem::Specification.new | ||
spec.source = source | ||
spec.source.should == source | ||
end | ||
|
||
it "requires a valid URI for the source" do | ||
spec = Gem::Specification.new | ||
lambda { spec.source = "fail" }.should raise_error(ArgumentError) | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters