rubygems-backports 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ RubyGems is copyrighted free software by Chad Fowler, Rich Kilmer, Jim
2
+ Weirich and others. You can redistribute it and/or modify it under
3
+ either the terms of the MIT license (see the file MIT.txt), or the
4
+ conditions below:
5
+
6
+ 1. You may make and give away verbatim copies of the source form of the
7
+ software without restriction, provided that you duplicate all of the
8
+ original copyright notices and associated disclaimers.
9
+
10
+ 2. You may modify your copy of the software in any way, provided that
11
+ you do at least ONE of the following:
12
+
13
+ a. place your modifications in the Public Domain or otherwise
14
+ make them Freely Available, such as by posting said
15
+ modifications to Usenet or an equivalent medium, or by allowing
16
+ the author to include your modifications in the software.
17
+
18
+ b. use the modified software only within your corporation or
19
+ organization.
20
+
21
+ c. give non-standard executables non-standard names, with
22
+ instructions on where to get the original software distribution.
23
+
24
+ d. make other distribution arrangements with the author.
25
+
26
+ 3. You may distribute the software in object code or executable
27
+ form, provided that you do at least ONE of the following:
28
+
29
+ a. distribute the executables and library files of the software,
30
+ together with instructions (in the manual page or equivalent)
31
+ on where to get the original distribution.
32
+
33
+ b. accompany the distribution with the machine-readable source of
34
+ the software.
35
+
36
+ c. give non-standard executables non-standard names, with
37
+ instructions on where to get the original software distribution.
38
+
39
+ d. make other distribution arrangements with the author.
40
+
41
+ 4. You may modify and include the part of the software into any other
42
+ software (possibly commercial). But some files in the distribution
43
+ are not written by the author, so that they are not under these terms.
44
+
45
+ For the list of those files and their copying conditions, see the
46
+ file LEGAL.
47
+
48
+ 5. The scripts and library files supplied as input to or produced as
49
+ output from the software do not automatically fall under the
50
+ copyright of the software, but belong to whomever generated them,
51
+ and may be sold commercially, and may be aggregated with this
52
+ software.
53
+
54
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
55
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
56
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
57
+ PURPOSE.
data/MIT.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Chad Fowler, Rich Kilmer, Jim Weirich and others.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ 'Software'), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,39 @@
1
+ # rubygems-backports
2
+
3
+ This gem backports (and forward ports) the old RubyGems 1.x-1.6.x API, reviving
4
+ the {Gem::SourceIndex} to its old pre-1.7.x state. It allows developers to
5
+ write library code that depends on any version of RubyGems and not have to
6
+ force users to upgrade to RubyGems 1.7.x+.
7
+
8
+ ## Usage
9
+
10
+ With this gem, you can continue using `Gem::SourceIndex` as you used to; currently
11
+ we simply use the old SourceIndex class verbatim, but in the near future we will
12
+ forward these methods to the new 1.7.x+ API, for instance:
13
+
14
+ gem.source_index.find_name('foo') # equivalent: Specification.find_by_name('foo')
15
+
16
+ If you want to use the new API
17
+
18
+ To use the gem, simply `require 'rubygems-backports'`. Alternatively, you can
19
+ call `Gem.load_plugins`. The gem will load the correct code (the old API, or
20
+ the new API) depending on what's missing.
21
+
22
+ ## Known Issues
23
+
24
+ This gem currently only supprts the SourceIndex class and Specification.find_by_name.
25
+ The other deprecated (and new) API calls will be added in the near future. Help
26
+ out by forking the project and submitting new backports.
27
+
28
+ ## Contributing
29
+
30
+ You can contribute and add new backports by forking the project on
31
+ [Github](http://github.com/lsegal/rubygems-backports) and submitting a
32
+ pull request. Pull requests are always appreciated!
33
+
34
+ ## License
35
+
36
+ This gem is mostly comprised of RubyGems code, and therefore uses the
37
+ RubyGems license, see {file:LICENSE.txt}. All RubyGems code is marked with
38
+ the copyright notice at the top of the file. All other files are under
39
+ the MIT license.
@@ -0,0 +1,17 @@
1
+ require 'rbconfig'
2
+
3
+ WINDOWS = (Config::CONFIG['host_os'] =~ /mingw|win32|cygwin/ ? true : false) rescue false
4
+ SUDO = WINDOWS ? '' : 'sudo'
5
+
6
+ task :default => :specs
7
+
8
+ desc "Builds the gem"
9
+ task :gem do
10
+ SPEC = eval(File.read('rubygems-backports.gemspec'))
11
+ Gem::Builder.new(SPEC).build
12
+ end
13
+
14
+ desc "Installs the gem"
15
+ task :install => :gem do
16
+ sh "#{SUDO} gem install #{SPEC.full_name} --no-rdoc --no-ri"
17
+ end
@@ -0,0 +1,10 @@
1
+ root = File.join(File.dirname(__FILE__), 'rubygems-backports')
2
+ if defined?(Gem::VERSION) && Gem::VERSION >= "1.8.0"
3
+ root = File.join(root, 'old_api')
4
+ else
5
+ root = File.join(root, 'new_api')
6
+ end
7
+
8
+ Dir.glob(File.join(root, '*.rb')).each do |file|
9
+ require file
10
+ end
@@ -0,0 +1,6 @@
1
+ # @todo Fill in other new APIs!
2
+ class Gem::Specification
3
+ def self.find_by_name(*args)
4
+ Gem.source_index.find_name(*args)
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ module Gem
8
+ ##
9
+ # Returns the Gem::SourceIndex of specifications that are in the Gem.path
10
+
11
+ def self.source_index
12
+ @@source_index ||= SourceIndex.from_installed_gems
13
+ end
14
+ end
@@ -0,0 +1,353 @@
1
+ #--
2
+ # Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
3
+ # All rights reserved.
4
+ # See LICENSE.txt for permissions.
5
+ #++
6
+
7
+ require 'rubygems/specification'
8
+
9
+ ##
10
+ # The SourceIndex object indexes all the gems available from a
11
+ # particular source (e.g. a list of gem directories, or a remote
12
+ # source). A SourceIndex maps a gem full name to a gem
13
+ # specification.
14
+ #
15
+ # NOTE:: The class used to be named Cache, but that became
16
+ # confusing when cached source fetchers where introduced. The
17
+ # constant Gem::Cache is an alias for this class to allow old
18
+ # YAMLized source index objects to load properly.
19
+
20
+ class Gem::SourceIndex
21
+
22
+ include Enumerable
23
+
24
+ attr_reader :gems # :nodoc:
25
+
26
+ ##
27
+ # Directories to use to refresh this SourceIndex when calling refresh!
28
+
29
+ attr_accessor :spec_dirs
30
+
31
+ class << self
32
+ ##
33
+ # Factory method to construct a source index instance for a given
34
+ # path.
35
+ #
36
+ # deprecated::
37
+ # If supplied, from_installed_gems will act just like
38
+ # +from_gems_in+. This argument is deprecated and is provided
39
+ # just for backwards compatibility, and should not generally
40
+ # be used.
41
+ #
42
+ # return::
43
+ # SourceIndex instance
44
+
45
+ def from_installed_gems(*deprecated)
46
+ if deprecated.empty?
47
+ from_gems_in(*installed_spec_directories)
48
+ else
49
+ from_gems_in(*deprecated) # HACK warn
50
+ end
51
+ end
52
+
53
+ ##
54
+ # Returns a list of directories from Gem.path that contain specifications.
55
+
56
+ def installed_spec_directories
57
+ Gem.path.collect { |dir| File.join(dir, "specifications") }
58
+ end
59
+
60
+ ##
61
+ # Creates a new SourceIndex from the ruby format gem specifications in
62
+ # +spec_dirs+.
63
+
64
+ def from_gems_in(*spec_dirs)
65
+ source_index = new
66
+ source_index.spec_dirs = spec_dirs
67
+ source_index.refresh!
68
+ end
69
+
70
+ ##
71
+ # Loads a ruby-format specification from +file_name+ and returns the
72
+ # loaded spec.
73
+
74
+ def load_specification(file_name)
75
+ Gem::Specification.load file_name
76
+ end
77
+
78
+ end
79
+
80
+ ##
81
+ # Constructs a source index instance from the provided specifications, which
82
+ # is a Hash of gem full names and Gem::Specifications.
83
+ #--
84
+ # TODO merge @gems and @prerelease_gems and provide a separate method
85
+ # #prerelease_gems
86
+
87
+ def initialize(specifications={})
88
+ @gems = {}
89
+ specifications.each{ |full_name, spec| add_spec spec }
90
+ @spec_dirs = nil
91
+ end
92
+
93
+ # TODO: remove method
94
+ def all_gems
95
+ @gems
96
+ end
97
+
98
+ def prerelease_gems
99
+ @gems.reject{ |name, gem| !gem.version.prerelease? }
100
+ end
101
+
102
+ def released_gems
103
+ @gems.reject{ |name, gem| gem.version.prerelease? }
104
+ end
105
+
106
+ ##
107
+ # Reconstruct the source index from the specifications in +spec_dirs+.
108
+
109
+ def load_gems_in(*spec_dirs)
110
+ @gems.clear
111
+
112
+ spec_dirs.reverse_each do |spec_dir|
113
+ spec_files = Dir.glob File.join(spec_dir, '*.gemspec')
114
+
115
+ spec_files.each do |spec_file|
116
+ gemspec = Gem::Specification.load spec_file
117
+ add_spec gemspec if gemspec
118
+ end
119
+ end
120
+
121
+ self
122
+ end
123
+
124
+ ##
125
+ # Returns an Array specifications for the latest released versions
126
+ # of each gem in this index.
127
+
128
+ def latest_specs(include_prerelease=false)
129
+ result = Hash.new { |h,k| h[k] = [] }
130
+ latest = {}
131
+
132
+ sort.each do |_, spec|
133
+ name = spec.name
134
+ curr_ver = spec.version
135
+ prev_ver = latest.key?(name) ? latest[name].version : nil
136
+
137
+ next if !include_prerelease && curr_ver.prerelease?
138
+ next unless prev_ver.nil? or curr_ver >= prev_ver or
139
+ latest[name].platform != Gem::Platform::RUBY
140
+
141
+ if prev_ver.nil? or
142
+ (curr_ver > prev_ver and spec.platform == Gem::Platform::RUBY) then
143
+ result[name].clear
144
+ latest[name] = spec
145
+ end
146
+
147
+ if spec.platform != Gem::Platform::RUBY then
148
+ result[name].delete_if do |result_spec|
149
+ result_spec.platform == spec.platform
150
+ end
151
+ end
152
+
153
+ result[name] << spec
154
+ end
155
+
156
+ # TODO: why is this a hash while @gems is an array? Seems like
157
+ # structural similarity would be good.
158
+ result.values.flatten
159
+ end
160
+
161
+ ##
162
+ # An array including only the prerelease gemspecs
163
+
164
+ def prerelease_specs
165
+ prerelease_gems.values
166
+ end
167
+
168
+ ##
169
+ # An array including only the released gemspecs
170
+
171
+ def released_specs
172
+ released_gems.values
173
+ end
174
+
175
+ ##
176
+ # Add a gem specification to the source index.
177
+
178
+ def add_spec(gem_spec, name = gem_spec.full_name)
179
+ # No idea why, but the Indexer wants to insert them using original_name
180
+ # instead of full_name. So we make it an optional arg.
181
+ @gems[name] = gem_spec
182
+ end
183
+
184
+ ##
185
+ # Add gem specifications to the source index.
186
+
187
+ def add_specs(*gem_specs)
188
+ gem_specs.each do |spec|
189
+ add_spec spec
190
+ end
191
+ end
192
+
193
+ ##
194
+ # Remove a gem specification named +full_name+.
195
+
196
+ def remove_spec(full_name)
197
+ @gems.delete full_name
198
+ end
199
+
200
+ ##
201
+ # Iterate over the specifications in the source index.
202
+
203
+ def each(&block) # :yields: gem.full_name, gem
204
+ @gems.each(&block)
205
+ end
206
+
207
+ ##
208
+ # The gem specification given a full gem spec name.
209
+
210
+ def specification(full_name)
211
+ @gems[full_name]
212
+ end
213
+
214
+ ##
215
+ # The signature for the source index. Changes in the signature indicate a
216
+ # change in the index.
217
+
218
+ def index_signature
219
+ require 'digest'
220
+
221
+ Digest::SHA256.new.hexdigest(@gems.keys.sort.join(',')).to_s
222
+ end
223
+
224
+ ##
225
+ # The signature for the given gem specification.
226
+
227
+ def gem_signature(gem_full_name)
228
+ require 'digest'
229
+
230
+ Digest::SHA256.new.hexdigest(@gems[gem_full_name].to_yaml).to_s
231
+ end
232
+
233
+ def size
234
+ @gems.size
235
+ end
236
+ alias length size
237
+
238
+ ##
239
+ # Find a gem by an exact match on the short name.
240
+
241
+ def find_name(gem_name, requirement = Gem::Requirement.default)
242
+ dep = Gem::Dependency.new gem_name, requirement
243
+ search dep
244
+ end
245
+
246
+ ##
247
+ # Search for a gem by Gem::Dependency +gem_pattern+. If +only_platform+
248
+ # is true, only gems matching Gem::Platform.local will be returned. An
249
+ # Array of matching Gem::Specification objects is returned.
250
+ #
251
+ # For backwards compatibility, a String or Regexp pattern may be passed as
252
+ # +gem_pattern+, and a Gem::Requirement for +platform_only+. This
253
+ # behavior is deprecated and will be removed.
254
+
255
+ def search(gem_pattern, platform_only = false)
256
+ requirement = nil
257
+ only_platform = false
258
+
259
+ # TODO - Remove support and warning for legacy arguments after 2008/11
260
+ unless Gem::Dependency === gem_pattern
261
+ warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated, use #find_name"
262
+ end
263
+
264
+ case gem_pattern
265
+ when Regexp then
266
+ requirement = platform_only || Gem::Requirement.default
267
+ when Gem::Dependency then
268
+ only_platform = platform_only
269
+ requirement = gem_pattern.requirement
270
+
271
+ gem_pattern = if Regexp === gem_pattern.name then
272
+ gem_pattern.name
273
+ elsif gem_pattern.name.empty? then
274
+ //
275
+ else
276
+ /^#{Regexp.escape gem_pattern.name}$/
277
+ end
278
+ else
279
+ requirement = platform_only || Gem::Requirement.default
280
+ gem_pattern = /#{gem_pattern}/i
281
+ end
282
+
283
+ unless Gem::Requirement === requirement then
284
+ requirement = Gem::Requirement.create requirement
285
+ end
286
+
287
+ specs = all_gems.values.select do |spec|
288
+ spec.name =~ gem_pattern and
289
+ requirement.satisfied_by? spec.version
290
+ end
291
+
292
+ if only_platform then
293
+ specs = specs.select do |spec|
294
+ Gem::Platform.match spec.platform
295
+ end
296
+ end
297
+
298
+ specs.sort_by { |s| s.sort_obj }
299
+ end
300
+
301
+ ##
302
+ # Replaces the gems in the source index from specifications in the
303
+ # directories this source index was created from. Raises an exception if
304
+ # this source index wasn't created from a directory (via from_gems_in or
305
+ # from_installed_gems, or having spec_dirs set).
306
+
307
+ def refresh!
308
+ raise 'source index not created from disk' if @spec_dirs.nil?
309
+ load_gems_in(*@spec_dirs)
310
+ end
311
+
312
+ ##
313
+ # Returns an Array of Gem::Specifications that are not up to date.
314
+
315
+ def outdated
316
+ outdateds = []
317
+
318
+ latest_specs.each do |local|
319
+ dependency = Gem::Dependency.new local.name, ">= #{local.version}"
320
+
321
+ fetcher = Gem::SpecFetcher.fetcher
322
+ remotes = fetcher.find_matching dependency
323
+ remotes = remotes.map { |(_, version, _), _| version }
324
+
325
+ latest = remotes.sort.last
326
+
327
+ outdateds << local.name if latest and local.version < latest
328
+ end
329
+
330
+ outdateds
331
+ end
332
+
333
+ def ==(other) # :nodoc:
334
+ self.class === other and @gems == other.gems
335
+ end
336
+
337
+ def dump
338
+ Marshal.dump(self)
339
+ end
340
+
341
+ end
342
+
343
+ # :stopdoc:
344
+ module Gem
345
+
346
+ ##
347
+ # Cache is an alias for SourceIndex to allow older YAMLized source index
348
+ # objects to load properly.
349
+
350
+ Cache = SourceIndex unless defined?(Cache)
351
+
352
+ end
353
+ # :startdoc:
metadata ADDED
@@ -0,0 +1,62 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems-backports
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 1.0.0
6
+ platform: ruby
7
+ authors:
8
+ - Loren Segal
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-05-08 00:00:00 Z
14
+ dependencies: []
15
+
16
+ description: " This gem backports and \"undeprecates\" Gem::SourceIndex and other RubyGems \n 1.6.x classes and libraries in order to allow library developers to use\n the old APIs with 1.8.x+. Support for using the new APIs with older versions\n is coming soon.\n"
17
+ email: lsegal@soen.ca
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/rubygems-backports/new_api/specification.rb
26
+ - lib/rubygems-backports/old_api/gem.rb
27
+ - lib/rubygems-backports/old_api/source_index.rb
28
+ - lib/rubygems-backports.rb
29
+ - LICENSE.txt
30
+ - MIT.txt
31
+ - README.md
32
+ - Rakefile
33
+ homepage: http://github.com/lsegal/rubygems-backports
34
+ licenses: []
35
+
36
+ post_install_message:
37
+ rdoc_options: []
38
+
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: "0"
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ requirements: []
54
+
55
+ rubyforge_project:
56
+ rubygems_version: 1.7.2
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Backports RubyGems 1.6.x SourceIndex and other classes
60
+ test_files: []
61
+
62
+ has_rdoc: