bundler 1.11.2 → 1.12.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (129) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +24 -0
  3. data/.gitignore +2 -2
  4. data/.rubocop.yml +17 -2
  5. data/.rubocop_todo.yml +145 -18
  6. data/.travis.yml +9 -2
  7. data/CHANGELOG.md +42 -0
  8. data/Rakefile +20 -13
  9. data/bin/rake +5 -0
  10. data/bin/rspec +5 -0
  11. data/bin/rubocop +7 -1
  12. data/bundler.gemspec +2 -1
  13. data/exe/bundle +10 -2
  14. data/exe/bundle_ruby +2 -1
  15. data/exe/bundler +3 -1
  16. data/lib/bundler.rb +54 -51
  17. data/lib/bundler/capistrano.rb +1 -0
  18. data/lib/bundler/cli.rb +26 -4
  19. data/lib/bundler/cli/binstubs.rb +1 -0
  20. data/lib/bundler/cli/cache.rb +1 -0
  21. data/lib/bundler/cli/check.rb +4 -1
  22. data/lib/bundler/cli/clean.rb +1 -0
  23. data/lib/bundler/cli/common.rb +1 -0
  24. data/lib/bundler/cli/config.rb +5 -5
  25. data/lib/bundler/cli/console.rb +1 -0
  26. data/lib/bundler/cli/exec.rb +4 -9
  27. data/lib/bundler/cli/gem.rb +12 -9
  28. data/lib/bundler/cli/init.rb +1 -0
  29. data/lib/bundler/cli/inject.rb +1 -0
  30. data/lib/bundler/cli/install.rb +8 -5
  31. data/lib/bundler/cli/lock.rb +2 -0
  32. data/lib/bundler/cli/open.rb +1 -0
  33. data/lib/bundler/cli/outdated.rb +36 -9
  34. data/lib/bundler/cli/package.rb +1 -0
  35. data/lib/bundler/cli/platform.rb +4 -1
  36. data/lib/bundler/cli/show.rb +1 -0
  37. data/lib/bundler/cli/update.rb +6 -6
  38. data/lib/bundler/cli/viz.rb +4 -6
  39. data/lib/bundler/constants.rb +1 -0
  40. data/lib/bundler/current_ruby.rb +34 -168
  41. data/lib/bundler/definition.rb +41 -15
  42. data/lib/bundler/dep_proxy.rb +1 -0
  43. data/lib/bundler/dependency.rb +10 -0
  44. data/lib/bundler/deployment.rb +1 -0
  45. data/lib/bundler/deprecate.rb +1 -0
  46. data/lib/bundler/dsl.rb +19 -9
  47. data/lib/bundler/endpoint_specification.rb +37 -8
  48. data/lib/bundler/env.rb +4 -3
  49. data/lib/bundler/environment.rb +1 -0
  50. data/lib/bundler/errors.rb +51 -32
  51. data/lib/bundler/fetcher.rb +44 -30
  52. data/lib/bundler/fetcher/base.rb +3 -2
  53. data/lib/bundler/fetcher/compact_index.rb +98 -0
  54. data/lib/bundler/fetcher/dependency.rb +36 -36
  55. data/lib/bundler/fetcher/downloader.rb +14 -8
  56. data/lib/bundler/fetcher/index.rb +28 -5
  57. data/lib/bundler/friendly_errors.rb +93 -85
  58. data/lib/bundler/gem_helper.rb +20 -21
  59. data/lib/bundler/gem_helpers.rb +9 -2
  60. data/lib/bundler/gem_remote_fetcher.rb +1 -0
  61. data/lib/bundler/gem_tasks.rb +1 -0
  62. data/lib/bundler/graph.rb +16 -17
  63. data/lib/bundler/index.rb +4 -6
  64. data/lib/bundler/injector.rb +1 -0
  65. data/lib/bundler/inline.rb +8 -2
  66. data/lib/bundler/installer.rb +4 -4
  67. data/lib/bundler/installer/gem_installer.rb +1 -0
  68. data/lib/bundler/installer/parallel_installer.rb +3 -2
  69. data/lib/bundler/installer/standalone.rb +5 -1
  70. data/lib/bundler/lazy_specification.rb +5 -2
  71. data/lib/bundler/lockfile_parser.rb +22 -15
  72. data/lib/bundler/match_platform.rb +1 -0
  73. data/lib/bundler/mirror.rb +218 -0
  74. data/lib/bundler/path_preserver.rb +12 -0
  75. data/lib/bundler/psyched_yaml.rb +1 -0
  76. data/lib/bundler/remote_specification.rb +4 -1
  77. data/lib/bundler/resolver.rb +17 -16
  78. data/lib/bundler/retry.rb +1 -0
  79. data/lib/bundler/ruby_dsl.rb +8 -2
  80. data/lib/bundler/ruby_version.rb +58 -61
  81. data/lib/bundler/rubygems_ext.rb +4 -3
  82. data/lib/bundler/rubygems_gem_installer.rb +1 -0
  83. data/lib/bundler/rubygems_integration.rb +9 -14
  84. data/lib/bundler/runtime.rb +17 -22
  85. data/lib/bundler/settings.rb +17 -21
  86. data/lib/bundler/setup.rb +1 -0
  87. data/lib/bundler/shared_helpers.rb +47 -17
  88. data/lib/bundler/similarity_detector.rb +1 -0
  89. data/lib/bundler/source.rb +2 -1
  90. data/lib/bundler/source/git.rb +2 -1
  91. data/lib/bundler/source/git/git_proxy.rb +33 -7
  92. data/lib/bundler/source/path.rb +17 -10
  93. data/lib/bundler/source/path/installer.rb +1 -0
  94. data/lib/bundler/source/rubygems.rb +4 -3
  95. data/lib/bundler/source/rubygems/remote.rb +16 -0
  96. data/lib/bundler/source_list.rb +1 -0
  97. data/lib/bundler/spec_set.rb +1 -0
  98. data/lib/bundler/ssl_certs/certificate_manager.rb +1 -0
  99. data/lib/bundler/stub_specification.rb +1 -0
  100. data/lib/bundler/templates/Executable +1 -0
  101. data/lib/bundler/templates/Gemfile +1 -0
  102. data/lib/bundler/templates/newgem/.travis.yml.tt +1 -0
  103. data/lib/bundler/templates/newgem/newgem.gemspec.tt +2 -2
  104. data/lib/bundler/ui.rb +1 -0
  105. data/lib/bundler/ui/rg_proxy.rb +1 -0
  106. data/lib/bundler/ui/shell.rb +2 -1
  107. data/lib/bundler/ui/silent.rb +1 -0
  108. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client.rb +78 -0
  109. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/cache.rb +97 -0
  110. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/updater.rb +55 -0
  111. data/lib/bundler/vendor/compact_index_client/lib/compact_index_client/version.rb +3 -0
  112. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +4 -0
  113. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +13 -0
  114. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +5 -0
  115. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +2 -1
  116. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +2 -1
  117. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +37 -14
  118. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +2 -1
  119. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +7 -7
  120. data/lib/bundler/vendored_molinillo.rb +1 -0
  121. data/lib/bundler/vendored_persistent.rb +1 -0
  122. data/lib/bundler/vendored_thor.rb +1 -0
  123. data/lib/bundler/version.rb +6 -1
  124. data/lib/bundler/vlad.rb +1 -0
  125. data/lib/bundler/worker.rb +12 -2
  126. data/man/bundle-config.ronn +6 -0
  127. data/man/bundle-gem.ronn +5 -5
  128. metadata +14 -6
  129. data/lib/bundler/gem_path_manipulation.rb +0 -8
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Bundler
2
3
  class Resolver
3
4
  require "bundler/vendored_molinillo"
@@ -12,7 +13,7 @@ module Bundler
12
13
  end
13
14
 
14
15
  def message
15
- conflicts.sort.reduce("") do |o, (name, conflict)|
16
+ conflicts.sort.reduce(String.new) do |o, (name, conflict)|
16
17
  o << %(Bundler could not find compatible versions for gem "#{name}":\n)
17
18
  if conflict.locked_requirement
18
19
  o << %( In snapshot (#{Bundler.default_lockfile.basename}):\n)
@@ -21,7 +22,7 @@ module Bundler
21
22
  end
22
23
  o << %( In Gemfile:\n)
23
24
  o << conflict.requirement_trees.sort_by {|t| t.reverse.map(&:name) }.map do |tree|
24
- t = ""
25
+ t = String.new
25
26
  depth = 2
26
27
  tree.each do |req|
27
28
  t << " " * depth << req.to_s
@@ -130,7 +131,7 @@ module Bundler
130
131
  def for?(platform, required_ruby_version)
131
132
  if spec = @specs[platform]
132
133
  if required_ruby_version && spec.respond_to?(:required_ruby_version) && spec_required_ruby_version = spec.required_ruby_version
133
- spec_required_ruby_version.satisfied_by?(required_ruby_version)
134
+ spec_required_ruby_version.satisfied_by?(required_ruby_version.gem_version)
134
135
  else
135
136
  true
136
137
  end
@@ -192,7 +193,7 @@ module Bundler
192
193
  @search_for = {}
193
194
  @base_dg = Molinillo::DependencyGraph.new
194
195
  @base.each {|ls| @base_dg.add_vertex(ls.name, Dependency.new(ls.name, ls.version), true) }
195
- @ruby_version = ruby_version ? Gem::Version.create(ruby_version) : nil
196
+ @ruby_version = ruby_version
196
197
  end
197
198
 
198
199
  def start(requirements)
@@ -216,15 +217,15 @@ module Bundler
216
217
  # @param [Integer] depth the current depth of the resolution process.
217
218
  # @return [void]
218
219
  def debug(depth = 0)
219
- if debug?
220
- debug_info = yield
221
- debug_info = debug_info.inspect unless debug_info.is_a?(String)
222
- STDERR.puts debug_info.split("\n").map {|s| " " * depth + s }
223
- end
220
+ return unless debug?
221
+ debug_info = yield
222
+ debug_info = debug_info.inspect unless debug_info.is_a?(String)
223
+ STDERR.puts debug_info.split("\n").map {|s| " " * depth + s }
224
224
  end
225
225
 
226
226
  def debug?
227
- ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"]
227
+ return @debug_mode if defined?(@debug_mode)
228
+ @debug_mode = ENV["DEBUG_RESOLVER"] || ENV["DEBUG_RESOLVER_TREE"]
228
229
  end
229
230
 
230
231
  def before_resolution
@@ -341,12 +342,12 @@ module Bundler
341
342
  elsif requirement.source
342
343
  name = requirement.name
343
344
  versions = @source_requirements[name][name].map(&:version)
344
- message = "Could not find gem '#{requirement}' in #{requirement.source}.\n"
345
- if versions.any?
346
- message << "Source contains '#{name}' at: #{versions.join(", ")}"
347
- else
348
- message << "Source does not contain any versions of '#{requirement}'"
349
- end
345
+ message = String.new("Could not find gem '#{requirement}' in #{requirement.source}.\n")
346
+ message << if versions.any?
347
+ "Source contains '#{name}' at: #{versions.join(", ")}"
348
+ else
349
+ "Source does not contain any versions of '#{requirement}'"
350
+ end
350
351
  else
351
352
  message = "Could not find gem '#{requirement}' in any of the gem sources " \
352
353
  "listed in your Gemfile or available on this machine."
data/lib/bundler/retry.rb CHANGED
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  module Bundler
2
3
  # General purpose class for retrying code that may fail
3
4
  class Retry
@@ -1,10 +1,16 @@
1
+ # frozen_string_literal: true
1
2
  module Bundler
2
3
  module RubyDsl
3
- def ruby(ruby_version, options = {})
4
+ def ruby(*ruby_version)
5
+ options = ruby_version.last.is_a?(Hash) ? ruby_version.pop : {}
6
+ ruby_version.flatten!
4
7
  raise GemfileError, "Please define :engine_version" if options[:engine] && options[:engine_version].nil?
5
8
  raise GemfileError, "Please define :engine" if options[:engine_version] && options[:engine].nil?
6
9
 
7
- raise GemfileEvalError, "ruby_version must match the :engine_version for MRI" if options[:engine] == "ruby" && options[:engine_version] && ruby_version != options[:engine_version]
10
+ if options[:engine] == "ruby" && options[:engine_version] &&
11
+ ruby_version != Array(options[:engine_version])
12
+ raise GemfileEvalError, "ruby_version must match the :engine_version for MRI"
13
+ end
8
14
  @ruby_version = RubyVersion.new(ruby_version, options[:patchlevel], options[:engine], options[:engine_version])
9
15
  end
10
16
  end
@@ -1,8 +1,14 @@
1
+ # frozen_string_literal: true
1
2
  module Bundler
2
3
  class RubyVersion
3
- attr_reader :version, :patchlevel, :engine, :engine_version
4
+ attr_reader :versions,
5
+ :patchlevel,
6
+ :engine,
7
+ :engine_versions,
8
+ :gem_version,
9
+ :engine_gem_version
4
10
 
5
- def initialize(version, patchlevel, engine, engine_version)
11
+ def initialize(versions, patchlevel, engine, engine_version)
6
12
  # The parameters to this method must satisfy the
7
13
  # following constraints, which are verified in
8
14
  # the DSL:
@@ -15,29 +21,42 @@ module Bundler
15
21
  # must not be specified, or the engine version
16
22
  # specified must match the version.
17
23
 
18
- @version = version
19
- @engine = engine || "ruby"
20
- # keep track of the engine specified by the user
21
- @input_engine = engine
22
- @engine_version = engine_version || version
23
- @patchlevel = patchlevel
24
+ @versions = Array(versions)
25
+ @gem_version = Gem::Requirement.create(@versions.first).requirements.first.last
26
+ @input_engine = engine
27
+ @engine = engine || "ruby"
28
+ @engine_versions = (engine_version && Array(engine_version)) || @versions
29
+ @engine_gem_version = Gem::Requirement.create(@engine_versions.first).requirements.first.last
30
+ @patchlevel = patchlevel
24
31
  end
25
32
 
26
- def to_s
27
- output = "ruby #{version}"
33
+ def to_s(versions = self.versions)
34
+ output = String.new("ruby #{versions_string(versions)}")
28
35
  output << "p#{patchlevel}" if patchlevel
29
- output << " (#{engine} #{engine_version})" unless engine == "ruby"
36
+ output << " (#{engine} #{versions_string(engine_versions)})" unless engine == "ruby"
30
37
 
31
38
  output
32
39
  end
33
40
 
41
+ def single_version_string
42
+ to_s(gem_version)
43
+ end
44
+
34
45
  def ==(other)
35
- version == other.version &&
46
+ versions == other.versions &&
36
47
  engine == other.engine &&
37
- engine_version == other.engine_version &&
48
+ engine_versions == other.engine_versions &&
38
49
  patchlevel == other.patchlevel
39
50
  end
40
51
 
52
+ def host
53
+ @host ||= [
54
+ RbConfig::CONFIG["host_cpu"],
55
+ RbConfig::CONFIG["host_vendor"],
56
+ RbConfig::CONFIG["host_os"]
57
+ ].join("-")
58
+ end
59
+
41
60
  # Returns a tuple of these things:
42
61
  # [diff, this, other]
43
62
  # The priority of attributes are
@@ -45,70 +64,48 @@ module Bundler
45
64
  # 2. ruby_version
46
65
  # 3. engine_version
47
66
  def diff(other)
67
+ raise ArgumentError, "Can only diff with a RubyVersion" unless other.is_a?(RubyVersion)
48
68
  if engine != other.engine && @input_engine
49
69
  [:engine, engine, other.engine]
50
- elsif version != other.version
51
- [:version, version, other.version]
52
- elsif engine_version != other.engine_version && @input_engine
53
- [:engine_version, engine_version, other.engine_version]
54
- elsif patchlevel != other.patchlevel && @patchlevel
70
+ elsif versions.empty? || !matches?(versions, other.gem_version)
71
+ [:version, versions_string(versions), versions_string(other.versions)]
72
+ elsif @input_engine && !matches?(engine_versions, other.engine_gem_version)
73
+ [:engine_version, versions_string(engine_versions), versions_string(other.engine_versions)]
74
+ elsif patchlevel && (!patchlevel.is_a?(String) || !other.patchlevel.is_a?(String) || !matches?(patchlevel, other.patchlevel))
55
75
  [:patchlevel, patchlevel, other.patchlevel]
56
76
  end
57
77
  end
58
78
 
59
- def host
60
- @host ||= [
61
- RbConfig::CONFIG["host_cpu"],
62
- RbConfig::CONFIG["host_vendor"],
63
- RbConfig::CONFIG["host_os"]
64
- ].join("-")
65
- end
66
- end
67
-
68
- # A subclass of RubyVersion that implements version,
69
- # engine and engine_version based upon the current
70
- # information in the system. It can be used anywhere
71
- # a RubyVersion object is expected, and can be
72
- # compared with a RubyVersion object.
73
- class SystemRubyVersion < RubyVersion
74
- def initialize(*)
75
- # override the default initialize, because
76
- # we will implement version, engine and
77
- # engine_version dynamically
78
- end
79
-
80
- def version
81
- RUBY_VERSION.dup
79
+ def versions_string(versions)
80
+ Array(versions).join(", ")
82
81
  end
83
82
 
84
- def gem_version
85
- @gem_version ||= Gem::Version.new(version)
86
- end
87
-
88
- def engine
89
- if defined?(RUBY_ENGINE)
83
+ def self.system
84
+ ruby_engine = if defined?(RUBY_ENGINE) && !RUBY_ENGINE.nil?
90
85
  RUBY_ENGINE.dup
91
86
  else
92
87
  # not defined in ruby 1.8.7
93
88
  "ruby"
94
89
  end
95
- end
96
-
97
- def engine_version
98
- case engine
99
- when "ruby"
100
- RUBY_VERSION.dup
101
- when "rbx"
102
- Rubinius::VERSION.dup
103
- when "jruby"
104
- JRUBY_VERSION.dup
105
- else
106
- raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized"
90
+ ruby_engine_version = case ruby_engine
91
+ when "ruby"
92
+ RUBY_VERSION.dup
93
+ when "rbx"
94
+ Rubinius::VERSION.dup
95
+ when "jruby"
96
+ JRUBY_VERSION.dup
97
+ else
98
+ raise BundlerError, "RUBY_ENGINE value #{RUBY_ENGINE} is not recognized"
107
99
  end
100
+ @ruby_version ||= RubyVersion.new(RUBY_VERSION.dup, RUBY_PATCHLEVEL.to_s, ruby_engine, ruby_engine_version)
108
101
  end
109
102
 
110
- def patchlevel
111
- RUBY_PATCHLEVEL.to_s
103
+ private
104
+
105
+ def matches?(requirements, version)
106
+ Array(requirements).all? do |requirement|
107
+ Gem::Requirement.create(requirement).satisfied_by?(Gem::Version.create(version))
108
+ end
112
109
  end
113
110
  end
114
111
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "pathname"
2
3
 
3
4
  if defined?(Gem::QuickLoader)
@@ -78,7 +79,7 @@ module Gem
78
79
  end
79
80
 
80
81
  def to_gemfile(path = nil)
81
- gemfile = "source 'https://rubygems.org'\n"
82
+ gemfile = String.new("source 'https://rubygems.org'\n")
82
83
  gemfile << dependencies_to_gemfile(nondevelopment_dependencies)
83
84
  unless development_dependencies.empty?
84
85
  gemfile << "\n"
@@ -94,7 +95,7 @@ module Gem
94
95
  private
95
96
 
96
97
  def dependencies_to_gemfile(dependencies, group = nil)
97
- gemfile = ""
98
+ gemfile = String.new
98
99
  if dependencies.any?
99
100
  gemfile << "group :#{group} do\n" if group
100
101
  dependencies.each do |dependency|
@@ -126,7 +127,7 @@ module Gem
126
127
  end
127
128
 
128
129
  def to_lock
129
- out = " #{name}"
130
+ out = String.new(" #{name}")
130
131
  unless requirement == Gem::Requirement.default
131
132
  reqs = requirement.requirements.map {|o, v| "#{o} #{v}" }.sort.reverse
132
133
  out << " (#{reqs.join(", ")})"
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "rubygems/installer"
2
3
 
3
4
  module Bundler
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "monitor"
2
3
  require "rubygems"
3
4
  require "rubygems/config_file"
@@ -64,7 +65,7 @@ module Bundler
64
65
  def configuration
65
66
  require "bundler/psyched_yaml"
66
67
  Gem.configuration
67
- rescue Gem::SystemExitException => e
68
+ rescue Gem::SystemExitException, LoadError => e
68
69
  Bundler.ui.error "#{e.class}: #{e.message}"
69
70
  Bundler.ui.trace e
70
71
  raise
@@ -181,7 +182,7 @@ module Bundler
181
182
  def fetch_prerelease_specs
182
183
  fetch_specs(false, true)
183
184
  rescue Gem::RemoteFetcher::FetchError
184
- [] # if we can't download them, there aren't any
185
+ {} # if we can't download them, there aren't any
185
186
  end
186
187
 
187
188
  # TODO: This is for older versions of Rubygems... should we support the
@@ -194,9 +195,9 @@ module Bundler
194
195
  # Fetch all specs, minus prerelease specs
195
196
  spec_list = fetch_specs(true, false)
196
197
  # Then fetch the prerelease specs
197
- fetch_prerelease_specs.each {|k, v| spec_list[k] += v }
198
+ fetch_prerelease_specs.each {|k, v| spec_list[k].push(*v) }
198
199
 
199
- spec_list
200
+ spec_list.values.first
200
201
  ensure
201
202
  Bundler.rubygems.sources = old_sources
202
203
  end
@@ -578,18 +579,12 @@ module Bundler
578
579
  end
579
580
 
580
581
  def fetch_all_remote_specs(remote)
581
- # Since SpecFetcher now returns NameTuples, we just fetch directly
582
- # and unmarshal the array ourselves.
583
- hash = {}
582
+ source = remote.uri.is_a?(URI) ? remote.uri : URI.parse(source.to_s)
584
583
 
585
- source = remote.uri
586
- source = URI.parse(source.to_s) unless source.is_a?(URI)
587
- hash[source] = fetch_specs(source, remote, "specs")
584
+ specs = fetch_specs(source, remote, "specs")
585
+ pres = fetch_specs(source, remote, "prerelease_specs") || []
588
586
 
589
- pres = fetch_specs(source, remote, "prerelease_specs")
590
- hash[source].push(*pres) if pres && !pres.empty?
591
-
592
- hash
587
+ specs.push(*pres)
593
588
  end
594
589
 
595
590
  def download_gem(spec, uri, path)
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require "digest/sha1"
2
3
 
3
4
  module Bundler
@@ -12,7 +13,7 @@ module Bundler
12
13
 
13
14
  specs = groups.any? ? @definition.specs_for(groups) : requested_specs
14
15
 
15
- setup_environment
16
+ SharedHelpers.set_bundle_environment
16
17
  Bundler.rubygems.replace_entrypoints(specs)
17
18
 
18
19
  # Activate the specs
@@ -52,7 +53,7 @@ module Bundler
52
53
  /^Missing API definition file in (.+)$/i,
53
54
  /^cannot load such file -- (.+)$/i,
54
55
  /^dlopen\([^)]*\): Library not loaded: (.+)$/i,
55
- ]
56
+ ].freeze
56
57
 
