berkshelf 2.0.0.beta → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/CHANGELOG.md +19 -1
  2. data/CONTRIBUTING.md +1 -3
  3. data/Gemfile +0 -20
  4. data/Guardfile +3 -3
  5. data/LICENSE +6 -5
  6. data/README.md +1 -0
  7. data/Thorfile +48 -67
  8. data/berkshelf.gemspec +48 -37
  9. data/features/apply_command.feature +17 -11
  10. data/features/config.feature +11 -11
  11. data/features/configure_command.feature +8 -8
  12. data/features/contingent_command.feature +37 -8
  13. data/features/cookbook_command.feature +17 -14
  14. data/features/groups_install.feature +24 -20
  15. data/features/install_command.feature +24 -33
  16. data/features/licenses.feature +112 -0
  17. data/features/list_command.feature +17 -5
  18. data/features/lockfile.feature +307 -188
  19. data/features/outdated_command.feature +1 -4
  20. data/features/package_command.feature +41 -19
  21. data/features/shelf/list.feature +39 -0
  22. data/features/shelf/show.feature +152 -0
  23. data/features/shelf/uninstall.feature +103 -0
  24. data/features/show_command.feature +49 -17
  25. data/features/step_definitions/filesystem_steps.rb +12 -3
  26. data/features/step_definitions/utility_steps.rb +0 -1
  27. data/features/support/env.rb +11 -4
  28. data/features/update_command.feature +22 -10
  29. data/features/upload_command.feature +174 -127
  30. data/features/vendor_install.feature +6 -6
  31. data/generator_files/Berksfile.erb +1 -1
  32. data/generator_files/metadata.rb.erb +7 -7
  33. data/lib/berkshelf.rb +39 -27
  34. data/lib/berkshelf/base_generator.rb +2 -3
  35. data/lib/berkshelf/berksfile.rb +69 -17
  36. data/lib/berkshelf/cached_cookbook.rb +17 -1
  37. data/lib/berkshelf/chef.rb +2 -4
  38. data/lib/berkshelf/chef/config.rb +51 -75
  39. data/lib/berkshelf/chef/cookbook.rb +1 -2
  40. data/lib/berkshelf/chef/cookbook/chefignore.rb +1 -1
  41. data/lib/berkshelf/cli.rb +144 -194
  42. data/lib/berkshelf/command.rb +11 -12
  43. data/lib/berkshelf/commands/shelf.rb +130 -0
  44. data/lib/berkshelf/commands/test_command.rb +11 -0
  45. data/lib/berkshelf/community_rest.rb +1 -2
  46. data/lib/berkshelf/config.rb +14 -10
  47. data/lib/berkshelf/cookbook_generator.rb +30 -24
  48. data/lib/berkshelf/cookbook_source.rb +1 -1
  49. data/lib/berkshelf/cookbook_store.rb +0 -1
  50. data/lib/berkshelf/core_ext.rb +1 -1
  51. data/lib/berkshelf/core_ext/file.rb +1 -1
  52. data/lib/berkshelf/downloader.rb +3 -1
  53. data/lib/berkshelf/errors.rb +128 -53
  54. data/lib/berkshelf/formatters.rb +2 -6
  55. data/lib/berkshelf/formatters/human_readable.rb +8 -2
  56. data/lib/berkshelf/formatters/json.rb +7 -1
  57. data/lib/berkshelf/formatters/null.rb +0 -1
  58. data/lib/berkshelf/git.rb +16 -16
  59. data/lib/berkshelf/init_generator.rb +28 -26
  60. data/lib/berkshelf/location.rb +12 -11
  61. data/lib/berkshelf/locations/chef_api_location.rb +2 -2
  62. data/lib/berkshelf/locations/git_location.rb +0 -1
  63. data/lib/berkshelf/locations/github_location.rb +0 -1
  64. data/lib/berkshelf/locations/path_location.rb +1 -2
  65. data/lib/berkshelf/locations/site_location.rb +3 -2
  66. data/lib/berkshelf/lockfile.rb +29 -10
  67. data/lib/berkshelf/mixin/config.rb +155 -0
  68. data/lib/berkshelf/mixin/logging.rb +0 -1
  69. data/lib/berkshelf/mixin/shellout.rb +71 -0
  70. data/lib/berkshelf/resolver.rb +7 -4
  71. data/lib/berkshelf/test.rb +1 -3
  72. data/lib/berkshelf/ui.rb +8 -4
  73. data/lib/berkshelf/version.rb +1 -1
  74. data/lib/thor/monkies/shell.rb +0 -1
  75. data/spec/config/berkshelf.pem +27 -0
  76. data/spec/config/knife.rb +12 -0
  77. data/spec/config/validator.pem +27 -0
  78. data/spec/spec_helper.rb +4 -8
  79. data/spec/support/chef_api.rb +14 -9
  80. data/spec/support/chef_server.rb +3 -4
  81. data/spec/unit/berkshelf/berksfile_spec.rb +1 -1
  82. data/spec/unit/berkshelf/cookbook_generator_spec.rb +12 -6
  83. data/spec/unit/berkshelf/cookbook_source_spec.rb +13 -1
  84. data/spec/unit/berkshelf/init_generator_spec.rb +5 -0
  85. data/spec/unit/chef/config_spec.rb +9 -10
  86. metadata +216 -93
  87. data/features/info_command.feature +0 -39
  88. data/features/open_command.feature +0 -36
  89. data/lib/berkshelf/cli_commands/test_command.rb +0 -11
  90. data/lib/berkshelf/mixin.rb +0 -10
  91. data/lib/berkshelf/mixin/path_helpers.rb +0 -30
  92. data/spec/support/knife.rb +0 -18
