Class: Chef::Provider::Package::Rubygems::AlternateGemEnvironment
Constant Summary
collapse
- JRUBY_PLATFORM =
/(:?universal|x86_64|x86)\-java\-[0-9\.]+/.freeze
GemEnvironment::DEFAULT_UNINSTALLER_OPTS
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#candidate_version_from_file, #dependency_installer, #find_newest_remote_version, #install, #installed_versions, #spec_from_file, #uninstall, #uninstaller, #with_correct_verbosity, #with_gem_sources
Constructor Details
304
305
306
|
# File 'lib/chef/provider/package/rubygems.rb', line 304
def initialize(gem_binary_location)
@gem_binary_location = gem_binary_location
end
|
Instance Attribute Details
#gem_binary_location ⇒ Object
Returns the value of attribute gem_binary_location.
302
303
304
|
# File 'lib/chef/provider/package/rubygems.rb', line 302
def gem_binary_location
@gem_binary_location
end
|
Class Method Details
.gempath_cache ⇒ Object
292
293
294
|
# File 'lib/chef/provider/package/rubygems.rb', line 292
def self.gempath_cache
@gempath_cache ||= {}
end
|
296
297
298
|
# File 'lib/chef/provider/package/rubygems.rb', line 296
def self.platform_cache
@platform_cache ||= {}
end
|
Instance Method Details
#candidate_version_from_remote(gem_dependency, *sources) ⇒ Object
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
|
# File 'lib/chef/provider/package/rubygems.rb', line 373
def candidate_version_from_remote(gem_dependency, *sources)
source_args = sources.compact.map { |s| "--source=#{s}" }.join(" ")
cmd = "#{@gem_binary_location} list #{gem_dependency.name} --remote --all #{source_args}"
result = shell_out!(cmd)
versions = []
result.stdout.each_line do |line|
next unless line.start_with?("#{gem_dependency.name} (")
version_string = line[/\((.*)\)/, 1]
next unless version_string
version_string.split(/,\s*/).each do |v|
version = Gem::Version.new(v.strip)
versions << version if gem_dependency.requirement.satisfied_by?(version)
rescue ArgumentError
end
end
versions.max
rescue Mixlib::ShellOut::ShellCommandFailed
with_gem_sources(*sources) do
with_gem_platforms(*gem_platforms) do
find_newest_remote_version(gem_dependency, *sources)
end
end
end
|
#gem_paths ⇒ Object
312
313
314
315
316
317
318
319
320
321
322
|
# File 'lib/chef/provider/package/rubygems.rb', line 312
def gem_paths
if self.class.gempath_cache.key?(@gem_binary_location)
self.class.gempath_cache[@gem_binary_location]
else
shell_style_paths = shell_out!("#{@gem_binary_location} env gempath").stdout
paths = shell_style_paths.split(::File::PATH_SEPARATOR).map(&:strip)
self.class.gempath_cache[@gem_binary_location] = paths
end
end
|
Attempt to detect the correct platform settings for the target gem environment.
In practice, this only makes a difference if different versions are available depending on platform, and only if the target gem environment has a radically different platform (i.e., jruby), so we just try to detect jruby and fall back to the current platforms (Gem.platforms) if we don’t detect it.
Returns
- String|Gem::Platform
-
returns an array of Gem::Platform-compatible
objects, i.e., Strings that are valid for Gem::Platform or actual Gem::Platform objects.
351
352
353
354
355
356
357
358
359
360
361
362
|
# File 'lib/chef/provider/package/rubygems.rb', line 351
def gem_platforms
if self.class.platform_cache.key?(@gem_binary_location)
self.class.platform_cache[@gem_binary_location]
else
gem_environment = shell_out!("#{@gem_binary_location} env").stdout
self.class.platform_cache[@gem_binary_location] = if jruby = gem_environment[JRUBY_PLATFORM]
["ruby", Gem::Platform.new(jruby)]
else
Gem.platforms
end
end
end
|
#gem_source_index ⇒ Object
324
325
326
|
# File 'lib/chef/provider/package/rubygems.rb', line 324
def gem_source_index
@source_index ||= Gem::SourceIndex.from_gems_in(*gem_paths.map { |p| p + "/specifications" })
end
|
#gem_specification ⇒ Object
328
329
330
331
332
333
334
335
|
# File 'lib/chef/provider/package/rubygems.rb', line 328
def gem_specification
unless @specification
Gem::Specification.dirs = gem_paths
@specification = Gem::Specification
end
@specification
end
|
#rubygems_version ⇒ Object
308
309
310
|
# File 'lib/chef/provider/package/rubygems.rb', line 308
def rubygems_version
@rubygems_version ||= shell_out!("#{@gem_binary_location} --version").stdout.chomp
end
|
364
365
366
367
368
369
370
371
|
# File 'lib/chef/provider/package/rubygems.rb', line 364
def with_gem_platforms(*alt_gem_platforms)
alt_gem_platforms.flatten!
original_gem_platforms = Gem.platforms
Gem.platforms = alt_gem_platforms
yield
ensure
Gem.platforms = original_gem_platforms
end
|