diff options
-rw-r--r-- | lib/bundler.rb | 5 | ||||
-rw-r--r-- | lib/bundler/cli.rb | 3 | ||||
-rw-r--r-- | lib/bundler/dependency.rb | 4 | ||||
-rw-r--r-- | lib/bundler/environment.rb | 11 | ||||
-rw-r--r-- | lib/bundler/installer.rb | 30 | ||||
-rw-r--r-- | lib/bundler/rubygems.rb | 8 | ||||
-rw-r--r-- | spec/install/gems_spec.rb | 21 | ||||
-rw-r--r-- | spec/support/helpers.rb | 2 |
8 files changed, 67 insertions, 17 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index 2a53e2ee6b..8e47d6f582 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -31,8 +31,9 @@ module Bundler @ui = ui end - def self.setup(gemfile = default_gemfile) - load(gemfile).setup + def self.setup(*groups) + gemfile = default_gemfile + load(gemfile).setup(*groups) end def self.load(gemfile = default_gemfile) diff --git a/lib/bundler/cli.rb b/lib/bundler/cli.rb index f0c144d06e..d700caa0ad 100644 --- a/lib/bundler/cli.rb +++ b/lib/bundler/cli.rb @@ -49,8 +49,9 @@ module Bundler end desc "install", "Install the current environment to the system" + method_option :without, :type => :array, :banner => "Exclude gems thar are part of the specified named group" def install - Installer.install(Bundler.root, Bundler.definition) + Installer.install(Bundler.root, Bundler.definition, options) end desc "lock", "Locks a resolve" diff --git a/lib/bundler/dependency.rb b/lib/bundler/dependency.rb index 21ebd82843..253efafd57 100644 --- a/lib/bundler/dependency.rb +++ b/lib/bundler/dependency.rb @@ -2,12 +2,12 @@ require 'rubygems/dependency' module Bundler class Dependency < Gem::Dependency - attr_accessor :source, :group + attr_accessor :source def initialize(name, version, options = {}, &blk) super(name, version) - @group = options[:group] + @group = options["group"] end end end
\ No newline at end of file diff --git a/lib/bundler/environment.rb b/lib/bundler/environment.rb index ba8f9273f4..b5d52d9f99 100644 --- a/lib/bundler/environment.rb +++ b/lib/bundler/environment.rb @@ -7,15 +7,15 @@ module Bundler @definition = definition end - def setup + def setup(*groups) # Has to happen first cripple_rubygems # Activate the specs - specs.each do |spec| + specs_for(*groups).each do |spec| Gem.loaded_specs[spec.name] = spec + $LOAD_PATH.unshift(*spec.load_paths) end - $LOAD_PATH.unshift(*load_paths) self end @@ -29,6 +29,11 @@ module Bundler write_rb_lock end + def specs_for(*groups) + return specs if groups.empty? + specs.select { |s| (s.groups & groups).any? } + end + def specs @specs ||= Resolver.resolve(@definition.actual_dependencies, index) end diff --git a/lib/bundler/installer.rb b/lib/bundler/installer.rb index 22db01b44e..9ee104d234 100644 --- a/lib/bundler/installer.rb +++ b/lib/bundler/installer.rb @@ -2,8 +2,8 @@ require 'rubygems/dependency_installer' module Bundler class Installer - def self.install(root, definition) - new(root, definition).run + def self.install(root, definition, options) + new(root, definition).run(options) end attr_reader :root @@ -13,14 +13,17 @@ module Bundler @definition = definition end - def run + def run(options) if dependencies.empty? Bundler.ui.warn "The Gemfile specifies no dependencies" return end + without = options[:without] ? options[:without].map {|w| w.to_sym } : [] + specs.each do |spec| next unless spec.source.respond_to?(:install) + next if (spec.groups & without).any? spec.source.install(spec) end @@ -32,7 +35,7 @@ module Bundler end def specs - @specs ||= resolve_locally || resolve_remotely + @specs ||= group_specs(resolve_locally || resolve_remotely) end private @@ -62,8 +65,25 @@ module Bundler specs end + def group_specs(specs) + dependencies.each do |d| + spec = specs.find { |s| s.name == d.name } + group_spec(specs, spec, d.group) + end + specs + end + + def group_spec(specs, spec, group) + spec.groups << group + spec.groups.uniq! + spec.dependencies.each do |d| + spec = specs.find { |s| s.name == d.name } + group_spec(specs, spec, group) + end + end + def unambiguous?(dep) - dep.version_requirements.requirements.all? { |op,_| op == '=' } + dep.version_requirements.requirements.all? { |op,_| op == '=' } end def index diff --git a/lib/bundler/rubygems.rb b/lib/bundler/rubygems.rb index 498f9f85ae..55c9af23de 100644 --- a/lib/bundler/rubygems.rb +++ b/lib/bundler/rubygems.rb @@ -10,5 +10,13 @@ module Gem def load_paths require_paths.map {|p| File.join(full_gem_path, p) } end + + def groups + @groups ||= [] + end + end + + class Dependency + attr_accessor :group end end
\ No newline at end of file diff --git a/spec/install/gems_spec.rb b/spec/install/gems_spec.rb index bf2d2d8b0e..c727cc5c57 100644 --- a/spec/install/gems_spec.rb +++ b/spec/install/gems_spec.rb @@ -171,7 +171,7 @@ describe "gemfile install with gem sources" do end describe "when excluding groups" do - it "does not install gems from the excluded group" do + before :each do install_gemfile <<-G, 'without' => 'emo' source "file://#{gem_repo1}" gem "rack" @@ -179,9 +179,24 @@ describe "gemfile install with gem sources" do gem "activesupport", "2.3.5" end G + end - should_be_installed "rack 1.0.0" - should_not_be_installed "activesupport 2.3.5" + it "installs gems in the default group" do + out = ruby <<-G + begin ; require 'rubygems' ; require 'rack' ; puts "WIN" ; end + G + out.should == "WIN" + end + + it "does not install gems from the excluded group" do + out = ruby <<-G + begin ; require 'rubygems' ; require 'activesupport' + rescue LoadError + puts "WIN" + end + G + + out.should == 'WIN' end end end
\ No newline at end of file diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 0f672364fd..72c0121da9 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -62,7 +62,7 @@ module Spec def install_gemfile(*args) gemfile(*args) opts = args.last.is_a?(Hash) ? args.last : {} - bundle :install + bundle :install, opts end def install_gems(*gems) |