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,26 @@
1
+ module Bundler
2
+ class Fetcher
3
+ class Base
4
+ attr_reader :downloader
5
+ attr_reader :remote_uri
6
+ attr_reader :fetch_uri
7
+ attr_reader :display_uri
8
+
9
+ def initialize(downloader, remote_uri, fetch_uri, display_uri)
10
+ raise "Abstract class" if self.class == Base
11
+ @downloader = downloader
12
+ @remote_uri = remote_uri
13
+ @fetch_uri = fetch_uri
14
+ @display_uri = display_uri
15
+ end
16
+
17
+ def api_available?
18
+ api_fetcher?
19
+ end
20
+
21
+ def api_fetcher?
22
+ false
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,88 @@
1
+ require "bundler/fetcher/base"
2
+ require "cgi"
3
+
4
+ module Bundler
5
+ class Fetcher
6
+ class Dependency < Base
7
+ def api_available?
8
+ downloader.fetch(dependency_api_uri)
9
+ rescue NetworkDownError => e
10
+ raise HTTPError, e.message
11
+ rescue AuthenticationRequiredError
12
+ # We got a 401 from the server. Just fail.
13
+ raise
14
+ rescue HTTPError
15
+ end
16
+
17
+ def api_fetcher?
18
+ true
19
+ end
20
+
21
+ def specs(gem_names, full_dependency_list = [], last_spec_list = [])
22
+ query_list = gem_names - full_dependency_list
23
+
24
+ # only display the message on the first run
25
+ if Bundler.ui.debug?
26
+ Bundler.ui.debug "Query List: #{query_list.inspect}"
27
+ else
28
+ Bundler.ui.info ".", false
29
+ end
30
+
31
+ return { remote_uri => last_spec_list } if query_list.empty?
32
+
33
+ remote_specs = Bundler::Retry.new("dependency api", AUTH_ERRORS).attempts do
34
+ dependency_specs(query_list)
35
+ end
36
+
37
+ spec_list, deps_list = remote_specs
38
+ returned_gems = spec_list.map(&:first).uniq
39
+ specs(deps_list, full_dependency_list + returned_gems, spec_list + last_spec_list)
40
+ rescue HTTPError, MarshalError, GemspecError
41
+ Bundler.ui.info "" unless Bundler.ui.debug? # new line now that the dots are over
42
+ Bundler.ui.debug "could not fetch from the dependency API, trying the full index"
43
+ return nil
44
+ end
45
+
46
+ def dependency_specs(gem_names)
47
+ Bundler.ui.debug "Query Gemcutter Dependency Endpoint API: #{gem_names.join(",")}"
48
+ gem_list = []
49
+ deps_list = []
50
+
51
+ gem_names.each_slice(Source::Rubygems::API_REQUEST_SIZE) do |names|
52
+ marshalled_deps = downloader.fetch dependency_api_uri(names)
53
+ gem_list += Bundler.load_marshal(marshalled_deps)
54
+ end
55
+
56
+ spec_list = gem_list.map do |s|
57
+ dependencies = s[:dependencies].map do |name, requirement|
58
+ dep = well_formed_dependency(name, requirement.split(", "))
59
+ deps_list << dep.name
60
+ dep
61
+ end
62
+
63
+ [s[:name], Gem::Version.new(s[:number]), s[:platform], dependencies]
64
+ end
65
+
66
+ [spec_list, deps_list.uniq]
67
+ end
68
+
69
+ def dependency_api_uri(gem_names = [])
70
+ uri = fetch_uri + "api/v1/dependencies"
71
+ uri.query = "gems=#{CGI.escape(gem_names.join(","))}" if gem_names.any?
72
+ uri
73
+ end
74
+
75
+ def well_formed_dependency(name, *requirements)
76
+ Gem::Dependency.new(name, *requirements)
77
+ rescue ArgumentError => e
78
+ illformed = 'Ill-formed requirement ["#<YAML::Syck::DefaultKey'
79
+ raise e unless e.message.include?(illformed)
80
+ puts # we shouldn't print the error message on the "fetching info" status line
81
+ raise GemspecError,
82
+ "Unfortunately, the gem #{s[:name]} (#{s[:number]}) has an invalid " \
83
+ "gemspec. \nPlease ask the gem author to yank the bad version to fix " \
84
+ "this issue. For more information, see http://bit.ly/syck-defaultkey."
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,60 @@
1
+ module Bundler
2
+ class Fetcher
3
+ class Downloader
4
+ attr_reader :connection
5
+ attr_reader :redirect_limit
6
+
7
+ def initialize(connection, redirect_limit)
8
+ @connection = connection
9
+ @redirect_limit = redirect_limit
10
+ end
11
+
12
+ def fetch(uri, counter = 0)
13
+ raise HTTPError, "Too many redirects" if counter >= redirect_limit
14
+
15
+ response = request(uri)
16
+ Bundler.ui.debug("HTTP #{response.code} #{response.message}")
17
+
18
+ case response
19
+ when Net::HTTPRedirection
20
+ new_uri = URI.parse(response["location"])
21
+ if new_uri.host == uri.host
22
+ new_uri.user = uri.user
23
+ new_uri.password = uri.password
24
+ end
25
+ fetch(new_uri, counter + 1)
26
+ when Net::HTTPSuccess
27
+ response.body
28
+ when Net::HTTPRequestEntityTooLarge
29
+ raise FallbackError, response.body
30
+ when Net::HTTPUnauthorized
31
+ raise AuthenticationRequiredError, uri.host
32
+ else
33
+ raise HTTPError, "#{response.class}: #{response.body}"
34
+ end
35
+ end
36
+
37
+ def request(uri)
38
+ Bundler.ui.debug "HTTP GET #{uri}"
39
+ req = Net::HTTP::Get.new uri.request_uri
40
+ if uri.user
41
+ user = CGI.unescape(uri.user)
42
+ password = uri.password ? CGI.unescape(uri.password) : nil
43
+ req.basic_auth(user, password)
44
+ end
45
+ connection.request(uri, req)
46
+ rescue OpenSSL::SSL::SSLError
47
+ raise CertificateFailureError.new(uri)
48
+ rescue *HTTP_ERRORS => e
49
+ Bundler.ui.trace e
50
+ case e.message
51
+ when /host down:/, /getaddrinfo: nodename nor servname provided/
52
+ raise NetworkDownError, "Could not reach host #{uri.host}. Check your network " \
53
+ "connection and try again."
54
+ else
55
+ raise HTTPError, "Network error while fetching #{uri}"
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,32 @@
1
+ require "bundler/fetcher/base"
2
+ require "rubygems/remote_fetcher"
3
+
4
+ module Bundler
5
+ class Fetcher
6
+ class Index < Base
7
+ def specs(_gem_names)
8
+ old_sources = Bundler.rubygems.sources
9
+ Bundler.rubygems.sources = [remote_uri.to_s]
10
+ Bundler.rubygems.fetch_all_remote_specs
11
+ rescue Gem::RemoteFetcher::FetchError, OpenSSL::SSL::SSLError, Net::HTTPFatalError => e
12
+ case e.message
13
+ when /certificate verify failed/
14
+ raise CertificateFailureError.new(display_uri)
15
+ when /401/
16
+ raise AuthenticationRequiredError, remote_uri
17
+ when /403/
18
+ if remote_uri.userinfo
19
+ raise BadAuthenticationError, remote_uri
20
+ else
21
+ raise AuthenticationRequiredError, remote_uri
22
+ end
23
+ else
24
+ Bundler.ui.trace e
25
+ raise HTTPError, "Could not fetch specs from #{display_uri}"
26
+ end
27
+ ensure
28
+ Bundler.rubygems.sources = old_sources
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,92 @@
1
+ # encoding: utf-8
2
+ require "cgi"
3
+ require "bundler/vendored_thor"
4
+
5
+ module Bundler
6
+ def self.with_friendly_errors
7
+ yield
8
+ rescue Bundler::Dsl::DSLError => e
9
+ Bundler.ui.error e.message
10
+ exit e.status_code
11
+ rescue Bundler::GemRequireError => e
12
+ Bundler.ui.error e.message
13
+ Bundler.ui.trace e.orig_exception, nil, true
14
+ exit e.status_code
15
+ rescue Bundler::BundlerError => e
16
+ Bundler.ui.error e.message, :wrap => true
17
+ Bundler.ui.trace e
18
+ exit e.status_code
19
+ rescue Thor::AmbiguousTaskError => e
20
+ Bundler.ui.error e.message
21
+ exit 15
22
+ rescue Thor::UndefinedTaskError => e
23
+ Bundler.ui.error e.message
24
+ exit 15
25
+ rescue Thor::Error => e
26
+ Bundler.ui.error e.message
27
+ exit 1
28
+ rescue LoadError => e
29
+ raise e unless e.message =~ /cannot load such file -- openssl|openssl.so|libcrypto.so/
30
+ Bundler.ui.error "\nCould not load OpenSSL."
31
+ Bundler.ui.warn <<-WARN, :wrap => true
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 http://rvm.io/packages/openssl.
35
+ WARN
36
+ Bundler.ui.trace e
37
+ exit 1
38
+ rescue Interrupt => e
39
+ Bundler.ui.error "\nQuitting..."
40
+ Bundler.ui.trace e
41
+ exit 1
42
+ rescue SystemExit => e
43
+ exit e.status
44
+ rescue Exception => e
45
+ request_issue_report_for(e)
46
+ exit 1
47
+ end
48
+
49
+ def self.request_issue_report_for(e)
50
+ Bundler.ui.info <<-EOS.gsub(/^ {6}/, "")
51
+ --- ERROR REPORT TEMPLATE -------------------------------------------------------
52
+ - What did you do?
53
+
54
+ I ran the command `#{$PROGRAM_NAME} #{ARGV.join(" ")}`
55
+
56
+ - What did you expect to happen?
57
+
58
+ I expected Bundler to...
59
+
60
+ - What happened instead?
61
+
62
+ Instead, what actually happened was...
63
+
64
+
65
+ Error details
66
+
67
+ #{e.class}: #{e.message}
68
+ #{e.backtrace.join("\n ")}
69
+
70
+ #{Bundler::Env.new.report(:print_gemfile => false, :print_gemspecs => false).gsub(/\n/, "\n ").strip}
71
+ --- TEMPLATE END ----------------------------------------------------------------
72
+
73
+ EOS
74
+
75
+ Bundler.ui.error "Unfortunately, an unexpected error occurred, and Bundler cannot continue."
76
+
77
+ Bundler.ui.warn <<-EOS.gsub(/^ {6}/, "")
78
+
79
+ First, try this link to see if there are any existing issue reports for this error:
80
+ #{issues_url(e)}
81
+
82
+ If there aren't any reports for this error yet, please create copy and paste the report template above into a new issue. Don't forget to anonymize any private data! The new issue form is located at:
83
+ https://github.com/bundler/bundler/issues/new
84
+ EOS
85
+ end
86
+
87
+ def self.issues_url(exception)
88
+ "https://github.com/bundler/bundler/search?q=" \
89
+ "#{CGI.escape(exception.message.lines.first.chomp)}&type=Issues"
90
+ end
91
+
92
+ end
@@ -0,0 +1,191 @@
1
+ require "bundler/vendored_thor" unless defined?(Thor)
2
+ require "bundler"
3
+
4
+ module Bundler
5
+ class GemHelper
6
+ include Rake::DSL if defined? Rake::DSL
7
+
8
+ class << self
9
+ # set when install'd.
10
+ attr_accessor :instance
11
+
12
+ def install_tasks(opts = {})
13
+ new(opts[:dir], opts[:name]).install
14
+ end
15
+
16
+ def gemspec(&block)
17
+ gemspec = instance.gemspec
18
+ block.call(gemspec) if block
19
+ gemspec
20
+ end
21
+ end
22
+
23
+ attr_reader :spec_path, :base, :gemspec
24
+
25
+ def initialize(base = nil, name = nil)
26
+ Bundler.ui = UI::Shell.new
27
+ @base = (base ||= SharedHelpers.pwd)
28
+ gemspecs = name ? [File.join(base, "#{name}.gemspec")] : Dir[File.join(base, "{,*}.gemspec")]
29
+ raise "Unable to determine name from existing gemspec. Use :name => 'gemname' in #install_tasks to manually set it." unless gemspecs.size == 1
30
+ @spec_path = gemspecs.first
31
+ @gemspec = Bundler.load_gemspec(@spec_path)
32
+ end
33
+
34
+ def install
35
+ built_gem_path = nil
36
+
37
+ desc "Build #{name}-#{version}.gem into the pkg directory."
38
+ task "build" do
39
+ built_gem_path = build_gem
40
+ end
41
+
42
+ desc "Build and install #{name}-#{version}.gem into system gems."
43
+ task "install" => "build" do
44
+ install_gem(built_gem_path)
45
+ end
46
+
47
+ desc "Build and install #{name}-#{version}.gem into system gems without network access."
48
+ task "install:local" => "build" do
49
+ install_gem(built_gem_path, :local)
50
+ end
51
+
52
+ desc "Create tag #{version_tag} and build and push #{name}-#{version}.gem to Rubygems\n" \
53
+ "To prevent publishing in Rubygems use `gem_push=no rake release`"
54
+ task "release", [:remote] => ["build", "release:guard_clean",
55
+ "release:source_control_push", "release:rubygem_push"] do
56
+ end
57
+
58
+ task "release:guard_clean" do
59
+ guard_clean
60
+ end
61
+
62
+ task "release:source_control_push", [:remote] do |_, args|
63
+ tag_version { git_push(args[:remote]) } unless already_tagged?
64
+ end
65
+
66
+ task "release:rubygem_push" do
67
+ rubygem_push(built_gem_path) if gem_push?
68
+ end
69
+
70
+ GemHelper.instance = self
71
+ end
72
+
73
+ def build_gem
74
+ file_name = nil
75
+ sh("gem build -V '#{spec_path}'") {
76
+ file_name = File.basename(built_gem_path)
77
+ SharedHelpers.filesystem_access(File.join(base, "pkg")) {|p| FileUtils.mkdir_p(p) }
78
+ FileUtils.mv(built_gem_path, "pkg")
79
+ Bundler.ui.confirm "#{name} #{version} built to pkg/#{file_name}."
80
+ }
81
+ File.join(base, "pkg", file_name)
82
+ end
83
+
84
+ def install_gem(built_gem_path = nil, local = false)
85
+ built_gem_path ||= build_gem
86
+ out, _ = sh_with_code("gem install '#{built_gem_path}'#{" --local" if local}")
87
+ raise "Couldn't install gem, run `gem install #{built_gem_path}' for more detailed output" unless out[/Successfully installed/]
88
+ Bundler.ui.confirm "#{name} (#{version}) installed."
89
+ end
90
+
91
+ protected
92
+
93
+ def rubygem_push(path)
94
+ if Pathname.new("~/.gem/credentials").expand_path.exist?
95
+ allowed_push_host = nil
96
+ gem_command = "gem push '#{path}'"
97
+ if spec.respond_to?(:metadata)
98
+ allowed_push_host = @gemspec.metadata["allowed_push_host"]
99
+ gem_command << " --host #{allowed_push_host}" if allowed_push_host
100
+ end
101
+ sh(gem_command)
102
+ Bundler.ui.confirm "Pushed #{name} #{version} to #{allowed_push_host ? allowed_push_host : "rubygems.org."}"
103
+ else
104
+ raise "Your rubygems.org credentials aren't set. Run `gem push` to set them."
105
+ end
106
+ end
107
+
108
+ def built_gem_path
109
+ Dir[File.join(base, "#{name}-*.gem")].sort_by {|f| File.mtime(f) }.last
110
+ end
111
+
112
+ def git_push(remote = "")
113
+ perform_git_push remote
114
+ perform_git_push "#{remote} --tags"
115
+ Bundler.ui.confirm "Pushed git commits and tags."
116
+ end
117
+
118
+ def perform_git_push(options = "")
119
+ cmd = "git push #{options}"
120
+ out, code = sh_with_code(cmd)
121
+ raise "Couldn't git push. `#{cmd}' failed with the following output:\n\n#{out}\n" unless code == 0
122
+ end
123
+
124
+ def already_tagged?
125
+ if sh("git tag").split(/\n/).include?(version_tag)
126
+ Bundler.ui.confirm "Tag #{version_tag} has already been created."
127
+ true
128
+ end
129
+ end
130
+
131
+ def guard_clean
132
+ clean? && committed? or raise("There are files that need to be committed first.")
133
+ end
134
+
135
+ def clean?
136
+ sh_with_code("git diff --exit-code")[1] == 0
137
+ end
138
+
139
+ def committed?
140
+ sh_with_code("git diff-index --quiet --cached HEAD")[1] == 0
141
+ end
142
+
143
+ def tag_version
144
+ sh "git tag -a -m \"Version #{version}\" #{version_tag}"
145
+ Bundler.ui.confirm "Tagged #{version_tag}."
146
+ yield if block_given?
147
+ rescue
148
+ Bundler.ui.error "Untagging #{version_tag} due to error."
149
+ sh_with_code "git tag -d #{version_tag}"
150
+ raise
151
+ end
152
+
153
+ def version
154
+ gemspec.version
155
+ end
156
+
157
+ def version_tag
158
+ "v#{version}"
159
+ end
160
+
161
+ def name
162
+ gemspec.name
163
+ end
164
+
165
+ def sh(cmd, &block)
166
+ out, code = sh_with_code(cmd, &block)
167
+ if code == 0
168
+ out
169
+ else
170
+ raise(out.empty? ? "Running `#{cmd}' failed. Run this command directly for more detailed output." : out)
171
+ end
172
+ end
173
+
174
+ def sh_with_code(cmd, &block)
175
+ cmd << " 2>&1"
176
+ outbuf = ""
177
+ Bundler.ui.debug(cmd)
178
+ SharedHelpers.chdir(base) {
179
+ outbuf = `#{cmd}`
180
+ if $? == 0
181
+ block.call(outbuf) if block
182
+ end
183
+ }
184
+ [outbuf, $?]
185
+ end
186
+
187
+ def gem_push?
188
+ ! %w{n no nil false off 0}.include?(ENV["gem_push"].to_s.downcase)
189
+ end
190
+ end
191
+ end