buildr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vbo...@apache.org
Subject svn commit: r698695 - in /incubator/buildr/trunk/lib/buildr: core/application.rb core/util.rb packaging/gems.rb
Date Wed, 24 Sep 2008 19:17:47 GMT
Author: vborja
Date: Wed Sep 24 12:17:46 2008
New Revision: 698695

URL: http://svn.apache.org/viewvc?rev=698695&view=rev
Log:
Made Buildr::Application#load_* methods private, they should not be invoked by the user.
Moven gem runner logic into Util::Gem so that it can be reused by packaging/gems.rb

Modified:
    incubator/buildr/trunk/lib/buildr/core/application.rb
    incubator/buildr/trunk/lib/buildr/core/util.rb
    incubator/buildr/trunk/lib/buildr/packaging/gems.rb

Modified: incubator/buildr/trunk/lib/buildr/core/application.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/application.rb?rev=698695&r1=698694&r2=698695&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/application.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/application.rb Wed Sep 24 12:17:46 2008
@@ -157,26 +157,15 @@
       buildfile.prerequisites
     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.
-    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
-      end
-    end
-    private :listed_gems
-
     def run
       standard_exception_handling do
+        load_requires
         find_buildfile
         load_gems
         load_artifacts
         load_tasks
         load_buildfile
+        load_imports
         task('buildr:initialize').invoke
         top_level
       end
@@ -184,6 +173,60 @@
       @on_completion.each { |block| block.call(title, message) rescue nil }
     end
 
+    # Yields to block on successful completion. Primarily used for notifications.
+    def on_completion(&block)
+      @on_completion << block
+    end
+
+    # Yields to block on failure with exception. Primarily used for notifications.
+    def on_failure(&block)
+      @on_failure << block
+    end
+
+    # Not for external consumption.
+    def switch_to_namespace(names) #:nodoc:
+      current, @scope = @scope, names
+      begin
+        yield
+      ensure
+        @scope = current
+      end
+    end
+
+    # :call-seq:
+    #   deprecated(message)
+    #
+    # Use with deprecated methods and classes. This method automatically adds the file name
and line number,
+    # and the text 'Deprecated' before the message, and eliminated duplicate warnings. It
only warns when
+    # running in verbose mode.
+    #
+    # For example:
+    #   deprecated 'Please use new_foo instead of foo.'
+    def deprecated(message) #:nodoc:
+      return unless verbose
+      "#{caller[1]}: Deprecated: #{message}".tap do |message|
+        @deprecated ||= {}
+        unless @deprecated[message]
+          @deprecated[message] = true
+          warn message
+        end
+      end
+    end
+
+  private
+
+    # Returns Gem::Specification for every listed and installed Gem, Gem::Dependency
+    # for listed and uninstalled Gem, which is the installed before loading the buildfile.
+    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
+      end
+    end
+
     # Load artifact specs from the build.yaml file, making them available 
     # by name ( ruby symbols ).
     def load_artifacts #:nodoc:
@@ -198,35 +241,25 @@
     def load_gems #:nodoc:
       missing_deps, installed = listed_gems.partition { |gem| gem.is_a?(Gem::Dependency)
}
       unless missing_deps.empty?
-        remote = missing_deps.map { |dep| Gem::SourceInfoCache.search(dep).last || dep }
-        not_found_deps, install = remote.partition { |gem| gem.is_a?(Gem::Dependency) }
-        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 #{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
-        install.each do |spec|
-          say "Installing #{spec.full_name} ... " if verbose
-          Util.ruby 'install', spec.name, '-v', spec.version.to_s, :command => 'gem',
:sudo => true, :verbose => false
-          Gem.source_index.load_gems_in Gem::SourceIndex.installed_spec_directories
-        end
-        installed += install
+        newly_installed = Util::Gems.install(*missing_deps)
+        installed += newly_installed
       end
-
       installed.each do |spec|
         if gem(spec.name, spec.version.to_s)
-        #  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
+          # 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
       end
       @gems = installed
     end
 
