diff options
-rw-r--r-- | lib/chef/client.rb | 2 | ||||
-rw-r--r-- | lib/chef/cookbook/metadata.rb | 4 | ||||
-rw-r--r-- | lib/chef/cookbook_version.rb | 8 | ||||
-rw-r--r-- | lib/chef/environment.rb | 4 | ||||
-rw-r--r-- | lib/chef/exceptions.rb | 2 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_download.rb | 4 | ||||
-rw-r--r-- | lib/chef/knife/cookbook_upload.rb | 4 | ||||
-rw-r--r-- | lib/chef/platform.rb | 6 | ||||
-rw-r--r-- | lib/chef/run_list/versioned_recipe_list.rb | 8 | ||||
-rw-r--r-- | lib/chef/version/platform.rb (renamed from lib/chef/version/cookbook.rb) | 25 | ||||
-rw-r--r-- | lib/chef/version_class.rb | 6 | ||||
-rw-r--r-- | lib/chef/version_constraint/platform.rb (renamed from lib/chef/version_constraint/cookbook.rb) | 6 | ||||
-rw-r--r-- | spec/unit/version/platform_spec.rb (renamed from spec/unit/version/cookbook_spec.rb) | 30 | ||||
-rw-r--r-- | spec/unit/version_class_spec.rb | 6 | ||||
-rw-r--r-- | spec/unit/version_constraint/platform_spec.rb (renamed from spec/unit/version_constraint/cookbook_spec.rb) | 14 | ||||
-rw-r--r-- | spec/unit/version_constraint_spec.rb | 2 |
16 files changed, 72 insertions, 59 deletions
diff --git a/lib/chef/client.rb b/lib/chef/client.rb index 969b8e6d1a..010f08acac 100644 --- a/lib/chef/client.rb +++ b/lib/chef/client.rb @@ -292,7 +292,7 @@ class Chef # # Convert @expanded_run_list, which is an # Array of Hashes of the form - # {:name => NAME, :version_constraint => Chef::VersionConstraint::Cookbook }, + # {:name => NAME, :version_constraint => Chef::VersionConstraint }, # into @expanded_run_list_with_versions, an # Array of Strings of the form # "#{NAME}@#{VERSION}" diff --git a/lib/chef/cookbook/metadata.rb b/lib/chef/cookbook/metadata.rb index b42a8df3fd..18368bd99f 100644 --- a/lib/chef/cookbook/metadata.rb +++ b/lib/chef/cookbook/metadata.rb @@ -209,7 +209,7 @@ class Chef # version<String>:: Returns the current version def version(arg=nil) if arg - @version = Chef::Version::Cookbook.new(arg) + @version = Chef::Version.new(arg) end @version.to_s @@ -516,7 +516,7 @@ OBSOLETED end def validate_version_constraint(caller_name, dep_name, constraint_str) - Chef::VersionConstraint::Cookbook.new(constraint_str) + Chef::VersionConstraint.new(constraint_str) rescue Chef::Exceptions::InvalidVersionConstraint => e Log.debug(e) diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index 61917fc889..a70c892e1b 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -25,7 +25,7 @@ require 'chef/resource_definition_list' require 'chef/recipe' require 'chef/cookbook/file_vendor' require 'chef/cookbook/metadata' -require 'chef/version/cookbook' +require 'chef/version_class' class Chef @@ -669,9 +669,9 @@ class Chef def <=>(o) raise Chef::Exceptions::CookbookVersionNameMismatch if self.name != o.name # FIXME: can we change the interface to the Metadata class such - # that metadata.version returns a Chef::Version::Cookbook instance - # instead of a string? - Chef::Version.new(self.version) <=> Chef::Version::Cookbook.new(o.version) + # that metadata.version returns a Chef::Version instance instead + # of a string? + Chef::Version.new(self.version) <=> Chef::Version.new(o.version) end private diff --git a/lib/chef/environment.rb b/lib/chef/environment.rb index 7439be0304..00cc253083 100644 --- a/lib/chef/environment.rb +++ b/lib/chef/environment.rb @@ -22,7 +22,7 @@ require 'chef/config' require 'chef/mash' require 'chef/mixin/params_validate' require 'chef/mixin/from_file' -require 'chef/version_constraint/cookbook' +require 'chef/version_constraint' class Chef class Environment @@ -276,7 +276,7 @@ class Chef def self.validate_cookbook_version(version) begin - Chef::VersionConstraint::Cookbook.new version + Chef::VersionConstraint.new version true rescue ArgumentError false diff --git a/lib/chef/exceptions.rb b/lib/chef/exceptions.rb index 3b2a75eb01..8d6eac7839 100644 --- a/lib/chef/exceptions.rb +++ b/lib/chef/exceptions.rb @@ -107,7 +107,7 @@ class Chef class CookbookVersionConflict < ArgumentError ; end # does not follow X.Y.Z format. ArgumentError? - class InvalidVersion < ArgumentError; end + class InvalidPlatformVersion < ArgumentError; end class InvalidCookbookVersion < ArgumentError; end # version constraint should be a string or array, or it doesn't diff --git a/lib/chef/knife/cookbook_download.rb b/lib/chef/knife/cookbook_download.rb index 58f61cb561..1da1121b22 100644 --- a/lib/chef/knife/cookbook_download.rb +++ b/lib/chef/knife/cookbook_download.rb @@ -98,7 +98,7 @@ class Chef if available_versions.size == 1 @version = available_versions.first elsif config[:latest] - @version = available_versions.map { |v| Chef::Version::Cookbook.new(v) }.sort.last + @version = available_versions.map { |v| Chef::Version.new(v) }.sort.last else ask_which_version end @@ -107,7 +107,7 @@ class Chef def available_versions @available_versions ||= begin versions = Chef::CookbookVersion.available_versions(@cookbook_name).map do |version| - Chef::Version::Cookbook.new(version) + Chef::Version.new(version) end versions.sort! versions diff --git a/lib/chef/knife/cookbook_upload.rb b/lib/chef/knife/cookbook_upload.rb index 37535734e9..f50296509b 100644 --- a/lib/chef/knife/cookbook_upload.rb +++ b/lib/chef/knife/cookbook_upload.rb @@ -274,7 +274,7 @@ WARNING versions = @server_side_cookbooks[cookbook_name]['versions'].collect {|versions| versions["version"]} Log.debug "Versions of cookbook '#{cookbook_name}' returned by the server: #{versions.join(", ")}" @server_side_cookbooks[cookbook_name]["versions"].each do |versions_hash| - if Chef::VersionConstraint::Cookbook.new(version).include?(versions_hash["version"]) + if Chef::VersionConstraint.new(version).include?(versions_hash["version"]) Log.debug "Matched cookbook '#{cookbook_name}' with constraint '#{version}' to cookbook version '#{versions_hash['version']}' on the server" return true end @@ -284,7 +284,7 @@ WARNING end def check_uploading_cookbooks(cookbook_name, version) - if (! cookbooks_to_upload[cookbook_name].nil?) && Chef::VersionConstraint::Cookbook.new(version).include?(cookbooks_to_upload[cookbook_name].version) + if (! cookbooks_to_upload[cookbook_name].nil?) && Chef::VersionConstraint.new(version).include?(cookbooks_to_upload[cookbook_name].version) Log.debug "Matched cookbook '#{cookbook_name}' with constraint '#{version}' to a local cookbook." return true end diff --git a/lib/chef/platform.rb b/lib/chef/platform.rb index bca003d35a..210aabd3e5 100644 --- a/lib/chef/platform.rb +++ b/lib/chef/platform.rb @@ -19,7 +19,7 @@ require 'chef/config' require 'chef/log' require 'chef/mixin/params_validate' -require 'chef/version_constraint' +require 'chef/version_constraint/platform' # This file depends on nearly every provider in chef, but requiring them # directly causes circular requires resulting in uninitialized constant errors. @@ -345,12 +345,12 @@ class Chef end platform_versions.each do |platform_version, provider| begin - version_constraint = Chef::VersionConstraint::Cookbook.new(platform_version) + version_constraint = Chef::VersionConstraint::Platform.new(platform_version) if version_constraint.include?(version) Chef::Log.debug("Platform #{name.to_s} version #{version} found") provider_map.merge!(provider) end - rescue Chef::Exceptions::InvalidCookbookVersion + rescue Chef::Exceptions::InvalidPlatformVersion Chef::Log.debug("Chef::Version::Comparable does not know how to parse the platform version: #{version}") end end diff --git a/lib/chef/run_list/versioned_recipe_list.rb b/lib/chef/run_list/versioned_recipe_list.rb index 9339985207..0eefded964 100644 --- a/lib/chef/run_list/versioned_recipe_list.rb +++ b/lib/chef/run_list/versioned_recipe_list.rb @@ -15,7 +15,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -require 'chef/version/cookbook' +require 'chef/version_class' require 'chef/version_constraint' # Why does this class exist? @@ -31,7 +31,7 @@ class Chef def add_recipe(name, version=nil) if version && @versions.has_key?(name) - unless Chef::Version::Cookbook.new(@versions[name]) == Chef::Version::Cookbook.new(version) + unless Chef::Version.new(@versions[name]) == Chef::Version.new(version) raise Chef::Exceptions::CookbookVersionConflict, "Run list requires #{name} at versions #{@versions[name]} and #{version}" end end @@ -44,10 +44,10 @@ class Chef end # Return an Array of Hashes, each of the form: - # {:name => RECIPE_NAME, :version_constraint => Chef::VersionConstraint::Cookbook } + # {:name => RECIPE_NAME, :version_constraint => Chef::VersionConstraint } def with_version_constraints self.map do |recipe_name| - constraint = Chef::VersionConstraint::Cookbook.new(@versions[recipe_name]) + constraint = Chef::VersionConstraint.new(@versions[recipe_name]) { :name => recipe_name, :version_constraint => constraint } end end diff --git a/lib/chef/version/cookbook.rb b/lib/chef/version/platform.rb index 391d46563c..2921341cd2 100644 --- a/lib/chef/version/cookbook.rb +++ b/lib/chef/version/platform.rb @@ -18,20 +18,23 @@ require 'chef/version_class' class Chef class Version - class Cookbook < Chef::Version + class Platform < Chef::Version protected - def parse(str='') - msg = "'#{str.to_s}' does not match 'x.y.z' or 'x.y'" - begin - super - rescue Chef::Exceptions::InvalidVersion => e - raise Chef::Exceptions::InvalidCookbookVersion.new( msg ) - end - if str.to_s =~ /^(\d+)$/ - raise Chef::Exceptions::InvalidCookbookVersion.new( msg ) - end + def parse(str="") + @major, @minor, @patch = + case str.to_s + when /^(\d+)\.(\d+)\.(\d+)$/ + [ $1.to_i, $2.to_i, $3.to_i ] + when /^(\d+)\.(\d+)$/ + [ $1.to_i, $2.to_i, 0 ] + when /^(\d+)$/ + [ $1.to_i, 0, 0 ] + else + msg = "'#{str.to_s}' does not match 'x.y.z', 'x.y' or 'x'" + raise Chef::Exceptions::InvalidPlatformVersion.new( msg ) + end end end diff --git a/lib/chef/version_class.rb b/lib/chef/version_class.rb index 25b393854b..01af6f1f55 100644 --- a/lib/chef/version_class.rb +++ b/lib/chef/version_class.rb @@ -60,11 +60,9 @@ class Chef [ $1.to_i, $2.to_i, $3.to_i ] when /^(\d+)\.(\d+)$/ [ $1.to_i, $2.to_i, 0 ] - when /^(\d+)$/ - [ $1.to_i, 0, 0 ] else - msg = "'#{str.to_s}' does not match 'x.y.z', 'x.y' or 'x'" - raise Chef::Exceptions::InvalidVersion.new( msg ) + msg = "'#{str.to_s}' does not match 'x.y.z' or 'x.y'" + raise Chef::Exceptions::InvalidCookbookVersion.new( msg ) end end diff --git a/lib/chef/version_constraint/cookbook.rb b/lib/chef/version_constraint/platform.rb index 2ed6ef2872..ada4f29b70 100644 --- a/lib/chef/version_constraint/cookbook.rb +++ b/lib/chef/version_constraint/platform.rb @@ -14,12 +14,12 @@ # See the License for the specific language governing permissions and # limitations under the License. require 'chef/version_constraint' -require 'chef/version/cookbook' +require 'chef/version/platform' class Chef class VersionConstraint - class Cookbook < Chef::VersionConstraint - VERSION_CLASS = Chef::Version::Cookbook + class Platform < Chef::VersionConstraint + VERSION_CLASS = Chef::Version::Platform end end diff --git a/spec/unit/version/cookbook_spec.rb b/spec/unit/version/platform_spec.rb index 4bbb9eedb3..6245800f9d 100644 --- a/spec/unit/version/cookbook_spec.rb +++ b/spec/unit/version/platform_spec.rb @@ -15,35 +15,47 @@ # limitations under the License. require 'spec_helper' -require 'chef/version/cookbook' +require 'chef/version/platform' -describe Chef::Version::Cookbook do +describe Chef::Version::Platform do it "is a subclass of Chef::Version" do - v = Chef::Version::Cookbook.new('1.1') - v.should be_an_instance_of(Chef::Version::Cookbook) + v = Chef::Version::Platform.new('1.1') + v.should be_an_instance_of(Chef::Version::Platform) v.should be_a_kind_of(Chef::Version) end + + it "should transform 1 to 1.0.0" do + Chef::Version::Platform.new("1").to_s.should == "1.0.0" + end describe "when creating valid Versions" do - good_versions = %w(1.2 1.2.3 1000.80.50000 0.300.25 001.02.00003) + good_versions = %w(1 1.2 1.2.3 1000.80.50000 0.300.25 001.02.00003) good_versions.each do |v| it "should accept '#{v}'" do - Chef::Version::Cookbook.new v + Chef::Version::Platform.new v end end end describe "when given bogus input" do - bad_versions = ["1.2.3.4", "1.2.a4", "1", "a", "1.2 3", "1.2 a", + bad_versions = ["1.2.3.4", "1.2.a4", "a", "1.2 3", "1.2 a", "1 2 3", "1-2-3", "1_2_3", "1.2_3", "1.2-3"] - the_error = Chef::Exceptions::InvalidCookbookVersion + the_error = Chef::Exceptions::InvalidPlatformVersion bad_versions.each do |v| it "should raise #{the_error} when given '#{v}'" do - lambda { Chef::Version::Cookbook.new v }.should raise_error(the_error) + lambda { Chef::Version::Platform.new v }.should raise_error(the_error) end end end + describe "<=>" do + + it "should equate versions 1 and 1.0.0" do + Chef::Version::Platform.new("1").should == Chef::Version::Platform.new("1.0.0") + end + + end + end diff --git a/spec/unit/version_class_spec.rb b/spec/unit/version_class_spec.rb index f95bfa1293..285588b031 100644 --- a/spec/unit/version_class_spec.rb +++ b/spec/unit/version_class_spec.rb @@ -44,7 +44,7 @@ describe Chef::Version do end describe "when creating valid Versions" do - good_versions = %w(1 1.2 1.2.3 1000.80.50000 0.300.25 001.02.00003) + good_versions = %w(1.2 1.2.3 1000.80.50000 0.300.25 001.02.00003) good_versions.each do |v| it "should accept '#{v}'" do Chef::Version.new v @@ -53,9 +53,9 @@ describe Chef::Version do end describe "when given bogus input" do - bad_versions = ["1.2.3.4", "1.2.a4", "a", "1.2 3", "1.2 a", + bad_versions = ["1.2.3.4", "1.2.a4", "1", "a", "1.2 3", "1.2 a", "1 2 3", "1-2-3", "1_2_3", "1.2_3", "1.2-3"] - the_error = Chef::Exceptions::InvalidVersion + the_error = Chef::Exceptions::InvalidCookbookVersion bad_versions.each do |v| it "should raise #{the_error} when given '#{v}'" do lambda { Chef::Version.new v }.should raise_error(the_error) diff --git a/spec/unit/version_constraint/cookbook_spec.rb b/spec/unit/version_constraint/platform_spec.rb index ddfd966ab8..11360a6595 100644 --- a/spec/unit/version_constraint/cookbook_spec.rb +++ b/spec/unit/version_constraint/platform_spec.rb @@ -15,19 +15,19 @@ # limitations under the License. require 'spec_helper' -require 'chef/version_constraint/cookbook' +require 'chef/version_constraint/platform' -describe Chef::VersionConstraint::Cookbook do +describe Chef::VersionConstraint::Platform do it "is a subclass of Chef::VersionConstraint" do - v = Chef::VersionConstraint::Cookbook.new - v.should be_an_instance_of(Chef::VersionConstraint::Cookbook) + v = Chef::VersionConstraint::Platform.new + v.should be_an_instance_of(Chef::VersionConstraint::Platform) v.should be_a_kind_of(Chef::VersionConstraint) end - it "should work with Chef::Version::Cookbook classes" do - vc = Chef::VersionConstraint::Cookbook.new("1.0") - vc.version.should be_an_instance_of(Chef::Version::Cookbook) + it "should work with Chef::Version::Platform classes" do + vc = Chef::VersionConstraint::Platform.new("1.0") + vc.version.should be_an_instance_of(Chef::Version::Platform) end end diff --git a/spec/unit/version_constraint_spec.rb b/spec/unit/version_constraint_spec.rb index ff8dd8b504..2c1246b776 100644 --- a/spec/unit/version_constraint_spec.rb +++ b/spec/unit/version_constraint_spec.rb @@ -23,7 +23,7 @@ describe Chef::VersionConstraint do bad_version = ["> >", ">= 1.2.z", "> 1.2.3 < 5.0", "> 1.2.3, < 5.0"] bad_op = ["<3.0.1", ">$ 1.2.3", "! 3.4"] o_error = Chef::Exceptions::InvalidVersionConstraint - v_error = Chef::Exceptions::InvalidVersion + v_error = Chef::Exceptions::InvalidCookbookVersion bad_version.each do |s| it "should raise #{v_error} when given #{s}" do lambda { Chef::VersionConstraint.new s }.should raise_error(v_error) |