57
58
  def require(*groups)
58
59
  groups.map!(&:to_sym)
@@ -189,26 +190,21 @@ module Bundler
189
190
 
190
191
  unless dry_run
191
192
  stale_files = stale_gem_bins + stale_gem_files + stale_gemspec_files
192
- stale_files.each {|file| FileUtils.rm(file) if File.exist?(file) }
193
- stale_git_cache_dirs.each {|dir| FileUtils.rm_rf(dir) if File.exist?(dir) }
193
+ stale_files.each do |file|
194
+ SharedHelpers.filesystem_access(File.dirname(file)) do |_p|
195
+ FileUtils.rm(file) if File.exist?(file)
196
+ end
197
+ end
198
+ stale_git_cache_dirs.each do |cache_dir|
199
+ SharedHelpers.filesystem_access(cache_dir) do |dir|
200
+ FileUtils.rm_rf(dir) if File.exist?(dir)
201
+ end
202
+ end
194
203
  end
195
204
 
196
205
  output
197
206
  end
198
207
 
199
- def setup_environment
200
- begin
201
- ENV["BUNDLE_BIN_PATH"] = Bundler.rubygems.bin_path("bundler", "bundle", VERSION)
202
- rescue Gem::GemNotFoundException
203
- ENV["BUNDLE_BIN_PATH"] = File.expand_path("../../../exe/bundle", __FILE__)
204
- end
205
-
206
- # Set BUNDLE_GEMFILE
207
- ENV["BUNDLE_GEMFILE"] = default_gemfile.to_s
208
-
209
- SharedHelpers.set_bundle_environment
210
- end
211
-
212
208
  private
