Permalink
Browse files

Vendor the latest version of the bundler

  • Loading branch information...
1 parent e3f5fd5 commit f416f9f0aef654fea94cae10027aca866d07c659 Carl Lerche committed Sep 3, 2009
Showing with 1,389 additions and 811 deletions.
  1. +162 −0 railties/lib/vendor/bundler/README.markdown
  2. +30 −25 railties/lib/vendor/bundler/Rakefile
  3. +0 −40 railties/lib/vendor/bundler/bin/gem_bundler
  4. +19 −9 railties/lib/vendor/bundler/lib/bundler.rb
  5. +35 −15 railties/lib/vendor/bundler/lib/bundler/cli.rb
  6. +31 −0 railties/lib/vendor/bundler/lib/bundler/commands/bundle_command.rb
  7. +31 −0 railties/lib/vendor/bundler/lib/bundler/commands/exec_command.rb
  8. +26 −5 railties/lib/vendor/bundler/lib/bundler/dependency.rb
  9. +109 −0 railties/lib/vendor/bundler/lib/bundler/dsl.rb
  10. +111 −0 railties/lib/vendor/bundler/lib/bundler/environment.rb
  11. +38 −29 railties/lib/vendor/bundler/lib/bundler/finder.rb
  12. +3 −15 railties/lib/vendor/bundler/lib/bundler/gem_bundle.rb
  13. +25 −0 railties/lib/vendor/bundler/lib/bundler/gem_ext.rb
  14. +0 −10 railties/lib/vendor/bundler/lib/bundler/gem_specification.rb
  15. +0 −44 railties/lib/vendor/bundler/lib/bundler/installer.rb
  16. +0 −130 railties/lib/vendor/bundler/lib/bundler/manifest.rb
  17. +151 −0 railties/lib/vendor/bundler/lib/bundler/repository.rb
  18. +46 −0 railties/lib/vendor/bundler/lib/bundler/repository/directory_repository.rb
  19. +108 −0 railties/lib/vendor/bundler/lib/bundler/repository/gem_repository.rb
  20. +182 −12 railties/lib/vendor/bundler/lib/bundler/resolver.rb
  21. +0 −61 railties/lib/vendor/bundler/lib/bundler/resolver/builders.rb
  22. +0 −38 railties/lib/vendor/bundler/lib/bundler/resolver/engine.rb
  23. +0 −24 railties/lib/vendor/bundler/lib/bundler/resolver/inspect.rb
  24. +0 −71 railties/lib/vendor/bundler/lib/bundler/resolver/search.rb
  25. +0 −72 railties/lib/vendor/bundler/lib/bundler/resolver/stack.rb
  26. +0 −172 railties/lib/vendor/bundler/lib/bundler/resolver/state.rb
  27. +2 −39 railties/lib/vendor/bundler/lib/bundler/runtime.rb
  28. +150 −0 railties/lib/vendor/bundler/lib/bundler/source.rb
  29. +3 −0 railties/lib/vendor/bundler/lib/bundler/templates/app_script.erb
  30. +127 −0 railties/lib/vendor/bundler/lib/bundler/templates/environment.erb
