diff options
author | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 09:41:32 +0000 |
---|---|---|
committer | ryan <ryan@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2011-03-01 09:41:32 +0000 |
commit | 25a9b62d45ddd60a231272567c7dda9337da9b62 (patch) | |
tree | e72ba4c9c01cba5fb510eb1eafaba76d998baf4c /lib/rubygems/commands | |
parent | 86bb0af7ea3b50f72e6845a6f5f64cb1b23fd279 (diff) | |
download | ruby-25a9b62d45ddd60a231272567c7dda9337da9b62.tar.gz |
Import rubygems 1.6.0 (released version @ 58d8a0b9)
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30996 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems/commands')
-rw-r--r-- | lib/rubygems/commands/owner_command.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/commands/pristine_command.rb | 8 | ||||
-rw-r--r-- | lib/rubygems/commands/push_command.rb | 12 | ||||
-rw-r--r-- | lib/rubygems/commands/setup_command.rb | 11 | ||||
-rw-r--r-- | lib/rubygems/commands/uninstall_command.rb | 5 | ||||
-rw-r--r-- | lib/rubygems/commands/unpack_command.rb | 26 | ||||
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 137 |
7 files changed, 118 insertions, 86 deletions
diff --git a/lib/rubygems/commands/owner_command.rb b/lib/rubygems/commands/owner_command.rb index 8b770e6f54..34f4efaa59 100644 --- a/lib/rubygems/commands/owner_command.rb +++ b/lib/rubygems/commands/owner_command.rb @@ -23,6 +23,7 @@ class Gem::Commands::OwnerCommand < Gem::Command def initialize super 'owner', description add_proxy_option + add_key_option defaults.merge! :add => [], :remove => [] add_option '-a', '--add EMAIL', 'Add an owner' do |value, options| @@ -45,7 +46,7 @@ class Gem::Commands::OwnerCommand < Gem::Command def show_owners name response = rubygems_api_request :get, "api/v1/gems/#{name}/owners.yaml" do |request| - request.add_field "Authorization", Gem.configuration.rubygems_api_key + request.add_field "Authorization", api_key end with_response response do |resp| @@ -70,7 +71,7 @@ class Gem::Commands::OwnerCommand < Gem::Command owners.each do |owner| response = rubygems_api_request method, "api/v1/gems/#{name}/owners" do |request| request.set_form_data 'email' => owner - request.add_field "Authorization", Gem.configuration.rubygems_api_key + request.add_field "Authorization", api_key end with_response response diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb index 64ea8ce91c..9a0b2e9f11 100644 --- a/lib/rubygems/commands/pristine_command.rb +++ b/lib/rubygems/commands/pristine_command.rb @@ -79,11 +79,13 @@ revert the gem. say "Restoring gem(s) to pristine condition..." specs.each do |spec| - gem = Dir[File.join(Gem.dir, 'cache', spec.file_name)].first + gem = spec.cache_gem if gem.nil? then - alert_error "Cached gem for #{spec.full_name} not found, use `gem install` to restore" - next + say "Cached gem for #{spec.full_name} not found, attempting to fetch..." + dep = Gem::Dependency.new spec.name, spec.version + Gem::RemoteFetcher.fetcher.download_to_cache dep + gem = spec.cache_gem end # TODO use installer options diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb index e72b74ebbf..c85a259564 100644 --- a/lib/rubygems/commands/push_command.rb +++ b/lib/rubygems/commands/push_command.rb @@ -27,7 +27,8 @@ class Gem::Commands::PushCommand < Gem::Command def initialize super 'push', description add_proxy_option - + add_key_option + add_option( '--host HOST', 'Push to another gemcutter-compatible host' @@ -42,17 +43,20 @@ class Gem::Commands::PushCommand < Gem::Command end def send_gem name - say "Pushing gem to #{options[:host] || Gem.host}..." - args = [:post, "api/v1/gems"] args << options[:host] if options[:host] + if Gem.latest_rubygems_version < Gem::Version.new(Gem::VERSION) then + alert_error "Using beta/unreleased version of rubygems. Not pushing." + terminate_interaction 1 + end + response = rubygems_api_request(*args) do |request| request.body = Gem.read_binary name request.add_field "Content-Length", request.body.size request.add_field "Content-Type", "application/octet-stream" - request.add_field "Authorization", Gem.configuration.rubygems_api_key + request.add_field "Authorization", api_key end with_response response diff --git a/lib/rubygems/commands/setup_command.rb b/lib/rubygems/commands/setup_command.rb index f40733a3ed..9090353e3b 100644 --- a/lib/rubygems/commands/setup_command.rb +++ b/lib/rubygems/commands/setup_command.rb @@ -33,13 +33,7 @@ class Gem::Commands::SetupCommand < Gem::Command end add_option '--[no-]vendor', - 'Install into vendorlibdir not sitelibdir', - '(Requires Ruby 1.8.7)' do |vendor, options| - if vendor and Gem.ruby_version < Gem::Version.new('1.8.7') then - raise OptionParser::InvalidOption, - "requires ruby 1.8.7+ (you have #{Gem.ruby_version})" - end - + 'Install into vendorlibdir not sitelibdir' do |vendor, options| options[:site_or_vendor] = vendor ? :vendorlibdir : :sitelibdir end @@ -61,7 +55,7 @@ class Gem::Commands::SetupCommand < Gem::Command end def check_ruby_version - required_version = Gem::Requirement.new '>= 1.8.6' + required_version = Gem::Requirement.new '>= 1.8.7' unless required_version.satisfied_by? Gem.ruby_version then alert_error "Expected Ruby version #{required_version}, is #{Gem.ruby_version}" @@ -341,7 +335,6 @@ abort "#{deprecation_message}" require 'rdoc/rdoc' - args << '--quiet' args << '--main' << 'README.rdoc' args << '.' args << 'README.rdoc' << 'UPGRADING.rdoc' diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 52d5b03edb..d190777825 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -55,6 +55,11 @@ class Gem::Commands::UninstallCommand < Gem::Command options[:user_install] = value end + add_option('--[no-]format-executable', + 'Assume executable names match Ruby\'s prefix and suffix.') do |value, options| + options[:format_executable] = value + end + add_version_option add_platform_option end diff --git a/lib/rubygems/commands/unpack_command.rb b/lib/rubygems/commands/unpack_command.rb index ac1d376106..ef0d65e073 100644 --- a/lib/rubygems/commands/unpack_command.rb +++ b/lib/rubygems/commands/unpack_command.rb @@ -7,6 +7,7 @@ require 'rubygems/command' require 'rubygems/installer' require 'rubygems/version_option' +require 'rubygems/remote_fetcher' class Gem::Commands::UnpackCommand < Gem::Command @@ -39,16 +40,6 @@ class Gem::Commands::UnpackCommand < Gem::Command "#{program_name} GEMNAME" end - def download dependency - found = Gem::SpecFetcher.fetcher.fetch dependency - - return if found.empty? - - spec, source_uri = found.first - - Gem::RemoteFetcher.fetcher.download spec, source_uri - end - #-- # TODO: allow, e.g., 'gem unpack rake-0.3.1'. Find a general solution for # this, so that it works for uninstall as well. (And check other commands @@ -79,8 +70,9 @@ class Gem::Commands::UnpackCommand < Gem::Command # TODO: see comments in get_path() about general service. def find_in_cache(filename) - Gem.path.each do |gem_dir| - this_path = File.join gem_dir, 'cache', filename + + Gem.path.each do |path| + this_path = Gem.cache_gem(filename, path) return this_path if File.exist? this_path end @@ -111,15 +103,17 @@ class Gem::Commands::UnpackCommand < Gem::Command selected = specs.sort_by { |s| s.version }.last - return download(dependency) if selected.nil? + return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless + selected return unless dependency.name =~ /^#{selected.name}$/i # We expect to find (basename).gem in the 'cache' directory. Furthermore, # the name match must be exact (ignoring case). - - path = find_in_cache(selected.file_name) - return download(dependency) unless path + + path = find_in_cache selected.file_name + + return Gem::RemoteFetcher.fetcher.download_to_cache(dependency) unless path path end diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb index b2f69a5b52..b7c65eb2a4 100644 --- a/lib/rubygems/commands/update_command.rb +++ b/lib/rubygems/commands/update_command.rb @@ -27,8 +27,16 @@ class Gem::Commands::UpdateCommand < Gem::Command add_install_update_options - add_option('--system', + OptionParser.accept Gem::Version do |value| + Gem::Version.new value + + value + end + + add_option('--system [VERSION]', Gem::Version, 'Update the RubyGems system software') do |value, options| + value = true unless value + options[:system] = value end @@ -50,33 +58,13 @@ class Gem::Commands::UpdateCommand < Gem::Command end def execute + @installer = Gem::DependencyInstaller.new options + @updated = [] + hig = {} if options[:system] then - say "Updating RubyGems" - - unless options[:args].empty? then - raise "No gem names are allowed with the --system option" - end - - rubygems_update = Gem::Specification.new - rubygems_update.name = 'rubygems-update' - rubygems_update.version = Gem::Version.new Gem::VERSION - hig['rubygems-update'] = rubygems_update - - options[:user_install] = false - - Gem.source_index.refresh! - - update_gems = Gem.source_index.find_name 'rubygems-update' - - latest_update_gem = update_gems.sort_by { |s| s.version }.last - - say "Updating RubyGems to #{latest_update_gem.version}" - installed = do_rubygems_update latest_update_gem.version - - say "RubyGems system software updated" if installed - + update_rubygems return else say "Updating installed gems" @@ -92,28 +80,7 @@ class Gem::Commands::UpdateCommand < Gem::Command gems_to_update = which_to_update hig, options[:args] - updated = [] - - installer = Gem::DependencyInstaller.new options - - gems_to_update.uniq.sort.each do |name| - next if updated.any? { |spec| spec.name == name } - success = false - - say "Updating #{name}" - begin - installer.install name - success = true - rescue Gem::InstallError => e - alert_error "Error installing #{name}:\n\t#{e.message}" - success = false - end - - installer.installed_gems.each do |spec| - updated << spec - say "Successfully installed #{spec.full_name}" if success - end - end + updated = update_gems gems_to_update if updated.empty? then say "Nothing to update" @@ -136,12 +103,77 @@ class Gem::Commands::UpdateCommand < Gem::Command end end + def update_gem name, version = Gem::Requirement.default + return if @updated.any? { |spec| spec.name == name } + success = false + + say "Updating #{name}" + begin + @installer.install name, version + success = true + rescue Gem::InstallError => e + alert_error "Error installing #{name}:\n\t#{e.message}" + success = false + end + + @installer.installed_gems.each do |spec| + @updated << spec + say "Successfully installed #{spec.full_name}" if success + end + end + + def update_gems gems_to_update + gems_to_update.uniq.sort.each do |name| + update_gem name + end + + @updated + end + ## - # Update the RubyGems software to +version+. + # Update RubyGems software to the latest version. + + def update_rubygems + unless options[:args].empty? then + alert_error "Gem names are not allowed with the --system option" + terminate_interaction 1 + end + + options[:user_install] = false + + version = options[:system] + if version == true then + version = Gem::Version.new Gem::VERSION + requirement = Gem::Requirement.new ">= #{Gem::VERSION}" + else + version = Gem::Version.new version + requirement = Gem::Requirement.new version + end + + rubygems_update = Gem::Specification.new + rubygems_update.name = 'rubygems-update' + rubygems_update.version = version + + hig = { + 'rubygems-update' => rubygems_update + } + + gems_to_update = which_to_update hig, options[:args] + + if gems_to_update.empty? then + say "Latest version currently installed. Aborting." + terminate_interaction + end + + update_gem gems_to_update.first, requirement + + Gem.source_index.refresh! + + installed_gems = Gem.source_index.find_name 'rubygems-update', requirement + version = installed_gems.last.version - def do_rubygems_update(version) args = [] - args.push '--prefix', Gem.prefix unless Gem.prefix.nil? + args << '--prefix' << Gem.prefix if Gem.prefix args << '--no-rdoc' unless options[:generate_rdoc] args << '--no-ri' unless options[:generate_ri] args << '--no-format-executable' if options[:no_format_executable] @@ -154,8 +186,9 @@ class Gem::Commands::UpdateCommand < Gem::Command # Make sure old rubygems isn't loaded old = ENV["RUBYOPT"] - ENV.delete("RUBYOPT") - system setup_cmd + ENV.delete("RUBYOPT") if old + installed = system setup_cmd + say "RubyGems system software updated" if installed ENV["RUBYOPT"] = old if old end end |