berkshelf 1.0.4 → 1.1.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ require 'vagrant/errors'
2
+
1
3
  module Berkshelf
2
4
  class BerkshelfError < StandardError
3
5
  class << self
@@ -11,6 +13,34 @@ module Berkshelf
11
13
  alias_method :message, :to_s
12
14
  end
13
15
 
16
+ # A wrapper for a BerkshelfError for Vagrant. All Berkshelf exceptions should be
17
+ # wrapped in this proxy object so they are properly handled when Vagrant encounters
18
+ # an exception.
19
+ #
20
+ # @example wrapping an error encountered within the Vagrant plugin
21
+ # rescue BerkshelfError => e
22
+ # VagrantWrapperError.new(e)
23
+ # end
24
+ class VagrantWrapperError < Vagrant::Errors::VagrantError
25
+ # @param [BerkshelfError]
26
+ attr_reader :original
27
+
28
+ # @param [BerkshelfError] original
29
+ def initialize(original)
30
+ @original = original
31
+ end
32
+
33
+ def to_s
34
+ "#{original.class}: #{original.to_s}"
35
+ end
36
+
37
+ private
38
+
39
+ def method_missing(fun, *args, &block)
40
+ original.send(fun, *args, &block)
41
+ end
42
+ end
43
+
14
44
  class InternalError < BerkshelfError; status_code(99); end
15
45
  class ArgumentError < InternalError; end
16
46
  class AbstractFunction < InternalError
@@ -36,6 +66,7 @@ module Berkshelf
36
66
  out << stderr.prepend_each("\n", "\t")
37
67
  end
38
68
  end
69
+ class PrivateGitRepo < GitError; end
39
70
 
40
71
  class DuplicateSourceDefined < BerkshelfError; status_code(105); end
41
72
  class NoSolution < BerkshelfError; status_code(106); end
@@ -47,7 +47,7 @@ module Berkshelf
47
47
  def to_s
48
48
  s = "#{self.class.location_key}: '#{repo_identifier}'"
49
49
  s << " with branch: '#{branch}'" if branch
50
- s << " over protocol: '#{protocol}'" unless default_protocol?
50
+ s << " over protocol: '#{protocol}'"
51
51
  s
52
52
  end
53
53
 
@@ -4,6 +4,34 @@ module Berkshelf
4
4
  def remove!
5
5
  FileUtils.rm_f DEFAULT_FILENAME
6
6
  end
7
+
8
+ # @param [Array<CookbookSource>] sources
9
+ def update!(sources)
10
+ contents = File.readlines(DEFAULT_FILENAME)
11
+ contents.delete_if do |line|
12
+ line =~ /cookbook '(#{sources.map(&:name).join('|')})'/
13
+ end
14
+
15
+ contents += sources.map { |source| definition(source) }
16
+ File.open(DEFAULT_FILENAME, 'wb') { |f| f.write(contents.join("\n").squeeze("\n")) }
17
+ end
18
+
19
+ # @param [CookbookSource] source
20
+ #
21
+ # @return [String]
22
+ def definition(source)
23
+ definition = "cookbook '#{source.name}'"
24
+
25
+ if source.location.is_a?(GitLocation)
26
+ definition += ", :git => '#{source.location.uri}', :ref => '#{source.location.branch || 'HEAD'}'"
27
+ elsif source.location.is_a?(PathLocation)
28
+ definition += ", :path => '#{source.location.path}'"
29
+ else
30
+ definition += ", :locked_version => '#{source.locked_version}'"
31
+ end
32
+
33
+ definition
34
+ end
7
35
  end
8
36
 
9
37
  DEFAULT_FILENAME = "#{Berkshelf::DEFAULT_FILENAME}.lock".freeze
@@ -15,28 +43,12 @@ module Berkshelf
15
43
  end
16
44
 
17
45
  def write(filename = DEFAULT_FILENAME)
