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
+ module GemHelpers
3
+
4
+ GENERIC_CACHE = {}
5
+ GENERICS = [
6
+ [Gem::Platform.new("java"), Gem::Platform.new("java")],
7
+ [Gem::Platform.new("mswin32"), Gem::Platform.new("mswin32")],
8
+ [Gem::Platform.new("mswin64"), Gem::Platform.new("mswin64")],
9
+ [Gem::Platform.new("universal-mingw32"), Gem::Platform.new("universal-mingw32")],
10
+ [Gem::Platform.new("x64-mingw32"), Gem::Platform.new("x64-mingw32")],
11
+ [Gem::Platform.new("x86_64-mingw32"), Gem::Platform.new("x64-mingw32")],
12
+ [Gem::Platform.new("mingw32"), Gem::Platform.new("x86-mingw32")]
13
+ ]
14
+
15
+ def generic(p)
16
+ return p if p == Gem::Platform::RUBY
17
+
18
+ GENERIC_CACHE[p] ||= begin
19
+ _, found = GENERICS.find do |match, _generic|
20
+ p.os == match.os && (!match.cpu || p.cpu == match.cpu)
21
+ end
22
+ found || Gem::Platform::RUBY
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,9 @@
1
+ require "rubygems/installer"
2
+
3
+ module Bundler
4
+ class GemInstaller < Gem::Installer
5
+ def check_executable_overwrite(filename)
6
+ # Bundler needs to install gems regardless of binstub overwriting
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ module Bundler
2
+ def self.preserve_gem_path
3
+ original_gem_path = ENV["_ORIGINAL_GEM_PATH"]
4
+ gem_path = ENV["GEM_PATH"]
5
+ ENV["_ORIGINAL_GEM_PATH"] = gem_path if original_gem_path.nil? || original_gem_path == ""
6
+ ENV["GEM_PATH"] = original_gem_path if gem_path.nil? || gem_path == ""
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ require "rake/clean"
2
+ CLOBBER.include "pkg"
3
+
4
+ require "bundler/gem_helper"
5
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,173 @@
1
+ require "set"
2
+ module Bundler
3
+ class Graph
4
+ GRAPH_NAME = :Gemfile
5
+
6
+ def initialize(env, output_file, show_version = false, show_requirements = false, output_format = "png", without = [])
7
+ @env = env
8
+ @output_file = output_file
9
+ @show_version = show_version
10
+ @show_requirements = show_requirements
11
+ @output_format = output_format
12
+ @without_groups = without.map(&:to_sym)
13
+
14
+ @groups = []
15
+ @relations = Hash.new {|h, k| h[k] = Set.new }
16
+ @node_options = {}
17
+ @edge_options = {}
18
+
19
+ _patching_gem_dependency_class
20
+ _populate_relations
21
+ end
22
+
23
+ attr_reader :groups, :relations, :node_options, :edge_options, :output_file, :output_format
24
+
25
+ def viz
26
+ GraphVizClient.new(self).run
27
+ end
28
+
29
+ private
30
+
31
+ def _populate_relations
32
+ parent_dependencies = _groups.values.to_set.flatten
33
+ loop do
34
+ if parent_dependencies.empty?
35
+ break
36
+ else
37
+ tmp = Set.new
38
+ parent_dependencies.each do |dependency|
39
+ # if the dependency is a prerelease, allow to_spec to be non-nil
40
+ dependency.prerelease = true
41
+
42
+ child_dependencies = dependency.to_spec.runtime_dependencies.to_set
43
+ @relations[dependency.name] += child_dependencies.map(&:name).to_set
44
+ tmp += child_dependencies
45
+
46
+ @node_options[dependency.name] = _make_label(dependency, :node)
47
+ child_dependencies.each do |c_dependency|
48
+ @edge_options["#{dependency.name}_#{c_dependency.name}"] = _make_label(c_dependency, :edge)
49
+ end
50
+ end
51
+ parent_dependencies = tmp
52
+ end
53
+ end
54
+ end
55
+
56
+ def _groups
57
+ relations = Hash.new {|h, k| h[k] = Set.new }
58
+ @env.current_dependencies.each do |dependency|
59
+ dependency.groups.each do |group|
60
+ next if @without_groups.include?(group)
61
+
62
+ relations[group.to_s].add(dependency)
63
+ @relations[group.to_s].add(dependency.name)
64
+
65
+ @node_options[group.to_s] ||= _make_label(group, :node)
66
+ @edge_options["#{group}_#{dependency.name}"] = _make_label(dependency, :edge)
67
+ end
68
+ end
69
+ @groups = relations.keys
70
+ relations
71
+ end
72
+
73
+ def _make_label(symbol_or_string_or_dependency, element_type)
74
+ case element_type.to_sym
75
+ when :node
76
+ if symbol_or_string_or_dependency.is_a?(Gem::Dependency)
77
+ label = symbol_or_string_or_dependency.name.dup
78
+ label << "\n#{symbol_or_string_or_dependency.to_spec.version}" if @show_version
79
+ else
80
+ label = symbol_or_string_or_dependency.to_s
81
+ end
82
+ when :edge
83
+ label = nil
84
+ if symbol_or_string_or_dependency.respond_to?(:requirements_list) && @show_requirements
85
+ tmp = symbol_or_string_or_dependency.requirements_list.join(", ")
86
+ label = tmp if tmp != ">= 0"
87
+ end
88
+ else
89
+ raise ArgumentError, "2nd argument is invalid"
90
+ end
91
+ label.nil? ? {} : { :label => label }
92
+ end
93
+
94
+ def _patching_gem_dependency_class
95
+ # method borrow from rubygems/dependency.rb
96
+ # redefinition of matching_specs will also redefine to_spec and to_specs
97
+ Gem::Dependency.class_eval do
98
+ def matching_specs(platform_only = false)
99
+ matches = Bundler.load.specs.select { |spec|
100
+ self.name == spec.name and
101
+ requirement.satisfied_by? spec.version
102
+ }
103
+
104
+ if platform_only
105
+ matches.select! { |spec|
106
+ Gem::Platform.match spec.platform
107
+ }
108
+ end
109
+
110
+ matches = matches.sort_by(&:sort_obj) # HACK: shouldn't be needed
111
+ end
112
+ end
113
+ end
114
+
115
+ class GraphVizClient
116
+ def initialize(graph_instance)
117
+ @graph_name = graph_instance.class::GRAPH_NAME
118
+ @groups = graph_instance.groups
119
+ @relations = graph_instance.relations
120
+ @node_options = graph_instance.node_options
121
+ @edge_options = graph_instance.edge_options
122
+ @output_file = graph_instance.output_file
123
+ @output_format = graph_instance.output_format
124
+ end
125
+
126
+ def g
127
+ @g ||= ::GraphViz.digraph(@graph_name, :concentrate => true, :normalize => true, :nodesep => 0.55) do |g|
128
+ g.edge[:weight] = 2
129
+ g.edge[:fontname] = g.node[:fontname] = "Arial, Helvetica, SansSerif"
130
+ g.edge[:fontsize] = 12
131
+ end
132
+ end
133
+
134
+ def run
135
+ @groups.each do |group|
136
+ g.add_nodes(
137
+ group, {
138
+ :style => "filled",
139
+ :fillcolor => "#B9B9D5",
140
+ :shape => "box3d",
141
+ :fontsize => 16
142
+ }.merge(@node_options[group])
143
+ )
144
+ end
145
+
146
+ @relations.each do |parent, children|
147
+ children.each do |child|
148
+ if @groups.include?(parent)
149
+ g.add_nodes(child, { :style => "filled", :fillcolor => "#B9B9D5" }.merge(@node_options[child]))
150
+ g.add_edges(parent, child, { :constraint => false }.merge(@edge_options["#{parent}_#{child}"]))
151
+ else
152
+ g.add_nodes(child, @node_options[child])
153
+ g.add_edges(parent, child, @edge_options["#{parent}_#{child}"])
154
+ end
155
+ end
156
+ end
157
+
158
+ if @output_format.to_s == "debug"
159
+ $stdout.puts g.output :none => String
160
+ Bundler.ui.info "debugging bundle viz..."
161
+ else
162
+ begin
163
+ g.output @output_format.to_sym => "#{@output_file}.#{@output_format}"
164
+ Bundler.ui.info "#{@output_file}.#{@output_format}"
165
+ rescue ArgumentError => e
166
+ $stderr.puts "Unsupported output format. See Ruby-Graphviz/lib/graphviz/constants.rb"
167
+ raise e
168
+ end
169
+ end
170
+ end
171
+ end
172
+ end
173
+ end
@@ -0,0 +1,199 @@
1
+ require "set"
2
+
3
+ module Bundler
4
+ class Index
5
+ include Enumerable
6
+
7
+ def self.build
8
+ i = new
9
+ yield i
10
+ i
11
+ end
12
+
13
+ attr_reader :specs, :all_specs, :sources
14
+ protected :specs, :all_specs
15
+
16
+ RUBY = "ruby".freeze
17
+ NULL = "\0".freeze
18
+
19
+ def initialize
20
+ @sources = []
21
+ @cache = {}
22
+ @specs = Hash.new {|h, k| h[k] = {} }
23
+ @all_specs = Hash.new {|h, k| h[k] = [] }
24
+ end
25
+
26
+ def initialize_copy(o)
27
+ super
28
+ @sources = @sources.dup
29
+ @cache = {}
30
+ @specs = Hash.new {|h, k| h[k] = {} }
31
+ @all_specs = Hash.new {|h, k| h[k] = [] }
32
+
33
+ o.specs.each do |name, hash|
34
+ @specs[name] = hash.dup
35
+ end
36
+ o.all_specs.each do |name, array|
37
+ @all_specs[name] = array.dup
38
+ end
39
+ end
40
+
41
+ def inspect
42
+ "#<#{self.class}:0x#{object_id} sources=#{sources.map(&:inspect)} specs.size=#{specs.size}>"
43
+ end
44
+
45
+ def empty?
46
+ each { return false }
47
+ true
48
+ end
49
+
50
+ def search_all(name)
51
+ all_matches = @all_specs[name] + local_search(name)
52
+ @sources.each do |source|
53
+ all_matches.concat(source.search_all(name))
54
+ end
55
+ all_matches
56
+ end
57
+
58
+ # Search this index's specs, and any source indexes that this index knows
59
+ # about, returning all of the results.
60
+ def search(query, base = nil)
61
+ results = local_search(query, base)
62
+ seen = Set.new(results.map {|spec| [spec.name, spec.version, spec.platform] })
63
+
64
+ @sources.each do |source|
65
+ source.search(query, base).each do |spec|
66
+ lookup = [spec.name, spec.version, spec.platform]
67
+ unless seen.include?(lookup)
68
+ results << spec
69
+ seen << lookup
70
+ end
71
+ end
72
+ end
73
+
74
+ results.sort_by {|s| [s.version, s.platform.to_s == RUBY ? NULL : s.platform.to_s] }
75
+ end
76
+
77
+ def local_search(query, base = nil)
78
+ case query
79
+ when Gem::Specification, RemoteSpecification, LazySpecification, EndpointSpecification then search_by_spec(query)
80
+ when String then specs_by_name(query)
81
+ when Gem::Dependency then search_by_dependency(query, base)
82
+ else
83
+ raise "You can't search for a #{query.inspect}."
84
+ end
85
+ end
86
+
87
+ alias_method :[], :search
88
+
89
+ def <<(spec)
90
+ @specs[spec.name]["#{spec.version}-#{spec.platform}"] = spec
91
+
92
+ spec
93
+ end
94
+
95
+ def each(&blk)
96
+ specs.values.each do |spec_sets|
97
+ spec_sets.values.each(&blk)
98
+ end
99
+ end
100
+
101
+ # returns a list of the dependencies
102
+ def unmet_dependency_names
103
+ names = dependency_names
104
+ names.delete_if {|n| n == "bundler" }
105
+ names.select {|n| search(n).empty? }
106
+ end
107
+
108
+ def dependency_names
109
+ names = []
110
+ each {|s| names.push(*s.dependencies.map(&:name)) }
111
+ names.uniq
112
+ end
113
+
114
+ def use(other, override_dupes = false)
115
+ return unless other
116
+ other.each do |s|
117
+ if (dupes = search_by_spec(s)) && dupes.any?
118
+ @all_specs[s.name] = [s] + dupes
119
+ next unless override_dupes
120
+ self << s
121
+ end
122
+ self << s
123
+ end
124
+ self
125
+ end
126
+
127
+ def size
128
+ @sources.inject(@specs.size) do |size, source|
129
+ size += source.size
130
+ end
131
+ end
132
+
133
+ def ==(other)
134
+ all? do |spec|
135
+ other_spec = other[spec].first
136
+ (spec.dependencies & other_spec.dependencies).empty? && spec.source == other_spec.source
137
+ end
138
+ end
139
+
140
+ def add_source(index)
141
+ if index.is_a?(Index)
142
+ @sources << index
143
+ @sources.uniq! # need to use uniq! here instead of checking for the item before adding
144
+ else
145
+ raise ArgumentError, "Source must be an index, not #{index.class}"
146
+ end
147
+ end
148
+
149
+ private
150
+
151
+ def specs_by_name(name)
152
+ @specs[name].values
153
+ end
154
+
155
+ def search_by_dependency(dependency, base = nil)
156
+ @cache[base || false] ||= {}
157
+ @cache[base || false][dependency] ||= begin
158
+ specs = specs_by_name(dependency.name) + (base || [])
159
+ found = specs.select do |spec|
160
+ if base # allow all platforms when searching from a lockfile
161
+ dependency.matches_spec?(spec)
162
+ else
163
+ dependency.matches_spec?(spec) && Gem::Platform.match(spec.platform)
164
+ end
165
+ end
166
+
167
+ wants_prerelease = dependency.requirement.prerelease?
168
+ only_prerelease = specs.all? {|spec| spec.version.prerelease? }
169
+
170
+ unless wants_prerelease || only_prerelease
171
+ found.reject! {|spec| spec.version.prerelease? }
172
+ end
173
+
174
+ found
175
+ end
176
+ end
177
+
178
+ def search_by_spec(spec)
179
+ spec = @specs[spec.name]["#{spec.version}-#{spec.platform}"]
180
+ spec ? [spec] : []
181
+ end
182
+
183
+ if RUBY_VERSION < "1.9"
184
+ def same_version?(a, b)
185
+ regex = /^(.*?)(?:\.0)*$/
186
+ a.to_s[regex, 1] == b.to_s[regex, 1]
187
+ end
188
+ else
189
+ def same_version?(a, b)
190
+ a == b
191
+ end
192
+ end
193
+
194
+ def spec_satisfies_dependency?(spec, dep)
195
+ return false unless dep.name == spec.name
196
+ dep.requirement.satisfied_by?(spec.version)
197
+ end
198
+ end
199
+ end
@@ -0,0 +1,62 @@
1
+ module Bundler
2
+ class Injector
3
+ def self.inject(new_deps)
4
+ injector = new(new_deps)
5
+ injector.inject(Bundler.default_gemfile, Bundler.default_lockfile)
6
+ end
7
+
8
+ def initialize(new_deps)
9
+ @new_deps = new_deps
10
+ end
11
+
12
+ def inject(gemfile_path, lockfile_path)
13
+ if Bundler.settings[:frozen]
14
+ # ensure the lock and Gemfile are synced
15
+ Bundler.definition.ensure_equivalent_gemfile_and_lockfile(true)
16
+ # temporarily remove frozen while we inject
17
+ frozen = Bundler.settings.delete(:frozen)
18
+ end
19
+
20
+ # evaluate the Gemfile we have now
21
+ builder = Dsl.new
22
+ builder.eval_gemfile(gemfile_path)
23
+
24
+ # don't inject any gems that are already in the Gemfile
25
+ @new_deps -= builder.dependencies
26
+
27
+ # add new deps to the end of the in-memory Gemfile
28
+ builder.eval_gemfile("injected gems", new_gem_lines) if @new_deps.any?
29
+
30
+ # resolve to see if the new deps broke anything
31
+ definition = builder.to_definition(lockfile_path, {})
32
+ definition.resolve_remotely!
33
+
34
+ # since nothing broke, we can add those gems to the gemfile
35
+ append_to(gemfile_path) if @new_deps.any?
36
+
37
+ # since we resolved successfully, write out the lockfile
38
+ definition.lock(Bundler.default_lockfile)
39
+
40
+ # return an array of the deps that we added
41
+ return @new_deps
42
+ ensure
43
+ Bundler.settings[:frozen] = "1" if frozen
44
+ end
45
+
46
+ private
47
+
48
+ def new_gem_lines
49
+ @new_deps.map do |d|
50
+ %|gem '#{d.name}', '#{d.requirement}'|
51
+ end.join("\n")
52
+ end
53
+
54
+ def append_to(gemfile_path)
55
+ gemfile_path.open("a") do |f|
56
+ f.puts
57
+ f.puts "# Added at #{Time.now} by #{`whoami`.chomp}:"
58
+ f.puts new_gem_lines
59
+ end
60
+ end
61
+ end
62
+ end