[macruby-changes] [5141] MacRuby/trunk/lib

source_changes at macosforge.org source_changes at macosforge.org
Sat Jan 8 09:08:19 PST 2011


Revision: 5141
          http://trac.macosforge.org/projects/ruby/changeset/5141
Author:   lsansonetti at apple.com
Date:     2011-01-08 09:08:14 -0800 (Sat, 08 Jan 2011)
Log Message:
-----------
upgrade to rubygems 1.4.1

Modified Paths:
--------------
    MacRuby/trunk/lib/rubygems/builder.rb
    MacRuby/trunk/lib/rubygems/command.rb
    MacRuby/trunk/lib/rubygems/command_manager.rb
    MacRuby/trunk/lib/rubygems/commands/build_command.rb
    MacRuby/trunk/lib/rubygems/commands/cert_command.rb
    MacRuby/trunk/lib/rubygems/commands/check_command.rb
    MacRuby/trunk/lib/rubygems/commands/cleanup_command.rb
    MacRuby/trunk/lib/rubygems/commands/contents_command.rb
    MacRuby/trunk/lib/rubygems/commands/dependency_command.rb
    MacRuby/trunk/lib/rubygems/commands/environment_command.rb
    MacRuby/trunk/lib/rubygems/commands/fetch_command.rb
    MacRuby/trunk/lib/rubygems/commands/generate_index_command.rb
    MacRuby/trunk/lib/rubygems/commands/help_command.rb
    MacRuby/trunk/lib/rubygems/commands/install_command.rb
    MacRuby/trunk/lib/rubygems/commands/lock_command.rb
    MacRuby/trunk/lib/rubygems/commands/pristine_command.rb
    MacRuby/trunk/lib/rubygems/commands/push_command.rb
    MacRuby/trunk/lib/rubygems/commands/query_command.rb
    MacRuby/trunk/lib/rubygems/commands/server_command.rb
    MacRuby/trunk/lib/rubygems/commands/setup_command.rb
    MacRuby/trunk/lib/rubygems/commands/sources_command.rb
    MacRuby/trunk/lib/rubygems/commands/specification_command.rb
    MacRuby/trunk/lib/rubygems/commands/unpack_command.rb
    MacRuby/trunk/lib/rubygems/commands/update_command.rb
    MacRuby/trunk/lib/rubygems/commands/which_command.rb
    MacRuby/trunk/lib/rubygems/config_file.rb
    MacRuby/trunk/lib/rubygems/custom_require.rb
    MacRuby/trunk/lib/rubygems/defaults.rb
    MacRuby/trunk/lib/rubygems/dependency.rb
    MacRuby/trunk/lib/rubygems/dependency_installer.rb
    MacRuby/trunk/lib/rubygems/dependency_list.rb
    MacRuby/trunk/lib/rubygems/doc_manager.rb
    MacRuby/trunk/lib/rubygems/exceptions.rb
    MacRuby/trunk/lib/rubygems/ext/builder.rb
    MacRuby/trunk/lib/rubygems/ext/rake_builder.rb
    MacRuby/trunk/lib/rubygems/format.rb
    MacRuby/trunk/lib/rubygems/gem_openssl.rb
    MacRuby/trunk/lib/rubygems/gem_path_searcher.rb
    MacRuby/trunk/lib/rubygems/gem_runner.rb
    MacRuby/trunk/lib/rubygems/gemcutter_utilities.rb
    MacRuby/trunk/lib/rubygems/indexer.rb
    MacRuby/trunk/lib/rubygems/install_update_options.rb
    MacRuby/trunk/lib/rubygems/installer.rb
    MacRuby/trunk/lib/rubygems/local_remote_options.rb
    MacRuby/trunk/lib/rubygems/old_format.rb
    MacRuby/trunk/lib/rubygems/package/f_sync_dir.rb
    MacRuby/trunk/lib/rubygems/package/tar_header.rb
    MacRuby/trunk/lib/rubygems/package/tar_input.rb
    MacRuby/trunk/lib/rubygems/package/tar_output.rb
    MacRuby/trunk/lib/rubygems/package/tar_reader.rb
    MacRuby/trunk/lib/rubygems/package/tar_writer.rb
    MacRuby/trunk/lib/rubygems/package.rb
    MacRuby/trunk/lib/rubygems/package_task.rb
    MacRuby/trunk/lib/rubygems/platform.rb
    MacRuby/trunk/lib/rubygems/remote_fetcher.rb
    MacRuby/trunk/lib/rubygems/requirement.rb
    MacRuby/trunk/lib/rubygems/security.rb
    MacRuby/trunk/lib/rubygems/server.rb
    MacRuby/trunk/lib/rubygems/source_index.rb
    MacRuby/trunk/lib/rubygems/spec_fetcher.rb
    MacRuby/trunk/lib/rubygems/specification.rb
    MacRuby/trunk/lib/rubygems/test_utilities.rb
    MacRuby/trunk/lib/rubygems/text.rb
    MacRuby/trunk/lib/rubygems/uninstaller.rb
    MacRuby/trunk/lib/rubygems/user_interaction.rb
    MacRuby/trunk/lib/rubygems/validator.rb
    MacRuby/trunk/lib/rubygems/version.rb
    MacRuby/trunk/lib/rubygems.rb

Added Paths:
-----------
    MacRuby/trunk/lib/rubygems/digest/
    MacRuby/trunk/lib/rubygems/errors.rb

Modified: MacRuby/trunk/lib/rubygems/builder.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/builder.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/builder.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,6 +4,18 @@
 # See LICENSE.txt for permissions.
 #++
 
+require 'rubygems/user_interaction'
+
+begin
+  require 'psych'
+rescue LoadError
+end
+
+Gem.load_yaml
+
+require 'rubygems/package'
+require 'rubygems/security'
+
 ##
 # The Builder class processes RubyGem specification files
 # to produce a .gem file.
@@ -18,10 +30,6 @@
   # spec:: [Gem::Specification] The specification instance
 
   def initialize(spec)
-    require "yaml"
-    require "rubygems/package"
-    require "rubygems/security"
-
     @spec = spec
   end
 
@@ -70,7 +78,8 @@
   def write_package
     open @spec.file_name, 'wb' do |gem_io|
       Gem::Package.open gem_io, 'w', @signer do |pkg|
-        pkg.metadata = @spec.to_yaml
+        yaml = @spec.to_yaml
+        pkg.metadata = yaml
 
         @spec.files.each do |file|
           next if File.directory? file

Modified: MacRuby/trunk/lib/rubygems/command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -146,6 +146,26 @@
   end
 
   ##
+  # Display to the user that a gem couldn't be found and reasons why
+
+  def show_lookup_failure(gem_name, version, errors, domain)
+    if errors and !errors.empty?
+      alert_error "Could not find a valid gem '#{gem_name}' (#{version}), here is why:"
+      errors.each { |x| say "          #{x.wordy}" }
+    else
+      alert_error "Could not find a valid gem '#{gem_name}' (#{version}) in any repository"
+    end
+
+    unless domain == :local then # HACK
+      suggestions = Gem::SpecFetcher.fetcher.suggest_gems_from_name gem_name
+
+      unless suggestions.empty?
+        alert_error "Possible alternatives: #{suggestions.join(", ")}"
+      end
+    end
+  end
+
+  ##
   # Get all gem names from the command line.
 
   def get_all_gem_names
@@ -156,7 +176,7 @@
             "Please specify at least one gem name (e.g. gem build GEMNAME)"
     end
 
-    gem_names = args.select { |arg| arg !~ /^-/ }
+    args.select { |arg| arg !~ /^-/ }
   end
 
   ##
@@ -418,7 +438,7 @@
     @parser.separator "  #{header}Options:"
 
     option_list.each do |args, handler|
-      dashes = args.select { |arg| arg =~ /^-/ }
+      args.select { |arg| arg =~ /^-/ }
       @parser.on(*args) do |value|
         handler.call(value, @options)
       end

Modified: MacRuby/trunk/lib/rubygems/command_manager.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/command_manager.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/command_manager.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,7 +4,6 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'timeout'
 require 'rubygems/command'
 require 'rubygems/user_interaction'
 
@@ -42,6 +41,7 @@
   # Register all the subcommands supported by the gem command.
 
   def initialize
+    require 'timeout'
     @commands = {}
     register_command :build
     register_command :cert
@@ -56,7 +56,6 @@
     register_command :install
     register_command :list
     register_command :lock
-    register_command :mirror
     register_command :outdated
     register_command :owner
     register_command :pristine
@@ -75,10 +74,10 @@
   end
 
   ##
-  # Register the command object.
+  # Register the Symbol +command+ as a gem command.
 
-  def register_command(command_obj)
-    @commands[command_obj] = false
+  def register_command(command)
+    @commands[command] = false
   end
 
   ##
@@ -123,7 +122,7 @@
       say Gem::Command::HELP
       terminate_interaction(0)
     when '-v', '--version'
-      say Gem::RubyGemsVersion
+      say Gem::VERSION
       terminate_interaction(0)
     when /^-/
       alert_error "Invalid option: #{args[0]}.  See 'gem --help'."
@@ -156,20 +155,25 @@
 
   def load_and_instantiate(command_name)
     command_name = command_name.to_s
+    const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase } << "Command"
+    commands = Gem::Commands
     retried = false
 
     begin
-      const_name = command_name.capitalize.gsub(/_(.)/) { $1.upcase }
-      Gem::Commands.const_get("#{const_name}Command").new
+      commands.const_get const_name
     rescue NameError
-      if retried then
-        raise
-      else
-        retried = true
+      raise if retried
+
+      retried = true
+      begin
         require "rubygems/commands/#{command_name}_command"
-        retry
+      rescue Exception => e
+        alert_error "Loading command: #{command_name} (#{e.class})\n    #{e}"
+        ui.errs.puts "\t#{e.backtrace.join "\n\t"}" if
+          Gem.configuration.backtrace
       end
-    end
+      retry
+    end.new
   end
 
 end

Modified: MacRuby/trunk/lib/rubygems/commands/build_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/build_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/build_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -35,7 +35,7 @@
           while not f.eof? and spec = Gem::Specification.from_yaml(f)
             result << spec
           end
-        rescue Gem::EndOfYAMLException => e
+        rescue Gem::EndOfYAMLException
           # OK
         end
       end

Modified: MacRuby/trunk/lib/rubygems/commands/cert_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/cert_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/cert_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -59,21 +59,21 @@
     add_option('-C', '--certificate CERT',
                'Certificate for --sign command.') do |value, options|
       cert = OpenSSL::X509::Certificate.new(File.read(value))
-      Gem::Security::OPT[:issuer_cert] = cert
+      options[:issuer_cert] = cert
     end
 
     add_option('-K', '--private-key KEY',
                'Private key for --sign command.') do |value, options|
       key = OpenSSL::PKey::RSA.new(File.read(value))
-      Gem::Security::OPT[:issuer_key] = key
+      options[:issuer_key] = key
     end
 
     add_option('-s', '--sign NEWCERT',
                'Sign a certificate with my key and',
                'certificate.') do |value, options|
       cert = OpenSSL::X509::Certificate.new(File.read(value))
-      my_cert = Gem::Security::OPT[:issuer_cert]
-      my_key = Gem::Security::OPT[:issuer_key]
+      my_cert = options[:issuer_cert]
+      my_key = options[:issuer_key]
       cert = Gem::Security.sign_cert(cert, my_key, my_cert)
       File.open(value, 'wb') { |file| file.write(cert.to_pem) }
     end

Modified: MacRuby/trunk/lib/rubygems/commands/check_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/check_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/check_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -21,25 +21,10 @@
       options[:alien] = true
     end
 
-    add_option('-v', '--verbose', "Spew more words") do |value, options|
-      options[:verbose] = true
-    end
-
-    add_option('-t', '--test', "Run unit tests for gem") do |value, options|
-      options[:test] = true
-    end
-
-    add_version_option 'run tests for'
+    add_version_option 'check'
   end
 
   def execute
-    if options[:test]
-      version = options[:version] || Gem::Requirement.default
-      dep = Gem::Dependency.new get_one_gem_name, version
-      gem_spec = Gem::SourceIndex.from_installed_gems.search(dep).first
-      Gem::Validator.new.unit_test(gem_spec)
-    end
-
     if options[:alien]
       say "Performing the 'alien' operation"
       say
@@ -52,7 +37,7 @@
             say "    #{error_entry.problem}"
           end
         else
-          say "#{key} is error-free" if options[:verbose]
+          say "#{key} is error-free" if Gem.configuration.verbose
         end
         say
       end
@@ -71,7 +56,7 @@
       say "Verifying gem: '#{gem_name}'"
       begin
         Gem::Validator.new.verify_gem_file(gem_name)
-      rescue Exception => e
+      rescue Exception
         alert_error "#{gem_name} is invalid."
       end
     end

Modified: MacRuby/trunk/lib/rubygems/commands/cleanup_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/cleanup_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/cleanup_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -8,7 +8,7 @@
   def initialize
     super 'cleanup',
           'Clean up old versions of installed gems in the local repository',
-          :force => false, :test => false, :install_dir => Gem.dir
+          :force => false, :install_dir => Gem.dir
 
     add_option('-d', '--dryrun', "") do |value, options|
       options[:dryrun] = true

Modified: MacRuby/trunk/lib/rubygems/commands/contents_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/contents_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/contents_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -7,7 +7,7 @@
 
   def initialize
     super 'contents', 'Display the contents of the installed gems',
-          :specdirs => [], :lib_only => false
+          :specdirs => [], :lib_only => false, :prefix => true
 
     add_version_option
 

Modified: MacRuby/trunk/lib/rubygems/commands/dependency_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/dependency_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/dependency_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -76,25 +76,13 @@
     if remote? and not options[:reverse_dependencies] then
       fetcher = Gem::SpecFetcher.fetcher
 
-      begin
-        specs_and_sources = fetcher.find_matching(dependency, false, true,
-                                                  dependency.prerelease?)
+      specs_and_sources = fetcher.find_matching(dependency, false, true,
+                                                dependency.prerelease?)
 
-        specs_and_sources.each do |spec_tuple, source_uri|
-          spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
+      specs_and_sources.each do |spec_tuple, source_uri|
+        spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
 
-          source_indexes[source_uri].add_spec spec
-        end
-      rescue Gem::RemoteFetcher::FetchError => e
-        raise unless fetcher.warn_legacy e do
-          require 'rubygems/source_info_cache'
-
-          specs = Gem::SourceInfoCache.search_with_source dependency, false
-
-          specs.each do |spec, source_uri|
-            source_indexes[source_uri].add_spec spec
-          end
-        end
+        source_indexes[source_uri].add_spec spec
       end
     end
 
@@ -159,7 +147,9 @@
     response
   end
 
-  # Retuns list of [specification, dep] that are satisfied by spec.
+  ##
+  # Returns an Array of [specification, dep] that are satisfied by +spec+.
+
   def find_reverse_dependencies(spec)
     result = []
 

Modified: MacRuby/trunk/lib/rubygems/commands/environment_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/environment_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/environment_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -13,6 +13,7 @@
           gempath         display path used to search for gems
           version         display the gem format version
           remotesources   display the remote gem servers
+          platform        display the supporte gem platforms
           <omitted>       display everything
     EOF
     return args.gsub(/^\s+/, '')
@@ -32,8 +33,6 @@
             levels
   :update_sources: Enable/disable automatic updating of repository metadata
   :backtrace: Print backtrace when RubyGems encounters an error
-  :bulk_threshold: Switch to a bulk update when this many sources are out of
-                   date (legacy setting)
   :gempath: The paths in which to look for gems
   gem_command: A string containing arguments for the specified gem command
 
@@ -69,17 +68,19 @@
     when /^packageversion/ then
       out << Gem::RubyGemsPackageVersion
     when /^version/ then
-      out << Gem::RubyGemsVersion
+      out << Gem::VERSION
     when /^gemdir/, /^gemhome/, /^home/, /^GEM_HOME/ then
       out << Gem.dir
     when /^gempath/, /^path/, /^GEM_PATH/ then
       out << Gem.path.join(File::PATH_SEPARATOR)
     when /^remotesources/ then
       out << Gem.sources.join("\n")
+    when /^platform/ then
+      out << Gem.platforms.join(File::PATH_SEPARATOR)
     when nil then
       out = "RubyGems Environment:\n"
 
-      out << "  - RUBYGEMS VERSION: #{Gem::RubyGemsVersion}\n"
+      out << "  - RUBYGEMS VERSION: #{Gem::VERSION}\n"
 
       out << "  - RUBY VERSION: #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
       out << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
@@ -109,6 +110,7 @@
 
       out << "  - GEM CONFIGURATION:\n"
       Gem.configuration.each do |name, value|
+        value = value.gsub(/./, '*') if name == 'gemcutter_key'
         out << "     - #{name.inspect} => #{value.inspect}\n"
       end
 

Modified: MacRuby/trunk/lib/rubygems/commands/fetch_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/fetch_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/fetch_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -34,7 +34,7 @@
 
   def execute
     version = options[:version] || Gem::Requirement.default
-    all = Gem::Requirement.default
+    all = Gem::Requirement.default != version
 
     gem_names = get_all_gem_names
 
@@ -42,13 +42,17 @@
       dep = Gem::Dependency.new gem_name, version
       dep.prerelease = options[:prerelease]
 
-      specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, false, true,
+      specs_and_sources = Gem::SpecFetcher.fetcher.fetch(dep, all, true,
                                                          dep.prerelease?)
 
+      specs_and_sources, errors =
+        Gem::SpecFetcher.fetcher.fetch_with_errors(dep, all, true,
+                                                   dep.prerelease?)
+
       spec, source_uri = specs_and_sources.sort_by { |s,| s.version }.last
 
       if spec.nil? then
-        alert_error "Could not find #{gem_name} in any repository"
+        show_lookup_failure gem_name, version, errors, options[:domain]
         next
       end
 

Modified: MacRuby/trunk/lib/rubygems/commands/generate_index_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/generate_index_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/generate_index_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -19,8 +19,7 @@
     end
 
     add_option '--[no-]legacy',
-               'Generate indexes for RubyGems older than',
-               '1.2.0' do |value, options|
+               'Generate Marshal.4.8' do |value, options|
       unless options[:build_modern] or value then
         raise OptionParser::InvalidOption, 'no indicies will be built'
       end
@@ -87,20 +86,12 @@
   quick/Marshal.<version>/<gemname>.gemspec.rz # Marshal quick index file
 
   # these files support legacy RubyGems
-  quick/index
-  quick/index.rz                               # quick index manifest
-  quick/<gemname>.gemspec.rz                   # legacy YAML quick index
-                                               # file
   Marshal.<version>
   Marshal.<version>.Z                          # Marshal full index
-  yaml
-  yaml.Z                                       # legacy YAML full index
 
 The .Z and .rz extension files are compressed with the inflate algorithm.
 The Marshal version number comes from ruby's Marshal::MAJOR_VERSION and
 Marshal::MINOR_VERSION constants.  It is used to ensure compatibility.
-The yaml indexes exist for legacy RubyGems clients and fallback in case of
-Marshal version changes.
 
 If --rss-host and --rss-gem-host are given an RSS feed will be generated at
 index.rss containing gems released in the last two days.

Modified: MacRuby/trunk/lib/rubygems/commands/help_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/help_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/help_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -14,11 +14,6 @@
 
     gem install rake --remote
 
