2011-01-18 19:08:49 -05:00
|
|
|
######################################################################
|
|
|
|
# This file is imported from the rubygems project.
|
|
|
|
# DO NOT make modifications in this repo. They _will_ be reverted!
|
|
|
|
# File a patch instead and assign it to Ryan Davis or Eric Hodel.
|
|
|
|
######################################################################
|
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/command'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/command_manager'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/install_update_options'
|
|
|
|
require 'rubygems/local_remote_options'
|
2008-06-17 18:04:18 -04:00
|
|
|
require 'rubygems/spec_fetcher'
|
2007-11-10 02:48:56 -05:00
|
|
|
require 'rubygems/version_option'
|
2008-03-31 18:40:06 -04:00
|
|
|
require 'rubygems/commands/install_command'
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
class Gem::Commands::UpdateCommand < Gem::Command
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
include Gem::InstallUpdateOptions
|
|
|
|
include Gem::LocalRemoteOptions
|
|
|
|
include Gem::VersionOption
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def initialize
|
|
|
|
super 'update',
|
2007-11-10 02:48:56 -05:00
|
|
|
'Update the named gems (or all installed gems) in the local repository',
|
2008-06-17 18:04:18 -04:00
|
|
|
:generate_rdoc => true,
|
2009-06-09 17:38:59 -04:00
|
|
|
:generate_ri => true,
|
2011-01-18 19:08:49 -05:00
|
|
|
:force => false
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_install_update_options
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
OptionParser.accept Gem::Version do |value|
|
|
|
|
Gem::Version.new value
|
|
|
|
|
|
|
|
value
|
|
|
|
end
|
|
|
|
|
|
|
|
add_option('--system [VERSION]', Gem::Version,
|
2007-12-20 03:39:12 -05:00
|
|
|
'Update the RubyGems system software') do |value, options|
|
2011-03-01 04:41:32 -05:00
|
|
|
value = true unless value
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
options[:system] = value
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
add_local_remote_options
|
|
|
|
add_platform_option
|
2010-02-21 21:52:35 -05:00
|
|
|
add_prerelease_option "as update targets"
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def arguments # :nodoc:
|
|
|
|
"GEMNAME name of gem to update"
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
def defaults_str # :nodoc:
|
2011-01-18 19:08:49 -05:00
|
|
|
"--rdoc --ri --no-force --install-dir #{Gem.dir}"
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def usage # :nodoc:
|
|
|
|
"#{program_name} GEMNAME [GEMNAME ...]"
|
|
|
|
end
|
|
|
|
|
|
|
|
def execute
|
2011-03-01 04:41:32 -05:00
|
|
|
@installer = Gem::DependencyInstaller.new options
|
|
|
|
@updated = []
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
hig = {}
|
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
if options[:system] then
|
2011-03-01 04:41:32 -05:00
|
|
|
update_rubygems
|
2011-01-18 19:08:49 -05:00
|
|
|
return
|
2007-12-20 03:39:12 -05:00
|
|
|
else
|
2008-03-31 18:40:06 -04:00
|
|
|
say "Updating installed gems"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
hig = {} # highest installed gems
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
Gem.source_index.each do |name, spec|
|
|
|
|
if hig[spec.name].nil? or hig[spec.name].version < spec.version then
|
|
|
|
hig[spec.name] = spec
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
gems_to_update = which_to_update hig, options[:args]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
updated = update_gems gems_to_update
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
if updated.empty? then
|
|
|
|
say "Nothing to update"
|
2007-12-20 03:39:12 -05:00
|
|
|
else
|
2011-01-18 19:08:49 -05:00
|
|
|
say "Gems updated: #{updated.map { |spec| spec.name }.join ', '}"
|
2009-06-09 17:38:59 -04:00
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
if options[:generate_ri] then
|
|
|
|
updated.each do |gem|
|
|
|
|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_ri
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
Gem::DocManager.update_ri_cache
|
|
|
|
end
|
|
|
|
|
|
|
|
if options[:generate_rdoc] then
|
|
|
|
updated.each do |gem|
|
|
|
|
Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
|
2009-06-09 17:38:59 -04:00
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2011-03-01 04:41:32 -05:00
|
|
|
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
|
|
|
|
|
2008-09-25 06:13:50 -04:00
|
|
|
##
|
2011-03-01 04:41:32 -05:00
|
|
|
# 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
|
2008-09-25 06:13:50 -04:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
args = []
|
2011-03-01 04:41:32 -05:00
|
|
|
args << '--prefix' << Gem.prefix if Gem.prefix
|
2007-12-20 03:39:12 -05:00
|
|
|
args << '--no-rdoc' unless options[:generate_rdoc]
|
|
|
|
args << '--no-ri' unless options[:generate_ri]
|
2008-04-11 16:57:02 -04:00
|
|
|
args << '--no-format-executable' if options[:no_format_executable]
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
update_dir = File.join Gem.dir, 'gems', "rubygems-update-#{version}"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
Dir.chdir update_dir do
|
|
|
|
say "Installing RubyGems #{version}"
|
|
|
|
setup_cmd = "#{Gem.ruby} setup.rb #{args.join ' '}"
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
# Make sure old rubygems isn't loaded
|
2007-12-27 08:33:04 -05:00
|
|
|
old = ENV["RUBYOPT"]
|
2011-03-01 04:41:32 -05:00
|
|
|
ENV.delete("RUBYOPT") if old
|
|
|
|
installed = system setup_cmd
|
|
|
|
say "RubyGems system software updated" if installed
|
2007-12-27 08:33:04 -05:00
|
|
|
ENV["RUBYOPT"] = old if old
|
2007-12-20 03:39:12 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2008-06-17 18:04:18 -04:00
|
|
|
def which_to_update(highest_installed_gems, gem_names)
|
2007-12-20 03:39:12 -05:00
|
|
|
result = []
|
2007-11-10 02:48:56 -05:00
|
|
|
|
2007-12-20 03:39:12 -05:00
|
|
|
highest_installed_gems.each do |l_name, l_spec|
|
2008-06-17 18:04:18 -04:00
|
|
|
next if not gem_names.empty? and
|
|
|
|
gem_names.all? { |name| /#{name}/ !~ l_spec.name }
|
|
|
|
|
|
|
|
dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
|
|
|
|
|
2011-01-18 19:08:49 -05:00
|
|
|
fetcher = Gem::SpecFetcher.fetcher
|
|
|
|
spec_tuples = fetcher.find_matching dependency
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2010-11-08 15:58:42 -05:00
|
|
|
matching_gems = spec_tuples.select do |(name, _, platform),|
|
2008-06-17 18:04:18 -04:00
|
|
|
name == l_name and Gem::Platform.match platform
|
|
|
|
end
|
|
|
|
|
2010-11-08 15:58:42 -05:00
|
|
|
highest_remote_gem = matching_gems.sort_by do |(_, version),|
|
2008-06-17 18:04:18 -04:00
|
|
|
version
|
|
|
|
end.last
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
if highest_remote_gem and
|
2008-06-17 18:04:18 -04:00
|
|
|
l_spec.version < highest_remote_gem.first[1] then
|
2007-12-20 03:39:12 -05:00
|
|
|
result << l_name
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
|
|
|
result
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|
2007-11-10 02:48:56 -05:00
|
|
|
end
|
2007-12-20 03:39:12 -05:00
|
|
|
|