summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/cookbook/cookbook_version_loader.rb29
-rw-r--r--lib/chef/cookbook/file_system_file_vendor.rb11
-rw-r--r--lib/chef/cookbook/metadata.rb2
-rw-r--r--lib/chef/cookbook/syntax_check.rb8
-rw-r--r--lib/chef/cookbook_uploader.rb2
-rw-r--r--lib/chef/cookbook_version.rb16
-rw-r--r--spec/data/cookbooks/not-nginx/attributes/default.rb1
-rw-r--r--spec/data/cookbooks/not-nginx/metadata.rb1
-rw-r--r--spec/data/kitchen/no-really-not-nginx/attributes/default.rb1
-rw-r--r--spec/data/kitchen/no-really-not-nginx/metadata.rb1
-rw-r--r--spec/unit/cookbook_loader_spec.rb23
11 files changed, 27 insertions, 68 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
diff --git a/lib/chef/cookbook_uploader.rb b/lib/chef/cookbook_uploader.rb
index 456c8b6c07..9ba5b2bd8b 100644
--- a/lib/chef/cookbook_uploader.rb
+++ b/lib/chef/cookbook_uploader.rb
@@ -159,7 +159,7 @@ class Chef
def validate_cookbooks
cookbooks.each do |cb|
- syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.pathname, @user_cookbook_path)
+ syntax_checker = Chef::Cookbook::SyntaxCheck.for_cookbook(cb.name, @user_cookbook_path)
Chef::Log.info("Validating ruby files")
exit(1) unless syntax_checker.validate_ruby_files
Chef::Log.info("Validating templates")
diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb
index 31ccbabe59..4e8b2a048e 100644
--- a/lib/chef/cookbook_version.rb
+++ b/lib/chef/cookbook_version.rb
@@ -50,7 +50,7 @@ class Chef
attr_accessor :resource_filenames
attr_accessor :provider_filenames
attr_accessor :root_filenames
- attr_accessor :pathname
+ attr_accessor :name
attr_accessor :metadata
attr_accessor :metadata_filenames
attr_accessor :status
@@ -83,8 +83,8 @@ class Chef
#
# === Returns
# object<Chef::CookbookVersion>:: Duh. :)
- def initialize(pathname)
- @pathname = pathname
+ def initialize(name)
+ @name = name
@frozen = false
@attribute_filenames = Array.new
@definition_filenames = Array.new
@@ -104,10 +104,6 @@ class Chef
@metadata = Chef::Cookbook::Metadata.new
end
- def name
- metadata.name || @pathname
- end
-
def version
metadata.version
end
@@ -602,11 +598,11 @@ class Chef
specificity = "default"
if segment == :root_files
- matcher = segment_file.match(".+/#{Regexp.escape(pathname.to_s)}/(.+)")
+ matcher = segment_file.match(".+/#{Regexp.escape(name.to_s)}/(.+)")
file_name = matcher[1]
path = file_name
elsif segment == :templates || segment == :files
- matcher = segment_file.match("/#{Regexp.escape(pathname.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+?)/(.+))")
unless matcher
Chef::Log.debug("Skipping file #{segment_file}, as it isn't in any of the proper directories (platform-version, platform or default)")
Chef::Log.debug("You probably need to move #{segment_file} into the 'default' sub-directory")
@@ -616,7 +612,7 @@ class Chef
specificity = matcher[2]
file_name = matcher[3]
else
- matcher = segment_file.match("/#{Regexp.escape(pathname.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
+ matcher = segment_file.match("/#{Regexp.escape(name.to_s)}/(#{Regexp.escape(segment.to_s)}/(.+))")
path = matcher[1]
file_name = matcher[2]
end
diff --git a/spec/data/cookbooks/not-nginx/attributes/default.rb b/spec/data/cookbooks/not-nginx/attributes/default.rb
deleted file mode 100644
index be06213478..0000000000
--- a/spec/data/cookbooks/not-nginx/attributes/default.rb
+++ /dev/null
@@ -1 +0,0 @@
-default[:cheese] = 'mr whiskers'
diff --git a/spec/data/cookbooks/not-nginx/metadata.rb b/spec/data/cookbooks/not-nginx/metadata.rb
deleted file mode 100644
index 85e7200e2b..0000000000
--- a/spec/data/cookbooks/not-nginx/metadata.rb
+++ /dev/null
@@ -1 +0,0 @@
-name "nginx"
diff --git a/spec/data/kitchen/no-really-not-nginx/attributes/default.rb b/spec/data/kitchen/no-really-not-nginx/attributes/default.rb
deleted file mode 100644
index 7987157ec2..0000000000
--- a/spec/data/kitchen/no-really-not-nginx/attributes/default.rb
+++ /dev/null
@@ -1 +0,0 @@
-default[:wine] = 'captain socks'
diff --git a/spec/data/kitchen/no-really-not-nginx/metadata.rb b/spec/data/kitchen/no-really-not-nginx/metadata.rb
deleted file mode 100644
index 85e7200e2b..0000000000
--- a/spec/data/kitchen/no-really-not-nginx/metadata.rb
+++ /dev/null
@@ -1 +0,0 @@
-name "nginx"
diff --git a/spec/unit/cookbook_loader_spec.rb b/spec/unit/cookbook_loader_spec.rb
index fd37aa1f08..c3303dd09a 100644
--- a/spec/unit/cookbook_loader_spec.rb
+++ b/spec/unit/cookbook_loader_spec.rb
@@ -68,8 +68,7 @@ describe Chef::CookbookLoader do
seen[2].should == "borken"
seen[3].should == "ignorken"
seen[4].should == "java"
- seen[5].should == "nginx"
- seen[6].should == "openldap"
+ seen[5].should == "openldap"
end
end
@@ -156,26 +155,6 @@ describe Chef::CookbookLoader do
end
@cookbook_loader.load_cookbooks
end
-
- it "should index cookbooks by name, not pathname" do
- @cookbook_loader.should_not have_key(:'not-nginx')
- @cookbook_loader.should_not have_key(:'no-really-not-nginx')
- @cookbook_loader.should have_key(:nginx)
- end
-
- it "should shadow cookbooks by name, not pathname" do
- @cookbook_loader[:nginx].attribute_filenames.detect { |f|
- f =~ /cookbooks\/not-nginx\/attributes\/default.rb/
- }.should_not eql(nil)
- @cookbook_loader[:nginx].attribute_filenames.detect { |f|
- f =~ /kitchen\/no-really-not-nginx\/attributes\/default.rb/
- }.should eql(nil)
- end
-
- it "should emit deprecation warning if name is not in metadata" do
- Chef::Log.should_receive(:warn).at_least(:once).with(/Inferring cookbook name from directory name \([^)]+\) is deprecated, please set a name in the metadata./)
- @cookbook_loader.load_cookbooks
- end
end # load_cookbooks
end # loading all cookbooks