@@ -1,6 +1,4 @@
1
1
  module Berkshelf
2
- # @author Michael Ivey <michael.ivey@riotgames.com>
3
- # @author Jamie Winsor <reset@riotgames.com>
4
2
  module Formatters
5
3
  class << self
6
4
  @@formatters = Hash.new
@@ -47,8 +45,6 @@ module Berkshelf
47
45
  alias_method :[], :get
48
46
  end
49
47
 
50
- # @author Michael Ivey <michael.ivey@riotgames.com>
51
- #
52
48
  # @abstract Include and override {#install} {#use} {#upload}
53
49
  # {#msg} {#error} to implement.
54
50
  #
@@ -81,7 +77,7 @@ module Berkshelf
81
77
  end
82
78
  end
83
79
 
84
- formatter_methods :install, :use, :upload, :msg, :error, :package
80
+ formatter_methods :install, :use, :upload, :msg, :error, :package, :show
85
81
 
86
82
  def cleanup_hook
87
83
  # run after the task is finished
@@ -95,5 +91,5 @@ module Berkshelf
95
91
  end
96
92
 
97
93
  Dir["#{File.dirname(__FILE__)}/formatters/*.rb"].sort.each do |path|
98
- require "berkshelf/formatters/#{File.basename(path, '.rb')}"
94
+ require_relative "formatters/#{File.basename(path, '.rb')}"
99
95
  end
@@ -1,6 +1,5 @@
1
1
  module Berkshelf
2
2
  module Formatters
3
- # @author Michael Ivey <michael.ivey@riotgames.com>
4
3
  class HumanReadable
5
4
  include AbstractFormatter
6
5
 
@@ -38,7 +37,14 @@ module Berkshelf
38
37
  # @param [String] cookbook
39
38
  # @param [String] destination
40
39
  def package(cookbook, destination)
41
- Berkshelf.ui.info "Cookbook '#{cookbook}' saved to #{destination}!"
40
+ Berkshelf.ui.info "Cookbook(s) packaged to #{destination}!"
41
+ end
42
+
43
+ # Output Cookbook info message using {Berkshelf.ui}
44
+ #
45
+ # @param [CachedCookbook] cookbook
46
+ def show(cookbook)
47
+ Berkshelf.ui.info(cookbook.pretty_print)
42
48
  end
43
49
 
44
50
  # Output a generic message using {Berkshelf.ui}
@@ -1,6 +1,5 @@
1
1
  module Berkshelf
2
2
  module Formatters
