berkshelf 5.2.0 → 8.0.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +19 -47
  3. data/Rakefile +14 -4
  4. data/berkshelf.gemspec +61 -40
  5. data/bin/berks +2 -2
  6. data/lib/berkshelf/api-client.rb +1 -0
  7. data/lib/berkshelf/api_client/chef_server_connection.rb +29 -0
  8. data/lib/berkshelf/api_client/connection.rb +57 -0
  9. data/lib/berkshelf/api_client/errors.rb +10 -0
  10. data/lib/berkshelf/api_client/remote_cookbook.rb +56 -0
  11. data/lib/berkshelf/api_client/version.rb +5 -0
  12. data/lib/berkshelf/api_client.rb +24 -0
  13. data/lib/berkshelf/berksfile.rb +149 -122
  14. data/lib/berkshelf/cached_cookbook.rb +127 -24
  15. data/lib/berkshelf/chef_config_compat.rb +51 -0
  16. data/lib/berkshelf/chef_repo_universe.rb +47 -0
  17. data/lib/berkshelf/cli.rb +143 -174
  18. data/lib/berkshelf/commands/shelf.rb +20 -19
  19. data/lib/berkshelf/community_rest.rb +59 -94
  20. data/lib/berkshelf/config.rb +97 -127
  21. data/lib/berkshelf/cookbook_store.rb +7 -6
  22. data/lib/berkshelf/core_ext/file.rb +1 -1
  23. data/lib/berkshelf/core_ext/file_utils.rb +4 -4
  24. data/lib/berkshelf/core_ext.rb +1 -1
  25. data/lib/berkshelf/dependency.rb +25 -32
  26. data/lib/berkshelf/downloader.rb +66 -39
  27. data/lib/berkshelf/errors.rb +23 -17
  28. data/lib/berkshelf/file_syncer.rb +24 -47
  29. data/lib/berkshelf/formatters/human.rb +7 -5
  30. data/lib/berkshelf/formatters/json.rb +6 -6
  31. data/lib/berkshelf/installer.rb +120 -111
  32. data/lib/berkshelf/location.rb +14 -14
  33. data/lib/berkshelf/locations/base.rb +1 -1
  34. data/lib/berkshelf/locations/git.rb +16 -24
  35. data/lib/berkshelf/locations/github.rb +2 -2
  36. data/lib/berkshelf/locations/path.rb +2 -2
  37. data/lib/berkshelf/lockfile.rb +326 -328
  38. data/lib/berkshelf/logger.rb +64 -1
  39. data/lib/berkshelf/mixin/git.rb +6 -5
  40. data/lib/berkshelf/packager.rb +44 -10
  41. data/lib/berkshelf/resolver/graph.rb +1 -1
  42. data/lib/berkshelf/resolver.rb +4 -4
  43. data/lib/berkshelf/ridley_compat.rb +109 -0
  44. data/lib/berkshelf/shell.rb +2 -1
  45. data/lib/berkshelf/shell_out.rb +18 -0
  46. data/lib/berkshelf/source.rb +77 -33
  47. data/lib/berkshelf/source_uri.rb +4 -4
  48. data/lib/berkshelf/ssl_policies.rb +38 -0
  49. data/lib/berkshelf/thor.rb +1 -1
  50. data/lib/berkshelf/thor_ext/hash_with_indifferent_access.rb +1 -1
  51. data/lib/berkshelf/thor_ext.rb +1 -1
  52. data/lib/berkshelf/uploader.rb +106 -70
  53. data/lib/berkshelf/validator.rb +13 -5
  54. data/lib/berkshelf/version.rb +1 -1
  55. data/lib/berkshelf/visualizer.rb +16 -11
  56. data/lib/berkshelf.rb +106 -81
  57. data/spec/config/knife.rb +4 -4
  58. data/spec/data/trusted_certs/example.crt +22 -0
  59. data/spec/fixtures/Berksfile +3 -3
  60. data/spec/fixtures/complex-cookbook-path/cookbooks/app/metadata.rb +2 -0
  61. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins/metadata.rb +2 -0
  62. data/spec/fixtures/complex-cookbook-path/cookbooks/jenkins-config/metadata.rb +4 -0
  63. data/spec/fixtures/cookbook-path/jenkins-config/metadata.rb +3 -3
  64. data/spec/fixtures/cookbook-path-uploader/apt-2.3.6/metadata.rb +2 -0
  65. data/spec/fixtures/cookbook-path-uploader/build-essential-1.4.2/metadata.rb +2 -0
  66. data/spec/fixtures/cookbook-path-uploader/jenkins-2.0.3/metadata.rb +5 -0
  67. data/spec/fixtures/cookbook-path-uploader/jenkins-config-0.1.0/metadata.rb +4 -0
  68. data/spec/fixtures/cookbook-path-uploader/runit-1.5.8/metadata.rb +5 -0
  69. data/spec/fixtures/cookbook-path-uploader/yum-3.0.6/metadata.rb +2 -0
  70. data/spec/fixtures/cookbook-path-uploader/yum-epel-0.2.0/metadata.rb +3 -0
  71. data/spec/fixtures/cookbook-store/jenkins-2.0.3/metadata.rb +5 -5
  72. data/spec/fixtures/cookbook-store/jenkins-2.0.4/metadata.rb +4 -4
  73. data/spec/fixtures/cookbooks/example_cookbook/metadata.rb +3 -3
  74. data/spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb +3 -3
  75. data/spec/spec_helper.rb +56 -64
  76. data/spec/support/chef_api.rb +15 -16
  77. data/spec/support/chef_server.rb +71 -69
  78. data/spec/support/git.rb +59 -58
  79. data/spec/support/kitchen.rb +0 -14
  80. data/spec/support/matchers/file_system_matchers.rb +4 -5
  81. data/spec/support/matchers/filepath_matchers.rb +2 -2
  82. data/spec/support/path_helpers.rb +17 -17
  83. data/spec/support/shared_examples/formatter.rb +1 -1
  84. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/attributes/default.rb +0 -0
  85. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/files/default/file.h +0 -0
  86. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/metadata.rb +2 -0
  87. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/recipes/default.rb +0 -0
  88. data/spec/tmp/berkshelf/cookbooks/fake-0.1.0/templates/default/template.erb +0 -0
  89. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/attributes/default.rb +0 -0
  90. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/files/default/file.h +0 -0
  91. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/metadata.rb +2 -0
  92. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/recipes/default.rb +0 -0
  93. data/spec/tmp/berkshelf/cookbooks/fake-0.2.0/templates/default/template.erb +0 -0
  94. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/attributes/default.rb +0 -0
  95. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/files/default/file.h +0 -0
  96. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/metadata.rb +2 -0
  97. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/recipes/default.rb +0 -0
  98. data/spec/tmp/berkshelf/cookbooks/fake-1.0.0/templates/default/template.erb +0 -0
  99. data/spec/unit/berkshelf/berksfile_spec.rb +84 -105
  100. data/spec/unit/berkshelf/berkshelf/api_client/chef_server_connection_spec.rb +65 -0
  101. data/spec/unit/berkshelf/berkshelf/api_client/connection_spec.rb +157 -0
  102. data/spec/unit/berkshelf/berkshelf/api_client/remote_cookbook_spec.rb +23 -0
  103. data/spec/unit/berkshelf/berkshelf/api_client_spec.rb +9 -0
  104. data/spec/unit/berkshelf/cached_cookbook_spec.rb +45 -47
  105. data/spec/unit/berkshelf/chef_repo_universe_spec.rb +37 -0
  106. data/spec/unit/berkshelf/cli_spec.rb +7 -8
  107. data/spec/unit/berkshelf/community_rest_spec.rb +82 -90
  108. data/spec/unit/berkshelf/config_spec.rb +51 -22
  109. data/spec/unit/berkshelf/cookbook_store_spec.rb +41 -41
  110. data/spec/unit/berkshelf/core_ext/file_utils_spec.rb +7 -8
  111. data/spec/unit/berkshelf/core_ext/pathname_spec.rb +1 -1
  112. data/spec/unit/berkshelf/dependency_spec.rb +48 -48
  113. data/spec/unit/berkshelf/downloader_spec.rb +191 -34
  114. data/spec/unit/berkshelf/errors_spec.rb +3 -3
  115. data/spec/unit/berkshelf/file_syncer_spec.rb +87 -87
  116. data/spec/unit/berkshelf/formatters/base_spec.rb +23 -23
  117. data/spec/unit/berkshelf/formatters/human_spec.rb +2 -2
  118. data/spec/unit/berkshelf/formatters/json_spec.rb +2 -2
  119. data/spec/unit/berkshelf/formatters/null_spec.rb +3 -3
  120. data/spec/unit/berkshelf/installer_spec.rb +8 -8
  121. data/spec/unit/berkshelf/location_spec.rb +11 -11
  122. data/spec/unit/berkshelf/locations/base_spec.rb +35 -36
  123. data/spec/unit/berkshelf/locations/git_spec.rb +90 -93
  124. data/spec/unit/berkshelf/locations/path_spec.rb +40 -41
  125. data/spec/unit/berkshelf/lockfile_parser_spec.rb +71 -71
  126. data/spec/unit/berkshelf/lockfile_spec.rb +205 -211
  127. data/spec/unit/berkshelf/logger_spec.rb +3 -3
  128. data/spec/unit/berkshelf/mixin/logging_spec.rb +5 -5
  129. data/spec/unit/berkshelf/packager_spec.rb +2 -2
  130. data/spec/unit/berkshelf/resolver/graph_spec.rb +10 -8
  131. data/spec/unit/berkshelf/resolver_spec.rb +17 -17
  132. data/spec/unit/berkshelf/ridley_compat_spec.rb +16 -0
  133. data/spec/unit/berkshelf/shell_spec.rb +34 -34
  134. data/spec/unit/berkshelf/source_spec.rb +186 -20
  135. data/spec/unit/berkshelf/source_uri_spec.rb +1 -1
  136. data/spec/unit/berkshelf/ssl_policies_spec.rb +86 -0
  137. data/spec/unit/berkshelf/uploader_spec.rb +146 -64
  138. data/spec/unit/berkshelf/validator_spec.rb +23 -16
  139. data/spec/unit/berkshelf/visualizer_spec.rb +24 -15
  140. data/spec/unit/berkshelf_spec.rb +18 -18
  141. metadata +138 -289
  142. data/.gitignore +0 -29
  143. data/.travis.yml +0 -64
  144. data/CHANGELOG.legacy.md +0 -307
  145. data/CHANGELOG.md +0 -1358
  146. data/CONTRIBUTING.md +0 -64
  147. data/Gemfile.lock +0 -399
  148. data/Guardfile +0 -23
  149. data/PLUGINS.md +0 -25
  150. data/README.md +0 -70
  151. data/Thorfile +0 -61
  152. data/appveyor.yml +0 -31
  153. data/docs/berkshelf_for_newcomers.md +0 -65
  154. data/features/berksfile.feature +0 -46
  155. data/features/commands/apply.feature +0 -41
  156. data/features/commands/contingent.feature +0 -48
  157. data/features/commands/cookbook.feature +0 -35
  158. data/features/commands/info.feature +0 -99
  159. data/features/commands/init.feature +0 -27
  160. data/features/commands/install.feature +0 -636
  161. data/features/commands/list.feature +0 -78
  162. data/features/commands/outdated.feature +0 -130
  163. data/features/commands/package.feature +0 -17
  164. data/features/commands/search.feature +0 -17
  165. data/features/commands/shelf/list.feature +0 -32
  166. data/features/commands/shelf/show.feature +0 -143
  167. data/features/commands/shelf/uninstall.feature +0 -96
  168. data/features/commands/show.feature +0 -83
  169. data/features/commands/update.feature +0 -142
  170. data/features/commands/upload.feature +0 -426
  171. data/features/commands/vendor.feature +0 -111
  172. data/features/commands/verify.feature +0 -29
  173. data/features/commands/viz.feature +0 -66
  174. data/features/community_site.feature +0 -37
  175. data/features/config.feature +0 -111
  176. data/features/help.feature +0 -11
  177. data/features/json_formatter.feature +0 -161
  178. data/features/lifecycle.feature +0 -378
  179. data/features/lockfile.feature +0 -378
  180. data/features/step_definitions/berksfile_steps.rb +0 -39
  181. data/features/step_definitions/chef/config_steps.rb +0 -12
  182. data/features/step_definitions/chef_server_steps.rb +0 -60
  183. data/features/step_definitions/cli_steps.rb +0 -18
  184. data/features/step_definitions/config_steps.rb +0 -46
  185. data/features/step_definitions/environment_steps.rb +0 -7
  186. data/features/step_definitions/filesystem_steps.rb +0 -269
  187. data/features/step_definitions/gem_steps.rb +0 -13
  188. data/features/step_definitions/json_steps.rb +0 -23
  189. data/features/step_definitions/utility_steps.rb +0 -11
  190. data/features/support/aruba.rb +0 -12
  191. data/features/support/env.rb +0 -82
  192. data/generator_files/Berksfile.erb +0 -11
  193. data/generator_files/CHANGELOG.md.erb +0 -3
  194. data/generator_files/Gemfile.erb +0 -8
  195. data/generator_files/README.md.erb +0 -42
  196. data/generator_files/Thorfile.erb +0 -11
  197. data/generator_files/Vagrantfile.erb +0 -117
  198. data/generator_files/chefignore +0 -94
  199. data/generator_files/default_recipe.erb +0 -6
  200. data/generator_files/default_test.rb.erb +0 -11
  201. data/generator_files/gitignore.erb +0 -23
  202. data/generator_files/helpers.rb.erb +0 -7
  203. data/generator_files/licenses/apachev2.erb +0 -13
  204. data/generator_files/licenses/gplv2.erb +0 -15
  205. data/generator_files/licenses/gplv3.erb +0 -14
  206. data/generator_files/licenses/mit.erb +0 -20
  207. data/generator_files/licenses/reserved.erb +0 -3
  208. data/generator_files/metadata.rb.erb +0 -11
  209. data/lib/berkshelf/base_generator.rb +0 -43
  210. data/lib/berkshelf/commands/test_command.rb +0 -13
  211. data/lib/berkshelf/cookbook_generator.rb +0 -133
  212. data/lib/berkshelf/init_generator.rb +0 -195
  213. data/spec/fixtures/cookbooks/example_cookbook/.gitignore +0 -2
  214. data/spec/fixtures/cookbooks/example_cookbook/.kitchen.yml +0 -26
  215. data/spec/unit/berkshelf/cookbook_generator_spec.rb +0 -110
  216. data/spec/unit/berkshelf/init_generator_spec.rb +0 -263