@@ -0,0 +1,162 @@
+## Bundler : A gem to bundle gems
+
+ Github: http://github.com/wycats/bundler
+ Mailing list: http://groups.google.com/group/ruby-bundler
+ IRC: #carlhuda on freenode
+
+## Intro
+
+Bundler is a tool that manages gem dependencies for your ruby application. It
+takes a gem manifest file and is able to fetch, download, and install the gems
+and all child dependencies specified in this manifest. It can manage any update
+to the gem manifest file and update the bundled gems accordingly. It also lets
+you run any ruby code in context of the bundled gem environment.
+
+## Disclaimer
+
+This project is under rapid development. It is usable today, but there will be
+many changes in the near future, including to the Gemfile DSL. We will bump up
+versions with changes though. We greatly appreciate feedback.
+
+## Installation
+
+Bundler has no dependencies. Just clone the git repository and install the gem
+with the following rake task:
+
+ rake install
+
+## Usage
+
+Bundler requires a gem manifest file to be created. This should be a file named
+`Gemfile` located in the root directory of your application. After the manifest
+has been created, in your shell, cd into your application's directory and run
+`gem bundle`. This will start the bundling process.
+
+### Manifest file
+
+This is where you specify all of your application's dependencies. By default
+this should be in a file named `Gemfile` located in your application's root
+directory. The following is an example of a potential `Gemfile`. For more
+information, please refer to Bundler::ManifestBuilder.
+
+ # Specify a dependency on rails. When the bundler downloads gems,
+ # it will download rails as well as all of rails' dependencies (such as
+ # activerecord, actionpack, etc...)
+ #
+ # At least one dependency must be specified
+ gem "rails"
+
+ # Specify a dependency on rack v.1.0.0. The version is optional. If present,
+ # it can be specified the same way as with rubygems' #gem method.
+ gem "rack", "1.0.0"
+
+ # Specify a dependency rspec, but only activate that gem in the "testing"
+ # environment (read more about environments later). :except is also a valid
+ # option to specify environment restrictions.
+ gem "rspec", :only => :testing
+
+ # Add http://gems.github.com as a source that the bundler will use
+ # to find gems listed in the manifest. By default,
+ # http://gems.rubyforge.org is already added to the list.
+ #
+ # This is an optional setting.
+ source "http://gems.github.com"
+
+ # Specify where the bundled gems should be stashed. This directory will
+ # be a gem repository where all gems are downloaded to and installed to.
+ #
+ # This is an optional setting.
+ # The default is: vendor/gems
+ bundle_path "my/bundled/gems"
+
+ # Specify where gem executables should be copied to.
+ #
+ # This is an optional setting.
+ # The default is: bin
+ bin_path "my/executables"
+
+ # Specify that rubygems should be completely disabled. This means that it
+ # will be impossible to require it and that available gems will be
+ # limited exclusively to gems that have been bundled.
+ #
+ # The default is to automatically require rubygems. There is also a
+ # `disable_system_gems` option that will limit available rubygems to
+ # the ones that have been bundled.
+ disable_rubygems
+
+### Running Bundler
+
+Once a manifest file has been created, the only thing that needs to be done
+is to run the `gem bundle` command anywhere in your application. The script
+will load the manifest file, resole all the dependencies, download all
+needed gems, and install them into the specified directory.
+
+Every time an update is made to the manifest file, run `gem bundle` again to
+get the changes installed. This will only check the remote sources if your
+currently installed gems do not satisfy the `Gemfile`. If you want to force
+checking for updates on the remote sources, use the `--update` option.
+
+### Running your application
+
+The easiest way to run your application is to start it with an executable
+copied to the specified bin directory (by default, simply bin). For example,
+if the application in question is a rack app, start it with `bin/rackup`.
+This will automatically set the gem environment correctly.
+
+Another way to run arbitrary ruby code in context of the bundled gems is to
+run it with the `gem exec` command. For example:
+
+ gem exec ruby my_ruby_script.rb
+
+Yet another way is to manually require the environment file first. This is
+located in `[bundle_path]/environments/default.rb`. For example:
+
+ ruby -r vendor/gems/environment.rb my_ruby_script.rb
+
+### Using Bundler with Rails today
+
+It should be possible to use Bundler with Rails today. Here are the steps
+to follow.
+
+* In your rails app, create a Gemfile and specify the gems that your
+ application depends on. Make sure to specify rails as well:
+
+ gem "rails", "2.1.2"
+ gem "will_paginate"
+
+ # Optionally, you can disable system gems all together and only
+ # use bundled gems.
+ disable_system_gems
+
+* Run `gem bundle`
+
+* You can now use rails if you prepend `gem exec` to every call to `script/*`
+ but that isn't fun.
+
+* At the top of `config/boot.rb`, add the following line:
+
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', 'vendor', 'gems', 'environment'))
+
+In theory, this should be enough to get going.
+
+## To require rubygems or not
+
+Ideally, no gem would assume the presence of rubygems at runtime. Rubygems provides
+enough features so that this isn't necessary. However, there are a number of gems
+that require specific rubygem features.
+
+If the `disable_rubygems` option is used, Bundler will stub out the most common
+of these features, but it is possible that things will not go as intended quite
+yet. So, if you are brave, try your code without rubygems at runtime.
+
+## Known Issues
+
+* When a gem points to a git repository, the git repository will be cloned
+ every time Bundler does a gem dependency resolve.
+
+## Reporting bugs
+
+Please report all bugs on the github issue tracker for the project located
+at:
+
+ http://github.com/wycats/bundler/issues/
@@ -1,52 +1,57 @@
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.name = "bundler"
+ s.version = "0.5.0.pre"
+ s.author = "Yehuda Katz"
+ s.email = "wycats@gmail.com"
+ s.homepage = "http://github.com/wycats/bundler"
+ s.description = s.summary = "An easy way to vendor gem dependencies"
s.platform = Gem::Platform::RUBY
s.has_rdoc = true
- s.extra_rdoc_files = ["README", "LICENSE"]
- s.summary = ""
+ s.extra_rdoc_files = ["README.markdown", "LICENSE"]
- # Uncomment this to add a dependency
- # s.add_dependency "foo"
+ s.required_rubygems_version = ">= 1.3.5"
- s.bindir = "bin"
- s.executables = %w( gem_bundler )
s.require_path = 'lib'
- s.files = %w(LICENSE README Rakefile) + Dir.glob("{bin,lib,spec}/**/*")
+ s.files = %w(LICENSE README.markdown Rakefile) + Dir.glob("lib/**/*")
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)
+begin
+ require 'spec/rake/spectask'
+rescue LoadError
+ task(:spec) { $stderr.puts '`gem install rspec` to run specs' }
+else
+ desc "Run specs"
+ Spec::Rake::SpecTask.new do |t|
+ t.spec_files = FileList['spec/**/*_spec.rb'] - FileList['spec/fixtures/**/*_spec.rb']
+ t.spec_opts = %w(-fs --color)
+ end
end
-
-Rake::GemPackageTask.new(spec) do |pkg|
- pkg.gem_spec = spec
+begin
+ require 'rake/gempackagetask'
+rescue LoadError
+ task(:gem) { $stderr.puts '`gem install rake` to package gems' }
+else
+ Rake::GemPackageTask.new(spec) do |pkg|
+ pkg.gem_spec = spec
+ end
end
desc "install the gem locally"
task :install => [:package] do
- sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
+ sh %{gem install pkg/#{spec.name}-#{spec.version}}
end
desc "create a gemspec file"
task :make_spec do
- File.open("#{GEM}.gemspec", "w") do |file|
+ File.open("#{spec.name}.gemspec", "w") do |file|
file.puts spec.to_ruby
end
-end
+end
@@ -1,40 +0,0 @@
-#!/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)
@@ -1,24 +1,34 @@
+require 'pathname'
require 'logger'
require 'set'
+require 'erb'
# Required elements of rubygems
require "rubygems/remote_fetcher"
require "rubygems/installer"
require "bundler/gem_bundle"
-require "bundler/installer"
+require "bundler/source"
require "bundler/finder"
-require "bundler/gem_specification"
+require "bundler/gem_ext"
require "bundler/resolver"
-require "bundler/manifest"
-require "bundler/dependency"
-require "bundler/runtime"
+require "bundler/environment"
+require "bundler/dsl"
require "bundler/cli"
+require "bundler/repository"
+require "bundler/dependency"
module Bundler
VERSION = "0.5.0"
- def self.run(options = {})
- manifest = ManifestBuilder.load(options[:path], options[:manifest])
- manifest.install
+ class << self
+ attr_writer :logger
+
+ def logger
+ @logger ||= begin
+ logger = Logger.new(STDOUT, Logger::INFO)
+ logger.formatter = proc {|_,_,_,msg| "#{msg}\n" }
+ logger
+ end
+ end
end
-end
+end
@@ -1,24 +1,44 @@
-module Bundler
- module CLI
+require "optparse"
- def default_manifest
- current = Pathname.new(Dir.pwd)
+module Bundler
+ class CLI
+ def self.run(command, options = {})
+ new(options).run(command)
+ rescue DefaultManifestNotFound => e
+ Bundler.logger.error "Could not find a Gemfile to use"
+ exit 2
+ rescue InvalidEnvironmentName => e
+ Bundler.logger.error "Gemfile error: #{e.message}"
+ exit
+ rescue InvalidRepository => e
+ Bundler.logger.error e.message
+ exit
+ rescue VersionConflict => e
+ Bundler.logger.error e.message
+ exit
+ rescue GemNotFound => e
+ Bundler.logger.error e.message
+ exit
+ end
- begin
- manifest = current.join("Gemfile")
- return manifest.to_s if File.exist?(manifest)
- current = current.parent
- end until current.root?
- nil
+ def initialize(options)
+ @options = options
+ @manifest = Bundler::Environment.load(@options[:manifest])
end
- module_function :default_manifest
+ def bundle
+ @manifest.install(@options[:update])
+ end
- def default_path
- Pathname.new(File.dirname(default_manifest)).join("vendor").join("gems").to_s
+ def exec
+ @manifest.setup_environment
+ # w0t?
+ super(*@options[:args])
end
- module_function :default_path
+ def run(command)
+ send(command)
+ end
end
-end
+end
Oops, something went wrong.

0 comments on commit f416f9f

Please sign in to comment.