summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-02-13 16:52:26 -0600
committerLuke Kanies <luke@madstop.com>2008-02-13 16:52:26 -0600
commitf8afe131699f1f0afe834b070af285fd56f6320d (patch)
tree7f3c5db91aeefaaaf4ffeb3efdaa80f6efe995fb
parentfe02591eaad7c8648699b53c9361ffab851e2022 (diff)
downloadpuppet-f8afe131699f1f0afe834b070af285fd56f6320d.tar.gz
puppet-f8afe131699f1f0afe834b070af285fd56f6320d.tar.xz
puppet-f8afe131699f1f0afe834b070af285fd56f6320d.zip
Fixed #1043 -- autoloading now searches the plugins directory
in each module, in addition to the lib directory. The 'lib' directory is also deprecated, but supported for now to give people a chance to convert.
-rw-r--r--CHANGELOG5
-rw-r--r--lib/puppet/util/autoload.rb11
-rwxr-xr-xtest/lib/puppettest.rb2
-rwxr-xr-xtest/util/autoload.rb19
4 files changed, 34 insertions, 3 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 6b039f1ed..01dd986e2 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,8 @@
+ Fixed #1043 -- autoloading now searches the plugins directory
+ in each module, in addition to the lib directory. The 'lib'
+ directory is also deprecated, but supported for now to give
+ people a chance to convert.
+
Fixed #1003 -- Applying DavidS's patch to fix searching for
tags in sql.
diff --git a/lib/puppet/util/autoload.rb b/lib/puppet/util/autoload.rb
index a52575522..4b77fa3eb 100644
--- a/lib/puppet/util/autoload.rb
+++ b/lib/puppet/util/autoload.rb
@@ -1,6 +1,9 @@
+require 'puppet/util/warnings'
+
# Autoload paths, either based on names or all at once.
class Puppet::Util::Autoload
include Puppet::Util
+ include Puppet::Util::Warnings
@autoloaders = {}
@loaded = []
@@ -123,8 +126,6 @@ class Puppet::Util::Autoload
end
end
- private
-
# Yield each subdir in turn.
def eachdir
searchpath.each do |dir|
@@ -137,7 +138,11 @@ class Puppet::Util::Autoload
def searchpath
# JJM: Search for optional lib directories in each module bundle.
module_lib_dirs = Puppet[:modulepath].split(":").collect do |d|
- Dir.glob("%s/*/lib" % d).select do |f|
+ Dir.glob("%s/*/{plugins,lib}" % d).select do |f|
+ if f =~ /lib$/
+ # LAK: Deprecated on 2/14/08
+ warnonce "Using 'lib' in modules is deprecated; switch %s to 'plugins'" % f
+ end
FileTest.directory?(f)
end
end.flatten
diff --git a/test/lib/puppettest.rb b/test/lib/puppettest.rb
index 64cb7aebe..902831e68 100755
--- a/test/lib/puppettest.rb
+++ b/test/lib/puppettest.rb
@@ -17,6 +17,8 @@ Dir["#{mainlib}/../vendor/gems/**"].each do |path|
end
end
+require 'mocha'
+
# Only load the test/unit class if we're not in the spec directory.
# Else we get the bogus 'no tests, no failures' message.
unless Dir.getwd =~ /spec/
diff --git a/test/util/autoload.rb b/test/util/autoload.rb
index 6babed774..3fe18352c 100755
--- a/test/util/autoload.rb
+++ b/test/util/autoload.rb
@@ -123,4 +123,23 @@ TestAutoload.newthing(:#{name.to_s})
Kernel.expects(:require).with(File.join(loadname, subname))
loader.loadall
end
+
+ def test_searchpath_includes_plugin_dirs
+ moddir = "/what/ever"
+ libdir = "/other/dir"
+ Puppet.settings.stubs(:value).with(:modulepath).returns(moddir)
+ Puppet.settings.stubs(:value).with(:libdir).returns(libdir)
+
+ loadname = "testing"
+ loader = Puppet::Util::Autoload.new(self.class, loadname)
+
+ # Currently, include both plugins and libs.
+ paths = %w{plugins lib}.inject({}) { |hash, d| hash[d] = File.join(moddir, "testing", d); FileTest.stubs(:directory?).with(hash[d]).returns(true); hash }
+ Dir.expects(:glob).with("#{moddir}/*/{plugins,lib}").returns(paths.values)
+
+ searchpath = loader.searchpath
+ paths.each do |dir, path|
+ assert(searchpath.include?(path), "search path did not include path for %s" % dir)
+ end
+ end
end