@@ -1,4 +1,6 @@
1
- require 'berkshelf/api-client'
1
+ require_relative "api-client"
2
+ require "concurrent/executors"
3
+ require "concurrent/future"
2
4
 
3
5
  module Berkshelf
4
6
  class Installer
@@ -10,19 +12,20 @@ module Berkshelf
10
12
  def initialize(berksfile)
11
13
  @berksfile = berksfile
12
14
  @lockfile = berksfile.lockfile
13
- @worker = Worker.pool(size: [(Celluloid.cores.to_i - 1), 2].max, args: [berksfile])
15
+ @pool = Concurrent::FixedThreadPool.new([Concurrent.processor_count - 1, 2].max)
16
+ @worker = Worker.new(berksfile)
14
17
  end
15
18
 
16
19
  def build_universe
17
20
  berksfile.sources.collect do |source|
18
21
  Thread.new do
19
- begin
20
- Berkshelf.formatter.msg("Fetching cookbook index from #{source.uri}...")
21
- source.build_universe
22
- rescue Berkshelf::APIClientError => ex
23
- Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
24
- Berkshelf.formatter.warn " * [#{ex.class}] #{ex}"
25
- end
22
+
23
+ Berkshelf.formatter.msg("Fetching cookbook index from #{source}...")
24
+ source.build_universe
25
+ rescue Berkshelf::APIClientError => ex
26
+ Berkshelf.formatter.warn "Error retrieving universe from source: #{source}"
27
+ Berkshelf.formatter.warn " * [#{ex.class}] #{ex}"
28
+
26
29
  end