3
- # @author Michael Ivey <michael.ivey@riotgames.com>
4
3
  class JSON
5
4
  include AbstractFormatter
6
5
 
@@ -69,6 +68,13 @@ module Berkshelf
69
68
  cookbooks[cookbook][:destination] = destination
70
69
  end
71
70
 
71
+ # Output Cookbook info entry to delayed output
72
+ #
73
+ # @param [CachedCookbook] cookbook
74
+ def show(cookbook)
75
+ cookbooks[cookbook.cookbook_name] = cookbook.pretty_hash
76
+ end
77
+
72
78
  # Add a generic message entry to delayed output
73
79
  #
74
80
  # @param [String] message
@@ -1,6 +1,5 @@
1
1
  module Berkshelf
2
2
  module Formatters
3
- # @author Seth Vargo <sethvargo@gmail.com>
4
3
  class Null
5
4
  include AbstractFormatter
6
5
 
@@ -1,9 +1,10 @@
1
1
  require 'uri'
2
- require 'mixlib/shellout'
3
2
 
4
3
  module Berkshelf
5
- # @author Jamie Winsor <reset@riotgames.com>
6
4
  class Git
5
+ require 'berkshelf/mixin/shellout'
6
+ extend Berkshelf::Mixin::Shellout
7
+
7
8
  GIT_REGEXP = URI.regexp(%w(http https ssh git+ssh git rsync))
8
9
  SCP_REGEXP = /^(.+@)?[\w\d\.-]+:.*$/
9
10
 
@@ -21,14 +22,13 @@ module Berkshelf
21
22
  def git(*command)
22
23
  command.unshift(git_cmd)
23
24
  command_str = command.map { |p| quote_cmd_arg(p) }.join(' ')
24
- cmd = Mixlib::ShellOut.new(command_str)
25
- cmd.run_command
25
+ result = shellout(command_str)
26
26
 
27
- unless cmd.exitstatus == 0
28
- raise GitError.new(cmd.stderr)
27
+ unless result.success?
28
+ raise GitError.new(result.stderr)
29
29
  end
30
30
 
31
- cmd.stdout.chomp
31
+ result.stdout
32
32
  end
33
33
 
34
34
  # Clone a remote Git repository to disk
@@ -41,7 +41,7 @@ module Berkshelf
41
41
  # @return [String]
42
42
  # the destination the URI was cloned to
43
43
  def clone(uri, destination = Dir.mktmpdir)
44
- git("clone", uri, destination.to_s)
44
+ git('clone', uri, destination.to_s)
45
45
 
46
46
  destination
47
47
  end
@@ -54,14 +54,14 @@ module Berkshelf
54
54
  # reference to checkout
55
55
  def checkout(repo_path, ref)
56
56
  Dir.chdir repo_path do
57
- git("checkout", "-qf", revision_from_ref(repo_path, ref))
57
+ git('checkout', '-qf', revision_from_ref(repo_path, ref))
58
58
  end
59
59
  end
60
60
 
61
61
  # @param [String] repo_path
62
62
  def rev_parse(repo_path)
63
63
  Dir.chdir repo_path do
64
- git("rev-parse", "HEAD")
64
+ git('rev-parse', 'HEAD')
65
65
  end
66
66
  end
67
67
 
@@ -78,7 +78,7 @@ module Berkshelf
78
78
  # @raise [AmbiguousGitRef] if the ref could refer to more than one revision
79
79
  def show_ref(repo_path, ref)
80
80
  Dir.chdir repo_path do
81
- lines = git('show-ref', "'#{ref}'").lines.to_a
81
+ lines = git('show-ref', ref).lines.to_a
82
82
 
83
83
  raise AmbiguousGitRef, ref if lines.size > 1
84
84
 
@@ -121,7 +121,7 @@ module Berkshelf
121
121
  # @raise [GitNotFound] if executable is not found in system path
122
122
  def find_git
123
123
  git_path = nil
124
- ENV["PATH"].split(::File::PATH_SEPARATOR).each do |path|
124
+ ENV['PATH'].split(::File::PATH_SEPARATOR).each do |path|
125
125
  git_path = detect_git_path(path)