-* Install 'rake' from remote server, and run unit tests,
-  and generate RDocs:
-
-    gem install --remote rake --test --rdoc --ri
-
 * Install 'rake', but only version 0.3.1, even if dependencies
   are not met, and into a user-specific directory:
 

Modified: MacRuby/trunk/lib/rubygems/commands/install_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/install_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/install_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -19,10 +19,11 @@
 
   def initialize
     defaults = Gem::DependencyInstaller::DEFAULT_OPTIONS.merge({
-      :generate_rdoc     => false,
-      :generate_ri       => false,
+      #:generate_rdoc     => true,
+      #:generate_ri       => true,
+      # XXX MACRUBY rdoc/ri generation disabled by default
+      :generate_rdoc => false, :generate_ri => false,
       :format_executable => false,
-      :test              => false,
       :version           => Gem::Requirement.default,
     })
 
@@ -41,7 +42,7 @@
 
   def defaults_str # :nodoc:
     "--both --version '#{Gem::Requirement.default}' --rdoc --ri --no-force\n" \
-    "--no-test --install-dir #{Gem.dir}"
+    "--install-dir #{Gem.dir}"
   end
 
   def description # :nodoc:
@@ -115,6 +116,8 @@
 
     get_all_gem_names.each do |gem_name|
       begin
+        next if options[:conservative] && Gem.available?(gem_name, options[:version])
+
         inst = Gem::DependencyInstaller.new options
         inst.install gem_name, options[:version]
 
@@ -127,7 +130,8 @@
         alert_error "Error installing #{gem_name}:\n\t#{e.message}"
         exit_code |= 1
       rescue Gem::GemNotFoundException => e
-        alert_error e.message
+        show_lookup_failure e.name, e.version, e.errors, options[:domain]
+
         exit_code |= 2
       end
     end
@@ -153,19 +157,6 @@
           Gem::DocManager.new(gem, options[:rdoc_args]).generate_rdoc
         end
       end
-
-      if options[:test] then
-        installed_gems.each do |spec|
-          gem_spec = Gem::SourceIndex.from_installed_gems.find_name(spec.name, spec.version.version).first
-          result = Gem::Validator.new.unit_test(gem_spec)
-          if result and not result.passed?
-            unless ask_yes_no("...keep Gem?", true)
-              require 'rubygems/uninstaller'
-              Gem::Uninstaller.new(spec.name, :version => spec.version.version).uninstall
-            end
-          end
-        end
-      end
     end
 
     raise Gem::SystemExitException, exit_code

Modified: MacRuby/trunk/lib/rubygems/commands/lock_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/lock_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/lock_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -75,7 +75,7 @@
     until pending.empty? do
       full_name = pending.shift
 
-      spec = Gem::SourceIndex.load_specification spec_path(full_name)
+      spec = Gem::Specification.load spec_path(full_name)
 
       if spec.nil? then
         complain "Could not find gem #{full_name}, try using the full name"

Modified: MacRuby/trunk/lib/rubygems/commands/pristine_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/pristine_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/pristine_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,4 +1,3 @@
-require 'fileutils'
 require 'rubygems/command'
 require 'rubygems/format'
 require 'rubygems/installer'

Modified: MacRuby/trunk/lib/rubygems/commands/push_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/push_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/push_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -21,6 +21,13 @@
   def initialize
     super 'push', description
     add_proxy_option
+    
+    add_option(
+      '--host HOST',
+      'Push to another gemcutter-compatible host'
+    ) do |value, options|
+      options[:host] = value
+    end
   end
 
   def execute
@@ -29,9 +36,13 @@
   end
 
   def send_gem name
-    say "Pushing gem to RubyGems.org..."
+    say "Pushing gem to #{options[:host] || Gem.host}..."
 
-    response = rubygems_api_request :post, "api/v1/gems" do |request|
+    args = [:post, "api/v1/gems"]
+
+    args << options[:host] if options[:host]
+
+    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"

Modified: MacRuby/trunk/lib/rubygems/commands/query_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/query_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/query_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -21,7 +21,7 @@
       options[:installed] = value
     end
 
