2016-02-01 07:43:26 -05:00
|
|
|
# frozen_string_literal: true
|
2013-07-09 19:21:36 -04:00
|
|
|
##
|
2013-11-25 14:14:49 -05:00
|
|
|
# Specifies a Specification object that should be activated. Also contains a
|
|
|
|
# dependency that was used to introduce this activation.
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-18 19:34:13 -05:00
|
|
|
class Gem::Resolver::ActivationRequest
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The parent request for this activation request.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :request
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The specification to be activated.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
attr_reader :spec
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Creates a new ActivationRequest that will activate +spec+. The parent
|
|
|
|
# +request+ is used to provide diagnostics in case of conflicts.
|
|
|
|
#
|
|
|
|
# +others_possible+ indicates that other specifications may also match this
|
|
|
|
# activation request.
|
|
|
|
|
|
|
|
def initialize spec, request, others_possible = true
|
2013-07-09 19:21:36 -04:00
|
|
|
@spec = spec
|
2013-11-25 14:14:49 -05:00
|
|
|
@request = request
|
2013-07-09 19:21:36 -04:00
|
|
|
@others_possible = others_possible
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
def == other # :nodoc:
|
2013-07-09 19:21:36 -04:00
|
|
|
case other
|
|
|
|
when Gem::Specification
|
|
|
|
@spec == other
|
2013-11-18 19:34:13 -05:00
|
|
|
when Gem::Resolver::ActivationRequest
|
2013-07-09 19:21:36 -04:00
|
|
|
@spec == other.spec && @request == other.request
|
|
|
|
else
|
|
|
|
false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-13 23:30:02 -04:00
|
|
|
##
|
|
|
|
# Is this activation request for a development dependency?
|
|
|
|
|
|
|
|
def development?
|
|
|
|
@request.development?
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# Downloads a gem at +path+ and returns the file path.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def download path
|
2016-02-01 07:43:26 -05:00
|
|
|
Gem.ensure_gem_subdirectories path
|
|
|
|
|
|
|
|
if @spec.respond_to? :sources
|
|
|
|
exception = nil
|
|
|
|
path = @spec.sources.find{ |source|
|
|
|
|
begin
|
|
|
|
source.download full_spec, path
|
|
|
|
rescue exception
|
|
|
|
end
|
|
|
|
}
|
|
|
|
return path if path
|
|
|
|
raise exception if exception
|
|
|
|
|
|
|
|
elsif @spec.respond_to? :source
|
2013-07-09 19:21:36 -04:00
|
|
|
source = @spec.source
|
2016-02-01 07:43:26 -05:00
|
|
|
source.download full_spec, path
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
else
|
|
|
|
source = Gem.sources.first
|
2016-02-01 07:43:26 -05:00
|
|
|
source.download full_spec, path
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The full name of the specification to be activated.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def full_name
|
|
|
|
@spec.full_name
|
|
|
|
end
|
|
|
|
|
2015-07-01 17:50:14 -04:00
|
|
|
alias_method :to_s, :full_name
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The Gem::Specification for this activation request.
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def full_spec
|
|
|
|
Gem::Specification === @spec ? @spec : @spec.spec
|
|
|
|
end
|
|
|
|
|
|
|
|
def inspect # :nodoc:
|
2013-11-10 12:51:40 -05:00
|
|
|
others =
|
|
|
|
case @others_possible
|
|
|
|
when true then # TODO remove at RubyGems 3
|
|
|
|
' (others possible)'
|
|
|
|
when false then # TODO remove at RubyGems 3
|
|
|
|
nil
|
|
|
|
else
|
|
|
|
unless @others_possible.empty? then
|
|
|
|
others = @others_possible.map { |s| s.full_name }
|
|
|
|
" (others possible: #{others.join ', '})"
|
|
|
|
end
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
|
|
|
|
'#<%s for %p from %s%s>' % [
|
2013-11-10 12:51:40 -05:00
|
|
|
self.class, @spec, @request, others
|
2013-07-09 19:21:36 -04:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
2013-11-25 14:14:49 -05:00
|
|
|
# True if the requested gem has already been installed.
|
2013-07-09 19:21:36 -04:00
|
|
|
|
|
|
|
def installed?
|
2013-11-10 12:51:40 -05:00
|
|
|
case @spec
|
2013-11-18 19:34:13 -05:00
|
|
|
when Gem::Resolver::VendorSpecification then
|
2013-11-10 12:51:40 -05:00
|
|
|
true
|
|
|
|
else
|
|
|
|
this_spec = full_spec
|
2013-07-09 19:21:36 -04:00
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
Gem::Specification.any? do |s|
|
|
|
|
s == this_spec
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The name of this activation request's specification
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def name
|
|
|
|
@spec.name
|
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Indicate if this activation is one of a set of possible
|
|
|
|
# requests for the same Dependency request.
|
|
|
|
|
|
|
|
def others_possible?
|
2013-11-10 12:51:40 -05:00
|
|
|
case @others_possible
|
|
|
|
when true, false then
|
|
|
|
@others_possible
|
|
|
|
else
|
|
|
|
not @others_possible.empty?
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
##
|
|
|
|
# Return the ActivationRequest that contained the dependency
|
|
|
|
# that we were activated for.
|
|
|
|
|
|
|
|
def parent
|
|
|
|
@request.requester
|
|
|
|
end
|
|
|
|
|
|
|
|
def pretty_print q # :nodoc:
|
|
|
|
q.group 2, '[Activation request', ']' do
|
|
|
|
q.breakable
|
|
|
|
q.pp @spec
|
|
|
|
|
|
|
|
q.breakable
|
|
|
|
q.text ' for '
|
|
|
|
q.pp @request
|
|
|
|
|
2013-11-10 12:51:40 -05:00
|
|
|
case @others_possible
|
|
|
|
when false then
|
|
|
|
when true then
|
|
|
|
q.breakable
|
|
|
|
q.text 'others possible'
|
|
|
|
else
|
|
|
|
unless @others_possible.empty? then
|
|
|
|
q.breakable
|
|
|
|
q.text 'others '
|
|
|
|
q.pp @others_possible.map { |s| s.full_name }
|
|
|
|
end
|
|
|
|
end
|
2013-07-09 19:21:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-11-25 14:14:49 -05:00
|
|
|
##
|
|
|
|
# The version of this activation request's specification
|
|
|
|
|
2013-07-09 19:21:36 -04:00
|
|
|
def version
|
|
|
|
@spec.version
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|