diff options
author | Xabier de Zuazo <xabier@onddo.com> | 2013-03-13 12:03:35 +0100 |
---|---|---|
committer | Bryan McLellan <btm@opscode.com> | 2013-04-11 13:04:33 -0700 |
commit | 7052e7712a6b159626c2077f86e8be551e79bbd4 (patch) | |
tree | ef0cb7faba3afcce049d2f8a34076344811625c6 /lib/chef | |
parent | f554a1c0fbc1f308462d3d62544a0fd7ed7df6ec (diff) | |
download | chef-7052e7712a6b159626c2077f86e8be551e79bbd4.tar.gz |
[CHEF-3919] Removed Chef::Version::Cookbook code and replaced by a Chef::Version::Platform class, reverting Chef::Version class changes
Diffstat (limited to 'lib/chef')
-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 |
12 files changed, 40 insertions, 39 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 |