18
- content = sources.map { |source| get_source_definition(source) }.join("\n")
46
+ content = sources.map { |source| self.class.definition(source) }.join("\n")
19
47
  File.open(filename, "wb") { |f| f.write content }
20
48
  end
21
49
 
22
50
  def remove!
23
51
  self.class.remove!
24
52
  end
25
-
26
- private
27
-
28
- def get_source_definition(source)
29
- definition = "cookbook '#{source.name}'"
30
-
31
- if source.location.is_a?(GitLocation)
32
- definition += ", :git => '#{source.location.uri}', :ref => '#{source.location.branch || 'HEAD'}'"
33
- elsif source.location.is_a?(PathLocation)
34
- definition += ", :path => '#{source.location.path}'"
35
- else
36
- definition += ", :locked_version => '#{source.locked_version}'"
37
- end
38
-
39
- return definition
40
- end
41
53
  end
42
54
  end
@@ -17,6 +17,8 @@ module Berkshelf
17
17
  end
18
18
 
19
19
  @app.call(env)
20
+ rescue BerkshelfError => e
21
+ raise VagrantWrapperError.new(e)
20
22
  end
21
23
  end
22
24
  end
@@ -20,6 +20,8 @@ module Berkshelf
20
20
  end
21
21
 
22
22
  @app.call(env)
23
+ rescue BerkshelfError => e
24
+ raise VagrantWrapperError.new(e)
23
25
  end
24
26
 
25
27
  private
@@ -16,6 +16,8 @@ module Berkshelf
16
16
  end
17
17
 
18
18
  @app.call(env)
19
+ rescue BerkshelfError => e
20
+ raise VagrantWrapperError.new(e)
19
21
  end
20
22
 
21
23
  private
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "1.0.4"
2
+ VERSION = "1.1.0.rc1"
3
3
  end
@@ -89,7 +89,10 @@ EOF
89
89
  end
90
90
  end
91
91
 
92
- File.write(cookbook_path.join("metadata.rb"), metadata)
92
+ File.open(cookbook_path.join("metadata.rb"), 'w+') do |f|
93
+ f.write metadata
94
+ end
95
+
93
96
  cookbook_path
94
97
  end
95
98
 
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ describe "berkshelf errors" do
4
+ describe Berkshelf::VagrantWrapperError do
5
+ subject { described_class }
6
+
7
+ it "proxies messages to the original exception" do
8
+ original = double('original_error')
9
+ original.should_receive(:a_message)
10
+
11
+ subject.new(original).a_message
12
+ end
13
+ end
14
+ end
@@ -46,7 +46,9 @@ module Berkshelf
46
46
  context "with a metadata entry in the Berksfile" do
47
47
  before do
48
48
  Dir.mkdir target
49
- File.write target.join("metadata.rb"), ""
49
+ File.open(target.join("metadata.rb"), 'w+') do |f|
50
+ f.write ""
51
+ end
50
52
  generator = subject.new([target], metadata_entry: true)
51
53
  capture(:stdout) { generator.invoke_all }
52
54
  end
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
5
- prerelease:
4
+ version: 1.1.0.rc1
5
+ prerelease: 6
6
6
  platform: ruby
7
7
  authors:
8
8
  - Jamie Winsor
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-11-16 00:00:00.000000000 Z
15
+ date: 2012-11-30 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: yajl-ruby
@@ -203,6 +203,7 @@ extra_rdoc_files: []
203
203
  files:
204
204
  - .gitignore
205
205
  - .rbenv-version
206
+ - .rvmrc
206
207
  - .travis.yml
207
208
  - Gemfile
208
209
  - Guardfile
@@ -217,9 +218,12 @@ files:
217
218
  - features/default_locations.feature
218
219
  - features/groups_install.feature
219
220
  - features/init_command.feature
220
- - features/install.feature
221
+ - features/install_command.feature
221
222
  - features/json_formatter.feature
223
+ - features/list_command.feature
222
224
  - features/lockfile.feature
