diff options
Diffstat (limited to 'lib/chef/cookbook')
-rw-r--r-- | lib/chef/cookbook/cookbook_version_loader.rb | 50 | ||||
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 52 |
2 files changed, 48 insertions, 54 deletions
diff --git a/lib/chef/cookbook/cookbook_version_loader.rb b/lib/chef/cookbook/cookbook_version_loader.rb index b2305d3870..b9de9a7482 100644 --- a/lib/chef/cookbook/cookbook_version_loader.rb +++ b/lib/chef/cookbook/cookbook_version_loader.rb @@ -305,40 +305,34 @@ class Chef end def apply_ruby_metadata(file) - begin - @metadata.from_file(file) - rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Error evaluating metadata.rb for #{@inferred_cookbook_name} in " + file) - raise - end + @metadata.from_file(file) + rescue Chef::Exceptions::JSON::ParseError + Chef::Log.error("Error evaluating metadata.rb for #{@inferred_cookbook_name} in " + file) + raise end def apply_json_metadata(file) - begin - @metadata.from_json(IO.read(file)) - rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) - raise - end + @metadata.from_json(IO.read(file)) + rescue Chef::Exceptions::JSON::ParseError + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) + raise end def apply_json_cookbook_version_metadata(file) - begin - data = Chef::JSONCompat.parse(IO.read(file)) - @metadata.from_hash(data["metadata"]) - # the JSON cookbok metadata file is only used by chef-zero. - # The Chef Server API currently does not enforce that the metadata - # have a `name` field, but that will cause an error when attempting - # to load the cookbook. To keep compatibility, we fake it by setting - # the metadata name from the cookbook version object's name. - # - # This behavior can be removed if/when Chef Server enforces that the - # metadata contains a name key. - @metadata.name(data["cookbook_name"]) unless data["metadata"].key?("name") - rescue Chef::Exceptions::JSON::ParseError - Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) - raise - end + data = Chef::JSONCompat.parse(IO.read(file)) + @metadata.from_hash(data["metadata"]) + # the JSON cookbok metadata file is only used by chef-zero. + # The Chef Server API currently does not enforce that the metadata + # have a `name` field, but that will cause an error when attempting + # to load the cookbook. To keep compatibility, we fake it by setting + # the metadata name from the cookbook version object's name. + # + # This behavior can be removed if/when Chef Server enforces that the + # metadata contains a name key. + @metadata.name(data["cookbook_name"]) unless data["metadata"].key?("name") + rescue Chef::Exceptions::JSON::ParseError + Chef::Log.error("Couldn't parse cookbook metadata JSON for #{@inferred_cookbook_name} in " + file) + raise end def set_frozen diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index c3698f3315..3f23bc2056 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -462,7 +462,7 @@ class Chef cookbook.fully_qualified_recipe_names.map do |recipe_name| unqualified_name = if recipe_name =~ /::default$/ - self.name.to_s + name.to_s else recipe_name end @@ -567,29 +567,29 @@ class Chef def to_hash { - NAME => self.name, - DESCRIPTION => self.description, - LONG_DESCRIPTION => self.long_description, - MAINTAINER => self.maintainer, - MAINTAINER_EMAIL => self.maintainer_email, - LICENSE => self.license, - PLATFORMS => self.platforms, - DEPENDENCIES => self.dependencies, - RECOMMENDATIONS => self.recommendations, - SUGGESTIONS => self.suggestions, - CONFLICTING => self.conflicting, - PROVIDING => self.providing, - REPLACING => self.replacing, - ATTRIBUTES => self.attributes, - GROUPINGS => self.groupings, - RECIPES => self.recipes, - VERSION => self.version, - SOURCE_URL => self.source_url, - ISSUES_URL => self.issues_url, - PRIVACY => self.privacy, - CHEF_VERSIONS => gem_requirements_to_array(*self.chef_versions), - OHAI_VERSIONS => gem_requirements_to_array(*self.ohai_versions), - GEMS => self.gems, + NAME => name, + DESCRIPTION => description, + LONG_DESCRIPTION => long_description, + MAINTAINER => maintainer, + MAINTAINER_EMAIL => maintainer_email, + LICENSE => license, + PLATFORMS => platforms, + DEPENDENCIES => dependencies, + RECOMMENDATIONS => recommendations, + SUGGESTIONS => suggestions, + CONFLICTING => conflicting, + PROVIDING => providing, + REPLACING => replacing, + ATTRIBUTES => attributes, + GROUPINGS => groupings, + RECIPES => recipes, + VERSION => version, + SOURCE_URL => source_url, + ISSUES_URL => issues_url, + PRIVACY => privacy, + CHEF_VERSIONS => gem_requirements_to_array(*chef_versions), + OHAI_VERSIONS => gem_requirements_to_array(*ohai_versions), + GEMS => gems, } end @@ -598,7 +598,7 @@ class Chef end def self.from_hash(o) - cm = self.new() + cm = new() cm.from_hash(o) cm end @@ -632,7 +632,7 @@ class Chef def self.from_json(string) o = Chef::JSONCompat.from_json(string) - self.from_hash(o) + from_hash(o) end def self.validate_json(json_str) |