-    add_version_option
+    add_version_option command, "for use with --installed"
 
     add_option('-n', '--name-matches REGEXP',
                'Name of gem(s) to query on matches the',
@@ -108,32 +108,12 @@
 
       all = options[:all]
 
-      begin
-        fetcher = Gem::SpecFetcher.fetcher
-        spec_tuples = fetcher.find_matching dep, all, false, prerelease
+      fetcher = Gem::SpecFetcher.fetcher
+      spec_tuples = fetcher.find_matching dep, all, false, prerelease
 
-        spec_tuples += fetcher.find_matching dep, false, false, true if
-          prerelease and all
-      rescue Gem::RemoteFetcher::FetchError => e
-        if prerelease then
-          raise Gem::OperationNotSupportedError,
-                "Prereleases not supported on legacy repositories"
-        end
+      spec_tuples += fetcher.find_matching dep, false, false, true if
+        prerelease and all
 
-        raise unless fetcher.warn_legacy e do
-          require 'rubygems/source_info_cache'
-
-          dep.name = '' if dep.name == //
-
-          specs = Gem::SourceInfoCache.search_with_source dep, false, all
-
-          spec_tuples = specs.map do |spec, source_uri|
-            [[spec.name, spec.version, spec.original_platform, spec],
-             source_uri]
-          end
-        end
-      end
-
       output_query_results spec_tuples
     end
   end
@@ -161,19 +141,19 @@
     end
 
     versions.each do |gem_name, matching_tuples|
-      matching_tuples = matching_tuples.sort_by do |(name, version,_),_|
+      matching_tuples = matching_tuples.sort_by do |(_, version,_),_|
         version
       end.reverse
 
       platforms = Hash.new { |h,version| h[version] = [] }
 
-      matching_tuples.map do |(name, version, platform,_),_|
+      matching_tuples.map do |(_, version, platform,_),_|
         platforms[version] << platform if platform
       end
 
       seen = {}
 
-      matching_tuples.delete_if do |(name, version,_),_|
+      matching_tuples.delete_if do |(_, version,_),_|
         if seen[version] then
           true
         else
@@ -185,8 +165,21 @@
       entry = gem_name.dup
 
       if options[:versions] then
-        versions = matching_tuples.map { |(name, version,_),_| version }.uniq
-        entry << " (#{versions.join ', '})"
+        list = if platforms.empty? or options[:details] then
+                 matching_tuples.map { |(_, version,_),_| version }.uniq
+               else
+                 platforms.sort.reverse.map do |version, pls|
+                   if pls == [Gem::Platform::RUBY] then
+                     version
+                   else
+                     ruby = pls.delete Gem::Platform::RUBY
+                     platform_list = [ruby, *pls.sort].compact
+                     "#{version} #{platform_list.join ' '}"
+                   end
+                 end
+               end.join ', '
+
+        entry << " (#{list})"
       end
 
       if options[:details] then

Modified: MacRuby/trunk/lib/rubygems/commands/server_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/server_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/server_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -5,7 +5,7 @@
 
   def initialize
     super 'server', 'Documentation and gem repository HTTP server',
-          :port => 8808, :gemdir => Gem.dir, :daemon => false
+          :port => 8808, :gemdir => [], :daemon => false
 
     OptionParser.accept :Port do |port|
       if port =~ /\A\d+\z/ then
@@ -17,7 +17,7 @@
       else
         begin
           Socket.getservbyname port
-        rescue SocketError => e
+        rescue SocketError
           raise OptionParser::InvalidArgument, "#{port}: no such named service"
         end
       end
@@ -29,8 +29,9 @@
     end
 
     add_option '-d', '--dir=GEMDIR',
-               'directory from which to serve gems' do |gemdir, options|
-      options[:gemdir] = File.expand_path gemdir
+               'directories from which to serve gems',
+               'multiple directories may be provided' do |gemdir, options|
+      options[:gemdir] << File.expand_path(gemdir)
     end
 
     add_option '--[no-]daemon', 'run as a daemon' do |daemon, options|
@@ -42,6 +43,14 @@
       options[:addresses] ||= []
       options[:addresses].push(*address)
     end
+
+    add_option '-l', '--launch[=COMMAND]', 
+               'launches a browser window',
+               "COMMAND defaults to 'start' on Windows",
+               "and 'open' on all other platforms" do |launch, options|
+      launch ||= Gem.win_platform? ? 'start' : 'open'
+      options[:launch] = launch
+    end
   end
 
   def defaults_str # :nodoc:
@@ -69,6 +78,7 @@
   end
 
   def execute
+    options[:gemdir] << Gem.dir if options[:gemdir].empty?
     Gem::Server.run options
   end
 

Modified: MacRuby/trunk/lib/rubygems/commands/setup_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/setup_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/setup_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,4 @@
 require 'rubygems/command'
-require 'fileutils'
-require 'rbconfig'
-require 'tmpdir'
 
 ##
 # Installs RubyGems itself.  This command is ordinarily only available from a
@@ -10,6 +7,8 @@
 class Gem::Commands::SetupCommand < Gem::Command
 
   def initialize
+    require 'tmpdir'
+
     super 'setup', 'Install RubyGems',
           :format_executable => true, :rdoc => true, :ri => true,
           :site_or_vendor => :sitelibdir,
@@ -98,6 +97,7 @@
 
     check_ruby_version
 
+    require 'fileutils'
     if Gem.configuration.really_verbose then
       extend FileUtils::Verbose
     else
@@ -231,7 +231,7 @@
 
   def install_rdoc
     gem_doc_dir = File.join Gem.dir, 'doc'
-    rubygems_name = "rubygems-#{Gem::RubyGemsVersion}"
+    rubygems_name = "rubygems-#{Gem::VERSION}"
     rubygems_doc_dir = File.join gem_doc_dir, rubygems_name
 
     if File.writable? gem_doc_dir and

Modified: MacRuby/trunk/lib/rubygems/commands/sources_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/sources_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/sources_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,4 +1,3 @@
-require 'fileutils'
 require 'rubygems/command'
 require 'rubygems/remote_fetcher'
 require 'rubygems/source_info_cache'
@@ -10,6 +9,8 @@
   include Gem::LocalRemoteOptions
 
   def initialize
+    require 'fileutils'
+
     super 'sources',
           'Manage the sources and cache file RubyGems uses to search for gems'
 
@@ -79,23 +80,7 @@
       rescue URI::Error, ArgumentError
         say "#{source_uri} is not a URI"
       rescue Gem::RemoteFetcher::FetchError => e
-        yaml_uri = uri + 'yaml'
-        gem_repo = Gem::RemoteFetcher.fetcher.fetch_size yaml_uri rescue false
-
-        if e.uri =~ /specs\.#{Regexp.escape Gem.marshal_version}\.gz$/ and
-           gem_repo then
-
-          alert_warning <<-EOF
-RubyGems 1.2+ index not found for:
-\t#{source_uri}
-
-Will cause RubyGems to revert to legacy indexes, degrading performance.
-          EOF
-
-          say "#{source_uri} added to sources"
-        else
-          say "Error fetching #{source_uri}:\n\t#{e.message}"
-        end
+        say "Error fetching #{source_uri}:\n\t#{e.message}"
       end
     end
 
@@ -115,15 +100,10 @@
     if options[:update] then
       fetcher = Gem::SpecFetcher.fetcher
 
-      if fetcher.legacy_repos.empty? then
-        Gem.sources.each do |update_uri|
-          update_uri = URI.parse update_uri
-          fetcher.load_specs update_uri, 'specs'
-          fetcher.load_specs update_uri, 'latest_specs'
-        end
-      else
-        Gem::SourceInfoCache.cache true
-        Gem::SourceInfoCache.cache.flush
+      Gem.sources.each do |update_uri|
+        update_uri = URI.parse update_uri
+        fetcher.load_specs update_uri, 'specs'
+        fetcher.load_specs update_uri, 'latest_specs'
       end
 
       say "source cache successfully updated"

Modified: MacRuby/trunk/lib/rubygems/commands/specification_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/specification_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/specification_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,4 +1,3 @@
-require 'yaml'
 require 'rubygems/command'
 require 'rubygems/local_remote_options'
 require 'rubygems/version_option'
@@ -11,6 +10,8 @@
   include Gem::VersionOption
 
   def initialize
+    Gem.load_yaml
+
     super 'specification', 'Display gem specification (in yaml)',
           :domain => :local, :version => Gem::Requirement.default,
           :format => :yaml

Modified: MacRuby/trunk/lib/rubygems/commands/unpack_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/unpack_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/unpack_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,4 +1,3 @@
-require 'fileutils'
 require 'rubygems/command'
 require 'rubygems/installer'
 require 'rubygems/version_option'
@@ -8,11 +7,14 @@
   include Gem::VersionOption
 
   def initialize
+    require 'fileutils'
+
     super 'unpack', 'Unpack an installed gem to the current directory',
           :version => Gem::Requirement.default,
           :target  => Dir.pwd
 
-    add_option('--target=DIR', 'target directory for unpacking') do |value, options|
+    add_option('--target=DIR',
+               'target directory for unpacking') do |value, options|
       options[:target] = value
     end
 
@@ -31,6 +33,16 @@
     "#{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
@@ -38,11 +50,12 @@
 
   def execute
     get_all_gem_names.each do |name|
-      path = get_path name, options[:version]
+      dependency = Gem::Dependency.new name, options[:version]
+      path = get_path dependency
 
       if path then
-        basename = File.basename(path, '.gem')
-        target_dir = File.expand_path File.join(options[:target], basename)
+        basename = File.basename path, '.gem'
+        target_dir = File.expand_path basename, options[:target]
         FileUtils.mkdir_p target_dir
         Gem::Installer.new(path, :unpack => true).unpack target_dir
         say "Unpacked gem: '#{target_dir}'"
@@ -52,14 +65,15 @@
     end
   end
 
+  ##
   # Return the full path to the cached gem file matching the given
   # name and version requirement.  Returns 'nil' if no match.
   #
   # Example:
   #
-  #   get_path('rake', '> 0.4')   # -> '/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem'
-  #   get_path('rake', '< 0.1')   # -> nil
-  #   get_path('rak')             # -> nil (exact name required)
+  #   get_path 'rake', '> 0.4' # "/usr/lib/ruby/gems/1.8/cache/rake-0.4.2.gem"
+  #   get_path 'rake', '< 0.1' # nil
+  #   get_path 'rak'           # nil (exact name required)
   #--
   # TODO: This should be refactored so that it's a general service. I don't
   # think any of our existing classes are the right place though.  Just maybe
@@ -67,30 +81,29 @@
   #
   # TODO: It just uses Gem.dir for now.  What's an easy way to get the list of
   # source directories?
-  def get_path(gemname, version_req)
-    return gemname if gemname =~ /\.gem$/i
 
-    specs = Gem::source_index.find_name gemname, version_req
+  def get_path dependency
+    return dependency.name if dependency.name =~ /\.gem$/i
 
+    specs = Gem.source_index.search dependency
+
     selected = specs.sort_by { |s| s.version }.last
 
-    return nil if selected.nil?
+    return download(dependency) 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.file_name
-      path = nil
+    return unless dependency.name =~ /^#{selected.name}$/i
 
-      Gem.path.find do |gem_dir|
-        path = File.join gem_dir, 'cache', filename
-        File.exist? path
-      end
+    # We expect to find (basename).gem in the 'cache' directory.  Furthermore,
+    # the name match must be exact (ignoring case).
+    filename = selected.file_name
+    path = nil
 
-      path
-    else
-      nil
+    Gem.path.find do |gem_dir|
+      path = File.join gem_dir, 'cache', filename
+      File.exist? path
     end
+
+    path
   end
 
 end

Modified: MacRuby/trunk/lib/rubygems/commands/update_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/update_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/update_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -17,8 +17,7 @@
           'Update the named gems (or all installed gems) in the local repository',
       :generate_rdoc => true,
       :generate_ri   => true,
-      :force         => false,
-      :test          => false
+      :force         => false
 
     add_install_update_options
 
@@ -37,7 +36,7 @@
   end
 
   def defaults_str # :nodoc:
-    "--rdoc --ri --no-force --no-test --install-dir #{Gem.dir}"
+    "--rdoc --ri --no-force --install-dir #{Gem.dir}"
   end
 
   def usage # :nodoc:
@@ -48,8 +47,8 @@
     hig = {}
 
     if options[:system] then
-      # XXX We can't allow people to self-update RubyGems at this point.
-      raise "This MacRuby version of RubyGems cannot be self-updated."
+      # XXX MACRUBY We can't allow people to self-update RubyGems at this point.
+      raise "This version of RubyGems cannot be self-updated."
 
       say "Updating RubyGems"
 
@@ -59,7 +58,7 @@
 
       rubygems_update = Gem::Specification.new
       rubygems_update.name = 'rubygems-update'
-      rubygems_update.version = Gem::Version.new Gem::RubyGemsVersion
+      rubygems_update.version = Gem::Version.new Gem::VERSION
       hig['rubygems-update'] = rubygems_update
 
       options[:user_install] = false
@@ -167,28 +166,14 @@
 
       dependency = Gem::Dependency.new l_spec.name, "> #{l_spec.version}"
 
-      begin
-        fetcher = Gem::SpecFetcher.fetcher
-        spec_tuples = fetcher.find_matching dependency
-      rescue Gem::RemoteFetcher::FetchError => e
-        raise unless fetcher.warn_legacy e do
-          require 'rubygems/source_info_cache'
+      fetcher = Gem::SpecFetcher.fetcher
+      spec_tuples = fetcher.find_matching dependency
 
-          dependency.name = '' if dependency.name == //
-
-          specs = Gem::SourceInfoCache.search_with_source dependency
-
-          spec_tuples = specs.map do |spec, source_uri|
-            [[spec.name, spec.version, spec.original_platform], source_uri]
-          end
-        end
-      end
-
-      matching_gems = spec_tuples.select do |(name, version, platform),|
+      matching_gems = spec_tuples.select do |(name, _, platform),|
         name == l_name and Gem::Platform.match platform
       end
 
-      highest_remote_gem = matching_gems.sort_by do |(name, version),|
+      highest_remote_gem = matching_gems.sort_by do |(_, version),|
         version
       end.last
 

Modified: MacRuby/trunk/lib/rubygems/commands/which_command.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/commands/which_command.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/commands/which_command.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -33,6 +33,7 @@
     found = false
 
     options[:args].each do |arg|
+      arg = arg.sub(/#{Regexp.union(*EXT)}$/, '')
       dirs = $LOAD_PATH
       spec = searcher.find arg
 

Modified: MacRuby/trunk/lib/rubygems/config_file.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/config_file.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/config_file.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -205,7 +205,7 @@
     dirname = File.dirname(credentials_path)
     Dir.mkdir(dirname) unless File.exists?(dirname)
 
-    require 'yaml'
+    Gem.load_yaml
 
     File.open(credentials_path, 'w') do |f|
       f.write config.to_yaml
@@ -215,9 +215,10 @@
   end
 
   def load_file(filename)
+    Gem.load_yaml
+
     return {} unless filename and File.exists?(filename)
     begin
-      require 'yaml'
       YAML.load(File.read(filename))
     rescue ArgumentError
       warn "Failed to load #{config_file_name}"
@@ -312,7 +313,6 @@
 
   # Writes out this config file, replacing its source.
   def write
-    require 'yaml'
     open config_file_name, 'w' do |io|
       io.write to_yaml
     end

Modified: MacRuby/trunk/lib/rubygems/custom_require.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/custom_require.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/custom_require.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,8 +4,6 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'rubygems'
-
 module Kernel
 
   ##

Modified: MacRuby/trunk/lib/rubygems/defaults.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/defaults.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/defaults.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -20,9 +20,8 @@
     if defined? RUBY_FRAMEWORK_VERSION then
       File.join File.dirname(ConfigMap[:sitedir]), 'Gems',
                 ConfigMap[:ruby_version]
-    # 1.9.2dev reverted to 1.8 style path
-    elsif RUBY_VERSION > '1.9' and RUBY_VERSION < '1.9.2' then
-      File.join(ConfigMap[:libdir], ConfigMap[:ruby_install_name], 'gems',
+    elsif ConfigMap[:rubylibprefix] then
+      File.join(ConfigMap[:rubylibprefix], 'gems',
                 ConfigMap[:ruby_version])
     else
       File.join(ConfigMap[:libdir], ruby_engine, 'gems',
@@ -34,15 +33,14 @@
   # Path for gems in the user's home directory
 
   def self.user_dir
-    File.join(Gem.user_home, '.gem', ruby_engine,
-              ConfigMap[:ruby_version])
+    File.join Gem.user_home, '.gem', ruby_engine, ConfigMap[:ruby_version]
   end
 
   ##
   # Default gem load path
 
   def self.default_path
-    if File.exist?(Gem.user_home)
+    if File.exist? Gem.user_home then
       [user_dir, default_dir]
     else
       [default_dir]

Modified: MacRuby/trunk/lib/rubygems/dependency.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/dependency.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/dependency.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -5,18 +5,6 @@
 
 class Gem::Dependency
 
-  # :stopdoc:
-  @warned_version_requirement = false
-
-  def self.warned_version_requirement
-    @warned_version_requirement
-  end
-
-  def self.warned_version_requirement= value
-    @warned_version_requirement = value
-  end
-  # :startdoc:
-
   ##
   # Valid dependency types.
   #--
@@ -54,7 +42,7 @@
 
     unless TYPES.include? type
       raise ArgumentError, "Valid types are #{TYPES.inspect}, "
-        + "not #{@type.inspect}"
+        + "not #{type.inspect}"
     end
 
     @name        = name
@@ -69,9 +57,6 @@
   end
 
   ##
-  # What does this dependency require?
-
-  ##
   # A dependency's hash is the XOR of the hashes of +name+, +type+,
   # and +requirement+.
 
@@ -91,7 +76,7 @@
     @prerelease || requirement.prerelease?
   end
 
-  def pretty_print(q) # :nodoc:
+  def pretty_print q # :nodoc:
     q.group 1, 'Gem::Dependency.new(', ')' do
       q.pp name
       q.text ','
@@ -106,6 +91,9 @@
     end
   end
 
+  ##
+  # What does this dependency require?
+
   def requirement
     return @requirement if defined?(@requirement) and @requirement
 
@@ -133,12 +121,6 @@
     @requirement = @version_requirements if defined?(@version_requirements)
   end
 
-  ##
-  # Rails subclasses Gem::Dependency and uses this method, so we'll hack
-  # around it.
-
-  alias __requirement requirement # :nodoc:
-
   def requirements_list
     requirement.as_list
   end
@@ -147,21 +129,6 @@
     "#{name} (#{requirement}, #{type})"
   end
 
-  def version_requirements # :nodoc:
-    unless Gem::Dependency.warned_version_requirement then
-      warn "#{Gem.location_of_caller.join ':'}:Warning: " \
-           "Gem::Dependency#version_requirements is deprecated " \
-           "and will be removed on or after August 2010.  " \
-           "Use #requirement"
-
-      Gem::Dependency.warned_version_requirement = true
-    end
-
-    __requirement
-  end
-
-  alias_method :version_requirement, :version_requirements
-
   def == other # :nodoc:
     Gem::Dependency === other &&
       self.name        == other.name &&
@@ -173,7 +140,7 @@
   # Dependencies are ordered by name.
 
   def <=> other
-    [@name] <=> [other.name]
+    @name <=> other.name
   end
 
   ##
@@ -184,14 +151,12 @@
 
   def =~ other
     unless Gem::Dependency === other
-      other = Gem::Dependency.new other.name, other.version rescue return false
+      return unless other.respond_to?(:name) && other.respond_to?(:version)
+      other = Gem::Dependency.new other.name, other.version
     end
 
-    pattern = name
-    pattern = /\A#{Regexp.escape pattern}\Z/ unless Regexp === pattern
+    return false unless name === other.name
 
-    return false unless pattern =~ other.name
-
     reqs = other.requirement.requirements
 
     return false unless reqs.length == 1
@@ -202,5 +167,19 @@
     requirement.satisfied_by? version
   end
 
+  def match? name, version
+    return false unless self.name === name
+    return true if requirement.none?
+
+    requirement.satisfied_by? Gem::Version.new(version)
+  end
+
+  def matches_spec? spec
+    return false unless name === spec.name
+    return true  if requirement.none?
+
+    requirement.satisfied_by?(spec.version)
+  end
+
 end
 

Modified: MacRuby/trunk/lib/rubygems/dependency_installer.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/dependency_installer.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/dependency_installer.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -69,6 +69,10 @@
 
     @install_dir = options[:install_dir] || Gem.dir
     @cache_dir = options[:cache_dir] || @install_dir
+
+    # Set with any errors that SpecFetcher finds while search through
+    # gemspecs for a dep
+    @errors = nil
   end
 
   ##
@@ -78,6 +82,8 @@
   # local gems preferred over remote gems.
 
   def find_gems_with_sources(dep)
+    # Reset the errors
+    @errors = nil
     gems_and_sources = []
 
     if @domain == :both or @domain == :local then
@@ -99,7 +105,7 @@
               (requirements.length > 1 or
                 (requirements.first != ">=" and requirements.first != ">"))
 
-        found = Gem::SpecFetcher.fetcher.fetch dep, all, true, dep.prerelease?
+        found, @errors = Gem::SpecFetcher.fetcher.fetch_with_errors dep, all, true, dep.prerelease?
 
         gems_and_sources.push(*found)
 
@@ -126,41 +132,48 @@
 
     dependency_list = Gem::DependencyList.new @development
     dependency_list.add(*specs)
+    to_do = specs.dup
 
-    unless @ignore_dependencies then
-      to_do = specs.dup
-      seen = {}
+    add_found_dependencies to_do, dependency_list unless @ignore_dependencies
 
-      until to_do.empty? do
-        spec = to_do.shift
-        next if spec.nil? or seen[spec.name]
-        seen[spec.name] = true
+    @gems_to_install = dependency_list.dependency_order.reverse
+  end
 
-        deps = spec.runtime_dependencies
-        deps |= spec.development_dependencies if @development
+  def add_found_dependencies to_do, dependency_list
+    seen = {}
 
-        deps.each do |dep|
-          results = find_gems_with_sources(dep).reverse
+    until to_do.empty? do
+      spec = to_do.shift
+      next if spec.nil? or seen[spec.name]
+      seen[spec.name] = true
 
-          results.reject! do |dep_spec,|
-            to_do.push dep_spec
+      deps = spec.runtime_dependencies
+      deps |= spec.development_dependencies if @development
 
-            @source_index.any? do |_, installed_spec|
-              dep.name == installed_spec.name and
-                dep.requirement.satisfied_by? installed_spec.version
-            end
-          end
+      deps.each do |dep|
+        results = find_gems_with_sources(dep).reverse
 
-          results.each do |dep_spec, source_uri|
-            next if seen[dep_spec.name]
-            @specs_and_sources << [dep_spec, source_uri]
-            dependency_list.add dep_spec
+        # FIX: throw in everything that satisfies, and let
+        # FIX: dependencylist reduce to the chosen few
+        results.reject! do |dep_spec,|
+          to_do.push dep_spec
+
+          # already locally installed
+          @source_index.any? do |_, installed_spec|
+            dep.name == installed_spec.name and
+              dep.requirement.satisfied_by? installed_spec.version
           end
         end
+
+        results.each do |dep_spec, source_uri|
+          next if seen[dep_spec.name]
+          @specs_and_sources << [dep_spec, source_uri]
+
+          # FIX: this is the bug
+          dependency_list.add dep_spec
+        end
       end
     end
-
-    @gems_to_install = dependency_list.dependency_order.reverse
   end
 
   ##
@@ -204,8 +217,9 @@
     end
 
     if spec_and_source.nil? then
-      raise Gem::GemNotFoundException,
-        "could not find gem #{gem_name} locally or in a repository"
+      raise Gem::GemNotFoundException.new(
+        "Could not find a valid gem '#{gem_name}' (#{version}) locally or in a repository",
+        gem_name, version, @errors)
     end
 
     @specs_and_sources = [spec_and_source]

Modified: MacRuby/trunk/lib/rubygems/dependency_list.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/dependency_list.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/dependency_list.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -187,6 +187,7 @@
           begin
             yield spec
           rescue TSort::Cyclic
+            # do nothing
           end
           break
         end
@@ -201,13 +202,7 @@
   # +ignored+.
 
   def active_count(specs, ignored)
-    result = 0
-
-    specs.each do |spec|
-      result += 1 unless ignored[spec.full_name]
-    end
-
-    result
+    specs.count { |spec| ignored[spec.full_name].nil? }
   end
 
 end

Modified: MacRuby/trunk/lib/rubygems/doc_manager.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/doc_manager.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/doc_manager.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,7 +4,6 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'fileutils'
 require 'rubygems'
 
 ##
@@ -77,7 +76,7 @@
       :formatter => RDoc::RI::Formatter,
     }
 
-    driver = RDoc::RI::Driver.new(options).class_cache
+    RDoc::RI::Driver.new(options).class_cache
   end
 
   ##
@@ -85,6 +84,7 @@
   # RDoc (template etc.) as a String.
 
   def initialize(spec, rdoc_args="")
+    require 'fileutils'
     @spec = spec
     @doc_dir = File.join(spec.installation_path, "doc", spec.full_name)
     @rdoc_args = rdoc_args.nil? ? [] : rdoc_args.split
@@ -179,7 +179,10 @@
     r = RDoc::RDoc.new
 
     old_pwd = Dir.pwd
-    Dir.chdir(@spec.full_gem_path)
+    Dir.chdir @spec.full_gem_path
+
+    say "rdoc #{args.join ' '}" if Gem.configuration.really_verbose
+
     begin
       r.document args
     rescue Errno::EACCES => e
@@ -193,7 +196,7 @@
       Gem.configuration.backtrace
       ui.errs.puts "(continuing with the rest of the installation)"
     ensure
-      Dir.chdir(old_pwd)
+      Dir.chdir old_pwd
     end
   end
 

Added: MacRuby/trunk/lib/rubygems/errors.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/errors.rb	                        (rev 0)
+++ MacRuby/trunk/lib/rubygems/errors.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -0,0 +1,35 @@
+class Gem::ErrorReason; end
+
+# Generated when trying to lookup a gem to indicate that the gem
+# was found, but that it isn't usable on the current platform.
+#
+# fetch and install read these and report them to the user to aid
+# in figuring out why a gem couldn't be installed.
+#
+class Gem::PlatformMismatch < Gem::ErrorReason
+
+  attr_reader :name
+  attr_reader :version
+  attr_reader :platforms
+
+  def initialize(name, version)
+    @name = name
+    @version = version
+    @platforms = []
+  end
+
+  def add_platform(platform)
+    @platforms << platform
+  end
+
+  def wordy
+    prefix = "Found #{@name} (#{@version})"
+
+    if @platforms.size == 1
+      "#{prefix}, but was for platform #{@platforms[0]}"
+    else
+      "#{prefix}, but was for platforms #{@platforms.join(' ,')}"
+    end
+  end
+
+end

Modified: MacRuby/trunk/lib/rubygems/exceptions.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/exceptions.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/exceptions.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -37,8 +37,17 @@
   attr_accessor :file_path
 end
 
-class Gem::GemNotFoundException < Gem::Exception; end
+class Gem::GemNotFoundException < Gem::Exception
+  def initialize(msg, name=nil, version=nil, errors=nil)
+    super msg
+    @name = name
+    @version = version
+    @errors = errors
+  end
 
+  attr_reader :name, :version, :errors
+end
+
 class Gem::InstallError < Gem::Exception; end
 
 ##

Modified: MacRuby/trunk/lib/rubygems/ext/builder.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/ext/builder.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/ext/builder.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -22,7 +22,9 @@
 
     File.open('Makefile', 'wb') {|f| f.print mf}
 
-    make_program = ENV['make']
+    # try to find make program from Ruby configue arguments first
+    RbConfig::CONFIG['configure_args'] =~ /with-make-prog\=(\w+)/
+    make_program = $1 || ENV['make']
     unless make_program then
       make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
     end

Modified: MacRuby/trunk/lib/rubygems/ext/rake_builder.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/ext/rake_builder.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/ext/rake_builder.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -19,7 +19,7 @@
     # Deal with possible spaces in the path, e.g. C:/Program Files
     dest_path = '"' + dest_path + '"' if dest_path.include?(' ')
 
-    cmd = ENV['rake'] || "#{Gem.ruby} -rubygems #{Gem.bin_path('rake')}" rescue Gem.default_exec_format % 'rake'
+    cmd = ENV['rake'] || "\"#{Gem.ruby}\" -rubygems #{Gem.bin_path('rake')}" rescue Gem.default_exec_format % 'rake'
     cmd += " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}" # ENV is frozen
 
     run cmd, results

Modified: MacRuby/trunk/lib/rubygems/format.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/format.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/format.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,8 +4,6 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'fileutils'
-
 require 'rubygems/package'
 
 ##
@@ -32,8 +30,6 @@
   # representing the data in the gem
 
   def self.from_file_by_path(file_path, security_policy = nil)
-    format = nil
-
     unless File.exist?(file_path)
       raise Gem::Exception, "Cannot load gem at [#{file_path}] in #{Dir.pwd}"
     end

Modified: MacRuby/trunk/lib/rubygems/gem_openssl.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/gem_openssl.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/gem_openssl.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -42,10 +42,8 @@
   # Reference a constant defined in the .rb portion of ssl (just to
   # make sure that part is loaded too).
 
-  dummy = OpenSSL::Digest::SHA1
+  Gem.ssl_available = !!OpenSSL::Digest::SHA1
 
-  Gem.ssl_available = true
-
   class OpenSSL::X509::Certificate # :nodoc:
     # Check the validity of this certificate.
     def check_validity(issuer_cert = nil, time = Time.now)

Modified: MacRuby/trunk/lib/rubygems/gem_path_searcher.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/gem_path_searcher.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/gem_path_searcher.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -22,7 +22,7 @@
   end
 
   ##
-  # Look in all the installed gems until a matching _path_ is found.
+  # Look in all the installed gems until a matching +glob+ is found.
   # Return the _gemspec_ of the gem where it was found.  If no match
   # is found, return nil.
   #
@@ -41,16 +41,18 @@
   # This method doesn't care about the full filename that matches;
   # only that there is a match.
 
-  def find(path)
-    @gemspecs.find do |spec| matching_file? spec, path end
+  def find(glob)
+    @gemspecs.find do |spec|
+      matching_file? spec, glob
+    end
   end
 
   ##
-  # Works like #find, but finds all gemspecs matching +path+.
+  # Works like #find, but finds all gemspecs matching +glob+.
 
-  def find_all(path)
+  def find_all(glob)
     @gemspecs.select do |spec|
-      matching_file? spec, path
+      matching_file? spec, glob
     end
   end
 

Modified: MacRuby/trunk/lib/rubygems/gem_runner.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/gem_runner.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/gem_runner.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -9,6 +9,11 @@
 require 'rubygems/doc_manager'
 
 ##
+# Load additional plugins from $LOAD_PATH
+
+Gem.load_env_plugins
+
+##
 # Run an instance of the gem program.
 #
 # Gem::GemRunner is only intended for internal use by RubyGems itself.  It
@@ -76,3 +81,4 @@
 
 end
 
+Gem.load_plugins

Modified: MacRuby/trunk/lib/rubygems/gemcutter_utilities.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/gemcutter_utilities.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/gemcutter_utilities.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,4 +1,3 @@
-require 'net/http'
 require 'rubygems/remote_fetcher'
 
 module Gem::GemcutterUtilities
@@ -23,8 +22,9 @@
     end
   end
 
-  def rubygems_api_request(method, path, &block)
-    host = ENV['RUBYGEMS_HOST'] || 'https://rubygems.org'
+  def rubygems_api_request(method, path, host = Gem.host, &block)
+    require 'net/http'
+    host = ENV['RUBYGEMS_HOST'] if ENV['RUBYGEMS_HOST']
     uri = URI.parse "#{host}/#{path}"
 
     request_method = Net::HTTP.const_get method.to_s.capitalize

Modified: MacRuby/trunk/lib/rubygems/indexer.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/indexer.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/indexer.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,3 @@
-require 'fileutils'
-require 'tmpdir'
-require 'zlib'
-
 require 'rubygems'
 require 'rubygems/format'
 
@@ -57,6 +53,10 @@
   # Create an indexer that will index the gems in +directory+.
 
   def initialize(directory, options = {})
+    require 'fileutils'
+    require 'tmpdir'
+    require 'zlib'
+
     unless ''.respond_to? :to_xs then
       raise "Gem::Indexer requires that the XML Builder library be installed:" \
            "\n\tgem install builder"
@@ -136,42 +136,6 @@
   # Builds indicies for RubyGems older than 1.2.x
 
   def build_legacy_indicies(index)
-    progress = ui.progress_reporter index.size,
-                                    "Generating YAML quick index gemspecs for #{index.size} gems",
-                                    "Complete"
-
-    Gem.time 'Generated YAML quick index gemspecs' do
-      index.released_gems.each do |original_name, spec|
-        spec_file_name = "#{original_name}.gemspec.rz"
-        yaml_name = File.join @quick_dir, spec_file_name
-
-        yaml_zipped = Gem.deflate spec.to_yaml
-        open yaml_name, 'wb' do |io| io.write yaml_zipped end
-
-        progress.updated original_name
-      end
-
-      progress.done
-    end
-
-    say "Generating quick index"
-
-    Gem.time 'Generated quick index' do
-      open @quick_index, 'wb' do |io|
-        io.puts index.sort.map { |_, spec| spec.original_name }
-      end
-    end
-
-    say "Generating latest index"
-
-    Gem.time 'Generated latest index' do
-      open @latest_index, 'wb' do |io|
-        io.puts index.latest_specs.sort.map { |spec| spec.original_name }
-      end
-    end
-
-    # Don't need prerelease legacy index
-
     say "Generating Marshal master index"
 
     Gem.time 'Generated Marshal master index' do
@@ -180,32 +144,6 @@
       end
     end
 
-    progress = ui.progress_reporter index.size,
-                                    "Generating YAML master index for #{index.size} gems (this may take a while)",
-                                    "Complete"
-
-    Gem.time 'Generated YAML master index' do
-      open @master_index, 'wb' do |io|
-        io.puts "--- !ruby/object:#{index.class}"
-        io.puts "gems:"
-
-        gems = index.sort_by { |name, gemspec| gemspec.sort_obj }
-        gems.each do |original_name, gemspec|
-          yaml = gemspec.to_yaml.gsub(/^/, '    ')
-          yaml = yaml.sub(/\A    ---/, '') # there's a needed extra ' ' here
-          io.print "  #{original_name}:"
-          io.puts yaml
-
-          progress.updated original_name
-        end
-      end
-
-      progress.done
-    end
-
-    @files << @quick_dir
-    @files << @master_index
-    @files << "#{@master_index}.Z"
     @files << @marshal_index
     @files << "#{@marshal_index}.Z"
   end
@@ -320,7 +258,7 @@
     <title>#{rss_title}</title>
     <link>http://#{rss_host}</link>
     <description>Recently released gems from http://#{rss_host}</description>
-    <generator>RubyGems v#{Gem::RubyGemsVersion}</generator>
+    <generator>RubyGems v#{Gem::VERSION}</generator>
     <docs>http://cyber.law.harvard.edu/rss/rss.html</docs>
         HEADER
 
@@ -462,17 +400,8 @@
 
     Gem.time 'Compressed indicies' do
       if @build_legacy then
-        compress @quick_index, 'rz'
-        paranoid @quick_index, 'rz'
-
-        compress @latest_index, 'rz'
-        paranoid @latest_index, 'rz'
-
         compress @marshal_index, 'Z'
         paranoid @marshal_index, 'Z'
-
-        compress @master_index, 'Z'
-        paranoid @master_index, 'Z'
       end
 
       if @build_modern then

Modified: MacRuby/trunk/lib/rubygems/install_update_options.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/install_update_options.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/install_update_options.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -58,11 +58,6 @@
       options[:force] = value
     end
 
-    add_option(:"Install/Update", '-t', '--[no-]test',
-               'Run unit tests prior to installation') do |value, options|
-      options[:test] = value
-    end
-
     add_option(:"Install/Update", '-w', '--[no-]wrappers',
                'Use bin wrappers for executables',
                'Not available on dosish platforms') do |value, options|
@@ -104,13 +99,19 @@
                 "dependencies") do |value, options|
       options[:development] = true
     end
+
+    add_option(:"Install/Update", "--conservative",
+                "Don't attempt to upgrade gems already",
+                "meeting version requirement") do |value, options|
+      options[:conservative] = true
+    end
   end
 
   ##
   # Default options for the gem install command.
 
   def install_update_defaults_str
-    '--rdoc --no-force --no-test --wrappers'
+    '--rdoc --no-force --wrappers'
   end
 
 end

Modified: MacRuby/trunk/lib/rubygems/installer.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/installer.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/installer.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,10 +4,8 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'fileutils'
-require 'rbconfig'
-
 require 'rubygems/format'
+require 'rubygems/exceptions'
 require 'rubygems/ext'
 require 'rubygems/require_paths_builder'
 
@@ -37,7 +35,6 @@
   # Raised when there is an error while building extensions.
   #
   class ExtensionBuildError < Gem::InstallError; end
-  class GenerateBinaryError < Gem::InstallError; end
 
   include Gem::UserInteraction
 
@@ -92,6 +89,8 @@
   # :wrappers:: Install wrappers if true, symlinks if false.
 
   def initialize(gem, options={})
+    require 'fileutils'
+
     @gem = gem
 
     options = {
@@ -134,7 +133,8 @@
     end
 
     FileUtils.mkdir_p @gem_home
-    raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
+    raise Gem::FilePermissionError, @gem_home unless
+      options[:unpack] or File.writable? @gem_home
 
     @spec = @format.spec
 
@@ -166,7 +166,7 @@
       end
 
       if rrgv = @spec.required_rubygems_version then
-        unless rrgv.satisfied_by? Gem::Version.new(Gem::RubyGemsVersion) then
+        unless rrgv.satisfied_by? Gem::Version.new(Gem::VERSION) then
           raise Gem::InstallError,
             "#{@spec.name} requires RubyGems version #{rrgv}. " +
             "Try 'gem update --system' to update RubyGems itself."
@@ -271,7 +271,7 @@
   ##
   # Creates windows .bat files for easy running of commands
 
-  def generate_windows_script(bindir, filename)
+  def generate_windows_script(filename, bindir)
     if Gem.win_platform? then
       script_name = filename + ".bat"
       script_path = File.join bindir, File.basename(script_name)
@@ -296,7 +296,7 @@
 
     @spec.executables.each do |filename|
       filename.untaint
-      bin_path = File.expand_path File.join(@gem_dir, @spec.bindir, filename)
+      bin_path = File.expand_path "#{@spec.bindir}/#{filename}", @gem_dir
       mode = File.stat(bin_path).mode | 0111
       File.chmod mode, bin_path
 
@@ -318,48 +318,24 @@
   def generate_bin_script(filename, bindir)
     bin_script_path = File.join bindir, formatted_program_filename(filename)
 
-    exec_path = File.join @gem_dir, @spec.bindir, filename
+    File.join @gem_dir, @spec.bindir, filename
 
     # HACK some gems don't have #! in their executables, restore 2008/06
     #if File.read(exec_path, 2) == '#!' then
-      # FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
+      FileUtils.rm_f bin_script_path # prior install may have been --no-wrappers
 
-      bin_script_exists = File.exists?(bin_script_path)
-      mode   = 'w' unless(bin_script_exists)
-      mode ||= 'r+'
-      new_shebang = shebang(filename)
-      File.open bin_script_path, mode, 0755 do |file|
-        if bin_script_exists
-          # If the first line is different than the shebang we want to insert
-          # we are probably overwriting a script installed by another ruby
-          # implementation / version
-          begin
-            old_shebang = file.readline.chomp
-          rescue
-            old_shebang = ""
-          end
-
-          if old_shebang != new_shebang
-            warn = <<-WARN_MESSAGE
-You are installing a new version of #{bin_script_path}.
-This file already exists with a different shebang, possibly from a different
-ruby implementation or version. This operation may break the script.
-WARN_MESSAGE
-            alert_warning(warn)
-            if !@force && !ask_yes_no("Do you still wish to continue?")
-              raise GenerateBinaryError, "Could not write #{bin_script_path}"
-            end
-            say "Overwrote #{bin_script_path}" if Gem.configuration.really_verbose
-          end
-          file.seek(0)
-          file.truncate(0)
-        end
+      File.open bin_script_path, 'w', 0755 do |file|
         file.print app_script_text(filename)
       end
 
       say bin_script_path if Gem.configuration.really_verbose
 
-      generate_windows_script bindir, filename
+      generate_windows_script filename, bindir
+    #else
+    #  FileUtils.rm_f bin_script_path
+    #  FileUtils.cp exec_path, bin_script_path,
+    #               :verbose => Gem.configuration.really_verbose
+    #end
   end
 
   ##
@@ -490,7 +466,7 @@
 
         say results.join("\n") if Gem.configuration.really_verbose
 
-      rescue => ex
+      rescue
         results = results.join "\n"
 
         File.open('gem_make.out', 'wb') { |f| f.puts results }
@@ -521,6 +497,8 @@
 
     raise ArgumentError, "format required to extract from" if @format.nil?
 
+    dirs = []
+
     @format.file_entries.each do |entry, file_data|
       path = entry['path'].untaint
 
@@ -538,8 +516,13 @@
       end
 
       FileUtils.rm_rf(path) if File.exists?(path)
-      FileUtils.mkdir_p File.dirname(path)
 
+      dir = File.dirname(path)
+      if !dirs.include?(dir)
+        dirs << dir
+        FileUtils.mkdir_p dir
+      end
+
       File.open(path, "wb") do |out|
         out.write file_data
       end

Modified: MacRuby/trunk/lib/rubygems/local_remote_options.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/local_remote_options.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/local_remote_options.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -51,6 +51,7 @@
     end
 
     add_bulk_threshold_option
+    add_clear_sources_option
     add_source_option
     add_proxy_option
     add_update_sources_option
@@ -69,6 +70,18 @@
   end
 
   ##
+  # Add the --clear-sources option
+
+  def add_clear_sources_option
+    add_option(:"Local/Remote", '--clear-sources',
+               'Clear the gem sources') do |value, options|
+
+      Gem.sources.clear
+      options[:sources_cleared] = true
+    end
+  end
+
+  ##
   # Add the --http-proxy option
 
   def add_proxy_option
@@ -88,14 +101,14 @@
     accept_uri_http
 
     add_option(:"Local/Remote", '--source URL', URI::HTTP,
-               'Use URL as the remote source for gems') do |source, options|
+               'Add URL as a remote source for gems') do |source, options|
+
       source << '/' if source !~ /\/\z/
 
-      if options[:added_source] then
+      if options.delete :sources_cleared then
+        Gem.sources = [source]
+      else
         Gem.sources << source unless Gem.sources.include?(source)
-      else
-        options[:added_source] = true
-        Gem.sources.replace [source]
       end
     end
   end

Modified: MacRuby/trunk/lib/rubygems/old_format.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/old_format.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/old_format.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -5,9 +5,6 @@
 #++
 
 require 'rubygems'
-require 'fileutils'
-require 'yaml'
-require 'zlib'
 
 ##
 # The format class knows the guts of the RubyGem .gem file format and provides
@@ -24,6 +21,10 @@
   # gem:: [String] The file name of the gem
 
   def initialize(gem_path)
+    require 'fileutils'
+    require 'zlib'
+    Gem.load_yaml
+
     @gem_path = gem_path
   end
 
@@ -143,7 +144,7 @@
         end
         yield [entry, Zlib::Inflate.inflate(file_data.strip.unpack("m")[0])]
       end
-    rescue Zlib::DataError => e
+    rescue Zlib::DataError
       raise Gem::Exception, errstr
     end
   end

Modified: MacRuby/trunk/lib/rubygems/package/f_sync_dir.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/f_sync_dir.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/f_sync_dir.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
+#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
 #++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
-#--
 
 module Gem::Package::FSyncDir
 

Modified: MacRuby/trunk/lib/rubygems/package/tar_header.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/tar_header.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/tar_header.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
+#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
 #++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
-#--
 
 ##
 #--

Modified: MacRuby/trunk/lib/rubygems/package/tar_input.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/tar_input.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/tar_input.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,6 +4,9 @@
 # See LICENSE.txt for additional licensing information.
 #--
 
+require 'zlib'
+Gem.load_yaml
+
 class Gem::Package::TarInput
 
   include Gem::Package::FSyncDir

Modified: MacRuby/trunk/lib/rubygems/package/tar_output.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/tar_output.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/tar_output.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
+#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
 #++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
-#--
 
 ##
 # TarOutput is a wrapper to TarWriter that builds gem-format tar file.

Modified: MacRuby/trunk/lib/rubygems/package/tar_reader.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/tar_reader.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/tar_reader.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
+#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
 #++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
-#--
 
 ##
 # TarReader reads tar files and allows iteration over their items

Modified: MacRuby/trunk/lib/rubygems/package/tar_writer.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package/tar_writer.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package/tar_writer.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,7 +1,8 @@
+# -*- coding: utf-8 -*-
+#--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
 #++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
-#--
 
 ##
 # Allows writing of tar files

Modified: MacRuby/trunk/lib/rubygems/package.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,22 +1,20 @@
-#++
-# Copyright (C) 2004 Mauricio Julio Fern\xE1ndez Pradier
-# See LICENSE.txt for additional licensing information.
+# -*- coding: utf-8 -*-
 #--
+# Copyright (C) 2004 Mauricio Julio Fernández Pradier
+# See LICENSE.txt for additional licensing information.
+#++
 
-require 'fileutils'
-require 'find'
-require 'stringio'
-require 'yaml'
-require 'zlib'
-
 require 'rubygems/security'
 require 'rubygems/specification'
 
+##
 # Wrapper for FileUtils meant to provide logging and additional operations if
 # needed.
+
 class Gem::FileOperations
 
   def initialize(logger = nil)
+    require 'fileutils'
     @logger = logger
   end
 

Modified: MacRuby/trunk/lib/rubygems/package_task.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/package_task.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/package_task.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -41,7 +41,7 @@
 #
 #   require 'rubygems'
 #   require 'rubygems/package_task'
-#   
+#
 #   spec = Gem::Specification.new do |s|
 #     s.platform = Gem::Platform::RUBY
 #     s.summary = "Ruby based make-like utility."
@@ -56,7 +56,7 @@
 #   and dependencies are specified in standard Ruby syntax.
 #     EOF
 #   end
-#   
+#
 #   Gem::PackageTask.new(spec) do |pkg|
 #     pkg.need_zip = true
 #     pkg.need_tar = true
@@ -102,6 +102,7 @@
 
     gem_file = gem_spec.file_name
     gem_path = File.join package_dir, gem_file
+    gem_dir  = File.join package_dir, gem_spec.full_name
 
     desc "Build the gem file #{gem_file}"
     task :gem => [gem_path]
@@ -109,15 +110,15 @@
     trace = Rake.application.options.trace
     Gem.configuration.verbose = trace
 
-    file gem_path => [package_dir] + @gem_spec.files do
-      when_writing "Creating #{gem_spec.file_name}" do
-        Gem::Builder.new(gem_spec).build
-        verbose trace do
-          mv gem_file, gem_path
+    file gem_path => [package_dir, gem_dir] + @gem_spec.files do
+      chdir(gem_dir) do
+        when_writing "Creating #{gem_spec.file_name}" do
+          Gem::Builder.new(gem_spec).build
+          verbose(true) {
+            mv gem_file, ".."
+          }
         end
       end
     end
   end
-
 end
-

Modified: MacRuby/trunk/lib/rubygems/platform.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/platform.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/platform.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -70,6 +70,8 @@
                       when /hpux(\d+)/ then            [ 'hpux',      $1  ]
                       when /^java$/, /^jruby$/ then    [ 'java',      nil ]
                       when /^java([\d.]*)/ then        [ 'java',      $1  ]
+                      when /^dotnet$/ then             [ 'dotnet',    nil ]
+                      when /^dotnet([\d.]*)/ then      [ 'dotnet',    $1  ]
                       when /linux/ then                [ 'linux',     $1  ]
                       when /mingw32/ then              [ 'mingw32',   nil ]
                       when /(mswin\d+)(\_(\d+))?/ then
@@ -103,7 +105,7 @@
   def to_s
     to_a.compact.join '-'
   end
-  
+
   def empty?
     to_s.empty?
   end
@@ -148,6 +150,7 @@
               when /^i686-darwin(\d)/     then ['x86',       'darwin',  $1    ]
               when /^i\d86-linux/         then ['x86',       'linux',   nil   ]
               when 'java', 'jruby'        then [nil,         'java',    nil   ]
+              when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet',  $2    ]
               when /mswin32(\_(\d+))?/    then ['x86',       'mswin32', $2    ]
               when 'powerpc-darwin'       then ['powerpc',   'darwin',  nil   ]
               when /powerpc-darwin(\d)/   then ['powerpc',   'darwin',  $1    ]

Modified: MacRuby/trunk/lib/rubygems/remote_fetcher.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/remote_fetcher.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/remote_fetcher.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,10 +1,7 @@
-require 'net/http'
-require 'stringio'
-require 'time'
+require 'rubygems'
+require 'rubygems/user_interaction'
 require 'uri'
 
-require 'rubygems'
-
 ##
 # RemoteFetcher handles the details of fetching gems and gem information from
 # a remote source.
@@ -56,6 +53,11 @@
   # * <tt>:no_proxy</tt>: ignore environment variables and _don't_ use a proxy
 
   def initialize(proxy = nil)
+    require 'net/http'
+    require 'stringio'
+    require 'time'
+    require 'uri'
+
     Socket.do_not_reverse_lookup = true
 
     @connections = {}
@@ -75,6 +77,8 @@
   # always replaced.
 
   def download(spec, source_uri, install_dir = Gem.dir)
+    Gem.ensure_gem_subdirectories(install_dir) rescue nil
+
     if File.writable?(install_dir)
       cache_dir = File.join install_dir, 'cache'
     else
@@ -88,7 +92,9 @@
 
    # Always escape URI's to deal with potential spaces and such
     unless URI::Generic === source_uri
-      source_uri = URI.parse(URI.escape(source_uri))
+      source_uri = URI.parse(URI.const_defined?(:DEFAULT_PARSER) ?
+                             URI::DEFAULT_PARSER.escape(source_uri) :
+                             URI.escape(source_uri))
     end
 
     scheme = source_uri.scheme
@@ -145,7 +151,7 @@
                       source_uri.path
                     end
 
-      source_path = URI.unescape source_path
+      source_path = unescape source_path
 
       begin
         FileUtils.cp source_path, local_gem_path unless
@@ -189,14 +195,22 @@
 
   def escape(str)
     return unless str
-    URI.escape(str)
+    @uri_parser ||= uri_escaper
+    @uri_parser.escape str
   end
 
   def unescape(str)
     return unless str
-    URI.unescape(str)
+    @uri_parser ||= uri_escaper
+    @uri_parser.unescape str
   end
 
+  def uri_escaper
+    URI::Parser.new
+  rescue NameError
+    URI
+  end
+
   ##
   # Returns an HTTP proxy URI if one is set in the environment variables.
 
@@ -239,7 +253,7 @@
       ]
     end
 
-    connection_id = net_http_args.join ':'
+    connection_id = [Thread.current.object_id, *net_http_args].join ':'
     @connections[connection_id] ||= Net::HTTP.new(*net_http_args)
     connection = @connections[connection_id]
 
@@ -252,6 +266,8 @@
     connection.start unless connection.started?
 
     connection
+  rescue Errno::EHOSTDOWN => e
+    raise FetchError.new(e.message, uri)
   end
 
   ##
@@ -259,20 +275,18 @@
   # read from the filesystem instead.
 
   def open_uri_or_path(uri, last_modified = nil, head = false, depth = 0)
-    if RUBY_ENGINE == 'macruby'
-      # XXX we are taking a _much faster_ code path here, this change should be
-      # removed once we re-implement the IO subsystem (and therefore Net::HTTP)
-      # on top of CF.
-      framework 'Foundation'
-      say "Fetching #{uri.to_s}" if Gem.configuration.really_verbose
-      url = NSURL.URLWithString(uri.to_s)
-      data = NSMutableData.dataWithContentsOfURL(url)
-      if data.nil?
-        raise Gem::RemoteFetcher::FetchError, "error when fetching data from #{uri}"
-      end
-      say "OK" if Gem.configuration.really_verbose
-      return String.new(data)
+    # XXX MACRUBY a much faster / more stable downloader code path, using
+    # Foundation instead of Net::HTTP
+    framework 'Foundation'
+    say "Fetching #{uri.to_s}" if Gem.configuration.really_verbose
+    url = NSURL.URLWithString(uri.to_s)
+    data = NSMutableData.dataWithContentsOfURL(url)
+    if data.nil?
+      raise Gem::RemoteFetcher::FetchError, "error when fetching data from #{uri}"
     end
+    say "OK" if Gem.configuration.really_verbose
+    return String.new(data)
+
     raise "block is dead" if block_given?
 
     uri = URI.parse uri unless URI::Generic === uri
@@ -323,7 +337,7 @@
       request.basic_auth uri.user, uri.password
     end
 
-    ua = "RubyGems/#{Gem::RubyGemsVersion} #{Gem::Platform.local}"
+    ua = "RubyGems/#{Gem::VERSION} #{Gem::Platform.local}"
     ua << " Ruby/#{RUBY_VERSION} (#{RUBY_RELEASE_DATE}"
     ua << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
     ua << ")"
@@ -349,7 +363,34 @@
 
       say "#{request.method} #{uri}" if
         Gem.configuration.really_verbose
-      response = connection.request request
+
+      file_name = File.basename(uri.path)
+      # perform download progress reporter only for gems
+      if request.response_body_permitted? && file_name =~ /\.gem$/
+        reporter = ui.download_reporter
+        response = connection.request(request) do |incomplete_response|
+          if Net::HTTPOK === incomplete_response
+            reporter.fetch(file_name, incomplete_response.content_length)
+            downloaded = 0
+            data = ''
+
+            incomplete_response.read_body do |segment|
+              data << segment
+              downloaded += segment.length
+              reporter.update(downloaded)
+            end
+            reporter.done
+            if incomplete_response.respond_to? :body=
+              incomplete_response.body = data
+            else
+              incomplete_response.instance_variable_set(:@body, data)
+            end
+          end
+        end
+      else
+        response = connection.request request
+      end
+
       say "#{response.code} #{response.message}" if
         Gem.configuration.really_verbose
 
@@ -365,7 +406,9 @@
     # HACK work around EOFError bug in Net::HTTP
     # NOTE Errno::ECONNABORTED raised a lot on Windows, and make impossible
     # to install gems.
-    rescue EOFError, Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
+    rescue EOFError, Timeout::Error,
+           Errno::ECONNABORTED, Errno::ECONNRESET, Errno::EPIPE
+
       requests = @requests[connection.object_id]
       say "connection reset after #{requests} requests, retrying" if
         Gem.configuration.really_verbose

Modified: MacRuby/trunk/lib/rubygems/requirement.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/requirement.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/requirement.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -14,7 +14,7 @@
     "<"  =>  lambda { |v, r| v < r  },
     ">=" =>  lambda { |v, r| v >= r },
     "<=" =>  lambda { |v, r| v <= r },
-    "~>" =>  lambda { |v, r| v = v.release; v >= r && v < r.bump }
+    "~>" =>  lambda { |v, r| v >= r && v.release < r.bump }
   }
 
   quoted  = OPS.keys.map { |k| Regexp.quote k }.join "|"
