1
1
require 'rubygems/command'
2
2
require 'rubygems/local_remote_options'
3
3
require 'rubygems/version_option'
4
require 'rubygems/source_info_cache'
6
5
class Gem::Commands::DependencyCommand < Gem::Command
46
if options[:reverse_dependencies] and remote? and not local? then
47
alert_error 'Only reverse dependencies for local gems are supported.'
48
terminate_interaction 1
47
51
options[:args] << '' if options[:args].empty?
50
source_indexes = Hash.new do |h, source_uri|
51
h[source_uri] = Gem::SourceIndex.new
54
53
pattern = if options[:args].length == 1 and
55
54
options[:args].first =~ /\A\/(.*)\/(i)?\z/m then
59
58
/\A#{Regexp.union(*options[:args])}/
62
dependency = Gem::Dependency.new pattern, options[:version]
61
# TODO: deprecate for real damnit
62
dependency = Deprecate.skip_during {
63
Gem::Dependency.new pattern, options[:version]
63
65
dependency.prerelease = options[:prerelease]
65
if options[:reverse_dependencies] and remote? and not local? then
66
alert_error 'Only reverse dependencies for local gems are supported.'
67
terminate_interaction 1
71
Gem.source_index.search(dependency).each do |spec|
72
source_indexes[:local].add_spec spec
69
specs.concat dependency.matching_specs if local?
76
71
if remote? and not options[:reverse_dependencies] then
77
72
fetcher = Gem::SpecFetcher.fetcher
80
specs_and_sources = fetcher.find_matching(dependency, false, true,
81
dependency.prerelease?)
83
specs_and_sources.each do |spec_tuple, source_uri|
84
spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
86
source_indexes[source_uri].add_spec spec
88
rescue Gem::RemoteFetcher::FetchError => e
89
raise unless fetcher.warn_legacy e do
90
require 'rubygems/source_info_cache'
92
specs = Gem::SourceInfoCache.search_with_source dependency, false
94
specs.each do |spec, source_uri|
95
source_indexes[source_uri].add_spec spec
74
# REFACTOR: fetcher.find_specs_matching => specs
75
specs_and_sources = fetcher.find_matching(dependency,
76
dependency.specific?, true,
77
dependency.prerelease?)
79
specs.concat specs_and_sources.map { |spec_tuple, source_uri|
80
fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
101
if source_indexes.empty? then
102
85
patterns = options[:args].join ','
103
86
say "No gems found matching #{patterns} (#{options[:version]})" if
104
87
Gem.configuration.verbose
106
89
terminate_interaction 1
111
source_indexes.values.each do |source_index|
112
source_index.gems.each do |name, spec|
113
specs[spec.full_name] = [source_index, spec]
92
specs = specs.uniq.sort
117
94
reverse = Hash.new { |h, k| h[k] = [] }
119
96
if options[:reverse_dependencies] then
120
specs.values.each do |_, spec|
121
98
reverse[spec.full_name] = find_reverse_dependencies spec
125
102
if options[:pipe_format] then
126
specs.values.sort_by { |_, spec| spec }.each do |_, spec|
127
104
unless spec.dependencies.empty?
128
105
spec.dependencies.sort_by { |dep| dep.name }.each do |dep|
129
106
say "#{dep.name} --version '#{dep.requirement}'"
165
142
def find_reverse_dependencies(spec)
168
Gem.source_index.each do |name, sp|
145
Gem::Specification.each do |sp|
169
146
sp.dependencies.each do |dep|
170
147
dep = Gem::Dependency.new(*dep) unless Gem::Dependency === dep