27
30
  end.map(&:join)
28
31
  end
@@ -31,13 +34,14 @@ module Berkshelf
31
34
  def run
32
35
  lockfile.reduce!
33
36
 
34
- Berkshelf.formatter.msg('Resolving cookbook dependencies...')
37
+ Berkshelf.formatter.msg("Resolving cookbook dependencies...")
35
38
 
36
- dependencies, cookbooks = if lockfile.trusted?
37
- install_from_lockfile
38
- else
39
- install_from_universe
40
- end
39
+ dependencies, cookbooks =
40
+ if lockfile.trusted?
41
+ install_from_lockfile
42
+ else
43
+ install_from_universe
44
+ end
41
45
 
42
46
  Berkshelf.log.debug " Finished resolving, calculating locks"
43
47
 
@@ -59,131 +63,136 @@ module Berkshelf
59
63
 
60
64
  private
61
65
 
62
- attr_reader :worker
63
-
64
- class Worker
65
- include Celluloid
66
+ attr_reader :worker
67
+ attr_reader :pool
66
68
 
67
- attr_reader :berksfile
68
- attr_reader :downloader
69
+ class Worker
70
+ attr_reader :berksfile
71
+ attr_reader :downloader
69
72
 
70
- def initialize(berksfile)
71
- @berksfile = berksfile
72
- @downloader = Downloader.new(berksfile)
73
- end
73
+ def initialize(berksfile)
74
+ @berksfile = berksfile
75
+ @downloader = Downloader.new(berksfile)
76
+ end
74
77
 
