summaryrefslogtreecommitdiff
path: root/lib/rubygems
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 21:29:41 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-18 21:29:41 +0000
commit95683e5cb2d1ab8351402b09ef853dcdf875bf8d (patch)
tree44500dba22e9aa94ecc5d4fd348512d0fb236501 /lib/rubygems
parent81629f05312cc4df2193a17f13c581eda174d9af (diff)
* lib/rubygems: Update to RubyGems 2.2.0.preview.1
This brings several new features to RubyGems summarized here: https://github.com/rubygems/rubygems/blob/v2.2.0.preview.1/History.txt * test/rubygems: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42967 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/rubygems')
-rw-r--r--lib/rubygems/commands/list_command.rb8
-rw-r--r--lib/rubygems/commands/pristine_command.rb15
-rw-r--r--lib/rubygems/commands/push_command.rb13
-rw-r--r--lib/rubygems/commands/query_command.rb46
-rw-r--r--lib/rubygems/commands/search_command.rb6
-rw-r--r--lib/rubygems/commands/uninstall_command.rb6
-rw-r--r--lib/rubygems/commands/update_command.rb3
-rw-r--r--lib/rubygems/commands/which_command.rb8
-rw-r--r--lib/rubygems/gemcutter_utilities.rb9
-rw-r--r--lib/rubygems/package.rb13
-rw-r--r--lib/rubygems/request.rb24
-rw-r--r--lib/rubygems/requirement.rb22
-rw-r--r--lib/rubygems/specification.rb22
13 files changed, 119 insertions, 76 deletions
diff --git a/lib/rubygems/commands/list_command.rb b/lib/rubygems/commands/list_command.rb
index 0d15950475e..4edeabef020 100644
--- a/lib/rubygems/commands/list_command.rb
+++ b/lib/rubygems/commands/list_command.rb
@@ -33,13 +33,7 @@ To search for remote gems use the search command.
end
def usage # :nodoc:
- "#{program_name} [STRING]"
- end
-
- def execute
- string = get_one_optional_argument || ''
- options[:name] = /^#{string}/i
- super
+ "#{program_name} [STRING ...]"
end
end
diff --git a/lib/rubygems/commands/pristine_command.rb b/lib/rubygems/commands/pristine_command.rb
index 3f3bca45be2..b54e7eac938 100644
--- a/lib/rubygems/commands/pristine_command.rb
+++ b/lib/rubygems/commands/pristine_command.rb
@@ -12,6 +12,7 @@ class Gem::Commands::PristineCommand < Gem::Command
'Restores installed gems to pristine condition from files located in the gem cache',
:version => Gem::Requirement.default,
:extensions => true,
+ :extensions_set => false,
:all => false
add_option('--all',
@@ -23,7 +24,8 @@ class Gem::Commands::PristineCommand < Gem::Command
add_option('--[no-]extensions',
'Restore gems with extensions',
'in addition to regular gems') do |value, options|
- options[:extensions] = value
+ options[:extensions_set] = true
+ options[:extensions] = value
end
add_option('--only-executables',
@@ -62,6 +64,9 @@ If the cached gem cannot be found it will be downloaded.
If --no-extensions is provided pristine will not attempt to restore a gem
with an extension.
+
+If --extensions is given (but not --all or gem names) only gems with
+extensions will be restored.
EOF
end
@@ -72,6 +77,14 @@ with an extension.
def execute
specs = if options[:all] then
Gem::Specification.map
+
+ # `--extensions` must be explicitly given to pristine only gems
+ # with extensions.
+ elsif options[:extensions_set] and
+ options[:extensions] and options[:args].empty? then
+ Gem::Specification.select do |spec|
+ spec.extensions and not spec.extensions.empty?
+ end
else
get_all_gem_names.map do |gem_name|
Gem::Specification.find_all_by_name gem_name, options[:version]
diff --git a/lib/rubygems/commands/push_command.rb b/lib/rubygems/commands/push_command.rb
index b90be7bd10d..6899b489ad7 100644
--- a/lib/rubygems/commands/push_command.rb
+++ b/lib/rubygems/commands/push_command.rb
@@ -69,13 +69,18 @@ You can upgrade or downgrade to the latest release version with:
terminate_interaction 1
end
+ gem_data = Gem::Package.new(name)
+
unless @host then
- if gem_data = Gem::Package.new(name) then
- @host = gem_data.spec.metadata['default_gem_server']
- end
+ @host = gem_data.spec.metadata['default_gem_server']
end
- args << @host if @host
+ # Always include this, even if it's nil
+ args << @host
+
+ if gem_data.spec.metadata.has_key?('allowed_push_host')
+ args << gem_data.spec.metadata['allowed_push_host']
+ end
say "Pushing gem to #{@host || Gem.host}..."
diff --git a/lib/rubygems/commands/query_command.rb b/lib/rubygems/commands/query_command.rb
index c9c30149754..55b950c1b7c 100644
--- a/lib/rubygems/commands/query_command.rb
+++ b/lib/rubygems/commands/query_command.rb
@@ -72,16 +72,26 @@ is too hard to use.
def execute
exit_code = 0
+ if options[:args].to_a.empty? and options[:name].source.empty?
+ name = options[:name]
+ no_name = true
+ elsif !options[:name].source.empty?
+ name = Array(options[:name])
+ else
+ name = options[:args].to_a.map{|arg| /#{arg}/i }
+ end
- name = options[:name]
prerelease = options[:prerelease]
unless options[:installed].nil? then
- if name.source.empty? then
+ if no_name then
alert_error "You must specify a gem name"
exit_code |= 4
+ elsif name.count > 1
+ alert_error "You must specify only ONE gem!"
+ exit_code |= 4
else
- installed = installed? name, options[:version]
+ installed = installed? name.first, options[:version]
installed = !installed unless options[:installed]
if installed then
@@ -95,6 +105,22 @@ is too hard to use.
terminate_interaction exit_code
end
+ names = Array(name)
+ names.each { |n| show_gems n, prerelease }
+ end
+
+ private
+
+ def display_header type
+ if (ui.outs.tty? and Gem.configuration.verbose) or both? then
+ say
+ say "*** #{type} GEMS ***"
+ say
+ end
+ end
+
+ #Guts of original execute
+ def show_gems name, prerelease
req = Gem::Requirement.default
# TODO: deprecate for real
dep = Gem::Deprecate.skip_during { Gem::Dependency.new name, req }
@@ -105,11 +131,7 @@ is too hard to use.
alert_warning "prereleases are always shown locally"
end
- if ui.outs.tty? or both? then
- say
- say "*** LOCAL GEMS ***"
- say
- end
+ display_header 'LOCAL'
specs = Gem::Specification.find_all { |s|
s.name =~ name and req =~ s.version
@@ -123,11 +145,7 @@ is too hard to use.
end
if remote? then
- if ui.outs.tty? or both? then
- say
- say "*** REMOTE GEMS ***"
- say
- end
+ display_header 'REMOTE'
fetcher = Gem::SpecFetcher.fetcher
@@ -155,8 +173,6 @@ is too hard to use.
end
end
- private
-
##
# Check if gem +name+ version +version+ is installed.
diff --git a/lib/rubygems/commands/search_command.rb b/lib/rubygems/commands/search_command.rb
index 5bc9650672b..5809690735f 100644
--- a/lib/rubygems/commands/search_command.rb
+++ b/lib/rubygems/commands/search_command.rb
@@ -36,11 +36,5 @@ To list local gems use the list command.
"#{program_name} [STRING]"
end
- def execute
- string = get_one_optional_argument
- options[:name] = /#{string}/i
- super
- end
-
end
diff --git a/lib/rubygems/commands/uninstall_command.rb b/lib/rubygems/commands/uninstall_command.rb
index 8e6af2ba653..e62095a3365 100644
--- a/lib/rubygems/commands/uninstall_command.rb
+++ b/lib/rubygems/commands/uninstall_command.rb
@@ -15,7 +15,7 @@ class Gem::Commands::UninstallCommand < Gem::Command
def initialize
super 'uninstall', 'Uninstall gems from the local repository',
:version => Gem::Requirement.default, :user_install => true,
- :install_dir => Gem.dir, :check_dev => false
+ :check_dev => false
add_option('-a', '--[no-]all',
'Uninstall all matching versions'
@@ -84,7 +84,6 @@ class Gem::Commands::UninstallCommand < Gem::Command
def defaults_str # :nodoc:
"--version '#{Gem::Requirement.default}' --no-force " +
- "--install-dir #{Gem.dir}\n" +
"--user-install"
end
@@ -104,8 +103,7 @@ that is a dependency of an existing gem. You can use the
def execute
if options[:all] and not options[:args].empty? then
- alert_error 'Gem names and --all may not be used together'
- terminate_interaction 1
+ uninstall_specific
elsif options[:all] then
uninstall_all
else
diff --git a/lib/rubygems/commands/update_command.rb b/lib/rubygems/commands/update_command.rb
index 77bf5edb452..e53798db86d 100644
--- a/lib/rubygems/commands/update_command.rb
+++ b/lib/rubygems/commands/update_command.rb
@@ -244,6 +244,9 @@ command to remove old versions.
args << '--no-rdoc' unless options[:document].include? 'rdoc'
args << '--no-ri' unless options[:document].include? 'ri'
args << '--no-format-executable' if options[:no_format_executable]
+ args << '--previous-version' << Gem::VERSION if
+ options[:system] == true or
+ Gem::Version.new(options[:system]) >= Gem::Version.new(2)
args
end
diff --git a/lib/rubygems/commands/which_command.rb b/lib/rubygems/commands/which_command.rb
index 99b9085b2bf..18706afdf5f 100644
--- a/lib/rubygems/commands/which_command.rb
+++ b/lib/rubygems/commands/which_command.rb
@@ -45,9 +45,9 @@ requiring to see why it does not behave as you expect.
if spec then
if options[:search_gems_first] then
- dirs = gem_paths(spec) + $LOAD_PATH
+ dirs = spec.full_require_paths + $LOAD_PATH
else
- dirs = $LOAD_PATH + gem_paths(spec)
+ dirs = $LOAD_PATH + spec.full_require_paths
end
end
@@ -81,10 +81,6 @@ requiring to see why it does not behave as you expect.
result
end
- def gem_paths(spec)
- spec.require_paths.collect { |d| File.join spec.full_gem_path, d }
- end
-
def usage # :nodoc:
"#{program_name} FILE [FILE ...]"
end
diff --git a/lib/rubygems/gemcutter_utilities.rb b/lib/rubygems/gemcutter_utilities.rb
index 9dbc18ba98b..6a4da9e983b 100644
--- a/lib/rubygems/gemcutter_utilities.rb
+++ b/lib/rubygems/gemcutter_utilities.rb
@@ -56,8 +56,10 @@ module Gem::GemcutterUtilities
##
# Creates an RubyGems API to +host+ and +path+ with the given HTTP +method+.
+ #
+ # If +allowed_push_host+ metadata is present, then it will only allow that host.
- def rubygems_api_request(method, path, host = nil, &block)
+ def rubygems_api_request(method, path, host = nil, allowed_push_host = nil, &block)
require 'net/http'
self.host = host if host
@@ -66,6 +68,11 @@ module Gem::GemcutterUtilities
terminate_interaction 1 # TODO: question this
end
+ if allowed_push_host and self.host != allowed_push_host
+ alert_error "#{self.host.inspect} is not allowed by the gemspec, which only allows #{allowed_push_host.inspect}"
+ terminate_interaction 1
+ end
+
uri = URI.parse "#{self.host}/#{path}"
request_method = Net::HTTP.const_get method.to_s.capitalize
diff --git a/lib/rubygems/package.rb b/lib/rubygems/package.rb
index ba379c24cb9..1dbce5d5263 100644
--- a/lib/rubygems/package.rb
+++ b/lib/rubygems/package.rb
@@ -349,11 +349,20 @@ EOM
FileUtils.rm_rf destination
- FileUtils.mkdir_p File.dirname destination
+ mkdir_options = {}
+ mkdir_options[:mode] = entry.header.mode if entry.directory?
+ mkdir =
+ if entry.directory? then
+ destination
+ else
+ File.dirname destination
+ end
+
+ FileUtils.mkdir_p mkdir, mkdir_options
open destination, 'wb', entry.header.mode do |out|
out.write entry.read
- end
+ end if entry.file?
say destination if Gem.configuration.really_verbose
end
diff --git a/lib/rubygems/request.rb b/lib/rubygems/request.rb
index b2e9dbc6798..00407971dd0 100644
--- a/lib/rubygems/request.rb
+++ b/lib/rubygems/request.rb
@@ -21,7 +21,7 @@ class Gem::Request
@proxy_uri =
case proxy
when :no_proxy then nil
- when nil then get_proxy_from_env
+ when nil then get_proxy_from_env uri.scheme
when URI::HTTP then proxy
else URI.parse(proxy)
end
@@ -203,19 +203,27 @@ class Gem::Request
end
##
- # Returns an HTTP proxy URI if one is set in the environment variables.
+ # Returns a proxy URI for the given +scheme+ if one is set in the
+ # environment variables.
- def get_proxy_from_env
- env_proxy = ENV['http_proxy'] || ENV['HTTP_PROXY']
+ def get_proxy_from_env scheme = 'http'
+ _scheme = scheme.downcase
+ _SCHEME = scheme.upcase
+ env_proxy = ENV["#{_scheme}_proxy"] || ENV["#{_SCHEME}_PROXY"]
- return nil if env_proxy.nil? or env_proxy.empty?
+ no_env_proxy = env_proxy.nil? || env_proxy.empty?
+
+ return get_proxy_from_env 'http' if no_env_proxy and _scheme != 'http'
+ return nil if no_env_proxy
uri = URI(Gem::UriFormatter.new(env_proxy).normalize)
if uri and uri.user.nil? and uri.password.nil? then
- # Probably we have http_proxy_* variables?
- uri.user = Gem::UriFormatter.new(ENV['http_proxy_user'] || ENV['HTTP_PROXY_USER']).escape
- uri.password = Gem::UriFormatter.new(ENV['http_proxy_pass'] || ENV['HTTP_PROXY_PASS']).escape
+ user = ENV["#{_scheme}_proxy_user"] || ENV["#{_SCHEME}_PROXY_USER"]
+ password = ENV["#{_scheme}_proxy_pass"] || ENV["#{_SCHEME}_PROXY_PASS"]
+
+ uri.user = Gem::UriFormatter.new(user).escape
+ uri.password = Gem::UriFormatter.new(password).escape
end
uri
diff --git a/lib/rubygems/requirement.rb b/lib/rubygems/requirement.rb
index ed768924a88..4bf1ed914f0 100644
--- a/lib/rubygems/requirement.rb
+++ b/lib/rubygems/requirement.rb
@@ -1,13 +1,3 @@
-##
-# A Requirement is a set of one or more version restrictions. It supports a
-# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.
-
-# REFACTOR: The fact that a requirement is singular or plural is kind of
-# awkward. Is Requirement the right name for this? Or should it be one
-# [op, number] pair, and we call the list of requirements something else?
-# Since a Requirement is held by a Dependency, maybe this should be made
-# singular and the list aspect should be pulled up into Dependency?
-
require "rubygems/version"
require "rubygems/deprecate"
@@ -15,6 +5,10 @@ require "rubygems/deprecate"
# load our yaml + workarounds now.
Gem.load_yaml if defined? ::YAML
+##
+# A Requirement is a set of one or more version restrictions. It supports a
+# few (<tt>=, !=, >, <, >=, <=, ~></tt>) different restriction operators.
+
class Gem::Requirement
OPS = { #:nodoc:
"=" => lambda { |v, r| v == r },
@@ -41,9 +35,6 @@ class Gem::Requirement
# If the input is "weird", the default version requirement is
# returned.
- # REFACTOR: There's no reason that this can't be unified with .new.
- # .new is the standard Ruby factory method.
-
def self.create input
case input
when Gem::Requirement then
@@ -78,11 +69,6 @@ class Gem::Requirement
# parse("1.0") # => ["=", "1.0"]
# parse(Gem::Version.new("1.0")) # => ["=, "1.0"]
- # REFACTOR: Little two element arrays like this have no real semantic
- # value. I'd love to see something like this:
- # Constraint = Struct.new(:operator, :version); (or similar)
- # and have a Requirement be a list of Constraints.
-
def self.parse obj
return ["=", obj] if Gem::Version === obj
diff --git a/lib/rubygems/specification.rb b/lib/rubygems/specification.rb
index 12943a3e24d..6de8c3bc776 100644
--- a/lib/rubygems/specification.rb
+++ b/lib/rubygems/specification.rb
@@ -327,7 +327,7 @@ class Gem::Specification < Gem::BasicSpecification
add_bindir(@executables),
@extra_rdoc_files,
@extensions,
- ].flatten.uniq.compact
+ ].flatten.sort.uniq.compact
end
######################################################################
@@ -1321,9 +1321,7 @@ class Gem::Specification < Gem::BasicSpecification
def add_self_to_load_path
return if default_gem?
- paths = require_paths.map do |path|
- File.join full_gem_path, path
- end
+ paths = full_require_paths
# gem directories must come after -I and ENV['RUBYLIB']
insert_index = Gem.load_path_insert_index
@@ -2017,6 +2015,17 @@ class Gem::Specification < Gem::BasicSpecification
end
##
+ # Full paths in the gem to add to <code>$LOAD_PATH</code> when this gem is
+ # activated.
+ #
+
+ def full_require_paths
+ require_paths.map do |path|
+ File.join full_gem_path, path
+ end
+ end
+
+ ##
# The RubyGems version required by this gem
def required_rubygems_version= req
@@ -2380,6 +2389,11 @@ class Gem::Specification < Gem::BasicSpecification
"[\"#{non_files.join "\", \""}\"] are not files"
end
+ if files.include? file_name then
+ raise Gem::InvalidSpecificationException,
+ "#{full_name} contains itself (#{file_name}), check your files list"
+ end
+
unless specification_version.is_a?(Fixnum)
raise Gem::InvalidSpecificationException,
'specification_version must be a Fixnum (did you mean version?)'