Skip to content

Commit

Permalink
Cleaned up a bunch of file names
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed Jul 7, 2009
1 parent eedced0 commit 325ace5
Show file tree
Hide file tree
Showing 12 changed files with 175 additions and 84 deletions.
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright (c) 2009 YOUR NAME
Copyright (c) 2009 Engine Yard

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
3 changes: 1 addition & 2 deletions Rakefile
Expand Up @@ -15,13 +15,12 @@ spec = Gem::Specification.new do |s|
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = ["README", "LICENSE", 'TODO']
s.summary = SUMMARY
s.summary = ""

# Uncomment this to add a dependency
# s.add_dependency "foo"

s.require_path = 'lib'
s.autorequire = GEM
s.files = %w(LICENSE README Rakefile TODO) + Dir.glob("{lib,spec}/**/*")
end

Expand Down
4 changes: 0 additions & 4 deletions TODO

This file was deleted.

39 changes: 4 additions & 35 deletions lib/bundler.rb
@@ -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"))
19 changes: 0 additions & 19 deletions lib/bundler/faster_source_index.rb

This file was deleted.

14 changes: 0 additions & 14 deletions lib/bundler/fetcher.rb

This file was deleted.

41 changes: 41 additions & 0 deletions lib/bundler/finder.rb
@@ -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
10 changes: 10 additions & 0 deletions lib/bundler/gem_specification.rb
@@ -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
42 changes: 36 additions & 6 deletions spec/fetcher_spec.rb
@@ -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
5 changes: 2 additions & 3 deletions spec/faster_source_index_spec.rb → spec/finder_spec.rb
@@ -1,7 +1,6 @@
require File.join(File.dirname(__FILE__), "spec_helper")
require "bundler/faster_source_index"

describe "FasterSourceIndex" do
describe "Finder" do
before(:all) do
index = build_index do
add_spec "activemerchant", "1.4.1" do
Expand All @@ -14,7 +13,7 @@
end
end

@faster = FasterSourceIndex.new(index)
@faster = Bundler::Finder.new.append(index, "http://foo")
end

def only_have_specs(*names)
Expand Down
40 changes: 40 additions & 0 deletions spec/gem_specification_spec.rb
@@ -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
40 changes: 40 additions & 0 deletions spec/spec_helper.rb
Expand Up @@ -2,6 +2,46 @@
$:.push File.join(File.dirname(__FILE__), '..', 'gem_resolver', 'lib')
require "gem_resolver/builders"
require "bundler"
require "pp"

Spec::Matchers.create :match_gems do |expected|
match do |actual|
@_messages = []
@dump = {}

if actual.nil?
@_messages << "The result is nil"
next
end

actual.each do |spec|
unless spec.is_a?(Gem::Specification)
@_messages << "#{spec.gem_resolver_inspect} was expected to be a Gem::Specification, but got #{spec.class}"
next
end
@dump[spec.name.to_s] ||= []
@dump[spec.name.to_s] << spec.version.to_s
end

if @_messages.any?
@_messages.unshift "The gems #{actual.gem_resolver_inspect} were not structured as expected"
next false
end

unless @dump == expected
@_messages << "The source index was expected to have the gems:"
@_messages << expected.to_a.sort.pretty_inspect
@_messages << "but got:"
@_messages << @dump.to_a.sort.pretty_inspect
next false
end
true
end

failure_message_for_should do |actual|
@_messages.join("\n")
end
end

Spec::Runner.configure do |config|
config.include GemResolver::Builders
Expand Down

0 comments on commit 325ace5

Please sign in to comment.