5
5
# See LICENSE.txt for permissions.
8
require 'rubygems/rubygems_version'
8
gem_disabled = !defined? Gem
11
# Nuke the Quickloader stuff
12
Gem::QuickLoader.remove
9
15
require 'rubygems/defaults'
20
# RubyGems is the Ruby standard for publishing and managing third party
23
# For user documentation, see:
25
# * <tt>gem help</tt> and <tt>gem help [command]</tt>
26
# * {RubyGems User Guide}[http://docs.rubygems.org/read/book/1]
27
# * {Frequently Asked Questions}[http://docs.rubygems.org/read/book/3]
29
# For gem developer documentation see:
31
# * {Creating Gems}[http://docs.rubygems.org/read/chapter/5]
32
# * Gem::Specification
33
# * Gem::Version for version dependency notes
35
# Further RubyGems documentation can be found at:
37
# * {RubyGems API}[http://rubygems.rubyforge.org/rdoc] (also available from
38
# <tt>gem server</tt>)
39
# * {RubyGems Bookshelf}[http://rubygem.org]
43
# As of RubyGems 1.3.2, RubyGems will load plugins installed in gems or
44
# $LOAD_PATH. Plugins must be named 'rubygems_plugin' (.rb, .so, etc) and
45
# placed at the root of your gem's #require_path. Plugins are discovered via
46
# Gem::find_files then loaded. Take care when implementing a plugin as your
47
# plugin file may be loaded multiple times if multiple versions of your gem
50
# For an example plugin, see the graph gem which adds a `gem graph` command.
52
# == RubyGems Defaults, Packaging
54
# RubyGems defaults are stored in rubygems/defaults.rb. If you're packaging
55
# RubyGems or implementing Ruby you can change RubyGems' defaults.
57
# For RubyGems packagers, provide lib/rubygems/operating_system.rb and
58
# override any defaults from lib/rubygems/defaults.rb.
60
# For Ruby implementers, provide lib/rubygems/#{RUBY_ENGINE}.rb and override
61
# any defaults from lib/rubygems/defaults.rb.
63
# If you need RubyGems to perform extra work on install or uninstall, your
64
# defaults override file can set pre and post install and uninstall hooks.
65
# See Gem::pre_install, Gem::pre_uninstall, Gem::post_install,
66
# Gem::post_uninstall.
70
# You can submit bugs to the
71
# {RubyGems bug tracker}[http://rubyforge.org/tracker/?atid=575&group_id=126]
76
# RubyGems is currently maintained by Eric Hodel.
78
# RubyGems was originally developed at RubyConf 2003 by:
80
# * Rich Kilmer -- rich(at)infoether.com
81
# * Chad Fowler -- chad(at)chadfowler.com
82
# * David Black -- dblack(at)wobblini.net
83
# * Paul Brannan -- paul(at)atdesk.com
84
# * Jim Weirch -- jim(at)weirichhouse.org
88
# * Gavin Sinclair -- gsinclair(at)soyabean.com.au
89
# * George Marrows -- george.marrows(at)ntlworld.com
90
# * Dick Davies -- rasputnik(at)hellooperator.net
91
# * Mauricio Fernandez -- batsman.geo(at)yahoo.com
92
# * Simon Strandgaard -- neoneye(at)adslhome.dk
93
# * Dave Glasser -- glasser(at)mit.edu
94
# * Paul Duncan -- pabs(at)pablotron.org
95
# * Ville Aine -- vaine(at)cs.helsinki.fi
96
# * Eric Hodel -- drbrain(at)segment7.net
97
# * Daniel Berger -- djberg96(at)gmail.com
98
# * Phil Hagelberg -- technomancy(at)gmail.com
99
# * Ryan Davis -- ryand-ruby(at)zenspider.com
101
# (If your name is missing, PLEASE let us know!)
108
RubyGemsVersion = VERSION = '1.3.7'
111
# Raised when RubyGems is unable to load or activate a gem. Contains the
112
# name and version requirements of the gem that either conflicts with
113
# already activated gems or that RubyGems is otherwise unable to activate.
13
115
class LoadError < ::LoadError
14
attr_accessor :name, :version_requirement
119
# Version requirement of gem
120
attr_accessor :version_requirement
21
# Use Kernel#gem to activate a specific version of +gem_name+.
23
# +version_requirements+ is a list of version requirements that the
24
# specified gem must match, most commonly "= example.version.number". See
25
# Gem::Requirement for how to specify a version requirement.
27
# If you will be activating the latest version of a gem, there is no need to
28
# call Kernel#gem, Kernel#require will do the right thing for you.
30
# Kernel#gem returns true if the gem was activated, otherwise false. If the
31
# gem could not be found, didn't match the version requirements, or a
32
# different version was already activated, an exception will be raised.
34
# Kernel#gem should be called *before* any require statements (otherwise
35
# RubyGems may load a conflicting library version).
37
# In older RubyGems versions, the environment variable GEM_SKIP could be
38
# used to skip activation of specified gems, for example to test out changes
39
# that haven't been installed yet. Now RubyGems defers to -I and the
40
# RUBYLIB environment variable to skip activation of a gem.
44
# GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
46
def gem(gem_name, *version_requirements) # :doc:
47
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
48
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
49
Gem.activate(gem_name, *version_requirements)
57
# Main module to hold all RubyGem classes/modules.
124
# Configuration settings from ::RbConfig
61
126
ConfigMap = {} unless defined?(ConfigMap)
62
128
require 'rbconfig'
63
RbConfig = Config unless defined? ::RbConfig
66
:BASERUBY => RbConfig::CONFIG["BASERUBY"],
67
:EXEEXT => RbConfig::CONFIG["EXEEXT"],
68
:RUBY_INSTALL_NAME => RbConfig::CONFIG["RUBY_INSTALL_NAME"],
69
:RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
70
:arch => RbConfig::CONFIG["arch"],
71
:bindir => RbConfig::CONFIG["bindir"],
72
:datadir => RbConfig::CONFIG["datadir"],
73
:libdir => RbConfig::CONFIG["libdir"],
131
:EXEEXT => RbConfig::CONFIG["EXEEXT"],
132
:RUBY_SO_NAME => RbConfig::CONFIG["RUBY_SO_NAME"],
133
:arch => RbConfig::CONFIG["arch"],
134
:bindir => RbConfig::CONFIG["bindir"],
135
:datadir => RbConfig::CONFIG["datadir"],
136
:libdir => RbConfig::CONFIG["libdir"],
74
137
:ruby_install_name => RbConfig::CONFIG["ruby_install_name"],
75
:ruby_version => RbConfig::CONFIG["ruby_version"],
76
:sitedir => RbConfig::CONFIG["sitedir"],
77
:sitelibdir => RbConfig::CONFIG["sitelibdir"],
78
:vendordir => RbConfig::CONFIG["vendordir"] ,
79
:vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
138
:ruby_version => RbConfig::CONFIG["ruby_version"],
139
:rubylibprefix => RbConfig::CONFIG["rubylibprefix"],
140
:sitedir => RbConfig::CONFIG["sitedir"],
141
:sitelibdir => RbConfig::CONFIG["sitelibdir"],
142
:vendordir => RbConfig::CONFIG["vendordir"] ,
143
:vendorlibdir => RbConfig::CONFIG["vendorlibdir"]
147
# Default directories in a gem repository
82
149
DIRECTORIES = %w[cache doc gems specifications] unless defined?(DIRECTORIES)
86
RubyGemsPackageVersion = RubyGemsVersion
154
RubyGemsPackageVersion = VERSION
89
158
# An Array of Regexps that match windows ruby platforms.
352
468
# Gem.find_files('rdoc/discover').each do |path| load path end
354
# find_files does not search $LOAD_PATH for files, only gems.
470
# find_files search $LOAD_PATH for files as well as gems.
472
# Note that find_files will return all files even if they are from different
473
# versions of the same gem.
356
475
def self.find_files(path)
476
load_path_files = $LOAD_PATH.map do |load_path|
477
files = Dir["#{File.expand_path path, load_path}#{Gem.suffix_pattern}"]
479
files.select do |load_path_file|
480
File.file? load_path_file.untaint
357
484
specs = searcher.find_all path
486
specs_files = specs.map do |spec|
360
487
searcher.matching_files spec, path
490
(load_path_files + specs_files).flatten.uniq
365
494
# Finds the user's home directory.
367
# Some comments from the ruby-talk list regarding finding the home
370
# I have HOME, USERPROFILE and HOMEDRIVE + HOMEPATH. Ruby seems
371
# to be depending on HOME in those code samples. I propose that
372
# it should fallback to USERPROFILE and HOMEDRIVE + HOMEPATH (at
375
496
def self.find_home
376
['HOME', 'USERPROFILE'].each do |homekey|
377
return ENV[homekey] if ENV[homekey]
380
if ENV['HOMEDRIVE'] && ENV['HOMEPATH'] then
381
return "#{ENV['HOMEDRIVE']}#{ENV['HOMEPATH']}"
385
File.expand_path("~")
387
if File::ALT_SEPARATOR then
499
if File::ALT_SEPARATOR then
585
683
# The directory prefix this RubyGems was installed at.
588
prefix = File.dirname File.expand_path(__FILE__)
686
dir = File.dirname File.expand_path(__FILE__)
687
prefix = File.dirname dir
590
if File.dirname(prefix) == File.expand_path(ConfigMap[:sitelibdir]) or
591
File.dirname(prefix) == File.expand_path(ConfigMap[:libdir]) or
592
'lib' != File.basename(prefix) then
689
if prefix == File.expand_path(ConfigMap[:sitelibdir]) or
690
prefix == File.expand_path(ConfigMap[:libdir]) or
691
'lib' != File.basename(dir) then
699
# Promotes the load paths of the +gem_name+ over the load paths of
700
# +over_name+. Useful for allowing one gem to override features in another
703
def self.promote_load_path(gem_name, over_name)
704
gem = Gem.loaded_specs[gem_name]
705
over = Gem.loaded_specs[over_name]
707
raise ArgumentError, "gem #{gem_name} is not activated" if gem.nil?
708
raise ArgumentError, "gem #{over_name} is not activated" if over.nil?
710
last_gem_path = File.join gem.full_gem_path, gem.require_paths.last
712
over_paths = over.require_paths.map do |path|
713
File.join over.full_gem_path, path
716
over_paths.each do |path|
717
$LOAD_PATH.delete path
720
gem = $LOAD_PATH.index(last_gem_path) + 1
722
$LOAD_PATH.insert(gem, *over_paths)
625
751
if matches.empty? then
626
752
error = Gem::LoadError.new(
627
"Could not find RubyGem #{gem.name} (#{gem.version_requirements})\n")
753
"Could not find RubyGem #{gem.name} (#{gem.requirement})\n")
629
755
error = Gem::LoadError.new(
630
756
"RubyGem version error: " +
631
"#{gem.name}(#{matches.first.version} not #{gem.version_requirements})\n")
757
"#{gem.name}(#{matches.first.version} not #{gem.requirement})\n")
634
760
error.name = gem.name
635
error.version_requirement = gem.version_requirements
761
error.version_requirement = gem.requirement
639
765
private_class_method :report_activate_error
641
def self.required_location(gemname, libfile, *version_constraints)
642
version_constraints = Gem::Requirement.default if version_constraints.empty?
643
matches = Gem.source_index.find_name(gemname, version_constraints)
768
# Full path to +libfile+ in +gemname+. Searches for the latest gem unless
769
# +requirements+ is given.
771
def self.required_location(gemname, libfile, *requirements)
772
requirements = Gem::Requirement.default if requirements.empty?
774
matches = Gem.source_index.find_name gemname, requirements
644
776
return nil if matches.empty?
645
778
spec = matches.last
646
779
spec.require_paths.each do |path|
647
result = File.join(spec.full_gem_path, path, libfile)
648
return result if File.exist?(result)
780
result = File.join spec.full_gem_path, path, libfile
781
return result if File.exist? result
1021
# Location of Marshal quick gemspecs on remote repositories
841
1023
MARSHAL_SPEC_DIR = "quick/Marshal.#{Gem.marshal_version}/"
1026
# Location of legacy YAML quick gemspecs on remote repositories
843
1028
YAML_SPEC_DIR = 'quick/'
850
# Return the path to the data directory associated with the named
851
# package. If the package is loaded as a gem, return the gem
852
# specific data directory. Otherwise return a path to the share
853
# area as define by "#{ConfigMap[:datadir]}/#{package_name}".
854
def datadir(package_name)
855
Gem.datadir(package_name) ||
856
File.join(Gem::ConfigMap[:datadir], package_name)
1034
remove_method :gem if respond_to?(:gem, true) # defined in gem_prelude.rb on 1.9
1037
# Use Kernel#gem to activate a specific version of +gem_name+.
1039
# +version_requirements+ is a list of version requirements that the
1040
# specified gem must match, most commonly "= example.version.number". See
1041
# Gem::Requirement for how to specify a version requirement.
1043
# If you will be activating the latest version of a gem, there is no need to
1044
# call Kernel#gem, Kernel#require will do the right thing for you.
1046
# Kernel#gem returns true if the gem was activated, otherwise false. If the
1047
# gem could not be found, didn't match the version requirements, or a
1048
# different version was already activated, an exception will be raised.
1050
# Kernel#gem should be called *before* any require statements (otherwise
1051
# RubyGems may load a conflicting library version).
1053
# In older RubyGems versions, the environment variable GEM_SKIP could be
1054
# used to skip activation of specified gems, for example to test out changes
1055
# that haven't been installed yet. Now RubyGems defers to -I and the
1056
# RUBYLIB environment variable to skip activation of a gem.
1060
# GEM_SKIP=libA:libB ruby -I../libA -I../libB ./mycode.rb
1062
def gem(gem_name, *version_requirements) # :doc:
1063
skip_list = (ENV['GEM_SKIP'] || "").split(/:/)
1064
raise Gem::LoadError, "skipping #{gem_name}" if skip_list.include? gem_name
1065
Gem.activate(gem_name, *version_requirements)
1073
# Return the path to the data directory associated with the named package. If
1074
# the package is loaded as a gem, return the gem specific data directory.
1075
# Otherwise return a path to the share area as define by
1076
# "#{ConfigMap[:datadir]}/#{package_name}".
1078
def RbConfig.datadir(package_name)
1079
Gem.datadir(package_name) ||
1080
File.join(Gem::ConfigMap[:datadir], package_name)
862
1083
require 'rubygems/exceptions'