summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/chef/resource.rb13
-rw-r--r--lib/chef/resource/lwrp_base.rb17
2 files changed, 22 insertions, 8 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb
index 15fdd87c84..2442b9a050 100644
--- a/lib/chef/resource.rb
+++ b/lib/chef/resource.rb
@@ -42,6 +42,7 @@ require_relative "mixin/deprecation"
require_relative "mixin/properties"
require_relative "mixin/provides"
require_relative "dsl/universal"
+require_relative "constants"
class Chef
class Resource
@@ -1362,8 +1363,9 @@ class Chef
#
# @param arg [String] version constraint to match against (e.g. "> 14")
#
- def self.chef_version_for_provides(constraint)
- @chef_version_for_provides = constraint
+ def self.chef_version_for_provides(constraint = NOT_PASSED)
+ @chef_version_for_provides = constraint unless constraint == NOT_PASSED
+ @chef_version_for_provides ||= nil
end
# Mark this resource as providing particular DSL.
@@ -1376,14 +1378,11 @@ class Chef
def self.provides(name, **options, &block)
name = name.to_sym
- # quell warnings
- @chef_version_for_provides = nil unless defined?(@chef_version_for_provides)
-
# deliberately do not go through the accessor here
@resource_name = name if resource_name.nil?
- if @chef_version_for_provides && !options.include?(:chef_version)
- options[:chef_version] = @chef_version_for_provides
+ if chef_version_for_provides && !options.include?(:chef_version)
+ options[:chef_version] = chef_version_for_provides
end
result = Chef.resource_handler_map.set(name, self, **options, &block)
diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb
index 5503bb5fce..1284572339 100644
--- a/lib/chef/resource/lwrp_base.rb
+++ b/lib/chef/resource/lwrp_base.rb
@@ -26,6 +26,7 @@ require_relative "../exceptions"
require_relative "../mixin/convert_to_class_name"
require_relative "../mixin/from_file"
require_relative "../mixin/params_validate" # for DelayedEvaluator
+require_relative "../version"
class Chef
class Resource
@@ -53,7 +54,7 @@ class Chef
resource_class.run_context = run_context
resource_class.class_from_file(filename)
- unless resource_class.unified_mode
+ if !resource_class.unified_mode && !deprecated_class(resource_class)
Chef.deprecated :unified_mode, "The #{resource_class.resource_name} resource in the #{cookbook_name} cookbook should declare `unified_mode true`", filename
end
@@ -121,6 +122,20 @@ class Chef
superclass.respond_to?(m) ? superclass.send(m) : default
end
+
+ # Return true if the resource has been deprecated on this version.
+ #
+ # XXX: for now we only look at chef_version_for_provides, reversing the
+ # resource node_map to determine if the resource provides anything which is
+ # wired up is difficult.
+ #
+ def deprecated_class(resource_class)
+ if resource_class.chef_version_for_provides && Chef::VERSION !~ resource_class.chef_version_for_provides
+ return true
+ end
+
+ false
+ end
end
end
end