75
- # Install a specific dependency.
76
- #
77
- # @param [Dependency]
78
- # the dependency to install
79
- # @return [CachedCookbook]
80
- # the installed cookbook
81
- def install(dependency)
82
- Berkshelf.log.info "Installing #{dependency}"
78
+ # Install a specific dependency.
79
+ #
80
+ # @param [Dependency]
81
+ # the dependency to install
82
+ # @return [CachedCookbook]
83
+ # the installed cookbook
84
+ def install(dependency)
85
+ Berkshelf.log.info "Installing #{dependency}"
83
86
 
84
- if dependency.installed?
85
- Berkshelf.log.debug " Already installed - skipping install"
87
+ if dependency.installed?
88
+ Berkshelf.log.debug " Already installed - skipping install"
86
89
 
87
- Berkshelf.formatter.use(dependency)
88
- dependency.cached_cookbook
89
- else
90
- name, version = dependency.name, dependency.locked_version.to_s
91
- source = berksfile.source_for(name, version)
90
+ Berkshelf.formatter.use(dependency)
91
+ dependency.cached_cookbook
92
+ else
93
+ name, version = dependency.name, dependency.locked_version.to_s
94
+ source = berksfile.source_for(name, version)
92
95
 
93
- # Raise error if our Berksfile.lock has cookbook versions that
94
- # can't be found in sources
95
- raise MissingLockfileCookbookVersion.new(name, version, 'in any of the sources') unless source
96
+ # Raise error if our Berksfile.lock has cookbook versions that
97
+ # can't be found in sources
98
+ raise MissingLockfileCookbookVersion.new(name, version, "in any of the sources") unless source
96
99
 