126
126
  break if git_path
127
127
  end
@@ -138,11 +138,11 @@ module Berkshelf
138
138
  # SSH protocol, or HTTPS protocol.
139
139
  #
140
140
  # @example Valid Git protocol URI
141
- # "git://github.com/reset/thor-foodcritic.git"
141
+ # 'git://github.com/reset/thor-foodcritic.git'
142
142
  # @example Valid HTTPS URI
143
- # "https://github.com/reset/solve.git"
143
+ # 'https://github.com/reset/solve.git'
144
144
  # @example Valid SSH protocol URI
145
- # "git@github.com:reset/solve.git"
145
+ # 'git@github.com:reset/solve.git'
146
146
  #
147
147
  # @param [String] uri
148
148
  #
@@ -188,7 +188,7 @@ module Berkshelf
188
188
  end
189
189
 
190
190
  def detect_git_path(base_dir)
191
- %w{ git git.exe git.cmd }.each do |git_cmd|
191
+ %w(git git.exe git.cmd).each do |git_cmd|
192
192
  potential_path = File.join(base_dir, git_cmd)
193
193
  if File.executable?(potential_path)
194
194
  return potential_path
@@ -1,6 +1,6 @@
1
+ require 'kitchen/generator/init'
2
+
1
3
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
- # @author Josiah Kiehl <jkiehl@riotgames.com>
4
4
  class InitGenerator < BaseGenerator
5
5
  def initialize(*args)
6
6
  super(*args)
@@ -20,17 +20,17 @@ module Berkshelf
20
20
  class_option :skip_vagrant,
21
21
  type: :boolean,
22
22
  default: false,
23
- desc: "Skips adding a Vagrantfile and adding supporting gems to the Gemfile"
23
+ desc: 'Skips adding a Vagrantfile and adding supporting gems to the Gemfile'
24
24
 
25
25
  class_option :skip_git,
26
26
  type: :boolean,
27
27
  default: false,
28
- desc: "Skips adding a .gitignore and running git init in the cookbook directory"
28
+ desc: 'Skips adding a .gitignore and running git init in the cookbook directory'
29
29
 
30
30
  class_option :foodcritic,
31
31
  type: :boolean,
32
32
  default: false,
33
- desc: "Creates a Thorfile with Foodcritic support to lint test your cookbook"
33
+ desc: 'Creates a Thorfile with Foodcritic support to lint test your cookbook'
34
34
 
35
35
  class_option :chef_minitest,
36
36
  type: :boolean,
@@ -39,12 +39,12 @@ module Berkshelf
39
39
  class_option :scmversion,
40
40
  type: :boolean,
41
41
  default: false,
42
- desc: "Creates a Thorfile with SCMVersion support to manage versions for continuous integration"
42
+ desc: 'Creates a Thorfile with SCMVersion support to manage versions for continuous integration'
43
43
 
44
44
  class_option :no_bundler,
45
45
  type: :boolean,
46
46
  default: false,
47
- desc: "Skips generation of a Gemfile and other Bundler specific support"
47
+ desc: 'Skips generation of a Gemfile and other Bundler specific support'
48
48
 
49
49
  class_option :cookbook_name,
50
50
  type: :string
@@ -52,53 +52,55 @@ module Berkshelf
52
52
  class_option :skip_test_kitchen,
53
53
  type: :boolean,
54
54
  default: false,
55
- desc: "Skip adding a testing environment to your cookbook"
55
+ desc: 'Skip adding a testing environment to your cookbook'
56
56
 
57
57
  def generate
58
58
  validate_configuration
59
59
  check_option_support
60
60
 
61
- template "Berksfile.erb", target.join("Berksfile")
61
+ template 'Berksfile.erb', target.join('Berksfile')
62
+ template 'Thorfile.erb', target.join('Thorfile')
62
63
 
63
64
  if options[:chefignore]
64
- copy_file "chefignore", target.join(Berkshelf::Chef::Cookbook::Chefignore::FILENAME)
65
+ copy_file 'chefignore', target.join(Berkshelf::Chef::Cookbook::Chefignore::FILENAME)
65
66
  end
