Skip to content

Commit

Permalink
Vendor the bundler project
Browse files Browse the repository at this point in the history
  • Loading branch information
Yehuda Katz + Carl Lerche committed Jul 21, 2009
1 parent d80316a commit e7a2496
Show file tree
Hide file tree
Showing 19 changed files with 940 additions and 0 deletions.
20 changes: 20 additions & 0 deletions railties/lib/vendor/bundler/LICENSE
@@ -0,0 +1,20 @@
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
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
52 changes: 52 additions & 0 deletions railties/lib/vendor/bundler/Rakefile
@@ -0,0 +1,52 @@
require 'rubygems' unless ENV['NO_RUBYGEMS']
require 'rake/gempackagetask'
require 'rubygems/specification'
require 'date'
require 'spec/rake/spectask'

spec = Gem::Specification.new do |s|
s.name = "bundler"
s.version = "0.0.1"
s.author = "Your Name"
s.email = "Your Email"
s.homepage = "http://example.com"
s.description = s.summary = "A gem that provides..."

s.platform = Gem::Platform::RUBY
s.has_rdoc = true
s.extra_rdoc_files = ["README", "LICENSE"]
s.summary = ""

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

s.bindir = "bin"
s.executables = %w( gem_bundler )
s.require_path = 'lib'
s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
end

task :default => :spec

desc "Run specs"
Spec::Rake::SpecTask.new do |t|
t.spec_files = FileList['spec/**/*_spec.rb']
t.spec_opts = %w(-fs --color)
end


Rake::GemPackageTask.new(spec) do |pkg|
pkg.gem_spec = spec
end

desc "install the gem locally"
task :install => [:package] do
sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
end

desc "create a gemspec file"
task :make_spec do
File.open("#{GEM}.gemspec", "w") do |file|
file.puts spec.to_ruby
end
end
40 changes: 40 additions & 0 deletions railties/lib/vendor/bundler/bin/gem_bundler
@@ -0,0 +1,40 @@
#!/usr/bin/env ruby
require "optparse"
require "bundler"

options = {}

parser = OptionParser.new do |op|
op.banner = "Usage: gem_bundler [OPTIONS] [PATH]"

op.on("-m", "--manifest MANIFEST") do |manifest|
options[:manifest] = manifest
end

op.on_tail("-h", "--help", "Show this message") do
puts op
exit
end
end
parser.parse!

options[:path] = ARGV.shift

unless options[:path]
puts parser
puts %(
[PATH] must be specified
)
exit
end

unless options[:manifest] && File.exist?(options[:manifest])
puts parser
puts %(
MANIFEST must be a valid manifest file
)
exit
end


Bundler.run(options)
24 changes: 24 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler.rb
@@ -0,0 +1,24 @@
require 'logger'
require 'set'
# Required elements of rubygems
require "rubygems/remote_fetcher"
require "rubygems/installer"

require "bundler/gem_bundle"
require "bundler/installer"
require "bundler/finder"
require "bundler/gem_specification"
require "bundler/resolver"
require "bundler/manifest"
require "bundler/dependency"
require "bundler/runtime"
require "bundler/cli"

module Bundler
VERSION = "0.5.0"

def self.run(options = {})
manifest = ManifestBuilder.load(options[:path], options[:manifest])
manifest.install
end
end
24 changes: 24 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler/cli.rb
@@ -0,0 +1,24 @@
module Bundler
module CLI

def default_manifest
current = Pathname.new(Dir.pwd)

begin
manifest = current.join("Gemfile")
return manifest.to_s if File.exist?(manifest)
current = current.parent
end until current.root?
nil
end

module_function :default_manifest

def default_path
Pathname.new(File.dirname(default_manifest)).join("vendor").join("gems").to_s
end

module_function :default_path

end
end
35 changes: 35 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler/dependency.rb
@@ -0,0 +1,35 @@
module Bundler
class Dependency

attr_reader :name, :version, :require_as, :only, :except

def initialize(name, options = {})
options.each do |k, v|
options[k.to_s] = v
end

@name = name
@version = options["version"] || ">= 0"
@require_as = Array(options["require_as"] || name)
@only = Array(options["only"]).map {|e| e.to_s } if options["only"]
@except = Array(options["except"]).map {|e| e.to_s } if options["except"]
end

def in?(environment)
environment = environment.to_s

return false unless !@only || @only.include?(environment)
return false if @except && @except.include?(environment)
true
end

def to_s
to_gem_dependency.to_s
end

def to_gem_dependency
@gem_dep ||= Gem::Dependency.new(name, version)
end

end
end
42 changes: 42 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler/finder.rb
@@ -0,0 +1,42 @@
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 = Resolver.resolve(dependencies, self)
resolved && GemBundle.new(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|
next unless Gem::Platform.match(spec.platform)
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
23 changes: 23 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb
@@ -0,0 +1,23 @@
module Bundler
class GemBundle < Array
def download(directory)
FileUtils.mkdir_p(directory)

current = Dir[File.join(directory, "cache", "*.gem*")]

each do |spec|
cached = File.join(directory, "cache", "#{spec.full_name}.gem")

unless File.file?(cached)
Gem::RemoteFetcher.fetcher.download(spec, spec.source, directory)
end

current.delete(cached)
end

current.each { |file| File.delete(file) }

self
end
end
end
10 changes: 10 additions & 0 deletions railties/lib/vendor/bundler/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
44 changes: 44 additions & 0 deletions railties/lib/vendor/bundler/lib/bundler/installer.rb
@@ -0,0 +1,44 @@
module Bundler
class Installer
def initialize(path)
if !File.directory?(path)
raise ArgumentError, "#{path} is not a directory"
elsif !File.directory?(File.join(path, "cache"))
raise ArgumentError, "#{path} is not a valid environment (it does not contain a cache directory)"
end

@path = path
@gems = Dir[(File.join(path, "cache", "*.gem"))]
end

def install(options = {})
bin_dir = options[:bin_dir] ||= File.join(@path, "bin")

specs = Dir[File.join(@path, "specifications", "*.gemspec")]
gems = Dir[File.join(@path, "gems", "*")]

@gems.each do |gem|
name = File.basename(gem).gsub(/\.gem$/, '')
installed = specs.any? { |g| File.basename(g) == "#{name}.gemspec" } &&
gems.any? { |g| File.basename(g) == name }

unless installed
installer = Gem::Installer.new(gem, :install_dir => @path,
:ignore_dependencies => true,
:env_shebang => true,
:wrappers => true,
:bin_dir => bin_dir)
installer.install
end

# remove this spec
specs.delete_if { |g| File.basename(g) == "#{name}.gemspec"}
gems.delete_if { |g| File.basename(g) == name }
end

(specs + gems).each do |path|
FileUtils.rm_rf(path)
end
end
end
end

0 comments on commit e7a2496

Please sign in to comment.