diff options
author | John Keiser <john@johnkeiser.com> | 2015-09-25 07:19:48 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-09-25 12:22:19 -0700 |
commit | 424b2dda9b4a2a0ca3e7ca8c9a598643b303ec0f (patch) | |
tree | a687cef44f257a6b7402da826ed9292164707f20 | |
parent | c576de210dc42889d796074187a109a8d0dd6a19 (diff) | |
download | chef-424b2dda9b4a2a0ca3e7ca8c9a598643b303ec0f.tar.gz |
Find the spot the user called and use that as the deprecation location
-rw-r--r-- | lib/chef/chef_class.rb | 13 | ||||
-rw-r--r-- | lib/chef/cookbook_version.rb | 6 | ||||
-rw-r--r-- | lib/chef/deprecation/provider/remote_directory.rb | 2 | ||||
-rw-r--r-- | lib/chef/deprecation/warnings.rb | 2 | ||||
-rw-r--r-- | lib/chef/formatters/base.rb | 2 | ||||
-rw-r--r-- | lib/chef/resource/file/verification.rb | 3 |
6 files changed, 19 insertions, 9 deletions
diff --git a/lib/chef/chef_class.rb b/lib/chef/chef_class.rb index c2cb9e2b24..b18c3fbdde 100644 --- a/lib/chef/chef_class.rb +++ b/lib/chef/chef_class.rb @@ -204,7 +204,18 @@ class Chef # # @api private this will likely be removed in favor of an as-yet unwritten # `Chef.log` - def log_deprecation(message, location=caller(2..2)[0]) + def log_deprecation(message, location=nil) + if !location + # Pick the first caller that is *not* part of the Chef gem, that's the + # thing the user wrote. + chef_gem_path = File.expand_path("../..", __FILE__) + caller(0..10).each do |c| + if !c.start_with?(chef_gem_path) + location = c + break + end + end + end # `run_context.events` is the primary deprecation target if we're in a # run. If we are not yet in a run, print to `Chef::Log`. if run_context && run_context.events diff --git a/lib/chef/cookbook_version.rb b/lib/chef/cookbook_version.rb index bff3146572..3cdfd8c10b 100644 --- a/lib/chef/cookbook_version.rb +++ b/lib/chef/cookbook_version.rb @@ -51,12 +51,12 @@ class Chef attr_accessor :metadata_filenames def status=(new_status) - Chef.log_deprecation("Deprecated method `status' called. This method will be removed.", caller(1..1)) + Chef.log_deprecation("Deprecated method `status' called. This method will be removed.") @status = new_status end def status - Chef.log_deprecation("Deprecated method `status' called. This method will be removed.", caller(1..1)) + Chef.log_deprecation("Deprecated method `status' called. This method will be removed.") @status end @@ -480,7 +480,7 @@ class Chef # @deprecated This method was used by the Ruby Chef Server and is no longer # needed. There is no replacement. def generate_manifest_with_urls(&url_generator) - Chef.log_deprecation("Deprecated method #generate_manifest_with_urls.", caller(1..1)) + Chef.log_deprecation("Deprecated method #generate_manifest_with_urls.") rendered_manifest = manifest.dup COOKBOOK_SEGMENTS.each do |segment| diff --git a/lib/chef/deprecation/provider/remote_directory.rb b/lib/chef/deprecation/provider/remote_directory.rb index b55a304696..cc8026ec55 100644 --- a/lib/chef/deprecation/provider/remote_directory.rb +++ b/lib/chef/deprecation/provider/remote_directory.rb @@ -22,7 +22,7 @@ class Chef module RemoteDirectory def directory_root_in_cookbook_cache - Chef::Log.deprecation "the Chef::Provider::RemoteDirectory#directory_root_in_cookbook_cache method is deprecated" + Chef.log_deprecation "the Chef::Provider::RemoteDirectory#directory_root_in_cookbook_cache method is deprecated" @directory_root_in_cookbook_cache ||= begin diff --git a/lib/chef/deprecation/warnings.rb b/lib/chef/deprecation/warnings.rb index 376629710e..0b1ec2d5ed 100644 --- a/lib/chef/deprecation/warnings.rb +++ b/lib/chef/deprecation/warnings.rb @@ -27,7 +27,7 @@ class Chef message = [] message << "Method '#{name}' of '#{self.class}' is deprecated. It will be removed in Chef 13." message << "Please update your cookbooks accordingly." - Chef.log_deprecation(message, caller(0..3)) + Chef.log_deprecation(message) super(*args) end end diff --git a/lib/chef/formatters/base.rb b/lib/chef/formatters/base.rb index d3756ef00c..e4056a00fc 100644 --- a/lib/chef/formatters/base.rb +++ b/lib/chef/formatters/base.rb @@ -213,7 +213,7 @@ class Chef end def deprecation(message, location=caller(2..2)[0]) - Chef::Log.deprecation("#{message} at #{location}") + Chef.log_deprecation("#{message} at #{location}") end end diff --git a/lib/chef/resource/file/verification.rb b/lib/chef/resource/file/verification.rb index 9b0788fad3..ba0bb08201 100644 --- a/lib/chef/resource/file/verification.rb +++ b/lib/chef/resource/file/verification.rb @@ -110,8 +110,7 @@ class Chef # is interpolated. Until `file` can be deprecated, interpolate both. Chef.log_deprecation( '%{file} is deprecated in verify command and will not be '\ - 'supported in Chef 13. Please use %{path} instead.', - caller(2..2)[0] + 'supported in Chef 13. Please use %{path} instead.' ) if @command.include?('%{file}') command = @command % {:file => path, :path => path} interpreter = Chef::GuardInterpreter.for_resource(@parent_resource, command, @command_opts) |