diff options
author | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-31 22:40:06 +0000 |
---|---|---|
committer | drbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-03-31 22:40:06 +0000 |
commit | 8cc45aae947d453acca029e13eb64f3f5f0bf942 () | |
tree | f9485a20c99defe1aae3f32555a41d23c2298ad8 /lib/rubygems/commands | |
parent | dc8359969ec71ece10357ba9396430db7f029e45 (diff) |
Import RubyGems 1.1.0
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | lib/rubygems/commands/cleanup_command.rb | 136 | ||||
-rw-r--r-- | lib/rubygems/commands/environment_command.rb | 20 | ||||
-rw-r--r-- | lib/rubygems/commands/fetch_command.rb | 16 | ||||
-rw-r--r-- | lib/rubygems/commands/install_command.rb | 12 | ||||
-rw-r--r-- | lib/rubygems/commands/list_command.rb | 6 | ||||
-rw-r--r-- | lib/rubygems/commands/mirror_command.rb | 2 | ||||
-rw-r--r-- | lib/rubygems/commands/query_command.rb | 57 | ||||
-rw-r--r-- | lib/rubygems/commands/sources_command.rb | 25 | ||||
-rw-r--r-- | lib/rubygems/commands/specification_command.rb | 12 | ||||
-rw-r--r-- | lib/rubygems/commands/uninstall_command.rb | 13 | ||||
-rw-r--r-- | lib/rubygems/commands/unpack_command.rb | 18 | ||||
-rw-r--r-- | lib/rubygems/commands/update_command.rb | 43 |
12 files changed, 224 insertions, 136 deletions
@@ -2,92 +2,90 @@ require 'rubygems/command' require 'rubygems/source_index' require 'rubygems/dependency_list' -module Gem - module Commands - class CleanupCommand < Command - def initialize - super( - 'cleanup', 'Clean up old versions of installed gems in the local repository', - { - :force => false, - :test => false, - :install_dir => Gem.dir - }) - add_option('-d', '--dryrun', "") do |value, options| - options[:dryrun] = true - end - end - def arguments # :nodoc: - "GEMNAME name of gem to cleanup" - end - def defaults_str # :nodoc: - "--no-dryrun" - end - def usage # :nodoc: - "#{program_name} [GEMNAME ...]" end - def execute - say "Cleaning up installed gems..." - srcindex = Gem::SourceIndex.from_installed_gems - primary_gems = {} - srcindex.each do |name, spec| - if primary_gems[spec.name].nil? or primary_gems[spec.name].version < spec.version - primary_gems[spec.name] = spec - end end - gems_to_cleanup = [] - - unless options[:args].empty? then - options[:args].each do |gem_name| - specs = Gem.cache.search(/^#{gem_name}$/i) - specs.each do |spec| - gems_to_cleanup << spec - end - end - else - srcindex.each do |name, spec| - gems_to_cleanup << spec - end - end - gems_to_cleanup = gems_to_cleanup.select { |spec| - primary_gems[spec.name].version != spec.version - } - uninstall_command = Gem::CommandManager.instance['uninstall'] - deplist = DependencyList.new - gems_to_cleanup.uniq.each do |spec| deplist.add(spec) end - deplist.dependency_order.each do |spec| - if options[:dryrun] then - say "Dry Run Mode: Would uninstall #{spec.full_name}" - else - say "Attempting uninstall on #{spec.full_name}" - options[:args] = [spec.name] - options[:version] = "= #{spec.version}" - options[:executables] = true - uninstall_command.merge_options(options) - begin - uninstall_command.execute - rescue Gem::DependencyRemovalException => ex - say "Unable to uninstall #{spec.full_name} ... continuing with remaining gems" - end - end end - - say "Clean Up Complete" end end - end end @@ -25,19 +25,18 @@ class Gem::Commands::EnvironmentCommand < Gem::Command def execute out = '' arg = options[:args][0] - if begins?("packageversion", arg) then out << Gem::RubyGemsPackageVersion - elsif begins?("version", arg) then out << Gem::RubyGemsVersion - elsif begins?("gemdir", arg) then out << Gem.dir - elsif begins?("gempath", arg) then - out << Gem.path.join("\n") - elsif begins?("remotesources", arg) then out << Gem.sources.join("\n") - elsif arg then - fail Gem::CommandLineError, "Unknown enviroment option [#{arg}]" - else out = "RubyGems Environment:\n" out << " - RUBYGEMS VERSION: #{Gem::RubyGemsVersion} (#{Gem::RubyGemsPackageVersion})\n" @@ -75,6 +74,9 @@ class Gem::Commands::EnvironmentCommand < Gem::Command Gem.sources.each do |s| out << " - #{s}\n" end end say out true @@ -44,17 +44,15 @@ class Gem::Commands::FetchCommand < Gem::Command spec, source_uri = specs_and_sources.last - gem_file = "#{spec.full_name}.gem" - - gem_path = File.join source_uri, 'gems', gem_file - - gem = Gem::RemoteFetcher.fetcher.fetch_path gem_path - - File.open gem_file, 'wb' do |fp| - fp.write gem end - say "Downloaded #{gem_file}" end end @@ -62,13 +62,15 @@ class Gem::Commands::InstallCommand < Gem::Command :install_dir => options[:install_dir], :security_policy => options[:security_policy], :wrappers => options[:wrappers], } get_all_gem_names.each do |gem_name| begin - inst = Gem::DependencyInstaller.new gem_name, options[:version], - install_options - inst.install inst.installed_gems.each do |spec| say "Successfully installed #{spec.full_name}" @@ -77,8 +79,10 @@ class Gem::Commands::InstallCommand < Gem::Command installed_gems.push(*inst.installed_gems) rescue Gem::InstallError => e alert_error "Error installing #{gem_name}:\n\t#{e.message}" rescue Gem::GemNotFoundException => e alert_error e.message # rescue => e # # TODO: Fix this handle to allow the error to propagate to # # the top level handler. Examine the other errors as @@ -121,6 +125,8 @@ class Gem::Commands::InstallCommand < Gem::Command end end end end end @@ -6,10 +6,8 @@ module Gem class ListCommand < QueryCommand def initialize - super( - 'list', - 'Display all gems whose name starts with STRING' - ) remove_option('--name-matches') end @@ -2,7 +2,7 @@ require 'yaml' require 'zlib' require 'rubygems/command' -require 'rubygems/gem_open_uri' class Gem::Commands::MirrorCommand < Gem::Command @@ -1,15 +1,25 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/source_info_cache' class Gem::Commands::QueryCommand < Gem::Command include Gem::LocalRemoteOptions def initialize(name = 'query', summary = 'Query gem information in local or remote repositories') super name, summary, - :name => /.*/, :domain => :local, :details => false, :versions => true add_option('-n', '--name-matches REGEXP', 'Name of gem(s) to query on matches the', @@ -28,33 +38,70 @@ class Gem::Commands::QueryCommand < Gem::Command options[:details] = false unless value end add_local_remote_options end def defaults_str # :nodoc: - "--local --name-matches '.*' --no-details --versions" end def execute name = options[:name] if local? then say say "*** LOCAL GEMS ***" say - output_query_results Gem.cache.search(name) end if remote? then say say "*** REMOTE GEMS ***" say - output_query_results Gem::SourceInfoCache.search(name) end end private def output_query_results(gemspecs) output = [] gem_list_with_version = {} @@ -98,7 +145,7 @@ class Gem::Commands::QueryCommand < Gem::Command ## # Used for wrapping and indenting text - # def format_text(text, wrap, indent=0) result = [] work = text.dup @@ -39,8 +39,11 @@ class Gem::Commands::SourcesCommand < Gem::Command options[:list] = !(options[:add] || options[:remove] || options[:clear_all] || options[:update]) if options[:clear_all] then - remove_cache_file("user", Gem::SourceInfoCache.user_cache_file) - remove_cache_file("system", Gem::SourceInfoCache.system_cache_file) end if options[:add] then @@ -48,7 +51,7 @@ class Gem::Commands::SourcesCommand < Gem::Command sice = Gem::SourceInfoCacheEntry.new nil, nil begin - sice.refresh source_uri Gem::SourceInfoCache.cache_data[source_uri] = sice Gem::SourceInfoCache.cache.update @@ -66,7 +69,7 @@ class Gem::Commands::SourcesCommand < Gem::Command end if options[:update] then - Gem::SourceInfoCache.cache.refresh Gem::SourceInfoCache.cache.flush say "source cache successfully updated" @@ -78,6 +81,11 @@ class Gem::Commands::SourcesCommand < Gem::Command unless Gem.sources.include? source_uri then say "source #{source_uri} not present in cache" else Gem::SourceInfoCache.cache_data.delete source_uri Gem::SourceInfoCache.cache.update Gem::SourceInfoCache.cache.flush @@ -100,11 +108,12 @@ class Gem::Commands::SourcesCommand < Gem::Command private - def remove_cache_file(desc, fn) - FileUtils.rm_rf fn rescue nil - if ! File.exist?(fn) say "*** Removed #{desc} source cache ***" - elsif ! File.writable?(fn) say "*** Unable to remove #{desc} source cache (write protected) ***" else say "*** Unable to remove #{desc} source cache ***" @@ -3,6 +3,7 @@ require 'rubygems/command' require 'rubygems/local_remote_options' require 'rubygems/version_option' require 'rubygems/source_info_cache' class Gem::Commands::SpecificationCommand < Gem::Command @@ -41,13 +42,16 @@ class Gem::Commands::SpecificationCommand < Gem::Command gem = get_one_gem_name if local? then - source_index = Gem::SourceIndex.from_installed_gems - specs.push(*source_index.search(/\A#{gem}\z/, options[:version])) end if remote? then - alert_warning "Remote information is not complete\n\n" - Gem::SourceInfoCache.cache_data.each do |_,sice| specs.push(*sice.source_index.search(gem, options[:version])) end @@ -35,6 +35,11 @@ module Gem options[:install_dir] = File.expand_path(value) end add_version_option add_platform_option end @@ -54,7 +59,13 @@ module Gem def execute get_all_gem_names.each do |gem_name| - Gem::Uninstaller.new(gem_name, options).uninstall end end end @@ -38,6 +38,7 @@ class Gem::Commands::UnpackCommand < Gem::Command def execute gemname = get_one_gem_name path = get_path(gemname, options[:version]) if path then basename = File.basename(path).sub(/\.gem$/, '') target_dir = File.expand_path File.join(options[:target], basename) @@ -66,16 +67,27 @@ class Gem::Commands::UnpackCommand < Gem::Command # source directories? def get_path(gemname, version_req) return gemname if gemname =~ /\.gem$/i - specs = Gem::SourceIndex.from_installed_gems.search(/\A#{gemname}\z/, version_req) selected = specs.sort_by { |s| s.version }.last return nil if selected.nil? # We expect to find (basename).gem in the 'cache' directory. # Furthermore, the name match must be exact (ignoring case). if gemname =~ /^#{selected.name}$/i filename = selected.full_name + '.gem' - return File.join(Gem.dir, 'cache', filename) else - return nil end end @@ -1,8 +1,10 @@ require 'rubygems/command' require 'rubygems/install_update_options' require 'rubygems/local_remote_options' require 'rubygems/source_info_cache' require 'rubygems/version_option' class Gem::Commands::UpdateCommand < Gem::Command @@ -45,7 +47,7 @@ class Gem::Commands::UpdateCommand < Gem::Command def execute if options[:system] then - say "Updating RubyGems..." unless options[:args].empty? then fail "No gem names are allowed with the --system option" @@ -53,10 +55,10 @@ class Gem::Commands::UpdateCommand < Gem::Command options[:args] = ["rubygems-update"] else - say "Updating installed gems..." end - hig = highest_installed_gems = {} Gem::SourceIndex.from_installed_gems.each do |name, spec| if hig[spec.name].nil? or hig[spec.name].version < spec.version then @@ -64,25 +66,28 @@ class Gem::Commands::UpdateCommand < Gem::Command end end - remote_gemspecs = Gem::SourceInfoCache.search(//) - gems_to_update = if options[:args].empty? then - which_to_update(highest_installed_gems, remote_gemspecs) - else - options[:args] - end - options[:domain] = :remote # install from remote source - # HACK use the real API - install_command = Gem::CommandManager.instance['install'] gems_to_update.uniq.sort.each do |name| - say "Attempting remote update of #{name}" - options[:args] = [name] - options[:ignore_dependencies] = true # HACK skip seen gems instead - install_command.merge_options(options) - install_command.execute end if gems_to_update.include? "rubygems-update" then @@ -97,12 +102,10 @@ class Gem::Commands::UpdateCommand < Gem::Command say "RubyGems system software updated" if installed else - updated = gems_to_update.uniq.sort.collect { |g| g.to_s } - if updated.empty? then say "Nothing to update" else - say "Gems updated: #{updated.join ', '}" end end end |