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

« back to all changes in this revision

Viewing changes to lib/rubygems/spec_fetcher.rb

  • Committer: Bazaar Package Importer
  • Author(s): Lucas Nussbaum
  • Date: 2010-07-31 17:08:39 UTC
  • mfrom: (1.1.4 upstream) (8.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20100731170839-j034dmpdqt1cc4p6
Tags: 1.9.2~svn28788-1
* New release based on upstream snapshot from the 1.9.2 branch,
  after 1.9.2 RC2. That branch is (supposed to be) binary-compatible
  with the 1.9.1 branch.
  + Builds fine on i386. Closes: #580852.
* Upgrade to Standards-Version: 3.9.1. No changes needed.
* Updated generated incs.
* Patches that still need work:
  + Unclear status, need more investigation:
   090729_fix_Makefile_deps.dpatch
   090803_exclude_rdoc.dpatch
   203_adjust_base_of_search_path.dpatch
   902_define_YAML_in_yaml_stringio.rb.dpatch
   919_common.mk_tweaks.dpatch
   931_libruby_suffix.dpatch
   940_test_thread_mutex_sync_shorter.dpatch
  + Maybe not needed anymore, keeping but not applying.
   102_skip_test_copy_stream.dpatch (test doesn't block anymore?)
   104_skip_btest_io.dpatch (test doesn't block anymore?)
   201_gem_prelude.dpatch (we don't use that rubygems anyway?)
   202_gem_default_dir.dpatch (we don't use that rubygems anyway?)
   940_test_file_exhaustive_fails_as_root.dpatch
   940_test_priority_fails.dpatch
   100518_load_libc_libm.dpatch
* Add disable-tests.diff: disable some tests that cause failures on FreeBSD.
  Closes: #590002, #543805, #542927.
* However, many new failures on FreeBSD. Since that version is still an
  improvement, add the check that makes test suite failures non-fatal on
  FreeBSD again. That still needs to be investigated.
* Re-add 903_skip_base_ruby_check.dpatch
* Add build-dependency on ruby1.8 and drop all pre-generated files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
require 'zlib'
 
2
require 'fileutils'
2
3
 
3
 
require 'rubygems'
4
4
require 'rubygems/remote_fetcher'
5
5
require 'rubygems/user_interaction'
 
6
require 'rubygems/errors'
6
7
 
7
8
##
8
9
# SpecFetcher handles metadata updates from remote gem repositories.
22
23
  attr_reader :latest_specs # :nodoc:
23
24
 
24
25
  ##
25
 
  # Cache of all spces
 
26
  # Cache of all released specs
26
27
 
27
28
  attr_reader :specs # :nodoc:
28
29
 
 
30
  ##
 
31
  # Cache of prerelease specs
 
32
 
 
33
  attr_reader :prerelease_specs # :nodoc:
 
34
 
29
35
  @fetcher = nil
30
36
 
31
37
  def self.fetcher
42
48
 
43
49
    @specs = {}
44
50
    @latest_specs = {}
 
51
    @prerelease_specs = {}
45
52
 
46
53
    @fetcher = Gem::RemoteFetcher.fetcher
47
54
  end
48
55
 
49
56
  ##
50
 
  # Retuns the local directory to write +uri+ to.
 
57
  # Returns the local directory to write +uri+ to.
51
58
 
52
59
  def cache_dir(uri)
53
60
    File.join @dir, "#{uri.host}%#{uri.port}", File.dirname(uri.path)
55
62
 
56
63
  ##
57
64
  # Fetch specs matching +dependency+.  If +all+ is true, all matching
58
 
  # versions are returned.  If +matching_platform+ is false, all platforms are
59
 
  # returned.
60
 
 
61
 
  def fetch(dependency, all = false, matching_platform = true)
62
 
    specs_and_sources = find_matching dependency, all, matching_platform
63
 
 
64
 
    specs_and_sources.map do |spec_tuple, source_uri|
 
65
  # (released) versions are returned.  If +matching_platform+ is
 
66
  # false, all platforms are returned. If +prerelease+ is true,
 
67
  # prerelease versions are included.
 
68
 
 
69
  def fetch_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
 
70
    specs_and_sources, errors = find_matching_with_errors dependency, all, matching_platform, prerelease
 
71
 
 
72
    ss = specs_and_sources.map do |spec_tuple, source_uri|
65
73
      [fetch_spec(spec_tuple, URI.parse(source_uri)), source_uri]
66
74
    end
67
75
 
 
76
    return [ss, errors]
 
77
 
68
78
  rescue Gem::RemoteFetcher::FetchError => e
69
79
    raise unless warn_legacy e do
70
80
      require 'rubygems/source_info_cache'
71
81
 
72
 
      return Gem::SourceInfoCache.search_with_source(dependency,
73
 
                                                     matching_platform, all)
 
82
      return [Gem::SourceInfoCache.search_with_source(dependency,
 
83
                                                     matching_platform, all), nil]
74
84
    end
75
85
  end
76
86
 
 
87
  def fetch(*args)
 
88
    fetch_with_errors(*args).first
 
89
  end
 
90
 
77
91
  def fetch_spec(spec, source_uri)
78
92
    spec = spec - [nil, 'ruby', '']
79
93
    spec_file_name = "#{spec.join '-'}.gemspec"
106
120
  end
107
121
 
108
122
  ##
109
 
  # Find spec names that match +dependency+.  If +all+ is true, all matching
110
 
  # versions are returned.  If +matching_platform+ is false, gems for all
111
 
  # platforms are returned.
 
123
  # Find spec names that match +dependency+.  If +all+ is true, all
 
124
  # matching released versions are returned.  If +matching_platform+
 
125
  # is false, gems for all platforms are returned.
112
126
 
113
 
  def find_matching(dependency, all = false, matching_platform = true)
 
127
  def find_matching_with_errors(dependency, all = false, matching_platform = true, prerelease = false)
114
128
    found = {}
115
129
 
116
 
    list(all).each do |source_uri, specs|
 
130
    rejected_specs = {}
 
131
 
 
132
    list(all, prerelease).each do |source_uri, specs|
117
133
      found[source_uri] = specs.select do |spec_name, version, spec_platform|
118
 
        dependency =~ Gem::Dependency.new(spec_name, version) and
119
 
          (not matching_platform or Gem::Platform.match(spec_platform))
 
134
        if dependency.match?(spec_name, version)
 
135
          if matching_platform and !Gem::Platform.match(spec_platform)
 
136
            pm = (rejected_specs[dependency] ||= Gem::PlatformMismatch.new(spec_name, version))
 
137
            pm.add_platform spec_platform
 
138
            false
 
139
          else
 
140
            true
 
141
          end
 
142
        end
120
143
      end
121
144
    end
122
145
 
 
146
    errors = rejected_specs.values
 
147
 
123
148
    specs_and_sources = []
124
149
 
125
150
    found.each do |source_uri, specs|
127
152
      specs_and_sources.push(*specs.map { |spec| [spec, uri_str] })
128
153
    end
129
154
 
130
 
    specs_and_sources
 
155
    [specs_and_sources, errors]
 
156
  end
 
157
 
 
158
  def find_matching(*args)
 
159
    find_matching_with_errors(*args).first
131
160
  end
132
161
 
133
162
  ##
155
184
 
156
185
  ##
157
186
  # Returns a list of gems available for each source in Gem::sources.  If
158
 
  # +all+ is true, all versions are returned instead of only latest versions.
159
 
 
160
 
  def list(all = false)
 
187
  # +all+ is true, all released versions are returned instead of only latest
 
188
  # versions. If +prerelease+ is true, include prerelease versions.
 
189
 
 
190
  def list(all = false, prerelease = false)
 
191
    # TODO: make type the only argument
 
192
    type = if all
 
193
             :all
 
194
           elsif prerelease
 
195
             :prerelease
 
196
           else
 
197
             :latest
 
198
           end
 
199
 
161
200
    list = {}
162
201
 
163
 
    file = all ? 'specs' : 'latest_specs'
 
202
    file = { :latest => 'latest_specs',
 
203
      :prerelease => 'prerelease_specs',
 
204
      :all => 'specs' }[type]
 
205
 
 
206
    cache = { :latest => @latest_specs,
 
207
      :prerelease => @prerelease_specs,
 
208
      :all => @specs }[type]
164
209
 
165
210
    Gem.sources.each do |source_uri|
166
211
      source_uri = URI.parse source_uri
167
212
 
168
 
      if all and @specs.include? source_uri then
169
 
        list[source_uri] = @specs[source_uri]
170
 
      elsif not all and @latest_specs.include? source_uri then
171
 
        list[source_uri] = @latest_specs[source_uri]
172
 
      else
173
 
        specs = load_specs source_uri, file
174
 
 
175
 
        cache = all ? @specs : @latest_specs
176
 
 
177
 
        cache[source_uri] = specs
178
 
        list[source_uri] = specs
 
213
      unless cache.include? source_uri
 
214
        cache[source_uri] = load_specs source_uri, file
 
215
      end
 
216
 
 
217
      list[source_uri] = cache[source_uri]
 
218
    end
 
219
 
 
220
    if type == :all
 
221
      list.values.map do |gems|
 
222
        gems.reject! { |g| !g[1] || g[1].prerelease? }
179
223
      end
180
224
    end
181
225
 
206
250
      loaded = true
207
251
    end
208
252
 
209
 
    specs = Marshal.load spec_dump
 
253
    specs = begin
 
254
              Marshal.load spec_dump
 
255
            rescue ArgumentError
 
256
              spec_dump = @fetcher.fetch_path spec_path
 
257
              loaded = true
 
258
 
 
259
              Marshal.load spec_dump
 
260
            end
210
261
 
211
262
    if loaded and @update_cache then
212
263
      begin
213
264
        FileUtils.mkdir_p cache_dir
214
265
 
215
266
        open local_file, 'wb' do |io|
216
 
          Marshal.dump specs, io
 
267
          io << spec_dump
217
268
        end
218
269
      rescue
219
270
      end