~ubuntu-branches/ubuntu/quantal/ruby1.9.1/quantal

« back to all changes in this revision

Viewing changes to lib/rubygems/commands/dependency_command.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2011-09-24 19:16:17 UTC
  • mfrom: (1.1.8 upstream) (13.1.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20110924191617-o1qz4rcmqjot8zuy
Tags: 1.9.3~rc1-1
* New upstream release: 1.9.3 RC1.
  + Includes load.c fixes. Closes: #639959.
* Upload to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'rubygems/command'
2
2
require 'rubygems/local_remote_options'
3
3
require 'rubygems/version_option'
4
 
require 'rubygems/source_info_cache'
5
4
 
6
5
class Gem::Commands::DependencyCommand < Gem::Command
7
6
 
44
43
  end
45
44
 
46
45
  def execute
 
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
 
49
    end
 
50
 
47
51
    options[:args] << '' if options[:args].empty?
48
 
    specs = {}
49
 
 
50
 
    source_indexes = Hash.new do |h, source_uri|
51
 
      h[source_uri] = Gem::SourceIndex.new
52
 
    end
53
52
 
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])}/
60
59
              end
61
60
 
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]
 
64
    }
63
65
    dependency.prerelease = options[:prerelease]
64
66
 
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
68
 
    end
 
67
    specs = []
69
68
 
70
 
    if local? then
71
 
      Gem.source_index.search(dependency).each do |spec|
72
 
        source_indexes[:local].add_spec spec
73
 
      end
74
 
    end
 
69
    specs.concat dependency.matching_specs if local?
75
70
 
76
71
    if remote? and not options[:reverse_dependencies] then
77
72
      fetcher = Gem::SpecFetcher.fetcher
78
73
 
79
 
      begin
80
 
        specs_and_sources = fetcher.find_matching(dependency, false, true,
81
 
                                                  dependency.prerelease?)
82
 
 
83
 
        specs_and_sources.each do |spec_tuple, source_uri|
84
 
          spec = fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
85
 
 
86
 
          source_indexes[source_uri].add_spec spec
87
 
        end
88
 
      rescue Gem::RemoteFetcher::FetchError => e
89
 
        raise unless fetcher.warn_legacy e do
90
 
          require 'rubygems/source_info_cache'
91
 
 
92
 
          specs = Gem::SourceInfoCache.search_with_source dependency, false
93
 
 
94
 
          specs.each do |spec, source_uri|
95
 
            source_indexes[source_uri].add_spec spec
96
 
          end
97
 
        end
98
 
      end
 
74
      # REFACTOR: fetcher.find_specs_matching => specs
 
75
      specs_and_sources = fetcher.find_matching(dependency,
 
76
                                                dependency.specific?, true,
 
77
                                                dependency.prerelease?)
 
78
 
 
79
      specs.concat specs_and_sources.map { |spec_tuple, source_uri|
 
80
        fetcher.fetch_spec spec_tuple, URI.parse(source_uri)
 
81
      }
99
82
    end
100
83
 
101
 
    if source_indexes.empty? then
 
84
    if specs.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
107
90
    end
108
91
 
109
 
    specs = {}
110
 
 
111
 
    source_indexes.values.each do |source_index|
112
 
      source_index.gems.each do |name, spec|
113
 
        specs[spec.full_name] = [source_index, spec]
114
 
      end
115
 
    end
 
92
    specs = specs.uniq.sort
116
93
 
117
94
    reverse = Hash.new { |h, k| h[k] = [] }
118
95
 
119
96
    if options[:reverse_dependencies] then
120
 
      specs.values.each do |_, spec|
 
97
      specs.each do |spec|
121
98
        reverse[spec.full_name] = find_reverse_dependencies spec
122
99
      end
123
100
    end
124
101
 
125
102
    if options[:pipe_format] then
126
 
      specs.values.sort_by { |_, spec| spec }.each do |_, spec|
 
103
      specs.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}'"
133
110
    else
134
111
      response = ''
135
112
 
136
 
      specs.values.sort_by { |_, spec| spec }.each do |_, spec|
 
113
      specs.each do |spec|
137
114
        response << print_dependencies(spec)
138
115
        unless reverse[spec.full_name].empty? then
139
116
          response << "  Used by\n"
165
142
  def find_reverse_dependencies(spec)
166
143
    result = []
167
144
 
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
171
148
 
179
156
    result
180
157
  end
181
158
 
182
 
  def find_gems(name, source_index)
183
 
    specs = {}
184
 
 
185
 
    spec_list = source_index.search name, options[:version]
186
 
 
187
 
    spec_list.each do |spec|
188
 
      specs[spec.full_name] = [source_index, spec]
189
 
    end
190
 
 
191
 
    specs
192
 
  end
193
 
 
194
159
end
195
160