You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@buildr.apache.org by do...@apache.org on 2011/07/27 13:48:19 UTC

svn commit: r1151434 - in /buildr/trunk: CHANGELOG buildr.gemspec lib/buildr/core/application.rb lib/buildr/core/util.rb lib/buildr/packaging/gems.rb spec/core/application_spec.rb

Author: donaldp
Date: Wed Jul 27 11:48:18 2011
New Revision: 1151434

URL: http://svn.apache.org/viewvc?rev=1151434&view=rev
Log:
* Upgrade to require rubygems > 1.8.6
* BUILDR-603 Remove install/uninstall actions from :gem packaging type
* BUILDR-602 Fail the build when gem dependencies are missing rather than attempting to install the dependencies
* BUILDR-601 Remove Buildr::Util::Gems

Modified:
    buildr/trunk/CHANGELOG
    buildr/trunk/buildr.gemspec
    buildr/trunk/lib/buildr/core/application.rb
    buildr/trunk/lib/buildr/core/util.rb
    buildr/trunk/lib/buildr/packaging/gems.rb
    buildr/trunk/spec/core/application_spec.rb

Modified: buildr/trunk/CHANGELOG
URL: http://svn.apache.org/viewvc/buildr/trunk/CHANGELOG?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/CHANGELOG (original)
+++ buildr/trunk/CHANGELOG Wed Jul 27 11:48:18 2011
@@ -1,4 +1,9 @@
 1.4.7 (Pending)
+* Change: Upgrade to require rubygems > 1.8.6
+* Change: BUILDR-603 Remove install/uninstall actions from :gem packaging type
+* Change: BUILDR-602 Fail the build when gem dependencies are missing rather than
+          attempting to install the dependencies
+* Change: BUILDR-601 Remove Buildr::Util::Gems
 * Change: BUILDR-600 Centralize the common ad internal requires into one location.
 * Change: Upgrade to JRuby 1.6.2
 * Change: Move to Bundler to manage the project dependencies

Modified: buildr/trunk/buildr.gemspec
URL: http://svn.apache.org/viewvc/buildr/trunk/buildr.gemspec?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/buildr.gemspec (original)
+++ buildr/trunk/buildr.gemspec Wed Jul 27 11:48:18 2011
@@ -49,6 +49,8 @@ for those one-off tasks, with a language
                           '--webcvs', 'http://svn.apache.org/repos/asf/buildr/trunk/'
   spec.post_install_message = "To get started run buildr --help"
 
+  spec.required_rubygems_version = ">= 1.8.6"
+
   # Tested against these dependencies.
   spec.add_dependency 'rake',                 '0.8.7'
   spec.add_dependency 'builder',              '2.1.2'

Modified: buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/application.rb?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/application.rb (original)
+++ buildr/trunk/lib/buildr/core/application.rb Wed Jul 27 11:48:18 2011
@@ -420,36 +420,36 @@ module Buildr
 
     # Load/install all Gems specified in build.yaml file.
     def load_gems #:nodoc:
-      missing_deps, installed = listed_gems.partition { |gem| gem.is_a?(Gem::Dependency) }
+      gems = listed_gems
+      installed, missing_deps = gems[0], gems[1]
       unless missing_deps.empty?
-        newly_installed = Util::Gems.install(*missing_deps)
-        installed += newly_installed
-      end
-      installed.each do |spec|
-        if gem(spec.name, spec.version.to_s)
-          # TODO: is this intended to load rake tasks from the installed gems?
-          # We should use a convention like .. if the gem has a _buildr.rb file, load it.
-
-          #FileList[spec.require_paths.map { |path| File.expand_path("#{path}/*.rb", spec.full_gem_path) }].
-          #  map { |path| File.basename(path) }.each { |file| require file }
-          #FileList[File.expand_path('tasks/*.rake', spec.full_gem_path)].each do |file|
-          #  Buildr.application.add_import file
-          #end
-        end
+        fail Gem::LoadError, "Build requires the gems #{missing_deps.join(', ')}, which cannot be found in the local repository. Please install the gems before attempting to build project."
       end
+      installed.each { |spec| spec.activate }
       @gems = installed
     end
 
-    # Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
-    # for listed and uninstalled Gem, which is the installed before loading the buildfile.
+    # Returns two lists. The first contains a Gem::Specification for every listed and installed
+    # Gem, the second contains a Gem::Dependency for every listed and uninstalled Gem.
     def listed_gems #:nodoc:
-      Array(settings.build['gems']).map do |dep|
-        name, trail = dep.scan(/^\s*(\S*)\s*(.*)\s*$/).first
-        versions = trail.scan(/[=><~!]{0,2}\s*[\d\.]+/)
-        versions = ['>= 0'] if versions.empty?
-        dep = Gem::Dependency.new(name, versions)
-        Gem::SourceIndex.from_installed_gems.search(dep).last || dep
+      found = []
+      missing = []
+      Array(settings.build['gems']).each do |dep|
+        name, versions = parse_gem_dependency(dep)
+        begin
+          found << Gem::Specification.find_by_name(name, versions)
+        rescue Exception
+          missing << Gem::Dependency.new(name, versions)
+        end
       end
+      return [found, missing]
+    end
+
+    def parse_gem_dependency(dep) #:nodoc:
+      name, trail = dep.scan(/^\s*(\S*)\s*(.*)\s*$/).first
+      versions = trail.scan(/[=><~!]{0,2}\s*[\d\.]+/)
+      versions = ['>= 0'] if versions.empty?
+      return name, versions
     end
 
     # Load artifact specs from the build.yaml file, making them available

Modified: buildr/trunk/lib/buildr/core/util.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/core/util.rb?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/core/util.rb (original)
+++ buildr/trunk/lib/buildr/core/util.rb Wed Jul 27 11:48:18 2011
@@ -120,58 +120,6 @@ module Buildr
       end
     end
 
-    # Utility methods for running gem commands
-    module Gems #:nodoc:
-      extend self
-
-      # Install gems specified by each Gem::Dependency if they are missing. This method prompts the user
-      # for permission before installing anything.
-      #
-      # Returns the installed Gem::Dependency objects or fails if permission not granted or when buildr
-      # is not running interactively (on a tty)
-      def install(*dependencies)
-        raise ArgumentError, "Expected at least one argument" if dependencies.empty?
-        not_found_deps = []
-        to_install = []
-        remote = dependencies.each do |dep|
-          if spec = Gem.source_index.search(dep).last
-            # Found in local repo
-            to_install << spec
-          elsif (spec = Gem::SpecFetcher.fetcher.fetch(dep, true).map { |spec, source| spec }.last)
-            # Found in remote repo
-            to_install << spec
-          else
-            # Not found anywhere
-            not_found_deps << "#{dep.name} #{dep.requirement}"
-          end
-        end
-        fail Gem::LoadError, "Build requires the gems #{not_found_deps.join(', ')}, which cannot be found in local or remote repository." unless not_found_deps.empty?
-        uses = "This build requires the gems #{to_install.map(&:full_name).join(', ')}:"
-        fail Gem::LoadError, "#{uses} to install, run Buildr interactively." unless $stdout.isatty
-        unless agree("#{uses} do you want me to install them? [Y/n]", true)
-          fail Gem::LoadError, 'Cannot build without these gems.'
-        end
-        to_install.each do |spec|
-          say "Installing #{spec.full_name} ... " if verbose
-          command 'install', spec.name, '-v', spec.version.to_s, :verbose => false
-          Gem.source_index.load_gems_in Gem::SourceIndex.installed_spec_directories
-        end
-        to_install
-      end
-
-      # Execute a GemRunner command
-      def command(cmd, *args)
-        options = Hash === args.last ? args.pop : {}
-        gem_home = ENV['GEM_HOME'] || Gem.path.find { |f| File.writable?(f) }
-        options[:sudo] = :root unless Util.win_os? || gem_home
-        options[:command] = 'gem'
-        args << options
-        args.unshift '-i', gem_home if cmd == 'install' && gem_home && !args.any?{ |a| a[/-i|--install-dir/] }
-        Util.ruby cmd, *args
-      end
-
-    end # Gems
-
   end # Util
 end
 

Modified: buildr/trunk/lib/buildr/packaging/gems.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/lib/buildr/packaging/gems.rb?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/lib/buildr/packaging/gems.rb (original)
+++ buildr/trunk/lib/buildr/packaging/gems.rb Wed Jul 27 11:48:18 2011
@@ -35,14 +35,6 @@ module Buildr
       @spec
     end
 