66
67
 
67
68
  unless options[:skip_git]
68
- template "gitignore.erb", target.join(".gitignore")
69
+ template 'gitignore.erb', target.join('.gitignore')
69
70
 
70
- unless File.exists?(target.join(".git"))
71
+ unless File.exists?(target.join('.git'))
71
72
  inside target do
72
- run "git init", capture: true
73
+ run 'git init', capture: true
73
74
  end
74
75
  end
75
76
  end
76
77
 
77
- if options[:foodcritic] || options[:scmversion]
78
- template "Thorfile.erb", target.join("Thorfile")
79
- end
80
-
81
78
  if options[:chef_minitest]
82
- empty_directory target.join("files/default/tests/minitest/support")
83
- template "default_test.rb.erb", target.join("files/default/tests/minitest/default_test.rb")
84
- template "helpers.rb.erb", target.join("files/default/tests/minitest/support/helpers.rb")
79
+ empty_directory target.join('files/default/tests/minitest/support')
80
+ template 'default_test.rb.erb', target.join('files/default/tests/minitest/default_test.rb')
81
+ template 'helpers.rb.erb', target.join('files/default/tests/minitest/support/helpers.rb')
85
82
  end
86
83
 
87
84
  if options[:scmversion]
88
- create_file target.join("VERSION"), "0.1.0"
85
+ create_file target.join('VERSION'), '0.1.0'
89
86
  end
90
87
 
91
88
  unless options[:no_bundler]
92
- template "Gemfile.erb", target.join("Gemfile")
89
+ template 'Gemfile.erb', target.join('Gemfile')
93
90
  end
94
91
 
95
92
  unless options[:skip_test_kitchen]
96
- Kitchen::Generator::Init.new([], options).invoke_all
93
+ # Temporarily use Dir.chdir to ensure the destionation_root of test kitchen's generator
94
+ # is where we expect until this bug can be addressed:
95
+ # https://github.com/opscode/test-kitchen/pull/140
96
+ Dir.chdir target do
97
+ # Kitchen::Generator::Init.new([], {}, destination_root: target).invoke_all
98
+ Kitchen::Generator::Init.new([], {}).invoke_all
99
+ end
97
100
  end
98
101
 
99
102
  unless options[:skip_vagrant]
100
- template "Vagrantfile.erb", target.join("Vagrantfile")
101
- ::Berkshelf::Cli.new([], berksfile: target.join("Berksfile")).invoke(:install)
103
+ template 'Vagrantfile.erb', target.join('Vagrantfile')
102
104
  end
103
105
  end
104
106
 
@@ -114,7 +116,7 @@ module Berkshelf
114
116
  # name of the cookbook
115
117
  def cookbook_name
116
118
  @cookbook_name ||= begin
117
- metadata = Ridley::Chef::Cookbook::Metadata.from_file(target.join("metadata.rb").to_s)
119
+ metadata = Ridley::Chef::Cookbook::Metadata.from_file(target.join('metadata.rb').to_s)
118
120
  metadata.name.empty? ? File.basename(target) : metadata.name
119
121
  rescue CookbookNotFound, IOError
120
122
  File.basename(target)
@@ -1,9 +1,10 @@
1
1
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  module Location
4
3
  OPSCODE_COMMUNITY_API = 'http://cookbooks.opscode.com/api/v1/cookbooks'.freeze
5
4
 
6
5
  module ClassMethods
6
+ require_relative 'cookbook_source'
7
+
7
8
  # Returns the location identifier key for the class
8
9
  #
9
10
  # @return [Symbol]
@@ -31,14 +32,14 @@ module Berkshelf
31
32
  # version of the Cookbook can be downloaded from
32
33
  #
33
34
  # @example:
34
- # constraint = Solve::Constraint.new("~> 0.101.2")
35
+ # constraint = Solve::Constraint.new('~> 0.101.2')
35
36
  # versions = {
36
- # "1.0.0" => "http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/1_0_0",
37
- # "2.0.0" => "http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0"
37
+ # '1.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/1_0_0',
38
+ # '2.0.0' => 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0'
38
39
  # }
