In ticket #1064 we made the use of 'plugins' directories in modules deprecated. This was released in 0.25.0 in 2009. This commit removes this deprecation warning and defaults the plugin directory to 'lib'.
All tests also fixed. Signed-off-by: James Turnbull <[email protected]> --- Local-branch: tickets/master/7591 lib/puppet/file_serving/mount/plugins.rb | 8 ++-- lib/puppet/indirector/facts/facter.rb | 2 +- lib/puppet/module.rb | 21 ++-------- lib/puppet/network/handler/fileserver.rb | 10 ++-- lib/puppet/util/autoload.rb | 2 +- .../util/rdoc/generators/puppet_generator.rb | 2 +- spec/unit/file_serving/mount/plugins_spec.rb | 10 ++-- spec/unit/module_spec.rb | 40 ++++---------------- spec/unit/network/handler/fileserver_spec.rb | 2 +- spec/unit/util/autoload_spec.rb | 8 +-- 10 files changed, 34 insertions(+), 71 deletions(-) diff --git a/lib/puppet/file_serving/mount/plugins.rb b/lib/puppet/file_serving/mount/plugins.rb index d21d6e9..bae68f1 100644 --- a/lib/puppet/file_serving/mount/plugins.rb +++ b/lib/puppet/file_serving/mount/plugins.rb @@ -1,14 +1,14 @@ require 'puppet/file_serving/mount' -# Find files in the modules' plugins directories. +# Find files in the modules' lib directories. # This is a very strange mount because it merges # many directories into one. class Puppet::FileServing::Mount::Plugins < Puppet::FileServing::Mount # Return an instance of the appropriate class. def find(relative_path, request) - return nil unless mod = request.environment.modules.find { |mod| mod.plugin(relative_path) } + return nil unless mod = request.environment.modules.find { |mod| mod.lib(relative_path) } - path = mod.plugin(relative_path) + path = mod.lib(relative_path) path end @@ -16,7 +16,7 @@ class Puppet::FileServing::Mount::Plugins < Puppet::FileServing::Mount def search(relative_path, request) # We currently only support one kind of search on plugins - return # them all. - paths = request.environment.modules.find_all { |mod| mod.plugins? }.collect { |mod| mod.plugin_directory } + paths = request.environment.modules.find_all { |mod| mod.lib? }.collect { |mod| mod.lib_directory } return(paths.empty? ? nil : paths) end diff --git a/lib/puppet/indirector/facts/facter.rb b/lib/puppet/indirector/facts/facter.rb index ab7378a..5254236 100644 --- a/lib/puppet/indirector/facts/facter.rb +++ b/lib/puppet/indirector/facts/facter.rb @@ -10,7 +10,7 @@ class Puppet::Node::Facts::Facter < Puppet::Indirector::Code def self.load_fact_plugins # Add any per-module fact directories to the factpath module_fact_dirs = Puppet[:modulepath].split(":").collect do |d| - ["lib", "plugins"].map do |subdirectory| + "lib".map do |subdirectory| Dir.glob("#{d}/*/#{subdirectory}/facter") end end.flatten diff --git a/lib/puppet/module.rb b/lib/puppet/module.rb index 059591e..58c9de8 100644 --- a/lib/puppet/module.rb +++ b/lib/puppet/module.rb @@ -15,7 +15,7 @@ class Puppet::Module TEMPLATES = "templates" FILES = "files" MANIFESTS = "manifests" - PLUGINS = "plugins" + PLUGINS = "lib" FILETYPES = [MANIFESTS, FILES, TEMPLATES, PLUGINS] @@ -141,9 +141,9 @@ class Puppet::Module environment.modulepath.collect { |path| File.join(path, name) }.find { |d| FileTest.directory?(d) } end - # Find all plugin directories. This is used by the Plugins fileserving mount. - def plugin_directory - subpath("plugins") + # Find all lib directories. This is used by the Plugins fileserving mount. + def lib_directory + subpath("lib") end def requires(name, version = nil) @@ -184,18 +184,7 @@ class Puppet::Module private def subpath(type) - return File.join(path, type) unless type.to_s == "plugins" - - backward_compatible_plugins_dir - end - - def backward_compatible_plugins_dir - if dir = File.join(path, "plugins") and FileTest.exist?(dir) - Puppet.warning "using the deprecated 'plugins' directory for ruby extensions; please move to 'lib'" - return dir - else - return File.join(path, "lib") - end + return File.join(path, type) end def assert_validity diff --git a/lib/puppet/network/handler/fileserver.rb b/lib/puppet/network/handler/fileserver.rb index 5b4b17a..3ee8e5a 100755 --- a/lib/puppet/network/handler/fileserver.rb +++ b/lib/puppet/network/handler/fileserver.rb @@ -678,11 +678,11 @@ class Puppet::Network::Handler end def mod_path_exists?(mod, relpath, client = nil) - ! mod.plugin(relpath).nil? + ! mod.lib(relpath).nil? end def path_exists?(relpath, client = nil) - !valid_modules(client).find { |mod| mod.plugin(relpath) }.nil? + !valid_modules(client).find { |mod| mod.lib(relpath) }.nil? end def valid? @@ -694,15 +694,15 @@ class Puppet::Network::Handler end def file_path(relpath, client = nil) - return nil unless mod = valid_modules(client).find { |m| m.plugin(relpath) } - mod.plugin(relpath) + return nil unless mod = valid_modules(client).find { |m| m.lib(relpath) } + mod.lib(relpath) end # create a list of files by merging all modules def list(relpath, recurse, ignore, client = nil) result = [] valid_modules(client).each do |mod| - if modpath = mod.plugin(relpath) + if modpath = mod.lib(relpath) if FileTest.directory?(modpath) and recurse ary = reclist(modpath, recurse, ignore) ary ||= [] diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb index f0dd0a5..d8555b2 100644 --- a/lib/puppet/util/autoload.rb +++ b/lib/puppet/util/autoload.rb @@ -145,7 +145,7 @@ class Puppet::Util::Autoload Thread.current[:env_module_directories] ||= {} Thread.current[:env_module_directories][real_env] ||= real_env.modulepath.collect do |dir| Dir.entries(dir).reject { |f| f =~ /^\./ }.collect { |f| File.join(dir, f) } - end.flatten.collect { |d| [File.join(d, "plugins"), File.join(d, "lib")] }.flatten.find_all do |d| + end.flatten.collect { |d| File.join(d, "lib") }.flatten.find_all do |d| FileTest.directory?(d) end end diff --git a/lib/puppet/util/rdoc/generators/puppet_generator.rb b/lib/puppet/util/rdoc/generators/puppet_generator.rb index 249c9a8..3155a8d 100644 --- a/lib/puppet/util/rdoc/generators/puppet_generator.rb +++ b/lib/puppet/util/rdoc/generators/puppet_generator.rb @@ -29,7 +29,7 @@ module Generators MODULE_DIR = "modules" NODE_DIR = "nodes" - PLUGIN_DIR = "plugins" + PLUGIN_DIR = "lib" # We're monkey patching RDoc markup to allow # lowercase class1::class2::class3 crossref hyperlinking diff --git a/spec/unit/file_serving/mount/plugins_spec.rb b/spec/unit/file_serving/mount/plugins_spec.rb index b6bed72..eb246b7 100755 --- a/spec/unit/file_serving/mount/plugins_spec.rb +++ b/spec/unit/file_serving/mount/plugins_spec.rb @@ -19,7 +19,7 @@ describe Puppet::FileServing::Mount::Plugins do it "should return nil if no module can be found with a matching plugin" do mod = mock 'module' - mod.stubs(:plugin).with("foo/bar").returns nil + mod.stubs(:lib).with("foo/bar").returns nil @environment.stubs(:modules).returns [mod] @mount.find("foo/bar", @request).should be_nil @@ -27,7 +27,7 @@ describe Puppet::FileServing::Mount::Plugins do it "should return the file path from the module" do mod = mock 'module' - mod.stubs(:plugin).with("foo/bar").returns "eh" + mod.stubs(:lib).with("foo/bar").returns "eh" @environment.stubs(:modules).returns [mod] @mount.find("foo/bar", @request).should == "eh" @@ -43,15 +43,15 @@ describe Puppet::FileServing::Mount::Plugins do it "should return nil if no modules can be found that have plugins" do mod = mock 'module' - mod.stubs(:plugins?).returns false + mod.stubs(:lib?).returns false @environment.stubs(:modules).returns [] @mount.search("foo/bar", @request).should be_nil end it "should return the plugin paths for each module that has plugins" do - one = stub 'module', :plugins? => true, :plugin_directory => "/one" - two = stub 'module', :plugins? => true, :plugin_directory => "/two" + one = stub 'module', :lib? => true, :lib_directory => "/one" + two = stub 'module', :lib? => true, :lib_directory => "/two" @environment.stubs(:modules).returns [one, two] @mount.search("foo/bar", @request).should == %w{/one /two} diff --git a/spec/unit/module_spec.rb b/spec/unit/module_spec.rb index 8d38657..7db3a8d 100755 --- a/spec/unit/module_spec.rb +++ b/spec/unit/module_spec.rb @@ -5,12 +5,6 @@ require 'puppet_spec/files' describe Puppet::Module do include PuppetSpec::Files - before do - # This is necessary because of the extra checks we have for the deprecated - # 'plugins' directory - FileTest.stubs(:exist?).returns false - end - it "should have a class method that returns a named module from a given environment" do env = mock 'module' env.expects(:module).with("mymod").returns "yep" @@ -316,12 +310,11 @@ describe Puppet::Module do mod.should_not be_exist end - [:plugins, :templates, :files, :manifests].each do |filetype| - dirname = filetype == :plugins ? "lib" : filetype.to_s + [:lib, :templates, :files, :manifests].each do |filetype| it "should be able to return individual #{filetype}" do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - path = File.join("/a/foo", dirname, "my/file") + path = File.join("/a/foo", filetype.to_s, "my/file") FileTest.expects(:exist?).with(path).returns true mod.send(filetype.to_s.sub(/s$/, ''), "my/file").should == path end @@ -329,7 +322,7 @@ describe Puppet::Module do it "should consider #{filetype} to be present if their base directory exists" do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - path = File.join("/a/foo", dirname) + path = File.join("/a/foo", filetype.to_s) FileTest.expects(:exist?).with(path).returns true mod.send(filetype.to_s + "?").should be_true end @@ -337,7 +330,7 @@ describe Puppet::Module do it "should consider #{filetype} to be absent if their base directory does not exist" do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - path = File.join("/a/foo", dirname) + path = File.join("/a/foo", filetype.to_s) FileTest.expects(:exist?).with(path).returns false mod.send(filetype.to_s + "?").should be_false end @@ -351,7 +344,7 @@ describe Puppet::Module do it "should return nil if asked to return individual #{filetype} that don't exist" do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - path = File.join("/a/foo", dirname, "my/file") + path = File.join("/a/foo", filetype.to_s, "my/file") FileTest.expects(:exist?).with(path).returns false mod.send(filetype.to_s.sub(/s$/, ''), "my/file").should be_nil end @@ -365,15 +358,14 @@ describe Puppet::Module do it "should return the base directory if asked for a nil path" do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - base = File.join("/a/foo", dirname) + base = File.join("/a/foo", filetype.to_s) FileTest.expects(:exist?).with(base).returns true mod.send(filetype.to_s.sub(/s$/, ''), nil).should == base end end - %w{plugins files}.each do |filetype| + %w{lib files}.each do |filetype| short = filetype.sub(/s$/, '') - dirname = filetype == "plugins" ? "lib" : filetype.to_s it "should be able to return the #{short} directory" do Puppet::Module.new("foo").should respond_to(short + "_directory") end @@ -382,25 +374,9 @@ describe Puppet::Module do mod = Puppet::Module.new("foo") mod.stubs(:path).returns "/a/foo" - mod.send(short + "_directory").should == "/a/foo/#{dirname}" + mod.send(short + "_directory").should == "/a/foo/#{filetype}" end end - - it "should throw a warning if plugins are in a 'plugins' directory rather than a 'lib' directory" do - mod = Puppet::Module.new("foo") - mod.stubs(:path).returns "/a/foo" - FileTest.expects(:exist?).with("/a/foo/plugins").returns true - - mod.plugin_directory.should == "/a/foo/plugins" - @logs.first.message.should == "using the deprecated 'plugins' directory for ruby extensions; please move to 'lib'" - @logs.first.level.should == :warning - end - - it "should default to 'lib' for the plugins directory" do - mod = Puppet::Module.new("foo") - mod.stubs(:path).returns "/a/foo" - mod.plugin_directory.should == "/a/foo/lib" - end end describe Puppet::Module, " when building its search path" do diff --git a/spec/unit/network/handler/fileserver_spec.rb b/spec/unit/network/handler/fileserver_spec.rb index 0885263..cd09fb6 100755 --- a/spec/unit/network/handler/fileserver_spec.rb +++ b/spec/unit/network/handler/fileserver_spec.rb @@ -124,7 +124,7 @@ describe Puppet::Network::Handler::FileServer do end describe Puppet::Network::Handler::FileServer::PluginMount, :'fails_on_ruby_1.9.2' => true do - PLUGINS = Puppet::Network::Handler::FileServer::PLUGINS + PLUGINS = Puppet::Module::PLUGINS # create a module plugin hierarchy def create_plugin(mod, plugin) diff --git a/spec/unit/util/autoload_spec.rb b/spec/unit/util/autoload_spec.rb index 512f06c..3817fbb 100755 --- a/spec/unit/util/autoload_spec.rb +++ b/spec/unit/util/autoload_spec.rb @@ -15,7 +15,7 @@ describe Puppet::Util::Autoload do end describe "when building the search path" do - it "should collect all of the plugins and lib directories that exist in the current environment's module path" do + it "should collect all of the lib directories that exist in the current environment's module path" do Puppet.settings.expects(:value).with(:environment).returns "foo" Puppet.settings.expects(:value).with(:modulepath, :foo).returns "/a:/b:/c" Dir.expects(:entries).with("/a").returns %w{one two} @@ -24,11 +24,11 @@ describe Puppet::Util::Autoload do FileTest.stubs(:directory?).returns false FileTest.expects(:directory?).with("/a").returns true FileTest.expects(:directory?).with("/b").returns true - %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib}.each do |d| + %w{/a/one/lib /a/two/lib /b/one/lib /b/two/lib}.each do |d| FileTest.expects(:directory?).with(d).returns true end - @autoload.module_directories.should == %w{/a/one/plugins /a/two/lib /b/one/plugins /b/two/lib} + @autoload.module_directories.should == %w{/a/one/lib /a/two/lib /b/one/lib /b/two/lib} end it "should not look for lib directories in directories starting with '.'" do @@ -38,9 +38,7 @@ describe Puppet::Util::Autoload do FileTest.expects(:directory?).with("/a").returns true FileTest.expects(:directory?).with("/a/./lib").never - FileTest.expects(:directory?).with("/a/./plugins").never FileTest.expects(:directory?).with("/a/../lib").never - FileTest.expects(:directory?).with("/a/../plugins").never @autoload.module_directories end -- 1.7.1 -- You received this message because you are subscribed to the Google Groups "Puppet Developers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/puppet-dev?hl=en.
