shopify-bundler 1.10.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +16 -0
  3. data/.rspec +3 -0
  4. data/.rubocop.yml +96 -0
  5. data/.rubocop_todo.yml +177 -0
  6. data/.travis.yml +104 -0
  7. data/CHANGELOG.md +2131 -0
  8. data/CODE_OF_CONDUCT.md +42 -0
  9. data/CONTRIBUTING.md +32 -0
  10. data/DEVELOPMENT.md +118 -0
  11. data/ISSUES.md +96 -0
  12. data/LICENSE.md +23 -0
  13. data/README.md +40 -0
  14. data/Rakefile +309 -0
  15. data/bin/rake +14 -0
  16. data/bin/rspec +10 -0
  17. data/bin/rubocop +11 -0
  18. data/bundler.gemspec +34 -0
  19. data/exe/bundle +21 -0
  20. data/exe/bundle_ruby +60 -0
  21. data/exe/bundler +21 -0
  22. data/lib/bundler.rb +499 -0
  23. data/lib/bundler/capistrano.rb +16 -0
  24. data/lib/bundler/cli.rb +435 -0
  25. data/lib/bundler/cli/binstubs.rb +37 -0
  26. data/lib/bundler/cli/cache.rb +34 -0
  27. data/lib/bundler/cli/check.rb +37 -0
  28. data/lib/bundler/cli/clean.rb +25 -0
  29. data/lib/bundler/cli/common.rb +56 -0
  30. data/lib/bundler/cli/config.rb +88 -0
  31. data/lib/bundler/cli/console.rb +37 -0
  32. data/lib/bundler/cli/exec.rb +51 -0
  33. data/lib/bundler/cli/gem.rb +208 -0
  34. data/lib/bundler/cli/init.rb +32 -0
  35. data/lib/bundler/cli/inject.rb +32 -0
  36. data/lib/bundler/cli/install.rb +188 -0
  37. data/lib/bundler/cli/lock.rb +35 -0
  38. data/lib/bundler/cli/open.rb +22 -0
  39. data/lib/bundler/cli/outdated.rb +86 -0
  40. data/lib/bundler/cli/package.rb +45 -0
  41. data/lib/bundler/cli/platform.rb +42 -0
  42. data/lib/bundler/cli/show.rb +74 -0
  43. data/lib/bundler/cli/update.rb +72 -0
  44. data/lib/bundler/cli/viz.rb +26 -0
  45. data/lib/bundler/constants.rb +5 -0
  46. data/lib/bundler/current_ruby.rb +218 -0
  47. data/lib/bundler/definition.rb +675 -0
  48. data/lib/bundler/dep_proxy.rb +45 -0
  49. data/lib/bundler/dependency.rb +119 -0
  50. data/lib/bundler/deployment.rb +62 -0
  51. data/lib/bundler/deprecate.rb +17 -0
  52. data/lib/bundler/dsl.rb +478 -0
  53. data/lib/bundler/endpoint_specification.rb +100 -0
  54. data/lib/bundler/env.rb +82 -0
  55. data/lib/bundler/environment.rb +41 -0
  56. data/lib/bundler/fetcher.rb +288 -0
  57. data/lib/bundler/fetcher/base.rb +26 -0
  58. data/lib/bundler/fetcher/dependency.rb +88 -0
  59. data/lib/bundler/fetcher/downloader.rb +60 -0
  60. data/lib/bundler/fetcher/index.rb +32 -0
  61. data/lib/bundler/friendly_errors.rb +92 -0
  62. data/lib/bundler/gem_helper.rb +191 -0
  63. data/lib/bundler/gem_helpers.rb +26 -0
  64. data/lib/bundler/gem_installer.rb +9 -0
  65. data/lib/bundler/gem_path_manipulation.rb +8 -0
  66. data/lib/bundler/gem_tasks.rb +5 -0
  67. data/lib/bundler/graph.rb +173 -0
  68. data/lib/bundler/index.rb +199 -0
  69. data/lib/bundler/injector.rb +62 -0
  70. data/lib/bundler/inline.rb +58 -0
  71. data/lib/bundler/installer.rb +242 -0
  72. data/lib/bundler/installer/parallel_installer.rb +122 -0
  73. data/lib/bundler/installer/standalone.rb +48 -0
  74. data/lib/bundler/lazy_specification.rb +82 -0
  75. data/lib/bundler/lockfile_parser.rb +199 -0
  76. data/lib/bundler/match_platform.rb +13 -0
  77. data/lib/bundler/psyched_yaml.rb +26 -0
  78. data/lib/bundler/remote_specification.rb +82 -0
  79. data/lib/bundler/resolver.rb +350 -0
  80. data/lib/bundler/retry.rb +60 -0
  81. data/lib/bundler/ruby_dsl.rb +11 -0
  82. data/lib/bundler/ruby_version.rb +116 -0
  83. data/lib/bundler/rubygems_ext.rb +175 -0
  84. data/lib/bundler/rubygems_integration.rb +674 -0
  85. data/lib/bundler/runtime.rb +285 -0
  86. data/lib/bundler/settings.rb +263 -0
  87. data/lib/bundler/setup.rb +26 -0
  88. data/lib/bundler/shared_helpers.rb +176 -0
  89. data/lib/bundler/similarity_detector.rb +61 -0
  90. data/lib/bundler/source.rb +35 -0
  91. data/lib/bundler/source/git.rb +286 -0
  92. data/lib/bundler/source/git/git_proxy.rb +190 -0
  93. data/lib/bundler/source/path.rb +224 -0
  94. data/lib/bundler/source/path/installer.rb +43 -0
  95. data/lib/bundler/source/rubygems.rb +436 -0
  96. data/lib/bundler/source/rubygems/remote.rb +38 -0
  97. data/lib/bundler/source_list.rb +101 -0
  98. data/lib/bundler/spec_set.rb +156 -0
  99. data/lib/bundler/ssl_certs/.document +1 -0
  100. data/lib/bundler/ssl_certs/AddTrustExternalCARoot-2048.pem +25 -0
  101. data/lib/bundler/ssl_certs/AddTrustExternalCARoot.pem +32 -0
  102. data/lib/bundler/ssl_certs/Class3PublicPrimaryCertificationAuthority.pem +14 -0
  103. data/lib/bundler/ssl_certs/DigiCertHighAssuranceEVRootCA.pem +23 -0
  104. data/lib/bundler/ssl_certs/EntrustnetSecureServerCertificationAuthority.pem +28 -0
  105. data/lib/bundler/ssl_certs/GeoTrustGlobalCA.pem +20 -0
  106. data/lib/bundler/ssl_certs/certificate_manager.rb +64 -0
  107. data/lib/bundler/stub_specification.rb +23 -0
  108. data/lib/bundler/templates/Executable +16 -0
  109. data/lib/bundler/templates/Executable.standalone +12 -0
  110. data/lib/bundler/templates/Gemfile +4 -0
  111. data/lib/bundler/templates/newgem/.travis.yml.tt +4 -0
  112. data/lib/bundler/templates/newgem/CODE_OF_CONDUCT.md.tt +22 -0
  113. data/lib/bundler/templates/newgem/Gemfile.tt +4 -0
  114. data/lib/bundler/templates/newgem/LICENSE.txt.tt +21 -0
  115. data/lib/bundler/templates/newgem/README.md.tt +41 -0
  116. data/lib/bundler/templates/newgem/Rakefile.tt +29 -0
  117. data/lib/bundler/templates/newgem/bin/console.tt +14 -0
  118. data/lib/bundler/templates/newgem/bin/setup.tt +8 -0
  119. data/lib/bundler/templates/newgem/exe/newgem.tt +3 -0
  120. data/lib/bundler/templates/newgem/ext/newgem/extconf.rb.tt +3 -0
  121. data/lib/bundler/templates/newgem/ext/newgem/newgem.c.tt +9 -0
  122. data/lib/bundler/templates/newgem/ext/newgem/newgem.h.tt +6 -0
  123. data/lib/bundler/templates/newgem/gitignore.tt +16 -0
  124. data/lib/bundler/templates/newgem/lib/newgem.rb.tt +12 -0
  125. data/lib/bundler/templates/newgem/lib/newgem/version.rb.tt +7 -0
  126. data/lib/bundler/templates/newgem/newgem.gemspec.tt +43 -0
  127. data/lib/bundler/templates/newgem/rspec.tt +2 -0
  128. data/lib/bundler/templates/newgem/spec/newgem_spec.rb.tt +11 -0
  129. data/lib/bundler/templates/newgem/spec/spec_helper.rb.tt +2 -0
  130. data/lib/bundler/templates/newgem/test/newgem_test.rb.tt +11 -0
  131. data/lib/bundler/templates/newgem/test/test_helper.rb.tt +4 -0
  132. data/lib/bundler/ui.rb +7 -0
  133. data/lib/bundler/ui/rg_proxy.rb +17 -0
  134. data/lib/bundler/ui/shell.rb +108 -0
  135. data/lib/bundler/ui/silent.rb +44 -0
  136. data/lib/bundler/vendor/molinillo/lib/molinillo.rb +5 -0
  137. data/lib/bundler/vendor/molinillo/lib/molinillo/dependency_graph.rb +277 -0
  138. data/lib/bundler/vendor/molinillo/lib/molinillo/errors.rb +69 -0
  139. data/lib/bundler/vendor/molinillo/lib/molinillo/gem_metadata.rb +3 -0
  140. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/specification_provider.rb +99 -0
  141. data/lib/bundler/vendor/molinillo/lib/molinillo/modules/ui.rb +63 -0
  142. data/lib/bundler/vendor/molinillo/lib/molinillo/resolution.rb +434 -0
  143. data/lib/bundler/vendor/molinillo/lib/molinillo/resolver.rb +43 -0
  144. data/lib/bundler/vendor/molinillo/lib/molinillo/state.rb +51 -0
  145. data/lib/bundler/vendor/net/http/faster.rb +26 -0
  146. data/lib/bundler/vendor/net/http/persistent.rb +1230 -0
  147. data/lib/bundler/vendor/net/http/persistent/ssl_reuse.rb +128 -0
  148. data/lib/bundler/vendor/thor/lib/thor.rb +484 -0
  149. data/lib/bundler/vendor/thor/lib/thor/actions.rb +319 -0
  150. data/lib/bundler/vendor/thor/lib/thor/actions/create_file.rb +103 -0
  151. data/lib/bundler/vendor/thor/lib/thor/actions/create_link.rb +59 -0
  152. data/lib/bundler/vendor/thor/lib/thor/actions/directory.rb +118 -0
  153. data/lib/bundler/vendor/thor/lib/thor/actions/empty_directory.rb +135 -0
  154. data/lib/bundler/vendor/thor/lib/thor/actions/file_manipulation.rb +316 -0
  155. data/lib/bundler/vendor/thor/lib/thor/actions/inject_into_file.rb +107 -0
  156. data/lib/bundler/vendor/thor/lib/thor/base.rb +656 -0
  157. data/lib/bundler/vendor/thor/lib/thor/command.rb +133 -0
  158. data/lib/bundler/vendor/thor/lib/thor/core_ext/hash_with_indifferent_access.rb +77 -0
  159. data/lib/bundler/vendor/thor/lib/thor/core_ext/io_binary_read.rb +10 -0
  160. data/lib/bundler/vendor/thor/lib/thor/core_ext/ordered_hash.rb +98 -0
  161. data/lib/bundler/vendor/thor/lib/thor/error.rb +32 -0
  162. data/lib/bundler/vendor/thor/lib/thor/group.rb +281 -0
  163. data/lib/bundler/vendor/thor/lib/thor/invocation.rb +178 -0
  164. data/lib/bundler/vendor/thor/lib/thor/line_editor.rb +17 -0
  165. data/lib/bundler/vendor/thor/lib/thor/line_editor/basic.rb +35 -0
  166. data/lib/bundler/vendor/thor/lib/thor/line_editor/readline.rb +88 -0
  167. data/lib/bundler/vendor/thor/lib/thor/parser.rb +4 -0
  168. data/lib/bundler/vendor/thor/lib/thor/parser/argument.rb +73 -0
  169. data/lib/bundler/vendor/thor/lib/thor/parser/arguments.rb +175 -0
  170. data/lib/bundler/vendor/thor/lib/thor/parser/option.rb +125 -0
  171. data/lib/bundler/vendor/thor/lib/thor/parser/options.rb +218 -0
  172. data/lib/bundler/vendor/thor/lib/thor/rake_compat.rb +71 -0
  173. data/lib/bundler/vendor/thor/lib/thor/runner.rb +322 -0
  174. data/lib/bundler/vendor/thor/lib/thor/shell.rb +81 -0
  175. data/lib/bundler/vendor/thor/lib/thor/shell/basic.rb +421 -0
  176. data/lib/bundler/vendor/thor/lib/thor/shell/color.rb +149 -0
  177. data/lib/bundler/vendor/thor/lib/thor/shell/html.rb +126 -0
  178. data/lib/bundler/vendor/thor/lib/thor/util.rb +267 -0
  179. data/lib/bundler/vendor/thor/lib/thor/version.rb +3 -0
  180. data/lib/bundler/vendored_molinillo.rb +2 -0
  181. data/lib/bundler/vendored_persistent.rb +11 -0
  182. data/lib/bundler/vendored_thor.rb +3 -0
  183. data/lib/bundler/version.rb +6 -0
  184. data/lib/bundler/vlad.rb +11 -0
  185. data/lib/bundler/worker.rb +72 -0
  186. data/man/bundle-config.ronn +187 -0
  187. data/man/bundle-exec.ronn +136 -0
  188. data/man/bundle-gem.ronn +77 -0
  189. data/man/bundle-install.ronn +398 -0
  190. data/man/bundle-package.ronn +66 -0
  191. data/man/bundle-platform.ronn +42 -0
  192. data/man/bundle-update.ronn +188 -0
  193. data/man/bundle.ronn +98 -0
  194. data/man/gemfile.5.ronn +495 -0
  195. data/man/index.txt +8 -0
  196. metadata +346 -0