97
- Berkshelf.log.debug " Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"
100
+ Berkshelf.log.debug " Downloading #{dependency.name} (#{dependency.locked_version}) from #{source}"
98
101
 
99
- cookbook = source.cookbook(name, version)
102
+ cookbook = source.cookbook(name, version)
100
103
 
101
- Berkshelf.log.debug " => #{cookbook.inspect}"
104
+ Berkshelf.log.debug " => #{cookbook.inspect}"
102
105
 
103
- Berkshelf.formatter.install(source, cookbook)
106
+ Berkshelf.formatter.install(source, cookbook)
104
107
 
105
- downloader.download(name, version) do |stash|
106
- CookbookStore.import(name, version, stash)
107
- end
108
+ downloader.download(name, version) do |stash|
109
+ CookbookStore.import(name, version, stash)
108
110
  end
109
111
  end
110
112
  end
113
+ end
111
114
 
112
- # Install all the dependencies from the lockfile graph.
113
- #
114
- # @return [Array<Array<Dependency> Array<CachedCookbook>>]
115
- # the list of installed dependencies and cookbooks
116
- def install_from_lockfile
117
- Berkshelf.log.info "Installing from lockfile"
118
-
119
- dependencies = lockfile.graph.locks.values
120
-
121
- Berkshelf.log.debug " Dependencies"
122
- dependencies.map do |dependency|
123
- Berkshelf.log.debug " #{dependency}"
124
- end
125
-
126
- download_locations(dependencies)
127
-
128
- # Only construct the universe if we are going to install things
129
- unless dependencies.all?(&:installed?)
130
- Berkshelf.log.debug " Not all dependencies are installed"
131
- build_universe
132
- end
115
+ # Install all the dependencies from the lockfile graph.
116
+ #
117
+ # @return [Array<Array<Dependency> Array<CachedCookbook>>]
118
+ # the list of installed dependencies and cookbooks
119
+ def install_from_lockfile
120
+ Berkshelf.log.info "Installing from lockfile"
133
121
 