213
209
 
214
210
  def prune_gem_cache(resolve, cache_path)
@@ -265,11 +261,10 @@ module Bundler
265
261
  man_subdir unless Dir[man_subdir + "/man?/"].empty?
266
262
  end.compact
267
263
 
268
- unless manuals.empty?
269
- ENV["MANPATH"] = manuals.concat(
270
- ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
271
- ).uniq.join(File::PATH_SEPARATOR)
272
- end
264
+ return if manuals.empty?
265
+ ENV["MANPATH"] = manuals.concat(
266
+ ENV["MANPATH"].to_s.split(File::PATH_SEPARATOR)
267
+ ).uniq.join(File::PATH_SEPARATOR)
273
268
  end
274
269
 
275
270
  def remove_dir(dir, dry_run)
@@ -1,10 +1,11 @@
1
+ # frozen_string_literal: true
1
2
  require "uri"
2
3
 
3
4
  module Bundler
4
5
  class Settings
5
- BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check ignore_messages gem.mit gem.coc silence_root_warning).freeze
6
+ BOOL_KEYS = %w(frozen cache_all no_prune disable_local_branch_check disable_shared_gems ignore_messages gem.mit gem.coc silence_root_warning).freeze
6
7
  NUMBER_KEYS = %w(retry timeout redirect ssl_verify_mode).freeze
