mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
86bb0af7ea
commit
25a9b62d45
73 changed files with 2408 additions and 719 deletions
|
@ -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
|
||||
|
||||
##
|
||||
# Update the RubyGems software to +version+.
|
||||
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 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue