summaryrefslogtreecommitdiff
path: root/lib/rubygems.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rubygems.rb')
-rw-r--r--lib/rubygems.rb58
1 files changed, 55 insertions, 3 deletions
diff --git a/lib/rubygems.rb b/lib/rubygems.rb
index 2c8dbee2a2..dfc1006fd4 100644
--- a/lib/rubygems.rb
+++ b/lib/rubygems.rb
@@ -8,7 +8,7 @@
require 'rbconfig'
module Gem
- VERSION = '2.0.4'
+ VERSION = '2.1.0'
end
# Must be first since it unloads the prelude from 1.9.2
@@ -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
@@ -971,10 +1000,33 @@ 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, prefix_pattern = nil
+
spec.files.each do |file|
+ if new_format == nil
+ new_format = spec.require_paths.any? {|path| file.start_with? path}
+
+ prefix_group = spec.require_paths.map {|f| f + "/"}.join("|")
+ prefix_pattern = /^(#{prefix_group})/
+ end
+
+ if new_format
+ file = file.sub(prefix_pattern, "")
+ next unless $~
+ end
+
@path_to_default_spec_map[file] = spec
end
end