-    def find_buildfile
+    def find_buildfile #:nodoc:
       here = original_dir
       Dir.chdir(here) unless Dir.pwd == here
       while ! have_rakefile
@@ -244,14 +277,16 @@
       end
     end
 
-    def load_buildfile
-      @requires.each { |name| require name }
+    def load_buildfile #:nodoc:
       info "(in #{Dir.pwd}, #{environment})"
       load File.expand_path(@rakefile) if @rakefile != ''
-      load_imports
       buildfile.enhance @requires.select { |f| File.file?(f) }.map{ |f| File.expand_path(f)
}
     end
 
+    def load_requires #:nodoc:
+      @requires.each { |name| require name }
+    end
+
     # Loads buildr.rb files from users home directory and project directory.
     # Loads custom tasks from .rake files in tasks directory.
     def load_tasks #:nodoc:
@@ -269,7 +304,6 @@
       buildfile.enhance files
       true
     end
-    private :load_tasks
 
     def display_prerequisites
       invoke_task('buildr:initialize')
@@ -280,49 +314,7 @@
         end
       end
     end
-
-    # :call-seq:
-    #   deprecated(message)
-    #
-    # Use with deprecated methods and classes. This method automatically adds the file name
and line number,
-    # and the text 'Deprecated' before the message, and eliminated duplicate warnings. It
only warns when
-    # running in verbose mode.
-    #
-    # For example:
-    #   deprecated 'Please use new_foo instead of foo.'
-    def deprecated(message) #:nodoc:
-      return unless verbose
-      "#{caller[1]}: Deprecated: #{message}".tap do |message|
-        @deprecated ||= {}
-        unless @deprecated[message]
-          @deprecated[message] = true
-          warn message
-        end
-      end
-    end
-
-    # Not for external consumption.
-    def switch_to_namespace(names) #:nodoc:
-      current, @scope = @scope, names
-      begin
-        yield
-      ensure
-        @scope = current
-      end
-    end
     
-    # Yields to block on successful completion. Primarily used for notifications.
-    def on_completion(&block)
-      @on_completion << block
-    end
-
-    # Yields to block on failure with exception. Primarily used for notifications.
-    def on_failure(&block)
-      @on_failure << block
-    end
-
-  private
-
     # Provide standard execption handling for the given block.
     def standard_exception_handling
       begin

Modified: incubator/buildr/trunk/lib/buildr/core/util.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/core/util.rb?rev=698695&r1=698694&r2=698695&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/core/util.rb (original)
+++ incubator/buildr/trunk/lib/buildr/core/util.rb Wed Sep 24 12:17:46 2008
@@ -108,7 +108,47 @@
       FileList[dirs.map { |dir| File.join(dir, '/**/{*,.*}') }].reject { |file| File.basename(file)
=~ /^[.]{1,2}$/ }
     end
 
-  end
+    # Utility methods for running gem commands
+    module Gems
+      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?
+        remote = dependencies.map { |dep| Gem::SourceInfoCache.search(dep).last || dep }
+        not_found_deps, to_install = remote.partition { |gem| gem.is_a?(Gem::Dependency)
}
+        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: incubator/buildr/trunk/lib/buildr/packaging/gems.rb
URL: http://svn.apache.org/viewvc/incubator/buildr/trunk/lib/buildr/packaging/gems.rb?rev=698695&r1=698694&r2=698695&view=diff
==============================================================================
--- incubator/buildr/trunk/lib/buildr/packaging/gems.rb (original)
+++ incubator/buildr/trunk/lib/buildr/packaging/gems.rb Wed Sep 24 12:17:46 2008
@@ -40,11 +40,11 @@
     end
 
     def install
-      Util.ruby 'install', name, :command => 'gem', :sudo => true
+      Util::Gems.command 'install', name
     end
 
     def uninstall
-      Util.ruby 'uninstall', spec.name, '-v', spec.version.to_s, :command => 'gem', :sudo
=> true
+      Util::Gems.command 'uninstall', spec.name, '-v', spec.version.to_s
     end
 
     def upload



Mime
View raw message