225
+ - features/outdated_command.feature
226
+ - features/show_command.feature
223
227
  - features/step_definitions/berksfile_steps.rb
224
228
  - features/step_definitions/chef_server_steps.rb
225
229
  - features/step_definitions/cli_steps.rb
@@ -229,7 +233,7 @@ files:
229
233
  - features/step_definitions/json_steps.rb
230
234
  - features/step_definitions/utility_steps.rb
231
235
  - features/support/env.rb
232
- - features/update.feature
236
+ - features/update_command.feature
233
237
  - features/upload_command.feature
234
238
  - features/vendor_install.feature
235
239
  - generator_files/Berksfile.erb
@@ -329,6 +333,7 @@ files:
329
333
  - spec/unit/berkshelf/cookbook_store_spec.rb
330
334
  - spec/unit/berkshelf/core_ext/file_utils_spec.rb
331
335
  - spec/unit/berkshelf/downloader_spec.rb
336
+ - spec/unit/berkshelf/errors_spec.rb
332
337
  - spec/unit/berkshelf/formatters_spec.rb
333
338
  - spec/unit/berkshelf/git_spec.rb
334
339
  - spec/unit/berkshelf/init_generator_spec.rb
@@ -356,12 +361,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
356
361
  required_rubygems_version: !ruby/object:Gem::Requirement
357
362
  none: false
358
363
  requirements:
359
- - - ! '>='
364
+ - - ! '>'
360
365
  - !ruby/object:Gem::Version
361
- version: '0'
362
- segments:
363
- - 0
364
- hash: -1057242199231529064
366
+ version: 1.3.1
365
367
  requirements: []
366
368
  rubyforge_project:
367
369
  rubygems_version: 1.8.23
@@ -375,9 +377,12 @@ test_files:
375
377
  - features/default_locations.feature
376
378
  - features/groups_install.feature
377
379
  - features/init_command.feature
378
- - features/install.feature
380
+ - features/install_command.feature
379
381
  - features/json_formatter.feature
382
+ - features/list_command.feature
380
383
  - features/lockfile.feature
384
+ - features/outdated_command.feature
385
+ - features/show_command.feature
381
386
  - features/step_definitions/berksfile_steps.rb
382
387
  - features/step_definitions/chef_server_steps.rb
383
388
  - features/step_definitions/cli_steps.rb
@@ -387,7 +392,7 @@ test_files:
387
392
  - features/step_definitions/json_steps.rb
388
393
  - features/step_definitions/utility_steps.rb
389
394
  - features/support/env.rb
390
- - features/update.feature
395
+ - features/update_command.feature
391
396
  - features/upload_command.feature
392
397
  - features/vendor_install.feature
393
398
  - spec/fixtures/Berksfile
@@ -430,6 +435,7 @@ test_files:
430
435
  - spec/unit/berkshelf/cookbook_store_spec.rb
431
436
  - spec/unit/berkshelf/core_ext/file_utils_spec.rb
432
437
  - spec/unit/berkshelf/downloader_spec.rb
438
+ - spec/unit/berkshelf/errors_spec.rb
433
439
  - spec/unit/berkshelf/formatters_spec.rb
434
440
  - spec/unit/berkshelf/git_spec.rb
435
441
  - spec/unit/berkshelf/init_generator_spec.rb
@@ -1,19 +0,0 @@
1
- Feature: update
2
- As a user
3
- I want a way to update the versions without clearing out the files I've downloaded
4
- So that I can update faster than a clean install
5
-
6
- Scenario: knife berkshelf update
7
- Given I write to "Berksfile" with:
8
- """
9
- cookbook "artifact", "0.10.0"
10
- """
11
- Given I write to "Berksfile.lock" with:
12
- """
13
- cookbook 'artifact', :locked_version => '0.1.0'
14
- """
15
- When I run the update command
16
- Then the file "Berksfile.lock" should contain exactly:
17
- """
18
- cookbook 'artifact', :locked_version => '0.10.0'
19
- """