@@ -93,9 +93,14 @@
     requirements.uniq!
 
     requirements << ">= 0" if requirements.empty?
+    @none = (requirements == ">= 0")
     @requirements = requirements.map! { |r| self.class.parse r }
   end
 
+  def none?
+    @none ||= (to_s == ">= 0")
+  end
+
   def as_list # :nodoc:
     requirements.map { |op, version| "#{op} #{version}" }
   end

Modified: MacRuby/trunk/lib/rubygems/security.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/security.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/security.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,9 +4,10 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'rubygems'
+require 'rubygems/exceptions'
 require 'rubygems/gem_openssl'
 
+#
 # = Signed Gems README
 #
 # == Table of Contents
@@ -218,7 +219,7 @@
 #
 #   # signing key (still kept in an undisclosed location!)
 #   s.signing_key = '/mnt/floppy/alf-private_key.pem'
-#   
+#
 #   # certificate chain (includes the issuer certificate now too)
 #   s.cert_chain  = ['/home/alf/doc/seattlerb-public_cert.pem',
 #                    '/home/alf/doc/alf_at_seattle-public_cert.pem']
@@ -265,7 +266,35 @@
 # A more detailed description of each options is available in the walkthrough
 # above.
 #
+# == Manually verifying signatures
 #
+# In case you don't trust RubyGems you can verify gem signatures manually:
+#
+# 1. Fetch and unpack the gem
+#
+#     gem fetch some_signed_gem
+#     tar -xf some_signed_gem-1.0.gem
+#
+# 2. Grab the public key from the gemspec
+#
+#     gem spec some_signed_gem-1.0.gem cert_chain | \
+#       ruby -pe 'sub(/^ +/, "")' > public_key.crt
+#
+# 3. Generate a SHA1 hash of the data.tar.gz
+#
+#     openssl dgst -sha1 < data.tar.gz > my.hash
+#
+# 4. Verify the signature
+#
+#     openssl rsautl -verify -inkey public_key.crt -certin \
+#       -in data.tar.gz.sig > verified.hash
+#
+# 5. Compare your hash to the verified hash
+#
+#     diff -s verified.hash my.hash
+#
+# 6. Repeat 5 and 6 with metadata.gz
+#
 # == OpenSSL Reference
 #
 # The .pem files generated by --build and --sign are just basic OpenSSL PEM