39
40
  #
40
41
  # subject.solve_for_constraint(versions, constraint) =>
41
- # [ "2.0.0", "http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0" ]
42
+ # [ '2.0.0', 'http://cookbooks.opscode.com/api/v1/cookbooks/nginx/versions/2_0_0' ]
42
43
  #
43
44
  # @param [String, Solve::Constraint] constraint
44
45
  # version constraint to solve for
@@ -71,19 +72,19 @@ module Berkshelf
71
72
  # instantiated.
72
73
  #
73
74
  # @example
74
- # Location.init("nginx", ">= 0.0.0", git: "git://github.com/RiotGames/artifact-cookbook.git") =>
75
+ # Location.init('nginx', '>= 0.0.0', git: 'git://github.com/RiotGames/artifact-cookbook.git') =>
75
76
  # instantiates a GitLocation
76
77
  #
77
- # Location.init("nginx", ">= 0.0.0", path: "/Users/reset/code/nginx-cookbook") =>
78
+ # Location.init('nginx', '>= 0.0.0', path: '/Users/reset/code/nginx-cookbook') =>
78
79
  # instantiates a PathLocation
79
80
  #
80
- # Location.init("nginx", ">= 0.0.0", site: "http://cookbooks.opscode.com/api/v1/cookbooks") =>
81
+ # Location.init('nginx', '>= 0.0.0', site: 'http://cookbooks.opscode.com/api/v1/cookbooks') =>
81
82
  # instantiates a SiteLocation
82
83
  #
83
- # Location.init("nginx", ">= 0.0.0", chef_api: "https://api.opscode.com/organizations/vialstudios") =>
84
+ # Location.init('nginx', '>= 0.0.0', chef_api: 'https://api.opscode.com/organizations/vialstudios') =>
84
85
  # instantiates a ChefAPILocation
85
86
  #
86
- # Location.init("nginx", ">= 0.0.0") =>
87
+ # Location.init('nginx', '>= 0.0.0') =>
87
88
  # instantiates a SiteLocation
88
89
  #
89
90
  # @param [String] name
@@ -179,5 +180,5 @@ module Berkshelf
179
180
  end
180
181
 
181
182
  Dir["#{File.dirname(__FILE__)}/locations/*.rb"].sort.each do |path|
182
- require "berkshelf/locations/#{File.basename(path, '.rb')}"
183
+ require_relative "locations/#{File.basename(path, '.rb')}"
183
184
  end
@@ -1,5 +1,4 @@
1
1
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class ChefAPILocation
4
3
  class << self
5
4
  # @return [Proc]
@@ -174,7 +173,8 @@ module Berkshelf
174
173
  else
175
174
  conn.cookbook.latest_version(name)
176
175
  end
177
- rescue Ridley::Errors::HTTPNotFound
176
+ rescue Ridley::Errors::HTTPNotFound,
177
+ Ridley::Errors::ResourceNotFound
178
178
  @target_cookbook = nil
179
179
  end
180
180
 
@@ -1,5 +1,4 @@
1
1
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class GitLocation
4
3
  class << self
5
4
  # Create a temporary directory for the cloned repository within Berkshelf's
@@ -1,5 +1,4 @@
1
1
  module Berkshelf
2
- # @author Josiah Kiehl <jkiehl@riotgames.com>
3
2
  class GithubLocation < GitLocation
4
3
  DEFAULT_PROTOCOL = :git
5
4
 
@@ -1,5 +1,4 @@
1
1
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class PathLocation
4
3
  class << self
5
4
  # Expand and return a string representation of the given path if it is
@@ -12,7 +11,7 @@ module Berkshelf
12
11
  # @return [String]
13
12
  def normalize_path(path)
14
13
  path = path.to_s
15
- if (path[0] == "~") || Pathname.new(path).absolute?
14
+ if (path[0] == '~') || Pathname.new(path).absolute?
16
15
  File.expand_path(path)
17
16
  else
18
17
  path
@@ -1,5 +1,4 @@
1
1
  module Berkshelf
2
- # @author Jamie Winsor <reset@riotgames.com>
3
2
  class SiteLocation