134
- cookbooks = dependencies.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
122
+ dependencies = lockfile.graph.locks.values
135
123
 
136
- [dependencies, cookbooks]
124
+ Berkshelf.log.debug " Dependencies"
125
+ dependencies.map do |dependency|
126
+ Berkshelf.log.debug " #{dependency}"
137
127
  end
138
128
 
139
- # Resolve and install the dependencies from the "universe", updating the
140
- # lockfile appropiately.
141
- #
142
- # @return [Array<Array<Dependency> Array<CachedCookbook>>]
143
- # the list of installed dependencies and cookbooks
144
- def install_from_universe
145
- Berkshelf.log.info "Installing from universe"
146
-
147
- dependencies = lockfile.graph.locks.values + berksfile.dependencies
148
- dependencies = dependencies.inject({}) do |hash, dependency|
149
- # Fancy way of ensuring no duplicate dependencies are used...
150
- hash[dependency.name] ||= dependency
151
- hash
152
- end.values
129
+ download_locations(dependencies)
153
130
 
154
- download_locations(dependencies)
131
+ # Only construct the universe if we are going to install things
132
+ unless dependencies.all?(&:installed?)
133
+ Berkshelf.log.debug " Not all dependencies are installed"
134
+ build_universe
135
+ end
155
136
 
156
- Berkshelf.log.debug " Creating a resolver"
157
- resolver = Resolver.new(berksfile, dependencies)
137
+ futures = dependencies.sort.map { |dependency| Concurrent::Future.execute(executor: pool) { worker.install(dependency) } }
138
+ cookbooks = futures.map(&:value)
139
+ rejects = futures.select(&:rejected?)
140
+ raise rejects.first.reason unless rejects.empty?
158
141
 
159
- # Unlike when installing from the lockfile, we _always_ need to build
160
- # the universe when installing from the universe... duh
161
- build_universe
142
+ [dependencies, cookbooks]
143
+ end
162
144
 
163
- # Add any explicit dependencies for already-downloaded cookbooks (like
164
- # path locations)
165
- dependencies.each do |dependency|
166
- if dependency.location
167
- cookbook = dependency.cached_cookbook
168
- Berkshelf.log.debug " Adding explicit dependency on #{cookbook}"
169
- resolver.add_explicit_dependencies(cookbook)
170
- end
145
+ # Resolve and install the dependencies from the "universe", updating the
146
+ # lockfile appropiately.
147
+ #
148
+ # @return [Array<Array<Dependency> Array<CachedCookbook>>]
149
+ # the list of installed dependencies and cookbooks
150
+ def install_from_universe
151
+ Berkshelf.log.info "Installing from universe"
152
+
153
+ dependencies = lockfile.graph.locks.values + berksfile.dependencies
154
+ dependencies = dependencies.inject({}) do |hash, dependency|
155
+ # Fancy way of ensuring no duplicate dependencies are used...
156
+ hash[dependency.name] ||= dependency
157
+ hash
158
+ end.values
159
+
160
+ download_locations(dependencies)
161
+
162
+ Berkshelf.log.debug " Creating a resolver"
163
+ resolver = Resolver.new(berksfile, dependencies)
164
+
165
+ # Unlike when installing from the lockfile, we _always_ need to build
166
+ # the universe when installing from the universe... duh
167
+ build_universe
168
+
169
+ # Add any explicit dependencies for already-downloaded cookbooks (like
170
+ # path locations)
171
+ dependencies.each do |dependency|
172
+ if dependency.location
173
+ cookbook = dependency.cached_cookbook
174
+ Berkshelf.log.debug " Adding explicit dependency on #{cookbook}"
175
+ resolver.add_explicit_dependencies(cookbook)
171
176
  end
