summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r--lib/rubygems.rb118
1 files changed, 102 insertions, 16 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 78bdc4867d..fac38e4143 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -8,7 +8,7 @@
require 'rbconfig'
module Gem
- VERSION = '2.0.8'
+ VERSION = '2.1.3'
end
# Must be first since it unloads the prelude from 1.9.2
@@ -115,7 +115,7 @@ module Gem
RUBYGEMS_DIR = File.dirname File.expand_path(__FILE__)
##
- # An Array of Regexps that match windows ruby platforms.
+ # An Array of Regexps that match windows Ruby platforms.
WIN_PATTERNS = [
/bccwin/i,
@@ -143,6 +143,14 @@ module Gem
specifications
]
+ ##
+ # Subdirectories in a gem repository for default gems
+
+ REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES = %w[
+ gems
+ specifications/default
+ ]
+
@@win_platform = nil
@configuration = nil
@@ -379,6 +387,10 @@ module Gem
paths.path
end
+ def self.spec_cache_dir
+ paths.spec_cache_dir
+ end
+
##
# Quietly ensure the Gem directory +dir+ contains all the proper
# subdirectories. If we can't create a directory due to a permission
@@ -389,6 +401,23 @@ module Gem
# World-writable directories will never be created.
def self.ensure_gem_subdirectories dir = Gem.dir, mode = nil
+ ensure_subdirectories(dir, mode, REPOSITORY_SUBDIRECTORIES)
+ end
+
+ ##
+ # Quietly ensure the Gem directory +dir+ contains all the proper
+ # subdirectories for handling default gems. If we can't create a
+ # directory due to a permission problem, then we will silently continue.
+ #
+ # If +mode+ is given, missing directories are created with this mode.
+ #
+ # World-writable directories will never be created.
+
+ def self.ensure_default_gem_subdirectories dir = Gem.dir, mode = nil
+ ensure_subdirectories(dir, mode, REPOSITORY_DEFAULT_GEM_SUBDIRECTORIES)
+ end
+
+ def self.ensure_subdirectories dir, mode, subdirs # :nodoc:
old_umask = File.umask
File.umask old_umask | 002
@@ -398,7 +427,7 @@ module Gem
options[:mode] = mode if mode
- REPOSITORY_SUBDIRECTORIES.each do |name|
+ subdirs.each do |name|
subdir = File.join dir, name
next if File.exist? subdir
FileUtils.mkdir_p subdir, options rescue nil
@@ -417,16 +446,12 @@ module Gem
# $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.
+ # versions of the same gem. See also find_latest_files
def self.find_files(glob, check_load_path=true)
files = []
- if check_load_path
- files = $LOAD_PATH.map { |load_path|
- Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
- }.flatten.select { |file| File.file? file.untaint }
- end
+ files = find_files_from_load_path glob if check_load_path
files.concat Gem::Specification.map { |spec|
spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
@@ -439,6 +464,40 @@ module Gem
return files
end
+ def self.find_files_from_load_path glob # :nodoc:
+ $LOAD_PATH.map { |load_path|
+ Dir["#{File.expand_path glob, load_path}#{Gem.suffix_pattern}"]
+ }.flatten.select { |file| File.file? file.untaint }
+ end
+
+ ##
+ # Returns a list of paths matching +glob+ from the latest gems that can be
+ # used by a gem to pick up features from other gems. For example:
+ #
+ # Gem.find_latest_files('rdoc/discover').each do |path| load path end
+ #
+ # if +check_load_path+ is true (the default), then find_latest_files also
+ # searches $LOAD_PATH for files as well as gems.
+ #
+ # Unlike find_files, find_latest_files will return only files from the
+ # latest version of a gem.
+
+ def self.find_latest_files(glob, check_load_path=true)
+ files = []
+
+ files = find_files_from_load_path glob if check_load_path
+
+ files.concat Gem::Specification.latest_specs(true).map { |spec|
+ spec.matches_for_glob("#{glob}#{Gem.suffix_pattern}")
+ }.flatten
+
+ # $LOAD_PATH might contain duplicate entries or reference
+ # the spec dirs directly, so we prune.
+ files.uniq! if check_load_path
+
+ return files
+ end
+
##
# Finds the user's home directory.
#--
@@ -793,7 +852,7 @@ module Gem
end
##
- # A Gem::Version for the currently running ruby.
+ # A Gem::Version for the currently running Ruby.
def self.ruby_version
return @ruby_version if defined? @ruby_version
@@ -916,9 +975,9 @@ module Gem
end
##
- # Load +plugins+ as ruby files
+ # Load +plugins+ as Ruby files
- def self.load_plugin_files(plugins)
+ def self.load_plugin_files plugins # :nodoc:
plugins.each do |plugin|
# Skip older versions of the GemCutter plugin: Its commands are in
@@ -936,10 +995,16 @@ module Gem
end
##
- # Find all 'rubygems_plugin' files in installed gems and load them
+ # Find the 'rubygems_plugin' files in the latest installed gems and load
+ # them
def self.load_plugins
- load_plugin_files find_files('rubygems_plugin', false)
+ # Remove this env var by at least 3.0
+ if ENV['RUBYGEMS_LOAD_ALL_PLUGINS']
+ load_plugin_files find_files('rubygems_plugin', false)
+ else
+ load_plugin_files find_latest_files('rubygems_plugin', false)
+ end
end
##
@@ -971,10 +1036,31 @@ module Gem
attr_reader :loaded_specs
##
- # Register a Gem::Specification for default gem
+ # Register a Gem::Specification for default gem.
+ #
+ # Two formats for the specification are supported:
+ #
+ # * MRI 2.0 style, where spec.files contains unprefixed require names.
+ # The spec's filenames will be registered as-is.
+ # * New style, where spec.files contains files prefixed with paths
+ # from spec.require_paths. The prefixes are stripped before
+ # registering the spec's filenames. Unprefixed files are omitted.
+ #
def register_default_spec(spec)
+ new_format = Gem.default_gems_use_full_paths? || spec.require_paths.any? {|path| spec.files.any? {|f| f.start_with? path } }
+
+ if new_format
+ prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
+ prefix_pattern = /^(#{prefix_group})/
+ end
+
spec.files.each do |file|
+ if new_format
+ file = file.sub(prefix_pattern, "")
+ next unless $~
+ end
+
@path_to_default_spec_map[file] = spec
end
end
@@ -1091,7 +1177,7 @@ unless gem_preluded then # TODO: remove guard after 1.9.2 dropped
if defined?(RUBY_ENGINE) then
begin
##
- # Defaults the ruby implementation wants to provide for RubyGems
+ # Defaults the Ruby implementation wants to provide for RubyGems
require "rubygems/defaults/#{RUBY_ENGINE}"
rescue LoadError