diff --git a/Manifest.txt b/Manifest.txt index 91bbe8977a90..321085d7f24c 100644 --- a/Manifest.txt +++ b/Manifest.txt @@ -48,6 +48,7 @@ lib/rubygems/commands/uninstall_command.rb lib/rubygems/commands/unpack_command.rb lib/rubygems/commands/update_command.rb lib/rubygems/commands/which_command.rb +lib/rubygems/compatability.rb lib/rubygems/config_file.rb lib/rubygems/custom_require.rb lib/rubygems/defaults.rb diff --git a/lib/rubygems.rb b/lib/rubygems.rb index ea97a8743da5..2af1251eeea7 100644 --- a/lib/rubygems.rb +++ b/lib/rubygems.rb @@ -95,87 +95,20 @@ # # -The RubyGems Team -# Ruby 1.9.x has introduced some things that are awkward, and we need to -# support them, so we define some constants to use later. -module Gem - QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/ - GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/ -end - -# Gem::QuickLoader exists in the gem prelude code in ruby 1.9.2 itself. -# We gotta get rid of it if it's there, before we do anything else. -# -# REFACTOR: Pulling this kind of thing out into some sort of file with -# all of the hacks would be a Good Idea. -if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then - Gem::QuickLoader.remove - - $LOADED_FEATURES.delete Gem::QuickLoader.path_to_full_rubygems_library - - if $LOADED_FEATURES.any? do |path| path.end_with? '/rubygems.rb' end then - # TODO path does not exist here - raise LoadError, "another rubygems is already loaded from #{path}" - end - - class << Gem - remove_method :try_activate if Gem.respond_to?(:try_activate, true) - end -end - -require 'rubygems/defaults' require 'rbconfig' -require "rubygems/deprecate" - module Gem VERSION = '1.8.10' - DEFAULT_HOST = "https://rubygems.org" - - ## - # Raised when RubyGems is unable to load or activate a gem. Contains the - # name and version requirements of the gem that either conflicts with - # already activated gems or that RubyGems is otherwise unable to activate. - - class LoadError < ::LoadError - # Name of gem - attr_accessor :name - - # Version requirement of gem - attr_accessor :requirement - end - - # REFACTOR: Things like stopdoc tend to indicate that something might not - # be particularly well factored, and in this case, this is true. We're - # sort of patching over weirdness with RbConfig. This should be pulled - # out into some sort of file with all the compatibility hacks in it. - - # :stopdoc: - - RubyGemsVersion = VERSION - - 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 +end - RubyGemsPackageVersion = VERSION +require 'rubygems/defaults' +require 'rubygems/deprecate' +require 'rubygems/compatability' +require 'rubygems/errors' +module Gem RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__) - - # :startdoc: - + ## # An Array of Regexps that match windows ruby platforms. diff --git a/lib/rubygems/compatability.rb b/lib/rubygems/compatability.rb new file mode 100644 index 000000000000..4546fd81c74f --- /dev/null +++ b/lib/rubygems/compatability.rb @@ -0,0 +1,50 @@ +# This file contains all sorts of little compatability hacks that we've +# had to introduce over the years. Quarantining them into one file helps +# us know when we can get rid of them. + +# Ruby 1.9.x has introduced some things that are awkward, and we need to +# support them, so we define some constants to use later. +module Gem + QUICKLOADER_SUCKAGE = RUBY_VERSION =~ /^1\.9\.1/ + GEM_PRELUDE_SUCKAGE = RUBY_VERSION =~ /^1\.9\.2/ +end + +# Gem::QuickLoader exists in the gem prelude code in ruby 1.9.2 itself. +# We gotta get rid of it if it's there, before we do anything else. +if Gem::GEM_PRELUDE_SUCKAGE and defined?(Gem::QuickLoader) then + Gem::QuickLoader.remove + + $LOADED_FEATURES.delete Gem::QuickLoader.path_to_full_rubygems_library + + if $LOADED_FEATURES.any? do |path| path.end_with? '/rubygems.rb' end then + # TODO path does not exist here + raise LoadError, "another rubygems is already loaded from #{path}" + end + + class << Gem + remove_method :try_activate if Gem.respond_to?(:try_activate, true) + end +end + +module Gem + RubyGemsVersion = VERSION + + 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 + + RubyGemsPackageVersion = VERSION +end diff --git a/lib/rubygems/defaults.rb b/lib/rubygems/defaults.rb index e257c170adf1..993cd80f341c 100644 --- a/lib/rubygems/defaults.rb +++ b/lib/rubygems/defaults.rb @@ -1,6 +1,5 @@ module Gem - - # TODO: move this whole file back into rubygems.rb + DEFAULT_HOST = "https://rubygems.org" @post_install_hooks ||= [] @done_installing_hooks ||= [] diff --git a/lib/rubygems/errors.rb b/lib/rubygems/errors.rb index f2fe954adbe5..903e122b2ddd 100644 --- a/lib/rubygems/errors.rb +++ b/lib/rubygems/errors.rb @@ -1,36 +1,73 @@ -class Gem::ErrorReason; end # TODO: remove, unnecessary superclass - -# TODO move to lib/rubygems/platform_mismatch.rb -# TODO write tests -#-- -# Generated when a gem is found that isn't usable on the current platform. +## +# This file contains all the various exceptions and other errors that are used +# inside of RubyGems. # -class Gem::PlatformMismatch < Gem::ErrorReason +# DOC: Confirm _all_ - attr_reader :name - attr_reader :version - attr_reader :platforms +module Gem + ## + # Raised when RubyGems is unable to load or activate a gem. Contains the + # name and version requirements of the gem that either conflicts with + # already activated gems or that RubyGems is otherwise unable to activate. - def initialize(name, version) - @name = name - @version = version - @platforms = [] - end + class LoadError < ::LoadError + # Name of gem + attr_accessor :name - def add_platform(platform) - @platforms << platform + # Version requirement of gem + attr_accessor :requirement end - #-- - # Replace only "platforms", remove duplicate strings - def wordy - prefix = "Found #{@name} (#{@version})" + # FIX: does this need to exist? The subclass is the only other reference + # I can find. + class 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 PlatformMismatch < ErrorReason + + ## + # the name of the gem + attr_reader :name + + ## + # the version + attr_reader :version + + ## + # The platforms that are mismatched + attr_reader :platforms - if @platforms.size == 1 - "#{prefix}, but was for platform #{@platforms[0]}" - else - "#{prefix}, but was for platforms #{@platforms.join(' ,')}" + def initialize(name, version) + @name = name + @version = version + @platforms = [] + end + + ## + # append a platform to the list of mismatched platforms. + # + # Platforms are added via this instead of injected via the constructor + # so that we can loop over a list of mismatches and just add them rather + # than perform some kind of calculation mismatch summary before creation. + def add_platform(platform) + @platforms << platform end - end + ## + # A wordy description of the error. + def wordy + prefix = "Found #{@name} (#{@version})" + + "Found %s (%), but was for platform%s %s" % + [@name, + @version, + @platforms.size == 1 ? 's' : '', + @platforms.join(' ,')] + end + end end diff --git a/lib/rubygems/test_case.rb b/lib/rubygems/test_case.rb index 02c34abc19ed..a37e9aa4735f 100644 --- a/lib/rubygems/test_case.rb +++ b/lib/rubygems/test_case.rb @@ -18,7 +18,7 @@ gem 'json' end -require "rubygems/deprecate" +require 'rubygems/deprecate' require 'minitest/autorun' require 'fileutils' require 'tmpdir'