@@ -274,7 +303,7 @@
 #   # convert a PEM format X509 certificate into DER format:
 #   # (note: Windows .cer files are X509 certificates in DER format)
 #   $ openssl x509 -in input.pem -outform der -out output.der
-#   
+#
 #   # print out the certificate in a human-readable format:
 #   $ openssl x509 -in input.pem -noout -text
 #
@@ -282,7 +311,7 @@
 #
 #   # convert a PEM format RSA key into DER format:
 #   $ openssl rsa -in input_key.pem -outform der -out output_key.der
-#   
+#
 #   # print out the key in a human readable format:
 #   $ openssl rsa -in input_key.pem -noout -text
 #
@@ -319,11 +348,14 @@
 
 module Gem::Security
 
+  ##
+  # Gem::Security default exception type
+
   class Exception < Gem::Exception; end
 
-  #
-  # default options for most of the methods below
-  #
+  ##
+  # Default options for most of the methods below
+
   OPT = {
     # private key options
     :key_algo   => Gem::SSL::PKEY_RSA,
@@ -338,38 +370,38 @@
       'basicConstraints'      => 'CA:FALSE',
       'subjectKeyIdentifier'  => 'hash',
       'keyUsage'              => 'keyEncipherment,dataEncipherment,digitalSignature',
-  },
+    },
 
-  # save the key and cert to a file in build_self_signed_cert()?
-  :save_key   => true,
-  :save_cert  => true,
+    # save the key and cert to a file in build_self_signed_cert()?
+    :save_key   => true,
+    :save_cert  => true,
 
-  # if you define either of these, then they'll be used instead of
-  # the output_fmt macro below
-  :save_key_path => nil,
-  :save_cert_path => nil,
+    # if you define either of these, then they'll be used instead of
+    # the output_fmt macro below
+    :save_key_path => nil,
+    :save_cert_path => nil,
 
-  # output name format for self-signed certs
-  :output_fmt => 'gem-%s.pem',
-  :munge_re   => Regexp.new(/[^a-z0-9_.-]+/),
+    # output name format for self-signed certs
+    :output_fmt => 'gem-%s.pem',
+    :munge_re   => Regexp.new(/[^a-z0-9_.-]+/),
 
-  # output directory for trusted certificate checksums
-  :trust_dir => File::join(Gem.user_home, '.gem', 'trust'),
+    # output directory for trusted certificate checksums
+    :trust_dir => File::join(Gem.user_home, '.gem', 'trust'),
 
-  # default permissions for trust directory and certs
-  :perms => {
-    :trust_dir      => 0700,
-    :trusted_cert   => 0600,
-    :signing_cert   => 0600,
-    :signing_key    => 0600,
-  },
+    # default permissions for trust directory and certs
+    :perms => {
+      :trust_dir      => 0700,
+      :trusted_cert   => 0600,
+      :signing_cert   => 0600,
+      :signing_key    => 0600,
+    },
   }
 
-  #
+  ##
   # A Gem::Security::Policy object encapsulates the settings for verifying
   # signed gem files.  This is the base class.  You can either declare an
   # instance of this or use one of the preset security policies below.
-  #
+
   class Policy
     attr_accessor :verify_data, :verify_signer, :verify_chain,
       :verify_root, :only_trusted, :only_signed
@@ -509,9 +541,9 @@
     end
   end
 
-  #
+  ##
   # No security policy: all package signature checks are disabled.
-  #
+
   NoSecurity = Policy.new(
     :verify_data      => false,
     :verify_signer    => false,
@@ -521,14 +553,14 @@
     :only_signed      => false
   )
 
-  #
+  ##
   # AlmostNo security policy: only verify that the signing certificate is the
   # one that actually signed the data.  Make no attempt to verify the signing
   # certificate chain.
   #
   # This policy is basically useless. better than nothing, but can still be
   # easily spoofed, and is not recommended.
-  #
+
   AlmostNoSecurity = Policy.new(
     :verify_data      => true,
     :verify_signer    => false,
@@ -538,13 +570,13 @@
     :only_signed      => false
   )
 
-  #
+  ##
   # Low security policy: only verify that the signing certificate is actually
   # the gem signer, and that the signing certificate is valid.
   #
   # This policy is better than nothing, but can still be easily spoofed, and
   # is not recommended.
-  #
+
   LowSecurity = Policy.new(
     :verify_data      => true,
     :verify_signer    => true,
@@ -554,7 +586,7 @@
     :only_signed      => false
   )
 
-  #
+  ##
   # Medium security policy: verify the signing certificate, verify the signing
   # certificate chain all the way to the root certificate, and only trust root
   # certificates that we have explicitly allowed trust for.
@@ -562,7 +594,7 @@
   # This security policy is reasonable, but it allows unsigned packages, so a
   # malicious person could simply delete the package signature and pass the
   # gem off as unsigned.
-  #
+
   MediumSecurity = Policy.new(
     :verify_data      => true,
     :verify_signer    => true,
@@ -572,7 +604,7 @@
     :only_signed      => false
   )
 
-  #
+  ##
   # High security policy: only allow signed gems to be installed, verify the
   # signing certificate, verify the signing certificate chain all the way to
   # the root certificate, and only trust root certificates that we have
@@ -580,7 +612,7 @@
   #
   # This security policy is significantly more difficult to bypass, and offers
   # a reasonable guarantee that the contents of the gem have not been altered.
-  #
+
   HighSecurity = Policy.new(
     :verify_data      => true,
     :verify_signer    => true,
@@ -590,9 +622,9 @@
     :only_signed      => true
   )
 
-  #
+  ##
   # Hash of configured security policies
-  #
+
   Policies = {
     'NoSecurity'       => NoSecurity,
     'AlmostNoSecurity' => AlmostNoSecurity,
@@ -601,25 +633,24 @@
     'HighSecurity'     => HighSecurity,
   }
 
-  #
+  ##
   # Sign the cert cert with @signing_key and @signing_cert, using the digest
   # algorithm opt[:dgst_algo]. Returns the newly signed certificate.
-  #
+
   def self.sign_cert(cert, signing_key, signing_cert, opt = {})
     opt = OPT.merge(opt)
 
-    # set up issuer information
     cert.issuer = signing_cert.subject
-    cert.sign(signing_key, opt[:dgst_algo].new)
+    cert.sign signing_key, opt[:dgst_algo].new
 
     cert
   end
 
-  #
+  ##
   # Make sure the trust directory exists.  If it does exist, make sure it's
   # actually a directory.  If not, then create it with the appropriate
   # permissions.
-  #
+
   def self.verify_trust_dir(path, perms)
     # if the directory exists, then make sure it is in fact a directory.  if
     # it doesn't exist, then create it with the appropriate permissions
@@ -636,94 +667,99 @@
     end
   end
 
-  #
+  ##
   # Build a certificate from the given DN and private key.
-  #
+
   def self.build_cert(name, key, opt = {})
     Gem.ensure_ssl_available
-    opt = OPT.merge(opt)
+    opt = OPT.merge opt
 
-    # create new cert
-    ret = OpenSSL::X509::Certificate.new
+    cert = OpenSSL::X509::Certificate.new
 
-    # populate cert attributes
-    ret.version = 2
-    ret.serial = 0
-    ret.public_key = key.public_key
-    ret.not_before = Time.now
-    ret.not_after = Time.now + opt[:cert_age]
-    ret.subject = name
+    cert.not_after  = Time.now + opt[:cert_age]
+    cert.not_before = Time.now
+    cert.public_key = key.public_key
+    cert.serial     = 0
+    cert.subject    = name
+    cert.version    = 2
 
-    # add certificate extensions
-    ef = OpenSSL::X509::ExtensionFactory.new(nil, ret)
-    ret.extensions = opt[:cert_exts].map { |k, v| ef.create_extension(k, v) }
+    ef = OpenSSL::X509::ExtensionFactory.new nil, cert
 
-    # sign cert
-    i_key, i_cert = opt[:issuer_key] || key, opt[:issuer_cert] || ret
-    ret = sign_cert(ret, i_key, i_cert, opt)
+    cert.extensions = opt[:cert_exts].map do |ext_name, value|
+      ef.create_extension ext_name, value
+    end
 
-    # return cert
-    ret
+    i_key  = opt[:issuer_key]  || key
+    i_cert = opt[:issuer_cert] || cert
+
+    cert = sign_cert cert, i_key, i_cert, opt
+
+    cert
   end
 
-  #
+  ##
   # Build a self-signed certificate for the given email address.
-  #
+
   def self.build_self_signed_cert(email_addr, opt = {})
     Gem.ensure_ssl_available
     opt = OPT.merge(opt)
     path = { :key => nil, :cert => nil }
 
-    # split email address up
-    cn, dcs = email_addr.split('@')
-    dcs = dcs.split('.')
+    name = email_to_name email_addr, opt[:munge_re]
 
-    # munge email CN and DCs
-    cn = cn.gsub(opt[:munge_re], '_')
-    dcs = dcs.map { |dc| dc.gsub(opt[:munge_re], '_') }
+    key = opt[:key_algo].new opt[:key_size]
 
-    # create DN
-    name = "CN=#{cn}/" << dcs.map { |dc| "DC=#{dc}" }.join('/')
-    name = OpenSSL::X509::Name::parse(name)
+    verify_trust_dir opt[:trust_dir], opt[:perms][:trust_dir]
 
-    # build private key
-    key = opt[:key_algo].new(opt[:key_size])
+    if opt[:save_key] then
+      path[:key] = opt[:save_key_path] || (opt[:output_fmt] % 'private_key')
 
-    # method name pretty much says it all :)
-    verify_trust_dir(opt[:trust_dir], opt[:perms][:trust_dir])
-
-    # if we're saving the key, then write it out
-    if opt[:save_key]
-      path[:key] = opt[:save_key_path] || (opt[:output_fmt] % 'private_key')
-      File.open(path[:key], 'wb') do |file|
-        file.chmod(opt[:perms][:signing_key])
-        file.write(key.to_pem)
+      open path[:key], 'wb' do |io|
+        io.chmod opt[:perms][:signing_key]
+        io.write key.to_pem
       end
     end
 
-    # build self-signed public cert from key
-    cert = build_cert(name, key, opt)
+    cert = build_cert name, key, opt
 
-    # if we're saving the cert, then write it out
-    if opt[:save_cert]
+    if opt[:save_cert] then
       path[:cert] = opt[:save_cert_path] || (opt[:output_fmt] % 'public_cert')
-      File.open(path[:cert], 'wb') do |file|
-        file.chmod(opt[:perms][:signing_cert])
-        file.write(cert.to_pem)
+
+      open path[:cert], 'wb' do |file|
+        file.chmod opt[:perms][:signing_cert]
+        file.write cert.to_pem
       end
     end
 
-    # return key, cert, and paths (if applicable)
     { :key => key, :cert => cert,
       :key_path => path[:key], :cert_path => path[:cert] }
   end
 
-  #
+  ##
+  # Turns +email_address+ into an OpenSSL::X509::Name
+
+  def self.email_to_name email_address, munge_re
+    cn, dcs = email_address.split '@'
+
+    dcs = dcs.split '.'
+
+    cn = cn.gsub munge_re, '_'
+
+    dcs = dcs.map do |dc|
+      dc.gsub munge_re, '_'
+    end
+
+    name = "CN=#{cn}/" << dcs.map { |dc| "DC=#{dc}" }.join('/')
+
+    OpenSSL::X509::Name.parse name
+  end
+
+  ##
   # Add certificate to trusted cert list.
   #
   # Note: At the moment these are stored in OPT[:trust_dir], although that
   # directory may change in the future.
-  #
+
   def self.add_trusted_cert(cert, opt = {})
     opt = OPT.merge(opt)
 
@@ -743,12 +779,14 @@
     nil
   end
 
-  #
+  ##
   # Basic OpenSSL-based package signing class.
-  #
+
   class Signer
-    attr_accessor :key, :cert_chain
 
+    attr_accessor :cert_chain
+    attr_accessor :key
+
     def initialize(key, cert_chain)
       Gem.ensure_ssl_available
       @algo = Gem::Security::OPT[:dgst_algo]
@@ -774,13 +812,14 @@
       end
     end
 
-    #
+    ##
     # Sign data with given digest algorithm
-    #
+
     def sign(data)
       @key.sign(@algo.new, data)
     end
 
   end
+
 end
 

Modified: MacRuby/trunk/lib/rubygems/server.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/server.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/server.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,5 +1,4 @@
 require 'webrick'
-require 'yaml'
 require 'zlib'
 require 'erb'
 
@@ -21,7 +20,6 @@
 # * legacy indexes:
 #   * "/Marshal.#{Gem.marshal_version}" - Full SourceIndex dump of metadata
 #     for installed gems
-#   * "/yaml" - YAML dump of metadata for installed gems - deprecated
 #
 # == Usage
 #
@@ -33,6 +31,8 @@
 
 class Gem::Server
 
+  attr_reader :spec_dirs
+
   include ERB::Util
   include Gem::UserInteraction
 
@@ -427,32 +427,40 @@
 
   def self.run(options)
     new(options[:gemdir], options[:port], options[:daemon],
-        options[:addresses]).run
+        options[:launch], options[:addresses]).run
   end
 
-  def initialize(gem_dir, port, daemon, addresses = nil)
+  ##
+  # Only the first directory in gem_dirs is used for serving gems
+
+  def initialize(gem_dirs, port, daemon, launch = nil, addresses = nil)
     Socket.do_not_reverse_lookup = true
 
-    @gem_dir = gem_dir
+    @gem_dirs = Array gem_dirs
     @port = port
     @daemon = daemon
+    @launch = launch
     @addresses = addresses
     logger = WEBrick::Log.new nil, WEBrick::BasicLog::FATAL
     @server = WEBrick::HTTPServer.new :DoNotListen => true, :Logger => logger
 
-    @spec_dir = File.join @gem_dir, 'specifications'
+    @spec_dirs = @gem_dirs.map do |gem_dir|
+      spec_dir = File.join gem_dir, 'specifications'
 
-    unless File.directory? @spec_dir then
-      raise ArgumentError, "#{@gem_dir} does not appear to be a gem repository"
+      unless File.directory? spec_dir then
+        raise ArgumentError, "#{gem_dir} does not appear to be a gem repository"
+      end
+
+      spec_dir
     end
 
-    @source_index = Gem::SourceIndex.from_gems_in @spec_dir
+    @source_index = Gem::SourceIndex.from_gems_in(*@spec_dirs)
   end
 
   def Marshal(req, res)
     @source_index.refresh!
 
-    res['date'] = File.stat(@spec_dir).mtime
+    add_date res
 
     index = Marshal.dump @source_index
 
@@ -471,12 +479,18 @@
     res.body << index
   end
 
+  def add_date res
+    res['date'] = @spec_dirs.map do |spec_dir|
+      File.stat(spec_dir).mtime
+    end.max
+  end
+
   def latest_specs(req, res)
     @source_index.refresh!
 
     res['content-type'] = 'application/x-gzip'
 
-    res['date'] = File.stat(@spec_dir).mtime
+    add_date res
 
     specs = @source_index.latest_specs.sort.map do |spec|
       platform = spec.original_platform
@@ -535,22 +549,9 @@
     @source_index.refresh!
 
     res['content-type'] = 'text/plain'
-    res['date'] = File.stat(@spec_dir).mtime
+    add_date res
 
     case req.request_uri.path