177
+ end
172
178
 
173
- Berkshelf.log.debug " Starting resolution..."
179
+ Berkshelf.log.debug " Starting resolution..."
174
180
 
175
- cookbooks = resolver.resolve.sort.map { |dependency| worker.future.install(dependency) }.map(&:value)
181
+ futures = resolver.resolve.sort.map { |dependency| Concurrent::Future.execute(executor: pool) { worker.install(dependency) } }
182
+ cookbooks = futures.map(&:value)
183
+ rejects = futures.select(&:rejected?)
184
+ raise rejects.first.reason unless rejects.empty?
176
185
 
177
- [dependencies, cookbooks]
178
- end
186
+ [dependencies, cookbooks]
187
+ end
179
188
 
180
- def download_locations(dependencies)
181
- dependencies.select(&:location).each do |dependency|
182
- unless dependency.location.installed?
183
- Berkshelf.formatter.fetch(dependency)
184
- dependency.location.install
185
- end
189
+ def download_locations(dependencies)
190
+ dependencies.select(&:location).each do |dependency|
191
+ unless dependency.location.installed?
192
+ Berkshelf.formatter.fetch(dependency)
193
+ dependency.location.install
186
194
  end
187
195
  end
196
+ end
188
197
  end
189
198
  end
@@ -9,7 +9,7 @@ module Berkshelf
9
9
  # is returned.
10
10
  #
11
11
  # @example Create a git location
12
- # Location.init(dependency, git: 'git://github.com/berkshelf/berkshelf.git')
12
+ # Location.init(dependency, git: 'https://github.com/berkshelf/berkshelf.git')
13
13
  #
14
14
  # @example Create a GitHub location
15
15
  # Location.init(dependency, github: 'berkshelf/berkshelf')
@@ -19,7 +19,7 @@ module Berkshelf
19
19
  #
20
20
  # @return [~BaseLocation, nil]
21
21
  def init(dependency, options = {})
22
- if klass = klass_from_options(options)
22
+ if ( klass = klass_from_options(options) )
23
23
  klass.new(dependency, options)
24
24
  else
25
25
  nil
@@ -28,20 +28,20 @@ module Berkshelf
28
28
 
29
29
  private
30
30
 
31
- # Load the correct location from the given options.
32
- #
33
- # @return [Class, nil]
34
- def klass_from_options(options)
35
- options.each do |key, _|
36
- id = key.to_s.capitalize
37
-
38
- begin
39
- return Berkshelf.const_get("#{id}Location")
40
- rescue NameError; end
41
- end
31
+ # Load the correct location from the given options.
32
+ #
33
+ # @return [Class, nil]
34
+ def klass_from_options(options)
35
+ options.each do |key, _|
36
+ id = key.to_s.capitalize
42
37
 
43
- nil
38
+ begin
39
+ return Berkshelf.const_get("#{id}Location")
40
+ rescue NameError; end
44
41
  end
42
+
43
+ nil
44
+ end
45
45
  end
46
46
  end
47
47
  end
@@ -61,7 +61,7 @@ module Berkshelf
61
61
 
62
62
  begin
63
63
  cookbook = CachedCookbook.from_path(path)
64
- rescue Ridley::Errors::RidleyError => e
64
+ rescue => e
65
65
  raise InternalError, "The following error occurred while reading the " \
66
66
  "cookbook `#{dependency.name}':\n#{e.class}: #{e.message}"
67
67
  end
@@ -1,5 +1,3 @@
1
- require 'buff/shell_out'
2
-
3
1
  module Berkshelf
4
2
  class GitLocation < BaseLocation
5
3
  include Mixin::Git
@@ -22,7 +20,7 @@ module Berkshelf
22
20
  @rel = options[:rel]
23
21
 
24
22
  # The revision to parse
25
- @rev_parse = options[:ref] || options[:branch] || options[:tag] || 'master'
23
+ @rev_parse = options[:ref] || options[:branch] || options[:tag] || "master"
26
24
  end
27
25
 
28
26
  # @see BaseLoation#installed?
@@ -39,28 +37,22 @@ module Berkshelf
39
37
  scratch_path = Pathname.new(Dir.mktmpdir)
40
38
 
41
39
  if cached?
