summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@rabbitmq.com>2012-10-26 13:37:57 +0100
committerMatthias Radestock <matthias@rabbitmq.com>2012-10-26 13:37:57 +0100
commitf69c26071effd0c5e2f923814b765e522996e588 (patch)
tree101b6b338257dc33fbe3dd557b3e83f2c27f2702
parentb9c8164436a44c771b4b456ffbedebb9c042dd2a (diff)
parentab67df9c62f7868e2157bcf88adfc235d941fffe (diff)
downloadrabbitmq-server-f69c26071effd0c5e2f923814b765e522996e588.tar.gz
merge default into bug24719
-rw-r--r--src/rabbit_plugins.erl15
-rw-r--r--src/rabbit_plugins_main.erl40
2 files changed, 38 insertions, 17 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index ecb19611..5fa9dd99 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -97,11 +97,22 @@ read_enabled(PluginsFile) ->
%% When Reverse =:= true the bottom/leaf level applications are returned in
%% the resulting list, otherwise they're skipped.
dependencies(Reverse, Sources, AllPlugins) ->
+ %% A dict here is used en lieu of sets to dedup each Name, while
+ %% still maintaining the Deps list for each whose deps are
+ %% known. Missing plugins' dependencies cannot be known.
+ DepMap = lists:foldl(
+ fun({Name, Deps}, Acc) ->
+ dict:append_list(Name, Deps, Acc)
+ end,
+ dict:new(),
+ [{Name, Deps} || #plugin{name = Name,
+ dependencies = Deps} <- AllPlugins] ++
+ [{Dep, []} || #plugin{dependencies = Deps} <- AllPlugins,
+ Dep <- Deps]),
{ok, G} = rabbit_misc:build_acyclic_graph(
fun (App, _Deps) -> [{App, App}] end,
fun (App, Deps) -> [{App, Dep} || Dep <- Deps] end,
- [{Name, Deps}
- || #plugin{name = Name, dependencies = Deps} <- AllPlugins]),
+ dict:to_list(DepMap)),
Dests = case Reverse of
false -> digraph_utils:reachable(Sources, G);
true -> digraph_utils:reaching(Sources, G)
diff --git a/src/rabbit_plugins_main.erl b/src/rabbit_plugins_main.erl
index 572cf150..b5429620 100644
--- a/src/rabbit_plugins_main.erl
+++ b/src/rabbit_plugins_main.erl
@@ -108,16 +108,20 @@ action(enable, ToEnable0, _Opts, PluginsFile, PluginsDir) ->
Enabled, AllPlugins),
ToEnable = [list_to_atom(Name) || Name <- ToEnable0],
Missing = ToEnable -- plugin_names(AllPlugins),
- case Missing of
- [] -> ok;
- _ -> throw({error_string,
- fmt_list("The following plugins could not be found:",
- Missing)})
- end,
NewEnabled = lists:usort(Enabled ++ ToEnable),
- write_enabled_plugins(PluginsFile, NewEnabled),
NewImplicitlyEnabled = rabbit_plugins:dependencies(false,
NewEnabled, AllPlugins),
+ MissingDeps = NewImplicitlyEnabled -- plugin_names(AllPlugins),
+ case {Missing, MissingDeps} of
+ {[], []} -> ok;
+ {Miss, []} -> throw({error_string,
+ fmt_list("The following plugins "
+ "could not be found:", Miss)});
+ {[], Miss} -> throw({error_string,
+ fmt_list("The following plugin dependencies "
+ "could not be found:", Miss)})
+ end,
+ write_enabled_plugins(PluginsFile, NewEnabled),
maybe_warn_mochiweb(NewImplicitlyEnabled),
case NewEnabled -- ImplicitlyEnabled of
[] -> io:format("Plugin configuration unchanged.~n");
@@ -183,9 +187,12 @@ format_plugins(Pattern, Opts, PluginsFile, PluginsDir) ->
EnabledImplicitly =
rabbit_plugins:dependencies(false, EnabledExplicitly,
AvailablePlugins) -- EnabledExplicitly,
+ Missing = [#plugin{name = Name} ||
+ Name <- ((EnabledExplicitly ++ EnabledImplicitly) --
+ plugin_names(AvailablePlugins))],
{ok, RE} = re:compile(Pattern),
Plugins = [ Plugin ||
- Plugin = #plugin{name = Name} <- AvailablePlugins,
+ Plugin = #plugin{name = Name} <- AvailablePlugins ++ Missing,
re:run(atom_to_list(Name), RE, [{capture, none}]) =:= match,
if OnlyEnabled -> lists:member(Name, EnabledExplicitly);
OnlyEnabledAll -> (lists:member(Name,
@@ -196,18 +203,21 @@ format_plugins(Pattern, Opts, PluginsFile, PluginsDir) ->
Plugins1 = usort_plugins(Plugins),
MaxWidth = lists:max([length(atom_to_list(Name)) ||
#plugin{name = Name} <- Plugins1] ++ [0]),
- [format_plugin(P, EnabledExplicitly, EnabledImplicitly, Format,
- MaxWidth) || P <- Plugins1],
+ [format_plugin(P, EnabledExplicitly, EnabledImplicitly,
+ plugin_names(Missing), Format, MaxWidth) || P <- Plugins1],
ok.
format_plugin(#plugin{name = Name, version = Version,
description = Description, dependencies = Deps},
- EnabledExplicitly, EnabledImplicitly, Format, MaxWidth) ->
+ EnabledExplicitly, EnabledImplicitly, Missing,
+ Format, MaxWidth) ->
Glyph = case {lists:member(Name, EnabledExplicitly),
- lists:member(Name, EnabledImplicitly)} of
- {true, false} -> "[E]";
- {false, true} -> "[e]";
- _ -> "[ ]"
+ lists:member(Name, EnabledImplicitly),
+ lists:member(Name, Missing)} of
+ {true, false, false} -> "[E]";
+ {false, true, false} -> "[e]";
+ {_, _, true} -> "[!]";
+ _ -> "[ ]"
end,
case Format of
minimal -> io:format("~s~n", [Name]);