-    when '/quick/index' then
-      res.body << @source_index.map { |name,| name }.sort.join("\n")
-    when '/quick/index.rz' then
-      index = @source_index.map { |name,| name }.sort.join("\n")
-      res['content-type'] = 'application/x-deflate'
-      res.body << Gem.deflate(index)
-    when '/quick/latest_index' then
-      index = @source_index.latest_specs.map { |spec| spec.full_name }
-      res.body << index.sort.join("\n")
-    when '/quick/latest_index.rz' then
-      index = @source_index.latest_specs.map { |spec| spec.full_name }
-      res['content-type'] = 'application/x-deflate'
-      res.body << Gem.deflate(index.sort.join("\n"))
     when %r|^/quick/(Marshal.#{Regexp.escape Gem.marshal_version}/)?(.*?)-([0-9.]+)(-.*?)?\.gemspec\.rz$| then
       dep = Gem::Dependency.new $2, $3
       specs = @source_index.search dep
@@ -575,9 +576,6 @@
       elsif marshal_format then
         res['content-type'] = 'application/x-deflate'
         res.body << Gem.deflate(Marshal.dump(specs.first))
-      else # deprecated YAML format
-        res['content-type'] = 'application/x-deflate'
-        res.body << Gem.deflate(specs.first.to_yaml)
       end
     else
       raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found."
@@ -586,7 +584,7 @@
 
   def root(req, res)
     @source_index.refresh!
-    res['date'] = File.stat(@spec_dir).mtime
+    add_date res
 
     raise WEBrick::HTTPStatus::NotFound, "`#{req.path}' not found." unless
       req.path == '/'
@@ -630,16 +628,16 @@
     specs << {
       "authors" => "Chad Fowler, Rich Kilmer, Jim Weirich, Eric Hodel and others",
       "dependencies" => [],
-      "doc_path" => "/doc_root/rubygems-#{Gem::RubyGemsVersion}/rdoc/index.html",
+      "doc_path" => "/doc_root/rubygems-#{Gem::VERSION}/rdoc/index.html",
       "executables" => [{"executable" => 'gem', "is_last" => true}],
       "only_one_executable" => true,
-      "full_name" => "rubygems-#{Gem::RubyGemsVersion}",
+      "full_name" => "rubygems-#{Gem::VERSION}",
       "has_deps" => false,
       "homepage" => "http://docs.rubygems.org/",
       "name" => 'rubygems',
       "rdoc_installed" => true,
       "summary" => "RubyGems itself",
-      "version" => Gem::RubyGemsVersion,
+      "version" => Gem::VERSION,
     }
 
     specs = specs.sort_by { |spec| [spec["name"].downcase, spec["version"]] }
@@ -660,6 +658,9 @@
     values = { "gem_count" => specs.size.to_s, "specs" => specs,
                "total_file_count" => total_file_count.to_s }
 
+    # suppress 1.9.3dev warning about unused variable
+    values = values
+
     result = template.result binding
     res.body = result
   end
@@ -718,7 +719,7 @@
   # documentation - just put it underneath the main doc folder.
 
   def show_rdoc_for_pattern(pattern, res)
-    found_gems = Dir.glob("#{@gem_dir}/doc/#{pattern}").select {|path|
+    found_gems = Dir.glob("{#{@gem_dirs.join ','}}/doc/#{pattern}").select {|path|
       File.exist? File.join(path, 'rdoc/index.html')
     }
     case found_gems.length
@@ -753,9 +754,6 @@
 
     WEBrick::Daemon.start if @daemon
 
-    @server.mount_proc "/yaml", method(:yaml)
-    @server.mount_proc "/yaml.Z", method(:yaml)
-
     @server.mount_proc "/Marshal.#{Gem.marshal_version}", method(:Marshal)
     @server.mount_proc "/Marshal.#{Gem.marshal_version}.Z", method(:Marshal)
 
@@ -771,7 +769,7 @@
 
     @server.mount_proc("/gem-server-rdoc-style.css") do |req, res|
       res['content-type'] = 'text/css'
-      res['date'] = File.stat(@spec_dir).mtime
+      add_date res
       res.body << RDOC_CSS
     end
 
@@ -782,19 +780,21 @@
     paths = { "/gems" => "/cache/", "/doc_root" => "/doc/" }
     paths.each do |mount_point, mount_dir|
       @server.mount(mount_point, WEBrick::HTTPServlet::FileHandler,
-                    File.join(@gem_dir, mount_dir), true)
+                    File.join(@gem_dirs.first, mount_dir), true)
     end
 
     trap("INT") { @server.shutdown; exit! }
     trap("TERM") { @server.shutdown; exit! }
 
+    launch if @launch
+
     @server.start
   end
 
   def specs(req, res)
     @source_index.refresh!
 
-    res['date'] = File.stat(@spec_dir).mtime
+    add_date res
 
     specs = @source_index.sort.map do |_, spec|
       platform = spec.original_platform
@@ -818,26 +818,14 @@
     end
   end
 
-  def yaml(req, res)
-    @source_index.refresh!
+  def launch
+    listeners = @server.listeners.map{|l| l.addr[2] }
 
-    res['date'] = File.stat(@spec_dir).mtime
+    host = listeners.any?{|l| l == '0.0.0.0'} ? 'localhost' : listeners.first
 
-    index = @source_index.to_yaml
+    say "Launching browser to http://#{host}:#{@port}"
 
-    if req.path =~ /Z$/ then
-      res['content-type'] = 'application/x-deflate'
-      index = Gem.deflate index
-    else
-      res['content-type'] = 'text/plain'
-    end
-
-    if req.request_method == 'HEAD' then
-      res['content-length'] = index.length
-      return
-    end
-
-    res.body << index
+    system("#{@launch} http://#{host}:#{@port}")
   end
 
 end

Modified: MacRuby/trunk/lib/rubygems/source_index.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/source_index.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/source_index.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,15 +4,8 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'rubygems/user_interaction'
 require 'rubygems/specification'
 
-# :stopdoc:
-module Gem
-  autoload :SpecFetcher, 'rubygems/spec_fetcher'
-end
-# :startdoc:
-
 ##
 # The SourceIndex object indexes all the gems available from a
 # particular source (e.g. a list of gem directories, or a remote
@@ -28,8 +21,6 @@
 
   include Enumerable
 
-  include Gem::UserInteraction
-
   attr_reader :gems # :nodoc:
 
   ##
@@ -38,8 +29,6 @@
   attr_accessor :spec_dirs
 
   class << self
-    include Gem::UserInteraction
-
     ##
     # Factory method to construct a source index instance for a given
     # path.
@@ -83,33 +72,7 @@
     # loaded spec.
 
     def load_specification(file_name)
-      return nil unless file_name and File.exist? file_name
-
-      spec_code = if RUBY_VERSION < '1.9' then
-                    File.read file_name
-                  else
-                    File.read file_name, :encoding => 'UTF-8'
-                  end.untaint
-
-      begin
-        gemspec = eval spec_code, binding, file_name
-
-        if gemspec.is_a?(Gem::Specification)
-          gemspec.loaded_from = file_name
-          return gemspec
-        end
-        alert_warning "File '#{file_name}' does not evaluate to a gem specification"
-      rescue SignalException, SystemExit
-        raise
-      rescue SyntaxError => e
-        alert_warning e
-        alert_warning spec_code
-      rescue Exception => e
-        alert_warning "#{e.inspect}\n#{spec_code}"
-        alert_warning "Invalid .gemspec format in '#{file_name}'"
-      end
-
-      return nil
+      Gem::Specification.load file_name
     end
 
   end
@@ -150,7 +113,7 @@
       spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
 
       spec_files.each do |spec_file|
-        gemspec = self.class.load_specification spec_file.untaint
+        gemspec = Gem::Specification.load spec_file
         add_spec gemspec if gemspec
       end
     end
@@ -275,8 +238,8 @@
   ##
   # Find a gem by an exact match on the short name.
 
-  def find_name(gem_name, version_requirement = Gem::Requirement.default)
-    dep = Gem::Dependency.new gem_name, version_requirement
+  def find_name(gem_name, requirement = Gem::Requirement.default)
+    dep = Gem::Dependency.new gem_name, requirement
     search dep
   end
 
@@ -290,7 +253,7 @@
   # behavior is deprecated and will be removed.
 
   def search(gem_pattern, platform_only = false)
-    version_requirement = nil
+    requirement = nil
     only_platform = false
 
     # TODO - Remove support and warning for legacy arguments after 2008/11
@@ -300,10 +263,10 @@
 
     case gem_pattern
     when Regexp then
-      version_requirement = platform_only || Gem::Requirement.default
+      requirement = platform_only || Gem::Requirement.default
     when Gem::Dependency then
       only_platform = platform_only
-      version_requirement = gem_pattern.requirement
+      requirement = gem_pattern.requirement
       gem_pattern = if Regexp === gem_pattern.name then
                       gem_pattern.name
                     elsif gem_pattern.name.empty? then
@@ -312,17 +275,17 @@
                       /^#{Regexp.escape gem_pattern.name}$/
                     end
     else
-      version_requirement = platform_only || Gem::Requirement.default
+      requirement = platform_only || Gem::Requirement.default
       gem_pattern = /#{gem_pattern}/i
     end
 
-    unless Gem::Requirement === version_requirement then
-      version_requirement = Gem::Requirement.create version_requirement
+    unless Gem::Requirement === requirement then
+      requirement = Gem::Requirement.create requirement
     end
 
     specs = all_gems.values.select do |spec|
       spec.name =~ gem_pattern and
-        version_requirement.satisfied_by? spec.version
+        requirement.satisfied_by? spec.version
     end
 
     if only_platform then
@@ -354,20 +317,10 @@
     latest_specs.each do |local|
       dependency = Gem::Dependency.new local.name, ">= #{local.version}"
 
-      begin
-        fetcher = Gem::SpecFetcher.fetcher
-        remotes = fetcher.find_matching dependency
-        remotes = remotes.map { |(name, version,_),_| version }
-      rescue Gem::RemoteFetcher::FetchError => e
-        raise unless fetcher.warn_legacy e do
-          require 'rubygems/source_info_cache'
+      fetcher = Gem::SpecFetcher.fetcher
+      remotes = fetcher.find_matching dependency
+      remotes = remotes.map { |(_, version, _), _| version }
 
-          specs = Gem::SourceInfoCache.search_with_source dependency, true
-
-          remotes = specs.map { |spec,| spec.version }
-        end
-      end
-
       latest = remotes.sort.last
 
       outdateds << local.name if latest and local.version < latest
@@ -376,211 +329,14 @@
     outdateds
   end
 
-  ##
-  # Updates this SourceIndex from +source_uri+.  If +all+ is false, only the
-  # latest gems are fetched.
-
-  def update(source_uri, all)
-    source_uri = URI.parse source_uri unless URI::Generic === source_uri
-    source_uri.path += '/' unless source_uri.path =~ /\/$/
-
-    use_incremental = false
-
-    begin
-      gem_names = fetch_quick_index source_uri, all
-      remove_extra gem_names
-      missing_gems = find_missing gem_names
-
-      return false if missing_gems.size.zero?
-
-      say "Missing metadata for #{missing_gems.size} gems" if
-      missing_gems.size > 0 and Gem.configuration.really_verbose
-
-      use_incremental = missing_gems.size <= Gem.configuration.bulk_threshold
-    rescue Gem::OperationNotSupportedError => ex
-      alert_error "Falling back to bulk fetch: #{ex.message}" if
-      Gem.configuration.really_verbose
-      use_incremental = false
-    end
-
-    if use_incremental then
-      update_with_missing(source_uri, missing_gems)
-    else
-      new_index = fetch_bulk_index(source_uri)
-      @gems.replace(new_index.gems)
-    end
-
-    true
-  end
-
   def ==(other) # :nodoc:
-    self.class === other and @gems == other.gems 
+    self.class === other and @gems == other.gems
   end
 
   def dump
     Marshal.dump(self)
   end
 
-  private
-
-  def fetcher
-    require 'rubygems/remote_fetcher'
-
-    Gem::RemoteFetcher.fetcher
-  end
-
-  def fetch_index_from(source_uri)
-    @fetch_error = nil
-
-    indexes = %W[
-        Marshal.#{Gem.marshal_version}.Z
-        Marshal.#{Gem.marshal_version}
-        yaml.Z
-        yaml
-      ]
-
-    indexes.each do |name|
-      spec_data = nil
-      index = source_uri + name
-      begin
-        spec_data = fetcher.fetch_path index
-        spec_data = unzip(spec_data) if name =~ /\.Z$/
-
-        if name =~ /Marshal/ then
-          return Marshal.load(spec_data)
-        else
-          return YAML.load(spec_data)
-        end
-      rescue => e
-        if Gem.configuration.really_verbose then
-          alert_error "Unable to fetch #{name}: #{e.message}"
-        end
-
-        @fetch_error = e
-      end
-    end
-
-    nil
-  end
-
-  def fetch_bulk_index(source_uri)
-    say "Bulk updating Gem source index for: #{source_uri}" if
-      Gem.configuration.verbose
-
-    index = fetch_index_from(source_uri)
-    if index.nil? then
-      raise Gem::RemoteSourceException,
-              "Error fetching remote gem cache: #{@fetch_error}"
-    end
-    @fetch_error = nil
-    index
-  end
-
-  ##
-  # Get the quick index needed for incremental updates.
-
-  def fetch_quick_index(source_uri, all)
-    index = all ? 'index' : 'latest_index'
-
-    zipped_index = fetcher.fetch_path source_uri + "quick/#{index}.rz"
-
-    unzip(zipped_index).split("\n")
-  rescue ::Exception => e
-    unless all then
-      say "Latest index not found, using quick index" if
-        Gem.configuration.really_verbose
-
-      fetch_quick_index source_uri, true
-    else
-      raise Gem::OperationNotSupportedError,
-            "No quick index found: #{e.message}"
-    end
-  end
-
-  ##
-  # Make a list of full names for all the missing gemspecs.
-
-  def find_missing(spec_names)
-    unless defined? @originals then
-      @originals = {}
-      each do |full_name, spec|
-        @originals[spec.original_name] = spec
-      end
-    end
-
-    spec_names.find_all { |full_name|
-      @originals[full_name].nil?
-    }
-  end
-
-  def remove_extra(spec_names)
-    dictionary = spec_names.inject({}) { |h, k| h[k] = true; h }
-    each do |name, spec|
-      remove_spec name unless dictionary.include? spec.original_name
-    end
-  end
-
-  ##
-  # Unzip the given string.
-
-  def unzip(string)
-    require 'zlib'
-    Gem.inflate string
-  end
-
-  ##
-  # Tries to fetch Marshal representation first, then YAML
-
-  def fetch_single_spec(source_uri, spec_name)
-    @fetch_error = nil
-
-    begin
-      marshal_uri = source_uri + "quick/Marshal.#{Gem.marshal_version}/#{spec_name}.gemspec.rz"
-      zipped = fetcher.fetch_path marshal_uri
-      return Marshal.load(unzip(zipped))
-    rescue => ex
-      @fetch_error = ex
-
-      if Gem.configuration.really_verbose then
-        say "unable to fetch marshal gemspec #{marshal_uri}: #{ex.class} - #{ex}"
-      end
-    end
-
-    begin
-      yaml_uri = source_uri + "quick/#{spec_name}.gemspec.rz"
-      zipped = fetcher.fetch_path yaml_uri
-      return YAML.load(unzip(zipped))
-    rescue => ex
-      @fetch_error = ex
-      if Gem.configuration.really_verbose then
-        say "unable to fetch YAML gemspec #{yaml_uri}: #{ex.class} - #{ex}"
-      end
-    end
-
-    nil
-  end
-
-  ##
-  # Update the cached source index with the missing names.
-
-  def update_with_missing(source_uri, missing_names)
-    progress = ui.progress_reporter(missing_names.size,
-        "Updating metadata for #{missing_names.size} gems from #{source_uri}")
-    missing_names.each do |spec_name|
-      gemspec = fetch_single_spec(source_uri, spec_name)
-      if gemspec.nil? then
-        ui.say "Failed to download spec #{spec_name} from #{source_uri}:\n" \
-                 "\t#{@fetch_error.message}"
-      else
-        add_spec gemspec
-        progress.updated spec_name
-      end
-      @fetch_error = nil
-    end
-    progress.done
-    progress.count
-  end
-
 end
 
 # :stopdoc:

Modified: MacRuby/trunk/lib/rubygems/spec_fetcher.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/spec_fetcher.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/spec_fetcher.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -1,8 +1,7 @@
-require 'zlib'
-require 'fileutils'
-
 require 'rubygems/remote_fetcher'
 require 'rubygems/user_interaction'
+require 'rubygems/errors'
+require 'rubygems/text'
 
 ##
 # SpecFetcher handles metadata updates from remote gem repositories.
@@ -10,7 +9,14 @@
 class Gem::SpecFetcher
 
   include Gem::UserInteraction
+  include Gem::Text
 
+  FILES = {
+    :all        => 'specs',
+    :latest     => 'latest_specs',
+    :prerelease => 'prerelease_specs',
+  }
+
   ##
   # The SpecFetcher cache dir.
 
@@ -42,6 +48,8 @@
   end
 
   def initialize
+    require 'fileutils'
+
     @dir = File.join Gem.user_home, '.gem', 'specs'
     @update_cache = File.stat(Gem.user_home).uid == Process.uid
 
@@ -49,11 +57,17 @@
     @latest_specs = {}
     @prerelease_specs = {}
 
+    @caches = {
+      :latest => @latest_specs,
+      :prerelease => @prerelease_specs,
+      :all => @specs
+    }
+
     @fetcher = Gem::RemoteFetcher.fetcher
   end
 
   ##
-  # Retuns the local directory to write +uri+ to.
+  # Returns the local directory to write +uri+ to.
 
   def cache_dir(uri)
     File.join @dir, "#{uri.host}%#{uri.port}", File.dirname(uri.path)
@@ -65,20 +79,18 @@
   # false, all platforms are returned. If +prerelease+ is true,
   # prerelease versions are included.
 
-  def fetch(dependency, all = false, matching_platform = true, prerelease = false)
-    specs_and_sources = find_matching dependency, all, matching_platform, prerelease
+  def fetch_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
+    specs_and_sources, errors = find_matching_with_errors dependency, all, matching_platform, prerelease
 
-    specs_and_sources.map do |spec_tuple, source_uri|
+    ss = specs_and_sources.map do |spec_tuple, source_uri|
       [fetch_spec(spec_tuple, URI.parse(source_uri)), source_uri]
     end
 
-  rescue Gem::RemoteFetcher::FetchError => e
-    raise unless warn_legacy e do
-      require 'rubygems/source_info_cache'
+    return [ss, errors]
+  end
 
-      return Gem::SourceInfoCache.search_with_source(dependency,
-                                                     matching_platform, all)
-    end
+  def fetch(*args)
+    fetch_with_errors(*args).first
   end
 
   def fetch_spec(spec, source_uri)
@@ -117,16 +129,27 @@
   # matching released versions are returned.  If +matching_platform+
   # is false, gems for all platforms are returned.
 
-  def find_matching(dependency, all = false, matching_platform = true, prerelease = false)
+  def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
     found = {}
 
+    rejected_specs = {}
+
     list(all, prerelease).each do |source_uri, specs|
       found[source_uri] = specs.select do |spec_name, version, spec_platform|
-        dependency =~ Gem::Dependency.new(spec_name, version) and
-          (not matching_platform or Gem::Platform.match(spec_platform))
+        if dependency.match?(spec_name, version)
+          if matching_platform and !Gem::Platform.match(spec_platform)
+            pm = (rejected_specs[dependency] ||= Gem::PlatformMismatch.new(spec_name, version))
+            pm.add_platform spec_platform
+            false
+          else
+            true
+          end
+        end
       end
     end
 
+    errors = rejected_specs.values
+
     specs_and_sources = []
 
     found.each do |source_uri, specs|
@@ -134,30 +157,39 @@
       specs_and_sources.push(*specs.map { |spec| [spec, uri_str] })
     end
 
-    specs_and_sources
+    [specs_and_sources, errors]
   end
 
+  def find_matching(*args)
+    find_matching_with_errors(*args).first
+  end
+
   ##
-  # Returns Array of gem repositories that were generated with RubyGems less
-  # than 1.2.
+  # Suggests a gem based on the supplied +gem_name+. Returns a string
+  # of the gem name if an approximate match can be found or nil
+  # otherwise. NOTE: for performance reasons only gems which exactly
+  # match the first character of +gem_name+ are considered.
 
-  def legacy_repos
-    Gem.sources.reject do |source_uri|
-      source_uri = URI.parse source_uri
-      spec_path = source_uri + "specs.#{Gem.marshal_version}.gz"
+  def suggest_gems_from_name gem_name
+    gem_name        = gem_name.downcase
+    max             = gem_name.size / 2
+    specs           = list.values.flatten(1) # flatten(1) is 1.8.7 and up
 
-      begin
-        @fetcher.fetch_size spec_path
-      rescue Gem::RemoteFetcher::FetchError
-        begin
-          @fetcher.fetch_size(source_uri + 'yaml') # re-raise if non-repo
-        rescue Gem::RemoteFetcher::FetchError
-          alert_error "#{source_uri} does not appear to be a repository"
-          raise
-        end
-        false
-      end
-    end
+    matches = specs.map { |name, version, platform|
+      next unless Gem::Platform.match platform
+
+      distance = levenshtein_distance gem_name, name.downcase
+
+      next if distance >= max
+
+      return [name] if distance == 0
+
+      [name, distance]
+    }.compact
+
+    matches = matches.uniq.sort_by { |name, dist| dist }
+
+    matches.first(5).map { |name, dist| name }
   end
 
   ##
@@ -175,16 +207,10 @@
              :latest
            end
 
-    list = {}
+    list  = {}
+    file  = FILES[type]
+    cache = @caches[type]
 
-    file = { :latest => 'latest_specs',
-      :prerelease => 'prerelease_specs',
-      :all => 'specs' }[type]
-
-    cache = { :latest => @latest_specs,
-      :prerelease => @prerelease_specs,
-      :all => @specs }[type]
-    
     Gem.sources.each do |source_uri|
       source_uri = URI.parse source_uri
 
@@ -251,28 +277,5 @@
     specs
   end
 
-  ##
-  # Warn about legacy repositories if +exception+ indicates only legacy
-  # repositories are available, and yield to the block.  Returns false if the
-  # exception indicates some other FetchError.
-
-  def warn_legacy(exception)
-    uri = exception.uri.to_s
-    if uri =~ /specs\.#{Regexp.escape Gem.marshal_version}\.gz$/ then
-      alert_warning <<-EOF
-RubyGems 1.2+ index not found for:
-\t#{legacy_repos.join "\n\t"}
-
-RubyGems will revert to legacy indexes degrading performance.
-      EOF
-
-      yield
-
-      return true
-    end
-
-    false
-  end
-
 end
 

Modified: MacRuby/trunk/lib/rubygems/specification.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/specification.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/specification.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -498,17 +498,37 @@
   end
 
   ##
-  # Loads ruby format gemspec from +filename+
+  # Loads Ruby format gemspec from +file+.
 
-  def self.load(filename)
-    gemspec = nil
-    raise "NESTED Specification.load calls not allowed!" if @@gather
-    @@gather = proc { |gs| gemspec = gs }
-    data = File.read(filename)
-    eval(data)
-    gemspec
-  ensure
-    @@gather = nil
+  def self.load file
+    return unless file && File.file?(file)
+
+    file = file.dup.untaint
+
+    code = if defined? Encoding
+             File.read file, :encoding => "UTF-8"
+           else
+             File.read file
+           end
+
+    code.untaint
+
+    begin
+      spec = eval code, binding, file
+
+      if Gem::Specification === spec
+        spec.loaded_from = file
+        return spec
+      end
+
+      warn "[#{file}] isn't a Gem::Specification (#{spec.class} instead)."
+    rescue SignalException, SystemExit
+      raise
+    rescue SyntaxError, Exception => e
+      warn "Invalid gemspec in [#{file}]: #{e}"
+    end
+
+    nil
   end
 
   ##
@@ -524,7 +544,7 @@
   # Sets the rubygems_version to the current RubyGems version
 
   def mark_version
-    @rubygems_version = Gem::RubyGemsVersion
+    @rubygems_version = Gem::VERSION
   end
 
   ##
@@ -671,41 +691,50 @@
   private :same_attributes?
 
   def hash # :nodoc:
-    @@attributes.inject(0) { |hash_code, (name, default_value)|
-      n = self.send(name).hash
-      hash_code + n
+    @@attributes.inject(0) { |hash_code, (name, _)|
+      hash_code ^ self.send(name).hash
     }
   end
 
-  def to_yaml(opts = {}) # :nodoc:
+  def encode_with coder # :nodoc:
     mark_version
 
     attributes = @@attributes.map { |name,| name.to_s }.sort
     attributes = attributes - %w[name version platform]
 
-    # Currently, MacRuby's #quick_emit works differently than Syck's
-    # yaml = YAML.quick_emit object_id, opts do |out|
-    yaml = YAML.quick_emit nil do |out|
+    coder.add 'name', @name
+    coder.add 'version', @version
+    platform = case @original_platform
+               when nil, '' then
+                 'ruby'
+               when String then
+                 @original_platform
+               else
+                 @original_platform.to_s
+               end
+    coder.add 'platform', platform
+
+    attributes.each do |name|
+      coder.add name, instance_variable_get("@#{name}")
+    end
+  end
+
+  def to_yaml(opts = {}) # :nodoc:
+    return super if YAML.const_defined?(:ENGINE) && !YAML::ENGINE.syck?
+
+    # XXX MACRUBY our quick_emit is different than syck
+    #YAML.quick_emit object_id, opts do |out|
+    YAML.quick_emit nil do |out|
       out.map taguri, to_yaml_style do |map|
-        map.add 'name', @name
-        map.add 'version', @version
-        platform = case @original_platform
-                   when nil, '' then
-                     'ruby'
-                   when String then
-                     @original_platform
-                   else
-                     @original_platform.to_s
-                   end
-        map.add 'platform', platform
-
-        attributes.each do |name|
-          map.add name, instance_variable_get("@#{name}")
-        end
+        encode_with map
       end
     end
   end
 
+  def init_with coder # :nodoc:
+    yaml_initialize coder.tag, coder.map
+  end
+
   def yaml_initialize(tag, vals) # :nodoc:
     vals.each do |ivar, val|
       instance_variable_set "@#{ivar}", val
@@ -757,11 +786,10 @@
 
     result << nil
     result << "  if s.respond_to? :specification_version then"
-    result << "    current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION"
     result << "    s.specification_version = #{specification_version}"
     result << nil
 
-    result << "    if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then"
+    result << "    if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then"
 
     unless dependencies.empty? then
       dependencies.each do |dep|
@@ -806,9 +834,9 @@
     extend Gem::UserInteraction
     normalize
 
-    if rubygems_version != Gem::RubyGemsVersion then
+    if rubygems_version != Gem::VERSION then
       raise Gem::InvalidSpecificationException,
-            "expected RubyGems version #{Gem::RubyGemsVersion}, was #{rubygems_version}"
+            "expected RubyGems version #{Gem::VERSION}, was #{rubygems_version}"
     end
 
     @@required_attributes.each do |symbol|
@@ -901,7 +929,7 @@
 
     # Warnings
 
-    %w[author description email homepage rubyforge_project summary].each do |attribute|
+    %w[author description email homepage summary].each do |attribute|
       value = self.send attribute
       alert_warning "no #{attribute} specified" if value.nil? or value.empty?
     end
@@ -1054,7 +1082,7 @@
   #
   # Do not set this, it is set automatically when the gem is packaged.
 
-  required_attribute :rubygems_version, Gem::RubyGemsVersion
+  required_attribute :rubygems_version, Gem::VERSION
 
   ##
   # :attr_accessor: specification_version
@@ -1483,14 +1511,12 @@
   end
 
   overwrite_accessor :files do
-    result = []
-    result.push(*@files) if defined?(@files)
-    result.push(*@test_files) if defined?(@test_files)
-    result.push(*(add_bindir(@executables)))
-    result.push(*@extra_rdoc_files) if defined?(@extra_rdoc_files)
-    result.push(*@extensions) if defined?(@extensions)
-    result.uniq.compact
+    # DO NOT CHANGE TO ||= ! This is not a normal accessor. (yes, it sucks)
+    @files = [@files,
+              @test_files,
+              add_bindir(@executables),
+              @extra_rdoc_files,
+              @extensions,
+             ].flatten.uniq.compact
   end
-
 end
-

Modified: MacRuby/trunk/lib/rubygems/test_utilities.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/test_utilities.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/test_utilities.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -11,9 +11,9 @@
 #   @fetcher = Gem::FakeFetcher.new
 #   @fetcher.data['http://gems.example.com/yaml'] = source_index.to_yaml
 #   Gem::RemoteFetcher.fetcher = @fetcher
-#   
+#
 #   # invoke RubyGems code
-#   
+#
 #   paths = @fetcher.paths
 #   assert_equal 'http://gems.example.com/yaml', paths.shift
 #   assert paths.empty?, paths.join(', ')

Modified: MacRuby/trunk/lib/rubygems/text.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/text.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/text.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -26,5 +26,40 @@
     result.join("\n").gsub(/^/, " " * indent)
   end
 
+  # This code is based directly on the Text gem implementation
+  # Returns a value representing the "cost" of transforming str1 into str2
+  def levenshtein_distance str1, str2
+    s = str1
+    t = str2
+    n = s.length
+    m = t.length
+    max = n/2
+
+    return m if (0 == n)
+    return n if (0 == m)
+    return n if (n - m).abs > max
+
+    d = (0..m).to_a
+    x = nil
+
+    n.times do |i|
+      e = i+1
+
+      m.times do |j|
+        cost = (s[i] == t[j]) ? 0 : 1
+        x = [
+             d[j+1] + 1, # insertion
+             e + 1,      # deletion
+             d[j] + cost # substitution
+            ].min
+        d[j] = e
+        e = x
+      end
+
+      d[m] = x
+    end
+
+    return x
+  end
 end
 

Modified: MacRuby/trunk/lib/rubygems/uninstaller.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/uninstaller.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/uninstaller.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -82,7 +82,7 @@
       gem_names = list.collect {|gem| gem.full_name} + ["All versions"]
 
       say
-      gem_name, index = choose_from_list "Select gem to uninstall:", gem_names
+      _, index = choose_from_list "Select gem to uninstall:", gem_names
 
       if index == list.size then
         remove_all list.dup

Modified: MacRuby/trunk/lib/rubygems/user_interaction.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/user_interaction.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/user_interaction.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -412,6 +412,76 @@
     end
   end
 
+  ##
+  # Return a download reporter object chosen from the current verbosity
+
+  def download_reporter(*args)
+    case Gem.configuration.verbose
+    when nil, false
+      SilentDownloadReporter.new(@outs, *args)
+    else
+      VerboseDownloadReporter.new(@outs, *args)
+    end
+  end
+
+  ##
+  # An absolutely silent download reporter.
+
+  class SilentDownloadReporter
+    def initialize(out_stream, *args)
+    end
+
+    def fetch(filename, filesize)
+    end
+
+    def update(current)
+    end
+
+    def done
+    end
+  end
+
+  ##
+  # A progress reporter that prints out messages about the current progress.
+
+  class VerboseDownloadReporter
+    attr_reader :file_name, :total_bytes, :progress
+
+    def initialize(out_stream, *args)
+      @out = out_stream
+      @progress = 0
+    end
+
+    def fetch(file_name, total_bytes)
+      @file_name, @total_bytes = file_name, total_bytes
+      update_display(false)
+    end
+
+    def update(bytes)
+      new_progress = ((bytes.to_f * 100) / total_bytes.to_f).ceil
+      return if new_progress == @progress
+
+      @progress = new_progress
+      update_display
+    end
+
+    def done
+      @progress = 100
+      update_display(true, true)
+    end
+
+    private
+
+    def update_display(show_progress = true, new_line = false)
+      return unless @out.tty?
+      if show_progress
+        @out.print "\rFetching: %s (%3d%%)" % [@file_name, @progress]
+      else
+        @out.print "Fetching: %s" % @file_name
+      end
+      @out.puts if new_line
+    end
+  end
 end
 
 ##

Modified: MacRuby/trunk/lib/rubygems/validator.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/validator.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/validator.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -4,19 +4,9 @@
 # See LICENSE.txt for permissions.
 #++
 
-require 'find'
-
-require 'digest'
 require 'rubygems/format'
 require 'rubygems/installer'
 
-# Load test-unit 2.x if it's a gem
-begin
-   Gem.activate('test-unit')
-rescue Gem::LoadError
-   # Ignore - use the test-unit library that's part of the standard library
-end   
-
 ##
 # Validator performs various gem file and gem database validation
 
@@ -24,6 +14,11 @@
 
   include Gem::UserInteraction
 
+  def initialize
+    require 'find'
+    require 'digest'
+  end
+
   ##
   # Given a gem file's contents, validates against its own MD5 checksum
   # gem_data:: [String] Contents of the gem file
@@ -166,73 +161,6 @@
     errors
   end
 
-  if RUBY_VERSION < '1.9' then
-    class TestRunner
-      def initialize(suite, ui)
-        @suite = suite
-        @ui = ui
-      end
-
-      def self.run(suite, ui)
-        require 'test/unit/ui/testrunnermediator'
-        return new(suite, ui).start
-      end
-
-      def start
-        @mediator = Test::Unit::UI::TestRunnerMediator.new(@suite)
-        @mediator.add_listener(Test::Unit::TestResult::FAULT, &method(:add_fault))
-        return @mediator.run_suite
-      end
-
-      def add_fault(fault)
-        if Gem.configuration.verbose then
-          @ui.say fault.long_display
-        end
-      end
-    end
-
-    autoload :TestRunner, 'test/unit/ui/testrunnerutilities'
-  end
-
-  ##
-  # Runs unit tests for a given gem specification
-
-  def unit_test(gem_spec)
-    start_dir = Dir.pwd
-    Dir.chdir(gem_spec.full_gem_path)
-    $: << gem_spec.full_gem_path
-    # XXX: why do we need this gem_spec when we've already got 'spec'?
-    test_files = gem_spec.test_files
-
-    if test_files.empty? then
-      say "There are no unit tests to run for #{gem_spec.full_name}"
-      return nil
-    end
-
-    gem gem_spec.name, "= #{gem_spec.version.version}"
-
-    test_files.each do |f| require f end
-
-    if RUBY_VERSION < '1.9' then
-      suite = Test::Unit::TestSuite.new("#{gem_spec.name}-#{gem_spec.version}")
-
-      ObjectSpace.each_object(Class) do |klass|
-        suite << klass.suite if (klass < Test::Unit::TestCase)
-      end
-
-      result = TestRunner.run suite, ui
-
-      alert_error result.to_s unless result.passed?
-    else
-      result = MiniTest::Unit.new
-      result.run
-    end
-
-    result
-  ensure
-    Dir.chdir(start_dir)
-  end
-
   def remove_leading_dot_dir(path)
     path.sub(/^\.\//, "")
   end

Modified: MacRuby/trunk/lib/rubygems/version.rb
===================================================================
--- MacRuby/trunk/lib/rubygems/version.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems/version.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -8,15 +8,18 @@
 #
 # If any part contains letters (currently only a-z are supported) then
 # that version is considered prerelease. Versions with a prerelease
-# part in the Nth part sort less than versions with N-1 parts. Prerelease
-# parts are sorted alphabetically using the normal Ruby string sorting
-# rules.
+# part in the Nth part sort less than versions with N-1
+# parts. Prerelease parts are sorted alphabetically using the normal
+# Ruby string sorting rules. If a prerelease part contains both
+# letters and numbers, it will be broken into multiple parts to
+# provide expected sort behavior (1.0.a10 becomes 1.0.a.10, and is
+# greater than 1.0.a9).
 #
 # Prereleases sort between real releases (newest to oldest):
 #
 # 1. 1.0
-# 2. 1.0.b
-# 3. 1.0.a
+# 2. 1.0.b1
+# 3. 1.0.a.2
 # 4. 0.9
 #
 # == How Software Changes
@@ -138,6 +141,8 @@
 #   "~> 3.5.0"    3.5.0 ... 3.6
 
 class Gem::Version
+  autoload :Requirement, 'rubygems/requirement'
+
   include Comparable
 
   VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*' # :nodoc:
@@ -184,15 +189,13 @@
 
     @version = version.to_s
     @version.strip!
-
-    segments # prime @segments
   end
 
   ##
   # Return a new version object where the next to the last revision
   # number is one greater (e.g., 5.3.1 => 5.4).
   #
-  # Pre-release (alpha) parts, e.g, 5.3.1.b2 => 5.4, are ignored.
+  # Pre-release (alpha) parts, e.g, 5.3.1.b.2 => 5.4, are ignored.
 
   def bump
     segments = self.segments.dup
@@ -208,11 +211,11 @@
   # same precision. Version "1.0" is not the same as version "1".
 
   def eql? other
-    self.class === other and segments == other.segments
+    self.class === other and @version == other.version
   end
 
   def hash # :nodoc:
-    segments.hash
+    @hash ||= segments.hash
   end
 
   def inspect # :nodoc:
@@ -239,7 +242,7 @@
   # A version is considered a prerelease if it contains a letter.
 
   def prerelease?
-    @prerelease ||= segments.any? { |s| String === s }
+    @prerelease ||= @version =~ /[a-zA-Z]/
   end
 
   def pretty_print q # :nodoc:
@@ -260,12 +263,10 @@
 
   def segments # :nodoc:
 
-    # @segments is lazy so it can pick up @version values that come
-    # from old marshaled versions, which don't go through
-    # marshal_load. +segments+ is called in +initialize+ to "prime
-    # the pump" in normal cases.
+    # segments is lazy so it can pick up version values that come from
+    # old marshaled versions, which don't go through marshal_load.
 
-    @segments ||= @version.scan(/[0-9a-z]+/i).map do |s|
+    @segments ||= @version.scan(/[0-9]+|[a-z]+/i).map do |s|
       /^\d+$/ =~ s ? s.to_i : s
     end
   end
@@ -284,23 +285,33 @@
   end
 
   ##
-  # Compares this version with +other+ returning -1, 0, or 1 if the other
-  # version is larger, the same, or smaller than this one.
+  # Compares this version with +other+ returning -1, 0, or 1 if the
+  # other version is larger, the same, or smaller than this
+  # one. Attempts to compare to something that's not a
+  # <tt>Gem::Version</tt> return +nil+.
 
   def <=> other
-    return   1 unless other # HACK: comparable with nil? why?
-    return nil unless self.class === other
+    return unless Gem::Version === other
+    return 0 if @version == other.version
 
-    lhsize = segments.size
-    rhsize = other.segments.size
+    lhsegments = segments
+    rhsegments = other.segments
+
+    lhsize = lhsegments.size
+    rhsize = rhsegments.size
     limit  = (lhsize > rhsize ? lhsize : rhsize) - 1
 
-    0.upto(limit) do |i|
-      lhs, rhs = segments[i] || 0, other.segments[i] || 0
+    i = 0
 
-      return  -1         if String  === lhs && Numeric === rhs
-      return   1         if Numeric === lhs && String  === rhs
-      return lhs <=> rhs if lhs != rhs
+    while i <= limit
+      lhs, rhs = lhsegments[i] || 0, rhsegments[i] || 0
+      i += 1
+
+      next      if lhs == rhs
+      return -1 if String  === lhs && Numeric === rhs
+      return  1 if Numeric === lhs && String  === rhs
+
+      return lhs <=> rhs
     end
 
     return 0

Modified: MacRuby/trunk/lib/rubygems.rb
===================================================================
--- MacRuby/trunk/lib/rubygems.rb	2011-01-08 09:13:15 UTC (rev 5140)
+++ MacRuby/trunk/lib/rubygems.rb	2011-01-08 17:08:14 UTC (rev 5141)
@@ -5,9 +5,27 @@
 # See LICENSE.txt for permissions.
 #++
 
+gem_preluded = defined? Gem
+
+if defined?(Gem::QuickLoader) then
+  Gem::QuickLoader.load_full_rubygems_library
+
+  class << Gem
+    remove_method :try_activate if Gem.respond_to?(:try_activate, true)
+
+    def try_activate(path)
+      spec = Gem.searcher.find(path)
+      return false unless spec
+
+      Gem.activate(spec.name, "= #{spec.version}")
+      return true
+    end
+  end
+end
+
 require 'rubygems/defaults'
-require 'thread'
-require 'etc'
+require 'rbconfig'
+require 'thread' # HACK: remove me for 1.5 - this is here just for rails
 
 ##
 # RubyGems is the Ruby standard for publishing and managing third party
@@ -98,7 +116,7 @@
 # -The RubyGems Team
 
 module Gem
-  RubyGemsVersion = VERSION = '1.3.6'
+  RubyGemsVersion = VERSION = '1.4.1'
 
   ##
   # Raised when RubyGems is unable to load or activate a gem.  Contains the
@@ -110,40 +128,50 @@
     attr_accessor :name
 
     # Version requirement of gem
-    attr_accessor :version_requirement
-  end
+    attr_accessor :requirement
 
-  ##
-  # Configuration settings from ::RbConfig
+    def version_requirement
+      warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+        "Gem::LoadError#version_requirement is deprecated " \
+        "and will be removed on or after January 2011. " \
+        "Use #requirement."
 
-  ConfigMap = {} unless defined?(ConfigMap)
+      requirement
+    end
 
-  require 'rbconfig'
+    def version_requirement= requirement
+      warn "#{Gem.location_of_caller.join ':'}:Warning: " \
+        "Gem::LoadError#version_requirement= is deprecated " \
+        "and will be removed on or after January 2011. " \
+        "Use #requirement."
 
-  ConfigMap.merge!(
-    :EXEEXT            => RbConfig::CONFIG["EXEEXT"],
-    :RUBY_SO_NAME      => RbConfig::CONFIG["RUBY_SO_NAME"],
-    :arch              => RbConfig::CONFIG["arch"],
-    :bindir            => RbConfig::CONFIG["bindir"],
-    :datadir           => RbConfig::CONFIG["datadir"],
-    :libdir            => RbConfig::CONFIG["libdir"],
-    :ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
-    :ruby_version      => RbConfig::CONFIG["ruby_version"],
-    :sitedir           => RbConfig::CONFIG["sitedir"],
-    :sitelibdir        => RbConfig::CONFIG["sitelibdir"],
-    :vendordir         => RbConfig::CONFIG["vendordir"] ,
-    :vendorlibdir      => RbConfig::CONFIG["vendorlibdir"]
-  )
+      self.requirement = requirement
+    end
+  end
 
+  RbConfigPriorities = %w[
+    EXEEXT RUBY_SO_NAME arch bindir datadir libdir ruby_install_name
+    ruby_version rubylibprefix sitedir sitelibdir vendordir vendorlibdir
+  ]
+
+  unless defined?(ConfigMap)
+    ##
+    # Configuration settings from ::RbConfig
+    ConfigMap = Hash.new do |cm, key|
+      cm[key] = RbConfig::CONFIG[key.to_s]
+    end
+  else
+    RbConfigPriorities.each do |key|
+      ConfigMap[key.to_sym] = RbConfig::CONFIG[key]
+    end
+  end
+
   ##
   # Default directories in a gem repository
 
   DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
 
-  # :stopdoc:
-  MUTEX = Mutex.new
-
-  RubyGemsPackageVersion = RubyGemsVersion
+  RubyGemsPackageVersion = VERSION
   # :startdoc:
 
   ##
@@ -175,7 +203,7 @@
 
   ##
   # Activates an installed gem matching +gem+.  The gem must satisfy
-  # +version_requirements+.
+  # +requirements+.
   #
   # Returns true if the gem is activated, false if it is already
   # loaded, or an exception otherwise.
@@ -189,22 +217,22 @@
   # More information on version requirements can be found in the
   # Gem::Requirement and Gem::Version documentation.
 
-  def self.activate(gem, *version_requirements)
-    if version_requirements.last.is_a?(Hash)
-      options = version_requirements.pop
+  def self.activate(gem, *requirements)
+    if requirements.last.is_a?(Hash)
+      options = requirements.pop
     else
       options = {}
     end
 
     sources = options[:sources] || []
 
-    if version_requirements.empty? then
-      version_requirements = Gem::Requirement.default
+    if requirements.empty? then
+      requirements = Gem::Requirement.default
     end
 
     unless gem.respond_to?(:name) and
            gem.respond_to?(:requirement) then
-      gem = Gem::Dependency.new(gem, version_requirements)
+      gem = Gem::Dependency.new(gem, requirements)
     end
 
     matches = Gem.source_index.find_name(gem.name, gem.requirement)
@@ -225,7 +253,7 @@
 
          e = Gem::LoadError.new msg
          e.name = gem.name
-         e.version_requirement = gem.requirement
+         e.requirement = gem.requirement
 
          raise e
       end
@@ -246,15 +274,10 @@
       activate dep_gem, :sources => [spec, *sources]
     end
 
-    # bin directory must come before library directories
-    spec.require_paths.unshift spec.bindir if spec.bindir
-
     require_paths = spec.require_paths.map do |path|
       File.join spec.full_gem_path, path
     end
 
-    sitelibdir = ConfigMap[:sitelibdir]
-
     # gem directories must come after -I and ENV['RUBYLIB']
     insert_index = load_path_insert_index
 
@@ -311,29 +334,33 @@
   ##
   # Find the full path to the executable for gem +name+.  If the +exec_name+
   # is not given, the gem's default_executable is chosen, otherwise the
-  # specifed executable's path is returned.  +version_requirements+ allows you
-  # to specify specific gem versions.
+  # specified executable's path is returned.  +requirements+ allows
+  # you to specify specific gem versions.
 
-  def self.bin_path(name, exec_name = nil, *version_requirements)
-    version_requirements = Gem::Requirement.default if
-      version_requirements.empty?
-    spec = Gem.source_index.find_name(name, version_requirements).last
+  def self.bin_path(name, exec_name = nil, *requirements)
+    requirements = Gem::Requirement.default if
+      requirements.empty?
+    specs = Gem.source_index.find_name(name, requirements)
 
     raise Gem::GemNotFoundException,
-          "can't find gem #{name} (#{version_requirements})" unless spec
+          "can't find gem #{name} (#{requirements})" if specs.empty?
 
+    specs = specs.find_all do |spec|
+      spec.executables.include?(exec_name)
+    end if exec_name
+
+    unless spec = specs.last
+      msg = "can't find gem #{name} (#{requirements}) with executable #{exec_name}"
+      raise Gem::GemNotFoundException, msg
+    end
+
     exec_name ||= spec.default_executable
 
     unless exec_name
-      msg = "no default executable for #{spec.full_name}"
+      msg = "no default executable for #{spec.full_name} and none given"
       raise Gem::Exception, msg
     end
 
-    unless spec.executables.include? exec_name
-      msg = "can't find executable #{exec_name} for #{spec.full_name}"
-      raise Gem::Exception, msg
-    end
-
     File.join(spec.full_gem_path, spec.bindir, exec_name)
   end
 
@@ -341,7 +368,7 @@
   # The mode needed to read a file as straight binary.
 
   def self.binary_mode
-    @binary_mode ||= RUBY_VERSION > '1.9' ? 'rb:ascii-8bit' : 'rb'
+    'rb'
   end
 
   ##
@@ -365,9 +392,7 @@
 
     @@source_index = nil
 
-    MUTEX.synchronize do
-      @searcher = nil
-    end
+    @searcher = nil
   end
 
   ##
@@ -415,7 +440,7 @@
 
   def self.dir
     @gem_home ||= nil
-    set_home(ENV['GEM_HOME'] || Gem.configuration.home || default_dir) unless @gem_home
+    set_home(ENV['GEM_HOME'] || default_dir) unless @gem_home
     @gem_home
   end
 
@@ -456,32 +481,41 @@
   end
 
   ##
-  # Returns a list of paths matching +file+ that can be used by a gem to pick
+  # Returns a list of paths matching +glob+ that can be used by a gem to pick
   # up features from other gems.  For example:
   #
   #   Gem.find_files('rdoc/discover').each do |path| load path end
   #
-  # find_files search $LOAD_PATH for files as well as gems.
+  # if +check_load_path+ is true (the default), then find_files also searches
+  # $LOAD_PATH for files as well as gems.
   #
   # Note that find_files will return all files even if they are from different
   # versions of the same gem.
 
-  def self.find_files(path)
-    load_path_files = $LOAD_PATH.map do |load_path|
-      files = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
+  def self.find_files(glob, check_load_path=true)
+    files = []
 
-      files.select do |load_path_file|
-        File.file? load_path_file.untaint
+    if check_load_path
+      $LOAD_PATH.each do |load_path|
+        globbed = Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
+
+        globbed.each do |load_path_file|
+          files << load_path_file if File.file?(load_path_file.untaint)
+        end
       end
-    end.flatten
+    end
 
-    specs = searcher.find_all path
+    specs = searcher.find_all glob
 
-    specs_files = specs.map do |spec|
-      searcher.matching_files spec, path
-    end.flatten
+    specs.each do |spec|
+      files.concat searcher.matching_files(spec, glob)
+    end
 
-    (load_path_files + specs_files).flatten.uniq
+    # $LOAD_PATH might contain duplicate entries or reference
+    # the spec dirs directly, so we prune.
+    files.uniq! if check_load_path
+
+    return files
   end
 
   ##
@@ -498,18 +532,19 @@
   def self.find_home
     unless RUBY_VERSION > '1.9' then
       ['HOME', 'USERPROFILE'].each do |homekey|
-        return ENV[homekey] if ENV[homekey]
+        return File.expand_path(ENV[homekey]) if ENV[homekey]
       end
 
       if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
-        return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
+        return File.expand_path("#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}")
       end
     end
 
     File.expand_path "~"
   rescue
     if File::ALT_SEPARATOR then
-      "C:/"
+      drive = ENV['HOMEDRIVE'] || ENV['SystemDrive']
+      File.join(drive.to_s, '/')
     else
       "/"
     end
@@ -550,6 +585,20 @@
   end
 
   ##
+  # Get the default RubyGems API host. This is normally
+  # <tt>https://rubygems.org</tt>.
+
+  def self.host
+    @host ||= "https://rubygems.org"
+  end
+
+  ## Set the default RubyGems API host.
+
+  def self.host= host
+    @host = host
+  end
+
+  ##
   # Return a list of all possible load paths for the latest version for all
   # gems in the Gem installation.
 
@@ -607,6 +656,16 @@
   end
 
   ##
+  # Loads YAML, preferring Psych
+
+  def self.load_yaml
+    require 'psych'
+  rescue ::LoadError
+  ensure
+    require 'yaml'
+  end
+
+  ##
   # The file name and line number of the caller of the caller of this method.
 
   def self.location_of_caller
@@ -631,7 +690,7 @@
     @gem_path ||= nil
 
     unless @gem_path then
-      paths = [ENV['GEM_PATH'] || Gem.configuration.path || default_path]
+      paths = [ENV['GEM_PATH'] || default_path]
 
       if defined?(APPLE_GEM_HOME) and not ENV['GEM_PATH'] then
         paths << APPLE_GEM_HOME
@@ -699,14 +758,15 @@
   # The directory prefix this RubyGems was installed at.
 
   def self.prefix
-    prefix = File.dirname File.expand_path(__FILE__)
+    dir = File.dirname File.expand_path(__FILE__)
+    prefix = File.dirname dir
 
-    if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or
-       File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or
-       'lib' != File.basename(prefix) then
+    if prefix == File.expand_path(ConfigMap[:sitelibdir]) or
+       prefix == File.expand_path(ConfigMap[:libdir]) or
+       'lib' != File.basename(dir) then
       nil
     else
-      File.dirname prefix
+      prefix
     end
   end
 
@@ -743,9 +803,7 @@
   def self.refresh
     source_index.refresh!
 
-    MUTEX.synchronize do
-      @searcher = nil
-    end
+    @searcher = nil
   end
 
   ##
@@ -773,7 +831,7 @@
     end
 
     error.name = gem.name
-    error.version_requirement = gem.requirement
+    error.requirement = gem.requirement
     raise error
   end
 
@@ -835,9 +893,7 @@
   # The GemPathSearcher object used to search for matching installed gems.
 
   def self.searcher
-    MUTEX.synchronize do
-      @searcher ||= Gem::GemPathSearcher.new
-    end
+    @searcher ||= Gem::GemPathSearcher.new
   end
 
   ##
@@ -974,6 +1030,51 @@
     @@win_platform
   end
 
+  ##
+  # Load +plugins+ as ruby files
+
+  def self.load_plugin_files(plugins)
+    plugins.each do |plugin|
+
+      # Skip older versions of the GemCutter plugin: Its commands are in
+      # RubyGems proper now.
+
+      next if plugin =~ /gemcutter-0\.[0-3]/
+
+      begin
+        load plugin
+      rescue ::Exception => e
+        details = "#{plugin.inspect}: #{e.message} (#{e.class})"
+        warn "Error loading RubyGems plugin #{details}"
+      end
+    end
+  end
+
+  ##
+  # Find all 'rubygems_plugin' files in installed gems and load them
+
+  def self.load_plugins
+    load_plugin_files find_files('rubygems_plugin', false)
+  end
+
+  ##
+  # Find all 'rubygems_plugin' files in $LOAD_PATH and load them
+
+  def self.load_env_plugins
+    path = "rubygems_plugin"
+
+    files = []
+    $LOAD_PATH.each do |load_path|
+      globbed = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
+
+      globbed.each do |load_path_file|
+        files << load_path_file if File.file?(load_path_file.untaint)
+      end
+    end
+
+    load_plugin_files files
+  end
+
   class << self
 
     ##
@@ -1015,19 +1116,27 @@
 
   MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
 
-  ##
-  # Location of legacy YAML quick gemspecs on remote repositories
-
-  YAML_SPEC_DIR = 'quick/'
-
+  autoload :Version, 'rubygems/version'
+  autoload :Requirement, 'rubygems/requirement'
+  autoload :Dependency, 'rubygems/dependency'
+  autoload :GemPathSearcher, 'rubygems/gem_path_searcher'
+  autoload :SpecFetcher, 'rubygems/spec_fetcher'
+  autoload :Specification, 'rubygems/specification'
+  autoload :Cache, 'rubygems/source_index'
+  autoload :SourceIndex, 'rubygems/source_index'
+  autoload :Platform, 'rubygems/platform'
+  autoload :Builder, 'rubygems/builder'
+  autoload :ConfigFile, 'rubygems/config_file'
 end
 
 module Kernel
 
+  undef gem if respond_to? :gem # defined in gem_prelude.rb on 1.9
+
   ##
   # Use Kernel#gem to activate a specific version of +gem_name+.
   #
-  # +version_requirements+ is a list of version requirements that the
+  # +requirements+ is a list of version requirements that the
   # specified gem must match, most commonly "= example.version.number".  See
   # Gem::Requirement for how to specify a version requirement.
   #
@@ -1050,10 +1159,10 @@
   #
   #   GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
 
-  def gem(gem_name, *version_requirements) # :doc:
+  def gem(gem_name, *requirements) # :doc:
     skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
     raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
-    Gem.activate(gem_name, *version_requirements)
+    Gem.activate(gem_name, *requirements)
   end
 
   private :gem
@@ -1067,53 +1176,40 @@
 # "#{ConfigMap[:datadir]}/#{package_name}".
 
 def RbConfig.datadir(package_name)
+  require 'rbconfig/datadir' # TODO Deprecate after January 2010.
   Gem.datadir(package_name) ||
     File.join(Gem::ConfigMap[:datadir], package_name)
 end
 
 require 'rubygems/exceptions'
-require 'rubygems/version'
-require 'rubygems/requirement'
-require 'rubygems/dependency'
-require 'rubygems/gem_path_searcher'    # Needed for Kernel#gem
-require 'rubygems/source_index'         # Needed for Kernel#gem
-require 'rubygems/platform'
-require 'rubygems/builder'              # HACK: Needed for rake's package task.
 
-begin
-  require 'rubygems/defaults/operating_system'
-rescue LoadError
-end
+unless gem_preluded then
+  begin
+    ##
+    # Defaults the operating system (or packager) wants to provide for RubyGems.
 
-if defined?(RUBY_ENGINE) then
-  begin
-    require "rubygems/defaults/#{RUBY_ENGINE}"
+    require 'rubygems/defaults/operating_system'
   rescue LoadError
   end
+
+  if defined?(RUBY_ENGINE) then
+    begin
+      ##
+      # Defaults the ruby implementation wants to provide for RubyGems
+
+      require "rubygems/defaults/#{RUBY_ENGINE}"
+    rescue LoadError
+    end
+  end
 end
 
-require 'rubygems/config_file'
+##
+# Enables the require hook for RubyGems.
+#
+# Ruby 1.9 allows --disable-gems, so we require it when we didn't detect a Gem
+# constant at rubygems.rb load time.
 
-# MacRuby requires this hack as we can't load the gem_prelude.rb file yet.
-# if RUBY_VERSION < '1.9' then
-  require 'rubygems/custom_require'
-# end
+require 'rubygems/custom_require' unless gem_preluded and RUBY_VERSION > '1.9'
 
 Gem.clear_paths
 
-plugins = Gem.find_files 'rubygems_plugin'
-
-plugins.each do |plugin|
-
-  # Skip older versions of the GemCutter plugin: Its commands are in
-  # RubyGems proper now.
-
-  next if plugin =~ /gemcutter-0\.[0-3]/
-
-  begin
-    load plugin
-  rescue => e
-    warn "error loading #{plugin.inspect}: #{e.message} (#{e.class})"
-  end
-end
-
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20110108/6ff181cd/attachment-0001.html>


More information about the macruby-changes mailing list