summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
-rw-r--r--lib/rubygems.rb334
1 files changed, 293 insertions, 41 deletions
@@ -8,11 +8,29 @@
require 'rubygems/rubygems_version'
require 'rubygems/defaults'
require 'thread'
module Gem
class LoadError < ::LoadError
- attr_accessor :name, :version_requirement
end
end
module Kernel
@@ -54,18 +72,102 @@ module Kernel
end
##
-# Main module to hold all RubyGem classes/modules.
module Gem
ConfigMap = {} unless defined?(ConfigMap)
require 'rbconfig'
- RbConfig = Config unless defined? ::RbConfig
ConfigMap.merge!(
- :BASERUBY => RbConfig::CONFIG["BASERUBY"],
:EXEEXT => RbConfig::CONFIG["EXEEXT"],
- :RUBY_INSTALL_NAME => RbConfig::CONFIG["RUBY_INSTALL_NAME"],
:RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
:arch => RbConfig::CONFIG["arch"],
:bindir => RbConfig::CONFIG["bindir"],
@@ -79,11 +181,16 @@ module Gem
:vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
)
DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
MUTEX = Mutex.new
RubyGemsPackageVersion = RubyGemsVersion
##
# An Array of Regexps that match windows ruby platforms.
@@ -102,6 +209,7 @@ module Gem
@configuration = nil
@loaded_specs = {}
@platforms = []
@ruby = nil
@sources = []
@@ -128,6 +236,14 @@ module Gem
# Gem::Requirement and Gem::Version documentation.
def self.activate(gem, *version_requirements)
if version_requirements.empty? then
version_requirements = Gem::Requirement.default
end
@@ -146,8 +262,18 @@ module Gem
existing_spec = @loaded_specs[gem.name]
unless matches.any? { |spec| spec.version == existing_spec.version } then
- raise Gem::Exception,
- "can't activate #{gem}, already activated #{existing_spec.full_name}"
end
return false
@@ -159,10 +285,11 @@ module Gem
spec.loaded = true
@loaded_specs[spec.name] = spec
# Load dependent gems first
spec.runtime_dependencies.each do |dep_gem|
- activate dep_gem
end
# bin directory must come before library directories
@@ -228,6 +355,35 @@ module Gem
end
##
# The mode needed to read a file as straight binary.
def self.binary_mode
@@ -351,14 +507,27 @@ module Gem
#
# Gem.find_files('rdoc/discover').each do |path| load path end
#
- # find_files does not search $LOAD_PATH for files, only gems.
def self.find_files(path)
specs = searcher.find_all path
- specs.map do |spec|
searcher.matching_files spec, path
end.flatten
end
##
@@ -373,7 +542,17 @@ module Gem
# least on Win32).
def self.find_home
- File.expand_path("~")
rescue
if File::ALT_SEPARATOR then
"C:/"
@@ -477,7 +656,7 @@ module Gem
# The file name and line number of the caller of the caller of this method.
def self.location_of_caller
- caller[1] =~ /(.*?):(\d+)$/i
file = $1
lineno = $2.to_i
@@ -485,15 +664,6 @@ module Gem
end
##
- # manage_gems is useless and deprecated. Don't call it anymore.
-
- def self.manage_gems # :nodoc:
- file, lineno = location_of_caller
-
- warn "#{file}:#{lineno}:Warning: Gem::manage_gems is deprecated and will be removed on or after March 2009."
- end
-
- ##
# The version of the Marshal format for your Ruby.
def self.marshal_version
@@ -587,6 +757,33 @@ module Gem
end
##
# Refresh source_index from disk and clear searcher.
def self.refresh
@@ -628,15 +825,23 @@ module Gem
private_class_method :report_activate_error
- def self.required_location(gemname, libfile, *version_constraints)
- version_constraints = Gem::Requirement.default if version_constraints.empty?
- matches = Gem.source_index.find_name(gemname, version_constraints)
return nil if matches.empty?
spec = matches.last
spec.require_paths.each do |path|
- result = File.join(spec.full_gem_path, path, libfile)
- return result if File.exist?(result)
end
nil
end
@@ -662,7 +867,13 @@ module Gem
def self.ruby_version
return @ruby_version if defined? @ruby_version
version = RUBY_VERSION.dup
- version << ".#{RUBY_LEVEL}" if defined? RUBY_LEVEL
@ruby_version = Gem::Version.new version
end
@@ -679,7 +890,7 @@ module Gem
# Set the Gem home directory (as reported by Gem.dir).
def self.set_home(home)
- home = home.gsub(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
@gem_home = home
end
@@ -757,6 +968,31 @@ module Gem
end
##
# Use the +home+ and +paths+ values for Gem.dir and Gem.path. Used mainly
# by the unit tests to provide environment isolation.
@@ -786,6 +1022,9 @@ module Gem
class << self
attr_reader :loaded_specs
##
@@ -817,25 +1056,27 @@ module Gem
end
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
YAML_SPEC_DIR = 'quick/'
end
-module RbConfig
- # :stopdoc:
- class << self
- # Return the path to the data directory associated with the named
- # package. If the package is loaded as a gem, return the gem
- # specific data directory. Otherwise return a path to the share
- # area as define by "#{ConfigMap[:datadir]}/#{package_name}".
- def datadir(package_name)
- Gem.datadir(package_name) ||
- File.join(Gem::ConfigMap[:datadir], package_name)
- end
- end
- # :startdoc:
end
require 'rubygems/exceptions'
@@ -866,3 +1107,14 @@ if RUBY_VERSION < '1.9' then
end
Gem.clear_paths