@@ -0,0 +1,100 @@
1
+ module Bundler
2
+ # used for Creating Specifications from the Gemcutter Endpoint
3
+ class EndpointSpecification < Gem::Specification
4
+ include MatchPlatform
5
+
6
+ attr_reader :name, :version, :platform, :dependencies
7
+ attr_accessor :source, :remote
8
+
9
+ def initialize(name, version, platform, dependencies)
10
+ @name = name
11
+ @version = version
12
+ @platform = platform
13
+ @dependencies = dependencies
14
+ end
15
+
16
+ def fetch_platform
17
+ @platform
18
+ end
19
+
20
+ # needed for standalone, load required_paths from local gemspec
21
+ # after the gem is installed
22
+ def require_paths
23
+ if @remote_specification
24
+ @remote_specification.require_paths
25
+ elsif _local_specification
26
+ _local_specification.require_paths
27
+ else
28
+ super
29
+ end
30
+ end
31
+
32
+ # needed for inline
33
+ def load_paths
34
+ # remote specs aren't installed, and can't have load_paths
35
+ if _local_specification
36
+ _local_specification.load_paths
37
+ else
38
+ super
39
+ end
40
+ end
41
+
42
+ # needed for binstubs
43
+ def executables
44
+ if @remote_specification
45
+ @remote_specification.executables
46
+ elsif _local_specification
47
+ _local_specification.executables
48
+ else
49
+ super
50
+ end
51
+ end
52
+
53
+ # needed for bundle clean
54
+ def bindir
55
+ if @remote_specification
56
+ @remote_specification.bindir
57
+ elsif _local_specification
58
+ _local_specification.bindir
59
+ else
60
+ super
61
+ end
62
+ end
63
+
64
+ # needed for post_install_messages during install
65
+ def post_install_message
66
+ if @remote_specification
67
+ @remote_specification.post_install_message
68
+ elsif _local_specification
69
+ _local_specification.post_install_message
70
+ end
71
+ end
72
+
73
+ # needed for "with native extensions" during install
74
+ def extensions
75
+ if @remote_specification
76
+ @remote_specification.extensions
77
+ elsif _local_specification
78
+ _local_specification.extensions
79
+ end
80
+ end
81
+
82
+ def _local_specification
83
+ if @loaded_from && File.exist?(local_specification_path)
84
+ eval(File.read(local_specification_path)).tap do |spec|
85
+ spec.loaded_from = @loaded_from
86
+ end
87
+ end
88
+ end
89
+
90
+ def __swap__(spec)
91
+ @remote_specification = spec
92
+ end
93
+
94
+ private
95
+
96
+ def local_specification_path
97
+ "#{base_dir}/specifications/#{full_name}.gemspec"
98
+ end
99
+ end
100
+ end
@@ -0,0 +1,82 @@
1
+ require "bundler/rubygems_integration"
2
+ require "bundler/source/git/git_proxy"
3
+
4
+ module Bundler
5
+ class Env
6
+ def write(io)
7
+ io.write report(:print_gemfile => true, :print_gemspecs => true)
8
+ end
9
+
10
+ def report(options = {})
11
+ print_gemfile = options.delete(:print_gemfile)
12
+ print_gemspecs = options.delete(:print_gemspecs)
13
+
14
+ out = "Environment\n\n"
15
+ out << " Bundler #{Bundler::VERSION}\n"
16
+ out << " Rubygems #{Gem::VERSION}\n"
17
+ out << " Ruby #{ruby_version}"
18
+ out << " GEM_HOME #{ENV["GEM_HOME"]}\n" unless ENV["GEM_HOME"].nil? || ENV["GEM_HOME"].empty?
19
+ out << " GEM_PATH #{ENV["GEM_PATH"]}\n" unless ENV["GEM_PATH"] == ENV["GEM_HOME"]
20
+ out << " RVM #{ENV["rvm_version"]}\n" if ENV["rvm_version"]
21
+ out << " Git #{git_version}\n"
22
+ %w(rubygems-bundler open_gem).each do |name|
23
+ specs = Bundler.rubygems.find_name(name)
24
+ out << " #{name} (#{specs.map(&:version).join(",")})\n" unless specs.empty?
25
+ end
26
+
27
+ out << "\nBundler settings\n\n" unless Bundler.settings.all.empty?
28
+ Bundler.settings.all.each do |setting|
29
+ out << " " << setting << "\n"
30
+ Bundler.settings.pretty_values_for(setting).each do |line|
31
+ out << " " << line << "\n"
32
+ end
33
+ end
34
+
35
+ if print_gemfile
36
+ out << "\n#{Bundler.default_gemfile.relative_path_from(SharedHelpers.pwd)}\n\n"
37
+ out << " " << read_file(Bundler.default_gemfile).gsub(/\n/, "\n ") << "\n"
38
+
39
+ out << "\n#{Bundler.default_lockfile.relative_path_from(SharedHelpers.pwd)}\n\n"
40
+ out << " " << read_file(Bundler.default_lockfile).gsub(/\n/, "\n ") << "\n"
41
+ end
42
+
43
+ if print_gemspecs
44
+ dsl = Dsl.new.tap {|d| d.eval_gemfile(Bundler.default_gemfile) }
45
+ dsl.gemspecs.each do |gs|
46
+ out << "\n#{Pathname.new(gs).basename}:"
47
+ out << "\n\n " << read_file(gs).gsub(/\n/, "\n ") << "\n"
48
+ end
49
+ end
50
+
51
+ out
52
+ end
53
+
54
+ private
55
+
56
+ def read_file(filename)
57
+ File.read(filename.to_s).strip
58
+ rescue Errno::ENOENT
59
+ "<No #{filename} found>"
60
+ rescue => e
61
+ "#{e.class}: #{e.message}"
62
+ end
63
+
64
+ def ruby_version
65
+ str = "#{RUBY_VERSION}"
66
+ if RUBY_VERSION < "1.9"
67
+ str << " (#{RUBY_RELEASE_DATE}"
68
+ str << " patchlevel #{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
69
+ str << ") [#{RUBY_PLATFORM}]\n"
70
+ else
71
+ str << "p#{RUBY_PATCHLEVEL}" if defined? RUBY_PATCHLEVEL
72
+ str << " (#{RUBY_RELEASE_DATE} revision #{RUBY_REVISION}) [#{RUBY_PLATFORM}]\n"
73
+ end
74
+ end
75
+
76
+ def git_version
77
+ Bundler::Source::Git::GitProxy.new(nil, nil, nil).version
78
+ rescue Bundler::Source::Git::GitNotInstalledError
79
+ "not installed"
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,41 @@
1
+ module Bundler
2
+ class Environment
3
+ attr_reader :root
4
+
5
+ def initialize(root, definition)
6
+ @root = root
7
+ @definition = definition
8
+
9
+ env_file = Bundler.app_config_path.join("environment.rb")
10
+ env_file.rmtree if env_file.exist?
11
+ end
12
+
13
+ def inspect
14
+ @definition.to_lock.inspect
15
+ end
16
+
17
+ def requested_specs
18
+ @definition.requested_specs
19
+ end
20
+
21
+ def specs
22
+ @definition.specs
23
+ end
24
+
25
+ def dependencies
26
+ @definition.dependencies
27
+ end
28
+
29
+ def current_dependencies
30
+ @definition.current_dependencies
31
+ end
32
+
33
+ def lock(opts = {})
34
+ @definition.lock(Bundler.default_lockfile, opts[:preserve_bundled_with])
35
+ end
36
+
37
+ def update(*gems)
38
+ # Nothing
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,288 @@
1
+ require "bundler/vendored_persistent"
2
+ require "cgi"
3
+ require "securerandom"
4
+
5
+ module Bundler
6
+
7
+ # Handles all the fetching with the rubygems server
8
+ class Fetcher
9
+ autoload :Downloader, "bundler/fetcher/downloader"
10
+ autoload :Dependency, "bundler/fetcher/dependency"
11
+ autoload :Index, "bundler/fetcher/index"
12
+
13
+ # This error is raised when it looks like the network is down
14
+ class NetworkDownError < HTTPError; end
15
+ # This error is raised if the API returns a 413 (only printed in verbose)
16
+ class FallbackError < HTTPError; end
17
+ # This is the error raised if OpenSSL fails the cert verification
18
+ class CertificateFailureError < HTTPError
19
+ def initialize(remote_uri)
20
+ super "Could not verify the SSL certificate for #{remote_uri}.\nThere" \
21
+ " is a chance you are experiencing a man-in-the-middle attack, but" \
22
+ " most likely your system doesn't have the CA certificates needed" \
23
+ " for verification. For information about OpenSSL certificates, see" \
24
+ " http://bit.ly/ruby-ssl. To connect without using SSL, edit your Gemfile" \
25
+ " sources and change 'https' to 'http'."
26
+ end
27
+ end
28
+ # This is the error raised when a source is HTTPS and OpenSSL didn't load
29
+ class SSLError < HTTPError
30
+ def initialize(msg = nil)
31
+ super msg || "Could not load OpenSSL.\n" \
32
+ "You must recompile Ruby with OpenSSL support or change the sources in your " \
33
+ "Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL " \
34
+ "using RVM are available at rvm.io/packages/openssl."
35
+ end
36
+ end
37
+ # This error is raised if HTTP authentication is required, but not provided.
38
+ class AuthenticationRequiredError < HTTPError
39
+ def initialize(remote_uri)
40
+ super "Authentication is required for #{remote_uri}.\n" \
41
+ "Please supply credentials for this source. You can do this by running:\n" \
42
+ " bundle config #{remote_uri} username:password"
43
+ end
44
+ end
45
+ # This error is raised if HTTP authentication is provided, but incorrect.
46
+ class BadAuthenticationError < HTTPError
47
+ def initialize(remote_uri)
48
+ super "Bad username or password for #{remote_uri}.\n" \
49
+ "Please double-check your credentials and correct them."
50
+ end
51
+ end
52
+
53
+ # Exceptions classes that should bypass retry attempts. If your password didn't work the
54
+ # first time, it's not going to the third time.
55
+ AUTH_ERRORS = [AuthenticationRequiredError, BadAuthenticationError]
56
+
57
+ class << self
58
+ attr_accessor :disable_endpoint, :api_timeout, :redirect_limit, :max_retries
59
+ end
60
+
61
+ self.redirect_limit = Bundler.settings[:redirect] # How many redirects to allow in one request
62
+ self.api_timeout = Bundler.settings[:timeout] # How long to wait for each API call
63
+ self.max_retries = Bundler.settings[:retry] # How many retries for the API call
64
+
65
+ def initialize(remote)
66
+ @remote = remote
67
+
68
+ Socket.do_not_reverse_lookup = true
69
+ connection # create persistent connection
70
+ end
71
+
72
+ def uri
73
+ @remote.anonymized_uri
74
+ end
75
+
76
+ # fetch a gem specification
77
+ def fetch_spec(spec)
78
+ spec -= [nil, "ruby", ""]
79
+ spec_file_name = "#{spec.join "-"}.gemspec"
80
+
81
+ uri = URI.parse("#{remote_uri}#{Gem::MARSHAL_SPEC_DIR}#{spec_file_name}.rz")
82
+ if uri.scheme == "file"
83
+ Bundler.load_marshal Gem.inflate(Gem.read_binary(uri.path))
84
+ elsif cached_spec_path = gemspec_cached_path(spec_file_name)
85
+ Bundler.load_gemspec(cached_spec_path)
86
+ else
87
+ Bundler.load_marshal Gem.inflate(downloader.fetch uri)
88
+ end
89
+ rescue MarshalError
90
+ raise HTTPError, "Gemspec #{spec} contained invalid data.\n" \
91
+ "Your network or your gem server is probably having issues right now."
92
+ end
93
+
94
+ # return the specs in the bundler format as an index
95
+ def specs(gem_names, source)
96
+ old = Bundler.rubygems.sources
97
+ index = Bundler::Index.new
98
+
99
+ specs = {}
100
+ fetchers.dup.each do |f|
101
+ unless f.api_fetcher? && !gem_names
102
+ break if specs = f.specs(gem_names)
103
+ end
104
+ fetchers.delete(f)
105
+ end
106
+ @use_api = false if fetchers.none?(&:api_fetcher?)
107
+
108
+ specs[remote_uri].each do |name, version, platform, dependencies|
109
+ next if name == "bundler"
110
+ spec = nil
111
+ if dependencies
112
+ spec = EndpointSpecification.new(name, version, platform, dependencies)
113
+ else
114
+ spec = RemoteSpecification.new(name, version, platform, self)
115
+ end
116
+ spec.source = source
117
+ spec.remote = @remote
118
+ index << spec
119
+ end
120
+
121
+ index
122
+ rescue CertificateFailureError
123
+ Bundler.ui.info "" if gem_names && use_api # newline after dots
124
+ raise
125
+ ensure
126
+ Bundler.rubygems.sources = old
127
+ end
128
+
129
+ def use_api
130
+ return @use_api if defined?(@use_api)
131
+
132
+ if remote_uri.scheme == "file" || Bundler::Fetcher.disable_endpoint
133
+ @use_api = false
134
+ else
135
+ fetchers.reject! {|f| f.api_fetcher? && !f.api_available? }
136
+ @use_api = fetchers.any?(&:api_fetcher?)
137
+ end
138
+ end
139
+
140
+ def user_agent
141
+ @user_agent ||= begin
142
+ ruby = Bundler.ruby_version
143
+
144
+ agent = "bundler/#{Bundler::VERSION}"
145
+ agent << " rubygems/#{Gem::VERSION}"
146
+ agent << " ruby/#{ruby.version}"
147
+ agent << " (#{ruby.host})"
148
+ agent << " command/#{ARGV.first}"
149
+
150
+ if ruby.engine != "ruby"
151
+ # engine_version raises on unknown engines
152
+ engine_version = ruby.engine_version rescue "???"
153
+ agent << " #{ruby.engine}/#{engine_version}"
154
+ end
155
+
156
+ agent << " options/#{Bundler.settings.all.join(",")}"
157
+
158
+ agent << " ci/#{cis.join(",")}" if cis.any?
159
+
160
+ # add a random ID so we can consolidate runs server-side
161
+ agent << " " << SecureRandom.hex(8)
162
+
163
+ # add any user agent strings set in the config
164
+ extra_ua = Bundler.settings[:user_agent]
165
+ agent << " " << extra_ua if extra_ua
166
+
167
+ agent
168
+ end
169
+ end
170
+
171
+ def fetchers
172
+ @fetchers ||= FETCHERS.map {|f| f.new(downloader, remote_uri, fetch_uri, uri) }
173
+ end
174
+
175
+ def http_proxy
176
+ if uri = connection.proxy_uri
177
+ uri.to_s
178
+ else
179
+ nil
180
+ end
181
+ end
182
+
183
+ def inspect
184
+ "#<#{self.class}:0x#{object_id} uri=#{uri}>"
185
+ end
186
+
187
+ private
188
+
189
+ FETCHERS = [Dependency, Index]
190
+
191
+ def cis
192
+ env_cis = {
193
+ "TRAVIS" => "travis",
194
+ "CIRCLECI" => "circle",
195
+ "SEMAPHORE" => "semaphore",
196
+ "JENKINS_URL" => "jenkins",
197
+ "BUILDBOX" => "buildbox",
198
+ "GO_SERVER_URL" => "go",
199
+ "SNAP_CI" => "snap",
200
+ "CI_NAME" => ENV["CI_NAME"],
201
+ "CI" => "ci"
202
+ }
203
+ env_cis.find_all {|env, _| ENV[env] }.map {|_, ci| ci }
204
+ end
205
+
206
+ def connection
207
+ @connection ||= begin
208
+ needs_ssl = remote_uri.scheme == "https" ||
209
+ Bundler.settings[:ssl_verify_mode] ||
210
+ Bundler.settings[:ssl_client_cert]
211
+ raise SSLError if needs_ssl && !defined?(OpenSSL::SSL)
212
+
213
+ con = Net::HTTP::Persistent.new "bundler", :ENV
214
+ if gem_proxy = Bundler.rubygems.configuration[:http_proxy]
215
+ con.proxy = URI.parse(gem_proxy)
216
+ end
217
+
218
+ if remote_uri.scheme == "https"
219
+ con.verify_mode = (Bundler.settings[:ssl_verify_mode] ||
220
+ OpenSSL::SSL::VERIFY_PEER)
221
+ con.cert_store = bundler_cert_store
222
+ end
223
+
224
+ if Bundler.settings[:ssl_client_cert]
225
+ pem = File.read(Bundler.settings[:ssl_client_cert])
226
+ con.cert = OpenSSL::X509::Certificate.new(pem)
227
+ con.key = OpenSSL::PKey::RSA.new(pem)
228
+ end
229
+
230
+ con.read_timeout = Fetcher.api_timeout
231
+ con.override_headers["User-Agent"] = user_agent
232
+ con
233
+ end
234
+ end
235
+
236
+ # cached gem specification path, if one exists
237
+ def gemspec_cached_path(spec_file_name)
238
+ paths = Bundler.rubygems.spec_cache_dirs.map {|dir| File.join(dir, spec_file_name) }
239
+ paths = paths.select {|path| File.file? path }
240
+ paths.first
241
+ end
242
+
243
+ HTTP_ERRORS = [
244
+ Timeout::Error, EOFError, SocketError, Errno::ENETDOWN, Errno::ENETUNREACH,
245
+ Errno::EINVAL, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::EAGAIN,
246
+ Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError,
247
+ Net::HTTP::Persistent::Error
248
+ ]
249
+
250
+ def bundler_cert_store
251
+ store = OpenSSL::X509::Store.new
252
+ if Bundler.settings[:ssl_ca_cert]
253
+ if File.directory? Bundler.settings[:ssl_ca_cert]
254
+ store.add_path Bundler.settings[:ssl_ca_cert]
255
+ else
256
+ store.add_file Bundler.settings[:ssl_ca_cert]
257
+ end
258
+ else
259
+ store.set_default_paths
260
+ certs = File.expand_path("../ssl_certs/*.pem", __FILE__)
261
+ Dir.glob(certs).each {|c| store.add_file c }
262
+ end
263
+ store
264
+ end
265
+
266
+ private
267
+
268
+ def fetch_uri
269
+ @fetch_uri ||= begin
270
+ if remote_uri.host == "rubygems.org"
271
+ uri = remote_uri.dup
272
+ uri.host = "bundler.rubygems.org"
273
+ uri
274
+ else
275
+ remote_uri
276
+ end
277
+ end
278
+ end
279
+
280
+ def remote_uri
281
+ @remote.uri
282
+ end
283
+
284
+ def downloader
285
+ @downloader ||= Downloader.new(connection, self.class.redirect_limit)
286
+ end
287
+ end
288
+ end