42
- Dir.chdir(cache_path) do
43
- git %|fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"|
44
- end
40
+ git(%{fetch --force --tags #{uri} "refs/heads/*:refs/heads/*"}, cwd: cache_path.to_s)
45
41
  else
46
- git %|clone #{uri} "#{cache_path}" --bare --no-hardlinks|
42
+ git %{clone #{uri} "#{cache_path}" --bare --no-hardlinks}
47
43
  end
48
44
 
49
- Dir.chdir(cache_path) do
50
- @revision ||= git %|rev-parse #{@rev_parse}|
51
- end
45
+ @revision ||= git(%{rev-parse #{@rev_parse}}, cwd: cache_path.to_s)
52
46
 
53
47
  # Clone into a scratch directory for validations
54
- git %|clone --no-checkout "#{cache_path}" "#{scratch_path}"|
48
+ git %{clone --no-checkout "#{cache_path}" "#{scratch_path}"}
55
49
 
56
50
  # Make sure the scratch directory is up-to-date and account for rel paths
57
- Dir.chdir(scratch_path) do
58
- git %|fetch --force --tags "#{cache_path}"|
59
- git %|reset --hard #{@revision}|
51
+ git(%{fetch --force --tags "#{cache_path}"}, cwd: scratch_path.to_s)
52
+ git(%{reset --hard #{@revision}}, cwd: scratch_path.to_s)
60
53
 
61
- if rel
62
- git %|filter-branch --subdirectory-filter "#{rel}" --force|
63
- end
54
+ if rel
55
+ git(%{filter-branch --subdirectory-filter "#{rel}" --force}, cwd: scratch_path.to_s)
64
56
  end
65
57
 
66
58
  # Validate the scratched path is a valid cookbook
@@ -71,7 +63,7 @@ module Berkshelf
71
63
  FileUtils.mv(scratch_path, install_path)
72
64
 
73
65
  # Remove the git history
74
- FileUtils.rm_rf(File.join(install_path, '.git'))
66
+ FileUtils.rm_rf(File.join(install_path, ".git"))
75
67
 
76
68
  install_path.chmod(0777 & ~File.umask)
77
69
  ensure
@@ -90,11 +82,11 @@ module Berkshelf
90
82
 
91
83
  def ==(other)
92
84
  other.is_a?(GitLocation) &&
93
- other.uri == uri &&
94
- other.branch == branch &&
95
- other.tag == tag &&
96
- other.shortref == shortref &&
97
- other.rel == rel
85
+ other.uri == uri &&
86
+ other.branch == branch &&
87
+ other.tag == tag &&
88
+ other.shortref == shortref &&
89
+ other.rel == rel
98
90
  end
99
91
 
100
92
  def to_s
@@ -149,7 +141,7 @@ module Berkshelf
149
141
  # @return [Pathname]
150
142
  def cache_path
151
143
  Pathname.new(Berkshelf.berkshelf_path)
152
- .join('.cache', 'git', Digest::SHA1.hexdigest(uri))
144
+ .join(".cache", "git", Digest::SHA1.hexdigest(uri))
153
145
  end
154
146
  end
155
147
  end
@@ -1,6 +1,6 @@
1
1
  module Berkshelf
2
2
  class GithubLocation < GitLocation
3
- HOST = 'github.com'
3
+ HOST = "github.com".freeze
4
4
  def initialize(dependency, options = {})
5
5
  protocol = Berkshelf::Config.instance.github_protocol || :https
6
6
  case protocol
@@ -9,7 +9,7 @@ module Berkshelf
9
9
  when :https
10
10
  options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
11
11
  when :git
12
- options[:git] = "git://#{HOST}/#{options.delete(:github)}.git"
12
+ options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
13
13
  else
14
14
  # if some bizarre value is provided, treat it as :https
15
15
  options[:git] = "https://#{HOST}/#{options.delete(:github)}.git"
@@ -49,8 +49,8 @@ module Berkshelf
49
49
 
50
50
  def ==(other)
51
51
  other.is_a?(PathLocation) &&
52
- other.metadata? == metadata? &&
53
- other.relative_path == relative_path
52
+ other.metadata? == metadata? &&
53
+ other.relative_path == relative_path
54
54
  end
55
55
 
56
56
  def to_lock