diff options
author | Bryan McLellan <btm@opscode.com> | 2013-07-03 07:39:59 -0700 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-07-03 07:39:59 -0700 |
commit | 39f8848aac823bbd2c5186e0454da3a0fb8e8b0e (patch) | |
tree | f938f9b84ab0bd96e3f7e21b79d34b6859eadc3a /lib/chef/cookbook | |
parent | 302c3c6cdf592a677d957975a9d2dc31435e12a8 (diff) | |
download | chef-39f8848aac823bbd2c5186e0454da3a0fb8e8b0e.tar.gz |
Revert "Merge branch 'CHEF-3307'"
This reverts commit 5713a002062c762e40e4378be6d7763eb3dd61a2, reversing
changes made to 4079a344f2001c1927132e7ed6b63453f459609f.
Conflicts:
spec/unit/cookbook_loader_spec.rb
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 29 | ||||
-rw-r--r-- | lib/chef/cookbook/file_system_file_vendor.rb | 11 | ||||
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook/syntax_check.rb | 8 |
4 files changed, 19 insertions, 31 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index 44782bd7bf..e98da77d7f 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -18,14 +18,15 @@ class Chef :provider_filenames] - attr_reader :cookbook_pathname + attr_reader :cookbook_name attr_reader :cookbook_settings attr_reader :metadata_filenames def initialize(path, chefignore=nil) @cookbook_path = File.expand_path( path ) - @cookbook_pathname = File.basename( path ) + @cookbook_name = File.basename( path ) @chefignore = chefignore + @metadata = Hash.new @relative_path = /#{Regexp.escape(@cookbook_path)}\/(.+)$/ @cookbook_settings = { :attribute_filenames => {}, @@ -64,18 +65,13 @@ class Chef if empty? Chef::Log.warn "found a directory #{cookbook_name} in the cookbook path, but it contains no cookbook files. skipping." end - @cookbook_settings end - def cookbook_name - metadata.name || @cookbook_pathname - end - def cookbook_version return nil if empty? - Chef::CookbookVersion.new(@cookbook_pathname.to_sym).tap do |c| + Chef::CookbookVersion.new(@cookbook_name.to_sym).tap do |c| c.root_dir = @cookbook_path c.attribute_filenames = cookbook_settings[:attribute_filenames].values c.definition_filenames = cookbook_settings[:definition_filenames].values @@ -87,16 +83,12 @@ class Chef c.provider_filenames = cookbook_settings[:provider_filenames].values c.root_filenames = cookbook_settings[:root_filenames].values c.metadata_filenames = @metadata_filenames - c.metadata = load_metadata(c) + c.metadata = metadata(c) end end - def metadata - @metadata ||= load_metadata(nil) - end - # Generates the Cookbook::Metadata object - def load_metadata(cookbook_version) + def metadata(cookbook_version) @metadata = Chef::Cookbook::Metadata.new(cookbook_version) @metadata_filenames.each do |metadata_file| case metadata_file @@ -108,7 +100,6 @@ class Chef raise RuntimeError, "Invalid metadata file: #{metadata_file} for cookbook: #{cookbook_version}" end end - Chef::Log.warn "Inferring cookbook name from directory name (#@cookbook_pathname) is deprecated, please set a name in the metadata." unless @metadata.name @metadata end @@ -159,18 +150,18 @@ class Chef def apply_ruby_metadata(file) begin - metadata.from_file(file) + @metadata.from_file(file) rescue JSON::ParserError - Chef::Log.error("Error evaluating metadata.rb for #{cookbook_name} in " + file) + Chef::Log.error("Error evaluating metadata.rb for #@cookbook_name in " + file) raise end end def apply_json_metadata(file) begin - metadata.from_json(IO.read(file)) + @metadata.from_json(IO.read(file)) rescue JSON::ParserError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #{cookbook_name} in " + file) + Chef::Log.error("Couldn't parse cookbook metadata JSON for #@cookbook_name in " + file) raise end end diff --git a/lib/chef/cookbook/file_system_file_vendor.rb b/lib/chef/cookbook/file_system_file_vendor.rb index 41c6691e02..8896e3ed30 100644 --- a/lib/chef/cookbook/file_system_file_vendor.rb +++ b/lib/chef/cookbook/file_system_file_vendor.rb @@ -37,17 +37,14 @@ class Chef raise ArgumentError, "You must specify at least one repo path" if @repo_paths.empty? end - def cookbooks - @cookbooks ||= Chef::CookbookLoader.new(@repo_paths).load_cookbooks - end - # Implements abstract base's requirement. It looks in the # Chef::Config.cookbook_path file hierarchy for the requested # file. def get_filename(filename) - if cookbooks.has_key?(@cookbook_name) - location = File.join(cookbooks[@cookbook_name].root_dir, filename) - location = nil unless File.exist?(location) + location = @repo_paths.inject(nil) do |memo, basepath| + candidate_location = File.join(basepath, @cookbook_name, filename) + memo = candidate_location if File.exist?(candidate_location) + memo end raise "File #{filename} does not exist for cookbook #{@cookbook_name}" unless location diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index 0cd740ea8f..18368bd99f 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -91,7 +91,7 @@ class Chef # metadata<Chef::Cookbook::Metadata> def initialize(cookbook=nil, maintainer='YOUR_COMPANY_NAME', maintainer_email='YOUR_EMAIL', license='none') @cookbook = cookbook - @name = cookbook ? cookbook.name : nil + @name = cookbook ? cookbook.name : "" @long_description = "" self.maintainer(maintainer) self.maintainer_email(maintainer_email) diff --git a/lib/chef/cookbook/syntax_check.rb b/lib/chef/cookbook/syntax_check.rb index 4a06c88cbc..0e757074e3 100644 --- a/lib/chef/cookbook/syntax_check.rb +++ b/lib/chef/cookbook/syntax_check.rb @@ -85,14 +85,14 @@ class Chef # validated. attr_reader :validated_files - # Creates a new SyntaxCheck given the +cookbook_pathname+ and a +cookbook_path+. + # Creates a new SyntaxCheck given the +cookbook_name+ and a +cookbook_path+. # If no +cookbook_path+ is given, +Chef::Config.cookbook_path+ is used. - def self.for_cookbook(cookbook_pathname, cookbook_path=nil) + def self.for_cookbook(cookbook_name, cookbook_path=nil) cookbook_path ||= Chef::Config.cookbook_path unless cookbook_path - raise ArgumentError, "Cannot find cookbook #{cookbook_pathname} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given" + raise ArgumentError, "Cannot find cookbook #{cookbook_name} unless Chef::Config.cookbook_path is set or an explicit cookbook path is given" end - new(File.join(cookbook_path, cookbook_pathname.to_s)) + new(File.join(cookbook_path, cookbook_name.to_s)) end # Create a new SyntaxCheck object |