diff options
author | Chris Walters <cw@opscode.com> | 2011-03-25 14:40:47 -0700 |
---|---|---|
committer | sdelano <stephen@opscode.com> | 2011-03-25 16:06:58 -0700 |
commit | 0c6e9a53cb38eeb85b869987710290c130d8a493 (patch) | |
tree | e3b094b32c04acaf02972b288116475bc56e7042 | |
parent | 88319de790e32e16ea31d463f1a872c6ac7098bc (diff) | |
download | chef-0c6e9a53cb38eeb85b869987710290c130d8a493.tar.gz |
Handling deprecated constraint specifications
-rw-r--r-- | chef/lib/chef/cookbook/metadata.rb | 28 | ||||
-rw-r--r-- | chef/lib/chef/cookbook_version_selector.rb | 6 | ||||
-rw-r--r-- | chef/spec/unit/cookbook/metadata_spec.rb | 2 |
3 files changed, 27 insertions, 9 deletions
diff --git a/chef/lib/chef/cookbook/metadata.rb b/chef/lib/chef/cookbook/metadata.rb index 0ea60bf8a3..c8692b1e69 100644 --- a/chef/lib/chef/cookbook/metadata.rb +++ b/chef/lib/chef/cookbook/metadata.rb @@ -423,12 +423,12 @@ class Chef @maintainer_email = o['maintainer_email'] if o.has_key?('maintainer_email') @license = o['license'] if o.has_key?('license') @platforms = o['platforms'] if o.has_key?('platforms') - @dependencies = o['dependencies'] if o.has_key?('dependencies') - @recommendations = o['recommendations'] if o.has_key?('recommendations') - @suggestions = o['suggestions'] if o.has_key?('suggestions') - @conflicting = o['conflicting'] if o.has_key?('conflicting') + @dependencies = handle_deprecated_constraints(o['dependencies']) if o.has_key?('dependencies') + @recommendations = handle_deprecated_constraints(o['recommendations']) if o.has_key?('recommendations') + @suggestions = handle_deprecated_constraints(o['suggestions']) if o.has_key?('suggestions') + @conflicting = handle_deprecated_constraints(o['conflicting']) if o.has_key?('conflicting') @providing = o['providing'] if o.has_key?('providing') - @replacing = o['replacing'] if o.has_key?('replacing') + @replacing = handle_deprecated_constraints(o['replacing']) if o.has_key?('replacing') @attributes = o['attributes'] if o.has_key?('attributes') @groupings = o['groupings'] if o.has_key?('groupings') @recipes = o['recipes'] if o.has_key?('recipes') @@ -502,6 +502,24 @@ class Chef end end + # This method translates version constraint strings from + # cookbooks with the old format. + # + # Before we began respecting version constraints, we allowed + # multiple constraints to be placed on cookbooks, as well as the + # << and >> operators, which are now just < and >. For + # specifications with more than one constraint, we return an + # empty array (otherwise, we're silently abiding only part of + # the contract they have specified to us). If there is only one + # constraint, we are replacing the old << and >> with the new < + # and >. + def handle_deprecated_constraints(specification) + specification.inject(Mash.new) do |acc, (cb, constraints)| + acc[cb] = constraints.size > 1 ? [] : constraints.map{|c| c.gsub(/>>/, '>').gsub(/<</, '<')} + acc + end + end + end end end diff --git a/chef/lib/chef/cookbook_version_selector.rb b/chef/lib/chef/cookbook_version_selector.rb index d7792d59a1..03fd8a24e0 100644 --- a/chef/lib/chef/cookbook_version_selector.rb +++ b/chef/lib/chef/cookbook_version_selector.rb @@ -50,10 +50,10 @@ class Chef # return the object and handle proper serialization and # de-serialization. For now, I'm just going to create a # Version object from the String representation. - pv = dep_graph.package(cb_name).add_version(DepSelector::Version.new(cb_version.version)) + pv = dep_graph.package(cb_name).add_version(Chef::Version.new(cb_version.version)) cb_version_deps.each_pair do |dep_name, constraint_str| - constraint = DepSelector::VersionConstraint.new(constraint_str) - pv.dependencies << DepSelector::Dependency.new(dep_graph.package(dep_name), constraint) + constraint = Chef::VersionConstraint.new(constraint_str) + pv.dependencies << Chef::Dependency.new(dep_graph.package(dep_name), constraint) end end end diff --git a/chef/spec/unit/cookbook/metadata_spec.rb b/chef/spec/unit/cookbook/metadata_spec.rb index b48d4ccc68..77f84deaea 100644 --- a/chef/spec/unit/cookbook/metadata_spec.rb +++ b/chef/spec/unit/cookbook/metadata_spec.rb @@ -477,7 +477,7 @@ describe Chef::Cookbook::Metadata do :display_name => "You have nothing" @meta.version "1.2.3" end - + describe "serialize" do before(:each) do @serial = Chef::JSONCompat.from_json(@meta.to_json) |