7
- DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }
8
+ DEFAULT_CONFIG = { :retry => 3, :timeout => 10, :redirect => 5 }.freeze
8
9
 
9
10
  def initialize(root = nil)
10
11
  @root = root
@@ -63,10 +64,7 @@ module Bundler
63
64
 
64
65
  def mirror_for(uri)
65
66
  uri = URI(uri.to_s) unless uri.is_a?(URI)
66
-
67
- # Settings keys are all downcased
68
- normalized_key = normalize_uri(uri.to_s.downcase)
69
- gem_mirrors[normalized_key] || uri
67
+ gem_mirrors.for(uri.to_s).uri
70
68
  end
71
69
 
72
70
  def credentials_for(uri)
@@ -74,12 +72,9 @@ module Bundler
74
72
  end
75
73
 
76
74
  def gem_mirrors
77
- all.inject({}) do |h, k|
78
- if k =~ /^mirror\./
79
- uri = normalize_uri($')
80
- h[uri] = normalize_uri(self[k])
81
- end
82
- h
75
+ all.inject(Mirrors.new) do |mirrors, k|
76
+ mirrors.parse(k, self[k]) if k =~ /^mirror\./
77
+ mirrors
83
78
  end
84
79
  end
85
80
 
@@ -161,7 +156,7 @@ module Bundler
161
156
  private
162
157
 
163
158
  def key_for(key)
164
- key = normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
159
+ key = Settings.normalize_uri(key).to_s if key.is_a?(String) && /https?:/ =~ key
165
160
  key = key.to_s.gsub(".", "__").upcase
166
161
  "BUNDLE_#{key}"
167
162
  end
@@ -215,8 +210,11 @@ module Bundler
215
210
  end
216
211
 
217
212
  def global_config_file
218
- file = ENV["BUNDLE_CONFIG"] || File.join(Bundler.rubygems.user_home, ".bundle/config")
219
- Pathname.new(file)
213
+ if ENV["BUNDLE_CONFIG"] && !ENV["BUNDLE_CONFIG"].empty?
214
+ Pathname.new(ENV["BUNDLE_CONFIG"])
215
+ else
216
+ Bundler.user_bundle_path.join("config")
217
+ end
220
218
  end
221
219
 
222
220
  def local_config_file
@@ -224,17 +222,15 @@ module Bundler
224
222
  end
225
223
 
226
224
  def load_config(config_file)
227
- valid_file = config_file && config_file.exist? && !config_file.size.zero?
228
- if !ignore_config? && valid_file
225
+ SharedHelpers.filesystem_access(config_file, :read) do
226
+ valid_file = config_file && config_file.exist? && !config_file.size.zero?
227
+ return {} if ignore_config? || !valid_file
229
228
  config_regex = /^(BUNDLE_.+): (['"]?)(.*(?:\n(?!BUNDLE).+)?)\2$/
230
- raise PermissionError.new(config_file, :read) unless config_file.readable?
231
229
  config_pairs = config_file.read.scan(config_regex).map do |m|
232
230
  key, _, value = m
233
231
  [convert_to_backward_compatible_key(key), value.gsub(/\s+/, " ").tr('"', "'")]
234
232
  end
235
233
  Hash[config_pairs]
236
- else
237
- {}
238
234
  end
239
235
  end
240
236
 
@@ -246,7 +242,7 @@ module Bundler
246
242
 
247
243
  # TODO: duplicates Rubygems#normalize_uri
248
244
  # TODO: is this the correct place to validate mirror URIs?
249
- def normalize_uri(uri)
245
+ def self.normalize_uri(uri)
250
246
  uri = uri.to_s
251
247
  uri = "#{uri}/" unless uri =~ %r{/\Z}
252
248
  uri = URI(uri)