diff options
author | Tim Watson <tim@rabbitmq.com> | 2012-05-04 12:04:43 +0100 |
---|---|---|
committer | Tim Watson <tim@rabbitmq.com> | 2012-05-04 12:04:43 +0100 |
commit | 29eef735d36b4c72e590e891c5ed24838402ee0c (patch) | |
tree | d46e1a36064d4df18eb8ecd5466c06000388b2bf /src/rabbit_plugins.erl | |
parent | ae28e4e11c70481f97ceae65decd060084762c8a (diff) | |
download | rabbitmq-server-29eef735d36b4c72e590e891c5ed24838402ee0c.tar.gz |
plugin environment bootstrap and introspection code moved to rabbit_plugins
Diffstat (limited to 'src/rabbit_plugins.erl')
-rw-r--r-- | src/rabbit_plugins.erl | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index 0a5f8d51..0ab0d3aa 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -17,7 +17,7 @@ -module(rabbit_plugins). -include("rabbit.hrl"). --export([start/0, stop/0, prepare_plugins/3]). +-export([start/0, stop/0, bootstrap_envinronment/0, active_plugins/0]). -define(VERBOSE_OPT, "-v"). -define(MINIMAL_OPT, "-m"). @@ -30,11 +30,8 @@ -spec(start/0 :: () -> no_return()). -spec(stop/0 :: () -> 'ok'). --spec(find_plugins/1 :: (file:filename()) -> [#plugin{}]). --spec(read_enabled_plugins/1 :: (file:filename()) -> [atom()]). --spec(lookup_plugins/2 :: ([atom()], [#plugin{}]) -> [#plugin{}]). --spec(calculate_required_plugins/2 :: ([atom()], [#plugin{}]) -> [atom()]). --spec(plugin_names/1 :: ([#plugin{}]) -> [atom()]). +-spec(bootstrap_envinronment/0 :: () -> [atom()]). +-spec(active_plugins/0 :: () -> [atom()]). -endif. @@ -83,6 +80,23 @@ start() -> stop() -> ok. +bootstrap_envinronment() -> + {ok, PluginDir} = application:get_env(rabbit, plugins_dir), + {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), + {ok, EnabledPluginsFile} = application:get_env(rabbit, + enabled_plugins_file), + prepare_plugins(EnabledPluginsFile, PluginDir, ExpandDir), + [prepare_dir_plugin(PluginName) || + PluginName <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")]. + +active_plugins() -> + {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), + InstalledPlugins = [ P#plugin.name || P <- find_plugins(ExpandDir) ], + [App || {App, _, _} <- application:which_applications(), + lists:member(App, InstalledPlugins)]. + +%%---------------------------------------------------------------------------- + prepare_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) -> AllPlugins = find_plugins(PluginsDistDir), Enabled = read_enabled_plugins(EnabledPluginsFile), @@ -110,6 +124,16 @@ prepare_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) -> [prepare_plugin(Plugin, DestDir) || Plugin <- ToUnpackPlugins]. +prepare_dir_plugin(PluginAppDescFn) -> + %% Add the plugin ebin directory to the load path + PluginEBinDirN = filename:dirname(PluginAppDescFn), + code:add_path(PluginEBinDirN), + + %% We want the second-last token + NameTokens = string:tokens(PluginAppDescFn,"/."), + PluginNameString = lists:nth(length(NameTokens) - 1, NameTokens), + list_to_atom(PluginNameString). + %%---------------------------------------------------------------------------- action(list, [], Opts, PluginsFile, PluginsDir) -> |