From 5d613c83ccb6992c6b99e5a23512719604bbdae9 Mon Sep 17 00:00:00 2001 From: drbrain Date: Sun, 10 Feb 2008 08:00:19 +0000 Subject: Import RubyGems r1601. [ruby-core:15381]. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15423 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- lib/rubygems/command.rb | 18 ++++++------ lib/rubygems/commands/environment_command.rb | 6 +++- lib/rubygems/commands/uninstall_command.rb | 16 ++++++---- lib/rubygems/exceptions.rb | 6 +++- lib/rubygems/install_update_options.rb | 2 +- lib/rubygems/installer.rb | 1 + lib/rubygems/package.rb | 18 +++++++----- lib/rubygems/source_index.rb | 3 +- lib/rubygems/specification.rb | 16 +++++----- lib/rubygems/uninstaller.rb | 44 +++++++++++++++++++++------- lib/rubygems/user_interaction.rb | 2 +- 11 files changed, 85 insertions(+), 47 deletions(-) (limited to 'lib/rubygems') diff --git a/lib/rubygems/command.rb b/lib/rubygems/command.rb index 66855c7c6a..61ed617cc6 100644 --- a/lib/rubygems/command.rb +++ b/lib/rubygems/command.rb @@ -136,7 +136,7 @@ module Gem execute end end - + # Call the given block when invoked. # # Normal command invocations just executes the +execute+ method of @@ -146,7 +146,7 @@ module Gem def when_invoked(&block) @when_invoked = block end - + # Add a command-line option and handler to the command. # # See OptionParser#make_switch for an explanation of +opts+. @@ -165,7 +165,7 @@ module Gem option_list.reject! { |args, _| args.any? { |x| x =~ /^#{name}/ } } end end - + # Merge a set of command options with the set of default options # (without modifying the default option hash). def merge_options(new_options) @@ -191,7 +191,7 @@ module Gem parser.parse!(args) @options[:args] = args end - + def add_extra_args(args) result = [] s_extra = Command.specific_extra_args(@command) @@ -291,7 +291,7 @@ module Gem def common_options @common_options ||= [] end - + def add_common_option(*args, &handler) Gem::Command.common_options << [args, handler] end @@ -315,7 +315,7 @@ module Gem def specific_extra_args(cmd) specific_extra_args_hash[cmd] end - + # Add a list of extra arguments for the given command. +args+ # may be an array or a string to be split on white space. def add_specific_extra_args(cmd,args) @@ -334,7 +334,7 @@ module Gem # ---------------------------------------------------------------- # Add the options common to all commands. - add_common_option('-h', '--help', + add_common_option('-h', '--help', 'Get help on this command') do |value, options| options[:help] = true @@ -358,11 +358,11 @@ module Gem # commands. Both options are actually handled before the other # options get parsed. - add_common_option('--config-file FILE', + add_common_option('--config-file FILE', "Use this config file instead of default") do end - add_common_option('--backtrace', + add_common_option('--backtrace', 'Show stack backtrace on errors') do end diff --git a/lib/rubygems/commands/environment_command.rb b/lib/rubygems/commands/environment_command.rb index 337d74893b..ab85361753 100644 --- a/lib/rubygems/commands/environment_command.rb +++ b/lib/rubygems/commands/environment_command.rb @@ -58,7 +58,11 @@ class Gem::Commands::EnvironmentCommand < Gem::Command end out << " - GEM PATHS:\n" - Gem.path.each do |p| + out << " - #{Gem.dir}\n" + + path = Gem.path.dup + path.delete Gem.dir + path.each do |p| out << " - #{p}\n" end diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb index 7d2908836c..2d9c46ee52 100644 --- a/lib/rubygems/commands/uninstall_command.rb +++ b/lib/rubygems/commands/uninstall_command.rb @@ -18,18 +18,23 @@ module Gem options[:all] = value end - add_option('-i', '--[no-]ignore-dependencies', - 'Ignore dependency requirements while', - 'uninstalling') do |value, options| + add_option('-I', '--[no-]ignore-dependencies', + 'Ignore dependency requirements while', + 'uninstalling') do |value, options| options[:ignore] = value end - add_option('-x', '--[no-]executables', + add_option('-x', '--[no-]executables', 'Uninstall applicable executables without', 'confirmation') do |value, options| options[:executables] = value end + add_option('-i', '--install-dir DIR', + 'Directory to uninstall gem from') do |value, options| + options[:install_dir] = File.expand_path(value) + end + add_version_option add_platform_option end @@ -39,7 +44,8 @@ module Gem end def defaults_str # :nodoc: - "--version '#{Gem::Requirement.default}' --no-force" + "--version '#{Gem::Requirement.default}' --no-force " \ + "--install-dir #{Gem.dir}" end def usage # :nodoc: diff --git a/lib/rubygems/exceptions.rb b/lib/rubygems/exceptions.rb index 294dad5748..b34bc718ff 100644 --- a/lib/rubygems/exceptions.rb +++ b/lib/rubygems/exceptions.rb @@ -11,8 +11,12 @@ class Gem::DependencyError < Gem::Exception; end class Gem::DependencyRemovalException < Gem::Exception; end +## +# Raised when attempting to uninstall a gem that isn't in GEM_HOME. +class Gem::GemNotInHomeException < Gem::Exception; end + class Gem::DocumentError < Gem::Exception; end - + ## # Potentially raised when a specification is validated. class Gem::EndOfYAMLException < Gem::Exception; end diff --git a/lib/rubygems/install_update_options.rb b/lib/rubygems/install_update_options.rb index b93e21551c..af6be423f6 100644 --- a/lib/rubygems/install_update_options.rb +++ b/lib/rubygems/install_update_options.rb @@ -37,7 +37,7 @@ module Gem::InstallUpdateOptions options[:generate_ri] = value end - add_option(:"Install/Update", '-E', '--env-shebang', + add_option(:"Install/Update", '-E', '--[no-]env-shebang', "Rewrite the shebang line on installed", "scripts to use /usr/bin/env") do |value, options| options[:env_shebang] = value diff --git a/lib/rubygems/installer.rb b/lib/rubygems/installer.rb index e652ac9c6d..552a803c12 100644 --- a/lib/rubygems/installer.rb +++ b/lib/rubygems/installer.rb @@ -63,6 +63,7 @@ class Gem::Installer :force => false, :install_dir => Gem.dir, :exec_format => false, + :env_shebang => false }.merge options @env_shebang = options[:env_shebang] diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb index ee136b6267..f15e4feecb 100644 --- a/lib/rubygems/package.rb +++ b/lib/rubygems/package.rb @@ -614,14 +614,16 @@ module Gem::Package # this method would use the String IO approach on all platforms at all # times. And that's the way it is. def zipped_stream(entry) - # This is Jamis Buck's ZLib workaround. The original code is - # commented out while we evaluate this patch. - entry.read(10) # skip the gzip header - zis = Zlib::Inflate.new(-Zlib::MAX_WBITS) - is = StringIO.new(zis.inflate(entry.read)) - # zis = Zlib::GzipReader.new entry - # dis = zis.read - # is = StringIO.new(dis) + if defined? Rubinius then + zis = Zlib::GzipReader.new entry + dis = zis.read + is = StringIO.new(dis) + else + # This is Jamis Buck's ZLib workaround for some unknown issue + entry.read(10) # skip the gzip header + zis = Zlib::Inflate.new(-Zlib::MAX_WBITS) + is = StringIO.new(zis.inflate(entry.read)) + end ensure zis.finish if zis end diff --git a/lib/rubygems/source_index.rb b/lib/rubygems/source_index.rb index 2df28d9561..1283f8f904 100644 --- a/lib/rubygems/source_index.rb +++ b/lib/rubygems/source_index.rb @@ -46,7 +46,7 @@ module Gem if deprecated.empty? from_gems_in(*installed_spec_directories) else - from_gems_in(*deprecated) + from_gems_in(*deprecated) # HACK warn end end @@ -118,6 +118,7 @@ module Gem def load_gems_in(*spec_dirs) @gems.clear specs = Dir.glob File.join("{#{spec_dirs.join(',')}}", "*.gemspec") + specs.each do |file_name| gemspec = self.class.load_specification(file_name.untaint) add_spec(gemspec) if gemspec diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb index 6338e73a1d..be03150c96 100644 --- a/lib/rubygems/specification.rb +++ b/lib/rubygems/specification.rb @@ -457,7 +457,7 @@ module Gem overwrite_accessor :default_executable do begin - if defined? @default_executable and @default_executable + if defined?(@default_executable) and @default_executable result = @default_executable elsif @executables and @executables.size == 1 result = Array(@executables).first @@ -471,14 +471,12 @@ module Gem end def add_bindir(executables) - if not defined? @executables || @executables.nil? - return nil - end + return nil if executables.nil? - if defined? @bindir and @bindir then - Array(@executables).map {|e| File.join(@bindir, e) } + if @bindir then + Array(executables).map { |e| File.join(@bindir, e) } else - @executables + executables end rescue return nil @@ -511,7 +509,7 @@ module Gem @test_files = [@test_suite_file].flatten @test_suite_file = nil end - if defined? @test_files and @test_files then + if defined?(@test_files) and @test_files then @test_files else @test_files = [] @@ -903,7 +901,7 @@ module Gem # Also, the summary and description are converted to a normal # format. def normalize - if defined? @extra_rdoc_files and @extra_rdoc_files then + if defined?(@extra_rdoc_files) and @extra_rdoc_files then @extra_rdoc_files.uniq! @files ||= [] @files.concat(@extra_rdoc_files) diff --git a/lib/rubygems/uninstaller.rb b/lib/rubygems/uninstaller.rb index 268c0b3b83..1c979d8573 100644 --- a/lib/rubygems/uninstaller.rb +++ b/lib/rubygems/uninstaller.rb @@ -25,6 +25,8 @@ class Gem::Uninstaller def initialize(gem, options) @gem = gem @version = options[:version] || Gem::Requirement.default + gem_home = options[:install_dir] || Gem.dir + @gem_home = File.expand_path gem_home @force_executables = options[:executables] @force_all = options[:all] @force_ignore = options[:ignore] @@ -71,31 +73,38 @@ class Gem::Uninstaller # def remove_executables(gemspec) return if gemspec.nil? - if(gemspec.executables.size > 0) - raise Gem::FilePermissionError.new(Gem.bindir) unless - File.writable?(Gem.bindir) + + if gemspec.executables.size > 0 then + bindir = Gem.bindir @gem_home + + raise Gem::FilePermissionError, bindir unless File.writable? bindir + list = Gem.source_index.search(gemspec.name).delete_if { |spec| spec.version == gemspec.version } + executables = gemspec.executables.clone + list.each do |spec| spec.executables.each do |exe_name| executables.delete(exe_name) end end + return if executables.size == 0 + answer = @force_executables || ask_yes_no( - "Remove executables and scripts for\n" + - "'#{gemspec.executables.join(", ")}' in addition to the gem?", + "Remove executables:\n" \ + "\t#{gemspec.executables.join(", ")}\n\nin addition to the gem?", true) # " # appease ruby-mode - don't ask - unless answer + + unless answer then say "Executables and scripts will remain installed." - return else gemspec.executables.each do |exe_name| say "Removing #{exe_name}" - File.unlink File.join(Gem.bindir, exe_name) rescue nil - File.unlink File.join(Gem.bindir, exe_name + ".bat") rescue nil + FileUtils.rm_f File.join(bindir, exe_name) + FileUtils.rm_f File.join(bindir, "#{exe_name}.bat") end end end @@ -119,11 +128,18 @@ class Gem::Uninstaller # uninstalled a gem, it is removed from that list. # def remove(spec, list) - unless ok_to_remove? spec then + unless dependencies_ok? spec then raise Gem::DependencyRemovalException, "Uninstallation aborted due to dependent gem(s)" end + unless path_ok? spec then + alert("In order to remove #{spec.name}, please execute:\n" \ + "\tgem uninstall #{spec.name} --install-dir=#{spec.installation_path}") + raise Gem::GemNotInHomeException, + "Gem is not installed in directory #{@gem_home}" + end + raise Gem::FilePermissionError, spec.installation_path unless File.writable?(spec.installation_path) @@ -157,7 +173,13 @@ class Gem::Uninstaller list.delete spec end - def ok_to_remove?(spec) + def path_ok?(spec) + match_path = File.join @gem_home, 'gems', spec.full_name + + match_path == spec.full_gem_path + end + + def dependencies_ok?(spec) return true if @force_ignore srcindex = Gem::SourceIndex.from_installed_gems diff --git a/lib/rubygems/user_interaction.rb b/lib/rubygems/user_interaction.rb index 7ff03eaadf..4970f33c00 100644 --- a/lib/rubygems/user_interaction.rb +++ b/lib/rubygems/user_interaction.rb @@ -75,7 +75,7 @@ module Gem ui.#{methname}(*args) end } - end + end end #################################################################### -- cgit v1.2.3