summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-01-23 07:48:44 -0800
committerdanielsdeleo <dan@opscode.com>2013-01-23 15:05:36 -0800
commit53fa8088240f19a1dfc589d9ba07098cbdd9bba2 (patch)
tree31f2a262eb1abb1a0be0d71a6a831a233e5967f5
parent0b7f0ab517733b00d55d75091c185f35434191ff (diff)
downloadchef-53fa8088240f19a1dfc589d9ba07098cbdd9bba2.tar.gz
[CHEF-3783] Make deprecated constants available
* Make deprecated constants in Chef::Mixin available by loading the relevant files from the chef/dsl files that replace them. * Add deprecation warnings via const_missing hook.
-rw-r--r--lib/chef/dsl/data_query.rb5
-rw-r--r--lib/chef/dsl/include_attribute.rb3
-rw-r--r--lib/chef/dsl/include_recipe.rb3
-rw-r--r--lib/chef/dsl/platform_introspection.rb5
-rw-r--r--lib/chef/dsl/recipe.rb5
-rw-r--r--lib/chef/mixin/deprecation.rb35
-rw-r--r--lib/chef/mixin/language.rb19
-rw-r--r--lib/chef/mixin/language_include_attribute.rb7
-rw-r--r--lib/chef/mixin/language_include_recipe.rb7
-rw-r--r--lib/chef/mixin/recipe_definition_dsl_core.rb6
-rw-r--r--lib/chef/mixins.rb1
-rw-r--r--spec/unit/mixin/deprecation_spec.rb23
12 files changed, 110 insertions, 9 deletions
diff --git a/lib/chef/dsl/data_query.rb b/lib/chef/dsl/data_query.rb
index ef5b490020..65e7b185a7 100644
--- a/lib/chef/dsl/data_query.rb
+++ b/lib/chef/dsl/data_query.rb
@@ -64,3 +64,8 @@ class Chef
end
end
end
+
+# **DEPRECATED**
+# This used to be part of chef/mixin/language. Load the file to activate the deprecation code.
+require 'chef/mixin/language'
+
diff --git a/lib/chef/dsl/include_attribute.rb b/lib/chef/dsl/include_attribute.rb
index d8342af6a7..3a95ce7268 100644
--- a/lib/chef/dsl/include_attribute.rb
+++ b/lib/chef/dsl/include_attribute.rb
@@ -56,5 +56,8 @@ class Chef
end
end
+# **DEPRECATED**
+# This used to be part of chef/mixin/language_include_attribute. Load the file to activate the deprecation code.
+require 'chef/mixin/language_include_attribute'
diff --git a/lib/chef/dsl/include_recipe.rb b/lib/chef/dsl/include_recipe.rb
index 8cbee7a733..b4d076da10 100644
--- a/lib/chef/dsl/include_recipe.rb
+++ b/lib/chef/dsl/include_recipe.rb
@@ -39,4 +39,7 @@ class Chef
end
end
+# **DEPRECATED**
+# This used to be part of chef/mixin/language_include_recipe. Load the file to activate the deprecation code.
+require 'chef/mixin/language_include_recipe'
diff --git a/lib/chef/dsl/platform_introspection.rb b/lib/chef/dsl/platform_introspection.rb
index 3328bb5c9a..33aa451f30 100644
--- a/lib/chef/dsl/platform_introspection.rb
+++ b/lib/chef/dsl/platform_introspection.rb
@@ -211,3 +211,8 @@ class Chef
end
end
end
+
+# **DEPRECATED**
+# This used to be part of chef/mixin/language. Load the file to activate the deprecation code.
+require 'chef/mixin/language'
+
diff --git a/lib/chef/dsl/recipe.rb b/lib/chef/dsl/recipe.rb
index 88006aced3..f3507a8031 100644
--- a/lib/chef/dsl/recipe.rb
+++ b/lib/chef/dsl/recipe.rb
@@ -20,7 +20,6 @@
require 'chef/resource'
require 'chef/resource_platform_map'
require 'chef/mixin/convert_to_class_name'
-require 'chef/mixin/language'
class Chef
module DSL
@@ -82,3 +81,7 @@ class Chef
end
end
end
+
+# **DEPRECATED**
+# This used to be part of chef/mixin/recipe_definition_dsl_core. Load the file to activate the deprecation code.
+require 'chef/mixin/recipe_definition_dsl_core'
diff --git a/lib/chef/mixin/deprecation.rb b/lib/chef/mixin/deprecation.rb
index cc85c4e976..489f27c339 100644
--- a/lib/chef/mixin/deprecation.rb
+++ b/lib/chef/mixin/deprecation.rb
@@ -18,7 +18,42 @@
class Chef
module Mixin
+
+
+ def self.deprecated_constants
+ @deprecated_constants ||= {}
+ end
+
+ # Add a deprecated constant to the Chef::Mixin namespace.
+ # === Arguments
+ # * name: the constant name, as a relative symbol.
+ # * replacement: the constant to return instead.
+ # * message: A message telling the user what to do instead.
+ # === Example:
+ # deprecate_constant(:RecipeDefinitionDSLCore, Chef::DSL::Recipe, <<-EOM)
+ # Chef::Mixin::RecipeDefinitionDSLCore is deprecated, use Chef::DSL::Recipe instead.
+ # EOM
+ def self.deprecate_constant(name, replacement, message)
+ deprecated_constants[name] = {:replacement => replacement, :message => message}
+ end
+
+ # Const missing hook to look up deprecated constants defined with
+ # deprecate_constant. Emits a warning to the logger and returns the
+ # replacement constant. Will call super, most likely causing an exception
+ # for the missing constant, if +name+ is not found in the
+ # deprecated_constants collection.
+ def self.const_missing(name)
+ if new_const = deprecated_constants[name]
+ Chef::Log.warn(new_const[:message])
+ Chef::Log.warn("Called from: \n#{caller[0...3].map {|l| "\t#{l}"}.join("\n")}")
+ new_const[:replacement]
+ else
+ super
+ end
+ end
+
module Deprecation
+
class DeprecatedObjectProxyBase
KEEPERS = %w{__id__ __send__ instance_eval == equal? initialize object_id}
instance_methods.each { |method_name| undef_method(method_name) unless KEEPERS.include?(method_name.to_s)}
diff --git a/lib/chef/mixin/language.rb b/lib/chef/mixin/language.rb
index 3aa6a6d800..48d5a8403a 100644
--- a/lib/chef/mixin/language.rb
+++ b/lib/chef/mixin/language.rb
@@ -22,15 +22,26 @@ require 'chef/dsl/data_query'
class Chef
module Mixin
- # == [DEPRECATED] Chef::Mixin::Language
- # This module is deprecated and remains only for backwards compatibility.
+ # == [DEPRECATED] Chef::Mixin::DeprecatedLanguageModule
+ # This module is a temporary replacement for the previous
+ # Chef::Mixin::Language. That module's functionality was split into two
+ # modules, Chef::DSL::PlatformIntrospection, and Chef::DSL::DataQuery.
#
- # See Chef::DSL::PlatformIntrospection and Chef::DSL::DataQuery
- module Language
+ # This module includes both PlatformIntrospection and DataQuery to provide
+ # the same interfaces and behavior as the prior Mixin::Language.
+ #
+ # This module is loaded via const_missing hook when Chef::Mixin::Language
+ # is accessed. See chef/mixin/deprecation for details.
+ module DeprecatedLanguageModule
include Chef::DSL::PlatformIntrospection
include Chef::DSL::DataQuery
end
+
+ deprecate_constant(:Language, DeprecatedLanguageModule, <<-EOM)
+Chef::Mixin::Language is deprecated. Use either (or both)
+Chef::DSL::PlatformIntrospection or Chef::DSL::DataQuery instead.
+EOM
end
end
diff --git a/lib/chef/mixin/language_include_attribute.rb b/lib/chef/mixin/language_include_attribute.rb
index 283773b25d..ab21b50408 100644
--- a/lib/chef/mixin/language_include_attribute.rb
+++ b/lib/chef/mixin/language_include_attribute.rb
@@ -23,7 +23,12 @@ class Chef
# DEPRECATED: This is just here for compatibility, use
# Chef::DSL::IncludeAttribute instead.
- LanguageIncludeAttribute = Chef::DSL::IncludeAttribute
+
+ deprecate_constant(:LanguageIncludeAttribute, Chef::DSL::IncludeAttribute, <<-EOM)
+Chef::Mixin::LanguageIncludeAttribute is deprecated. Use
+Chef::DSL::IncludeAttribute instead.
+EOM
+
end
end
diff --git a/lib/chef/mixin/language_include_recipe.rb b/lib/chef/mixin/language_include_recipe.rb
index 0566046560..ccbfb38c65 100644
--- a/lib/chef/mixin/language_include_recipe.rb
+++ b/lib/chef/mixin/language_include_recipe.rb
@@ -20,7 +20,12 @@ require 'chef/dsl/include_recipe'
class Chef
module Mixin
- LanguageIncludeRecipe = Chef::DSL::IncludeRecipe
+
+ deprecate_constant(:LanguageIncludeRecipe, Chef::DSL::IncludeRecipe, <<-EOM)
+Chef::Mixin::LanguageIncludeRecipe is deprecated, use Chef::DSL::Recipe
+instead.
+EOM
+
end
end
diff --git a/lib/chef/mixin/recipe_definition_dsl_core.rb b/lib/chef/mixin/recipe_definition_dsl_core.rb
index ff422d892f..704ee162be 100644
--- a/lib/chef/mixin/recipe_definition_dsl_core.rb
+++ b/lib/chef/mixin/recipe_definition_dsl_core.rb
@@ -24,10 +24,12 @@
# This constant (module name) will eventually be deprecated and then removed.
###
-require 'chef/dsl/recipe'
+require 'chef/mixin/deprecation'
class Chef
module Mixin
- RecipeDefinitionDSLCore = Chef::DSL::Recipe
+ deprecate_constant(:RecipeDefinitionDSLCore, Chef::DSL::Recipe, <<-EOM)
+Chef::Mixin::RecipeDefinitionDSLCore is deprecated. Use Chef::DSL::Recipe instead.
+EOM
end
end
diff --git a/lib/chef/mixins.rb b/lib/chef/mixins.rb
index 557932c0e6..8fa9c699e6 100644
--- a/lib/chef/mixins.rb
+++ b/lib/chef/mixins.rb
@@ -12,3 +12,4 @@ require 'chef/mixin/path_sanity'
require 'chef/mixin/template'
require 'chef/mixin/securable'
require 'chef/mixin/xml_escape'
+
diff --git a/spec/unit/mixin/deprecation_spec.rb b/spec/unit/mixin/deprecation_spec.rb
index 1b62dcd124..c3170007de 100644
--- a/spec/unit/mixin/deprecation_spec.rb
+++ b/spec/unit/mixin/deprecation_spec.rb
@@ -19,6 +19,29 @@
require 'spec_helper'
require 'chef/mixin/deprecation'
+describe Chef::Mixin do
+ describe "deprecating constants (Class/Module)" do
+ before do
+ Chef::Mixin.deprecate_constant(:DeprecatedClass, Chef::Node, "This is a test deprecation")
+ @log_io = StringIO.new
+ Chef::Log.init(@log_io)
+ end
+
+ it "has a list of deprecated constants" do
+ Chef::Mixin.deprecated_constants.should have_key(:DeprecatedClass)
+ end
+
+ it "returns the replacement when accessing the deprecated constant" do
+ Chef::Mixin::DeprecatedClass.should == Chef::Node
+ end
+
+ it "warns when accessing the deprecated constant" do
+ Chef::Mixin::DeprecatedClass
+ @log_io.string.should include("This is a test deprecation")
+ end
+ end
+end
+
describe Chef::Mixin::Deprecation::DeprecatedInstanceVariable do
before do
Chef::Log.logger = Logger.new(StringIO.new)