-    def install
-      Util::Gems.command 'install', name
-    end
-
-    def uninstall
-      Util::Gems.command 'uninstall', spec.name, '-v', spec.version.to_s
-    end
-
     def upload
       rubyforge = RubyForge.new
       rubyforge.login

Modified: buildr/trunk/spec/core/application_spec.rb
URL: http://svn.apache.org/viewvc/buildr/trunk/spec/core/application_spec.rb?rev=1151434&r1=1151433&r2=1151434&view=diff
==============================================================================
--- buildr/trunk/spec/core/application_spec.rb (original)
+++ buildr/trunk/spec/core/application_spec.rb Wed Jul 27 11:48:18 2011
@@ -181,71 +181,20 @@ describe Buildr::Application do
     end
 
     it 'should install nothing if specified gems already installed' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
+      Buildr.application.should_receive(:listed_gems).and_return([[Gem.loaded_specs['rspec']],[]])
       Util.should_not_receive(:ruby)
       lambda { Buildr.application.load_gems }.should_not raise_error
     end
 
-    it 'should fail if required gem not found in remote repository' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).at_least(:once).and_return([])
+    it 'should fail if required gem not installed' do
+      Buildr.application.should_receive(:listed_gems).and_return([[],[Gem::Dependency.new('buildr-foo', '>=1.1')]])
       lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot be found/i)
     end
 
-    it 'should fail if need to install gem and not running in interactive mode' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $stdout.should_receive(:isatty).and_return(false)
-      lambda { Buildr.application.load_gems }.should raise_error(LoadError, /this build requires the gems/i)
-    end
-
-    it 'should ask permission before installing required gems' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $terminal.should_receive(:agree).with(/install/, true)
-      lambda { Buildr.application.load_gems }.should raise_error
-    end
-
-    it 'should fail if permission not granted to install gem' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $terminal.should_receive(:agree).and_return(false)
-      lambda { Buildr.application.load_gems }.should raise_error(LoadError, /cannot build without/i)
-    end
-
-    it 'should install gem if permission granted' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $terminal.should_receive(:agree).and_return(true)
-      Util.should_receive(:ruby) do |*args|
-        args.should include('install', 'buildr-foo', '-v', '1.2')
-      end
-      Buildr.application.should_receive(:gem).and_return(false)
-      Buildr.application.load_gems
-    end
-
-    it 'should reload gem cache after installing required gems' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $terminal.should_receive(:agree).and_return(true)
-      Util.should_receive(:ruby)
-      Gem.source_index.should_receive(:load_gems_in).with(Gem::SourceIndex.installed_spec_directories)
-      Buildr.application.should_receive(:gem).and_return(false)
-      Buildr.application.load_gems
-    end
-
     it 'should load previously installed gems' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem.loaded_specs['rspec']])
-      Buildr.application.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
-      Buildr.application.load_gems
-    end
-
-    it 'should load newly installed gems' do
-      Buildr.application.should_receive(:listed_gems).and_return([Gem::Dependency.new('buildr-foo', '>=1.1')])
-      Gem.source_index.should_receive(:search).and_return([@spec])
-      $terminal.should_receive(:agree).and_return(true)
-      Util.should_receive(:ruby)
-      Buildr.application.should_receive(:gem).with('buildr-foo', @spec.version.to_s)
+      Gem.loaded_specs['rspec'].should_receive(:activate)
+      Buildr.application.should_receive(:listed_gems).and_return([[Gem.loaded_specs['rspec']],[]])
+      #Buildr.application.should_receive(:gem).with('rspec', Gem.loaded_specs['rspec'].version.to_s)
       Buildr.application.load_gems
     end
 
@@ -270,12 +219,9 @@ describe Buildr::Application do
     end
 
     def should_attempt_to_load_dependency(dep)
-      Gem.source_index.should_receive(:search).with(dep).and_return([])
-      lambda { Buildr.application.load_gems }.should raise_missing_gem_error(dep)
-    end
-
-    def raise_missing_gem_error(dep)
-      raise_error(Gem::LoadError, /Build requires the gems #{dep.name} #{dep.requirement}, which cannot be found in local or remote repository./)
+      missing_gems = Buildr.application.send(:listed_gems)[1]
+      missing_gems.size.should eql(1)
+      missing_gems[0].should eql(dep)
     end
   end