summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGerhard Lazu <gerhard@rabbitmq.com>2016-12-19 12:40:27 +0000
committerGerhard Lazu <gerhard@lazu.co.uk>2016-12-19 12:42:42 +0000
commit2044cb1eed02e67c4ea749a807694c55ed574756 (patch)
tree75fa2434b834734f2e7fef30114ce30c83521fbc
parent76a8c66c8092cc1c37bb4aa90a0a3d18b27f7d9d (diff)
downloadrabbitmq-server-git-2044cb1eed02e67c4ea749a807694c55ed574756.tar.gz
Use the code path to find loaded plugins
We were using the expand_dir before, which no longer exists Signed-off-by: Jean-Sébastien Pedron <jean-sebastien@rabbitmq.com> [#118562759]
-rw-r--r--src/rabbit_plugins.erl52
1 files changed, 49 insertions, 3 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index 858ef6d49a..40dbf91cfd 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -135,10 +135,56 @@ extract_schema(#plugin{type = dir, location = Location}, SchemaDir) ->
%% @doc Lists the plugins which are currently running.
active() ->
- {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir),
- InstalledPlugins = plugin_names(list(ExpandDir)),
+ LoadedPluginNames = maybe_keep_required_deps(false, loaded_plugin_names()),
[App || {App, _, _} <- rabbit_misc:which_applications(),
- lists:member(App, InstalledPlugins)].
+ lists:member(App, LoadedPluginNames)].
+
+loaded_plugin_names() ->
+ {ok, PluginsDir} = application:get_env(rabbit, plugins_dir),
+ PluginsDirComponents = filename:split(PluginsDir),
+ loaded_plugin_names(code:get_path(), PluginsDirComponents, []).
+
+loaded_plugin_names([Path | OtherPaths], PluginsDirComponents, PluginNames) ->
+ case lists:sublist(filename:split(Path), length(PluginsDirComponents)) of
+ PluginsDirComponents ->
+ case build_plugin_name_from_code_path(Path) of
+ undefined ->
+ loaded_plugin_names(
+ OtherPaths, PluginsDirComponents, PluginNames);
+ PluginName ->
+ loaded_plugin_names(
+ OtherPaths, PluginsDirComponents,
+ [list_to_atom(PluginName) | PluginNames])
+ end;
+ _ ->
+ loaded_plugin_names(OtherPaths, PluginsDirComponents, PluginNames)
+ end;
+loaded_plugin_names([], _, PluginNames) ->
+ PluginNames.
+
+build_plugin_name_from_code_path(Path) ->
+ AppPath = case filelib:is_dir(Path) of
+ true ->
+ case filelib:wildcard(filename:join(Path, "*.app")) of
+ [AP | _] -> AP;
+ [] -> undefined
+ end;
+ false ->
+ EZ = filename:dirname(filename:dirname(Path)),
+ case filelib:is_regular(EZ) of
+ true ->
+ case find_app_path_in_ez(EZ) of
+ {ok, AP} -> AP;
+ _ -> undefined
+ end;
+ _ ->
+ undefined
+ end
+ end,
+ case AppPath of
+ undefined -> undefined;
+ _ -> filename:basename(AppPath, ".app")
+ end.
%% @doc Get the list of plugins which are ready to be enabled.
list(PluginsPath) ->