4
3
  extend Forwardable
5
4
  include Location
@@ -22,7 +21,9 @@ module Berkshelf
22
21
  @name = name
23
22
  @version_constraint = version_constraint
24
23
 
25
- api_uri = if options[:site].nil? || SHORTNAMES.has_key?(options[:site])
24
+ api_uri = if options[:site].nil?
25
+ SHORTNAMES[:opscode]
26
+ elsif SHORTNAMES.has_key?(options[:site])
26
27
  SHORTNAMES[options[:site]]
27
28
  elsif options[:site].kind_of?(Symbol)
28
29
  raise InvalidSiteShortnameError.new(options[:site])
@@ -2,9 +2,9 @@ module Berkshelf
2
2
  # The object representation of the Berkshelf lockfile. The lockfile is useful
3
3
  # when working in teams where the same cookbook versions are desired across
4
4
  # multiple workstations.
5
- #
6
- # @author Seth Vargo <sethvargo@gmail.com>
7
5
  class Lockfile
6
+ require_relative 'cookbook_source'
7
+
8
8
  # @return [Pathname]
9
9
  # the path to this Lockfile
10
10
  attr_reader :filepath
@@ -39,8 +39,8 @@ module Berkshelf
39
39
  hash = JSON.parse(contents, symbolize_names: true)
40
40
  rescue JSON::ParserError
41
41
  if contents =~ /^cookbook ["'](.+)["']/
42
- Berkshelf.ui.warn "You are using the old lockfile format. Attempting to convert..."
43
- hash = LockfileLegacy.parse(contents)
42
+ Berkshelf.ui.warn 'You are using the old lockfile format. Attempting to convert...'
43
+ hash = LockfileLegacy.parse(berksfile, contents)
44
44
  else
45
45
  raise
46
46
  end
@@ -194,20 +194,23 @@ module Berkshelf
194
194
 
195
195
  # Legacy support for old lockfiles
196
196
  #
197
- # @author Seth Vargo <sethvargo@gmail.com>
198
- # @todo Remove this class in the next major release.
197
+ # @todo Remove this class in Berkshelf 3.0.0
199
198
  class LockfileLegacy
199
+ require 'pathname'
200
+
200
201
  class << self
201
202
  # Read the old lockfile content and instance eval in context.
202
203
  #
204
+ # @param [Berkshelf::Berksfile] berksfile
205
+ # the associated berksfile
203
206
  # @param [String] content
204
207
  # the string content read from a legacy lockfile
205
- def parse(content)
208
+ def parse(berksfile, content)
206
209
  sources = {}.tap do |hash|
207
210
  content.split("\n").each do |line|
208
211
  next if line.empty?
209
212
 
210
- source = self.new(line)
213
+ source = self.new(berksfile, line)
211
214
  hash[source.name] = source.options
212
215
  end
213
216
  end
@@ -227,11 +230,16 @@ module Berkshelf
227
230
  # the name of this cookbook
228
231
  attr_reader :name
229
232
 
233
+ # @return [Berkshelf::Berksfile]
234
+ # the berksfile
235
+ attr_reader :berksfile
236
+
230
237
  # Create a new legacy lockfile for processing
231
238
  #
232
239
  # @param [String] content
233
240
  # the content to parse out and convert to a hash
234
- def initialize(content)
241
+ def initialize(berksfile, content)
242
+ @berksfile = berksfile
235
243
  instance_eval(content).to_hash
236
244
  end
237
245
 
@@ -244,8 +252,19 @@ module Berkshelf
244
252
  # the locked version of this cookbook
245
253
  def cookbook(name, options = {})
246
254
  @name = name
247
- @options = options
255
+ @options = manipulate(options)
248
256
  end
257
+
258
+ private
259
+ # Perform various manipulations on the hash.
260
+ #
261
+ # @param [Hash] options
262
+ def manipulate(options = {})
263
+ if options[:path]
264
+ options[:path] = berksfile.find(name).instance_variable_get(:@options)[:path] || options[:path]
265
+ end
266
+ options
267
+ end
249
268
  end
250
269
  end
251
270
  end