summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rabbit.hrl1
-rw-r--r--src/rabbit_file.erl15
-rw-r--r--src/rabbit_plugins.erl28
-rw-r--r--src/rabbit_prelaunch.erl19
4 files changed, 39 insertions, 24 deletions
diff --git a/include/rabbit.hrl b/include/rabbit.hrl
index 9c79fbed51..a603886c4b 100644
--- a/include/rabbit.hrl
+++ b/include/rabbit.hrl
@@ -78,6 +78,7 @@
-record(plugin, {name, %% atom()
version, %% string()
description, %% string()
+ type, %% 'ez' or 'dir'
dependencies, %% [{atom(), string()}]
location}). %% string()
diff --git a/src/rabbit_file.erl b/src/rabbit_file.erl
index 7b3a3e7568..5cb8e7b69d 100644
--- a/src/rabbit_file.erl
+++ b/src/rabbit_file.erl
@@ -120,17 +120,12 @@ read_term_file(File) ->
error:{badmatch, Error} -> Error
end.
-group_tokens(Ts) -> lists:reverse([lists:reverse(G) || G <- group_tokens1(Ts)]).
+group_tokens(Ts) -> [lists:reverse(G) || G <- group_tokens([], Ts)].
-group_tokens1([]) -> [];
-group_tokens1([{_, N, _} | _] = Tokens) -> group_tokens([], N, Tokens);
-group_tokens1([{_, N} | _] = Tokens) -> group_tokens([], N, Tokens).
-
-group_tokens(Cur, _, []) -> [Cur];
-group_tokens(Cur, N, [T = {_, N} | Ts]) -> group_tokens([T | Cur], N, Ts);
-group_tokens(Cur, _, [{_, M} | _] = Ts) -> [Cur | group_tokens([], M, Ts)];
-group_tokens(Cur, N, [T = {_, N, _} | Ts]) -> group_tokens([T | Cur], N, Ts);
-group_tokens(Cur, _, [{_, M, _} | _] = Ts) -> [Cur | group_tokens([], M, Ts)].
+group_tokens([], []) -> [];
+group_tokens(Cur, []) -> [Cur];
+group_tokens(Cur, [T = {dot, _} | Ts]) -> [[T | Cur] | group_tokens([], Ts)];
+group_tokens(Cur, [T | Ts]) -> group_tokens([T | Cur], Ts).
write_term_file(File, Terms) ->
write_file(File, list_to_binary([io_lib:format("~w.~n", [Term]) ||
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl
index 69523c0cab..b93b7bed99 100644
--- a/src/rabbit_plugins.erl
+++ b/src/rabbit_plugins.erl
@@ -121,15 +121,17 @@ action(disable, ToDisable0, _Opts) ->
find_plugins() ->
find_plugins(get(plugins_dist_dir)).
find_plugins(PluginsDistDir) ->
- EZs = filelib:wildcard("*.ez", PluginsDistDir),
+ EZs = [{ez, EZ} || EZ <- filelib:wildcard("*.ez", PluginsDistDir)],
+ FreeApps = [{app, App} ||
+ App <- filelib:wildcard("*/ebin/*.app", PluginsDistDir)],
{Plugins, Problems} =
lists:foldl(fun ({error, EZ, Reason}, {Plugins1, Problems1}) ->
{Plugins1, [{EZ, Reason} | Problems1]};
(Plugin = #plugin{}, {Plugins1, Problems1}) ->
{[Plugin|Plugins1], Problems1}
end, {[], []},
- [get_plugin_info(filename:join([PluginsDistDir, EZ]))
- || EZ <- EZs]),
+ [get_plugin_info(PluginsDistDir, Plug) ||
+ Plug <- EZs ++ FreeApps]),
case Problems of
[] -> ok;
_ -> io:format("Warning: Problem reading some plugins: ~p~n", [Problems])
@@ -137,7 +139,8 @@ find_plugins(PluginsDistDir) ->
Plugins.
%% Get the #plugin{} from an .ez.
-get_plugin_info(EZ) ->
+get_plugin_info(Base, {ez, EZ0}) ->
+ EZ = filename:join([Base, EZ0]),
case read_app_file(EZ) of
{application, Name, Props} ->
Version = proplists:get_value(vsn, Props, "0"),
@@ -145,9 +148,24 @@ get_plugin_info(EZ) ->
Dependencies =
filter_applications(proplists:get_value(applications, Props, [])),
#plugin{name = Name, version = Version, description = Description,
- dependencies = Dependencies, location = EZ};
+ dependencies = Dependencies, location = EZ, type = ez};
{error, Reason} ->
{error, EZ, Reason}
+ end;
+%% Get the #plugin{} from an .app.
+get_plugin_info(Base, {app, App0}) ->
+ App = filename:join([Base, App0]),
+ case rabbit_file:read_term_file(App) of
+ {ok, [{application, Name, Props}]} ->
+ Version = proplists:get_value(vsn, Props, "0"),
+ Description = proplists:get_value(description, Props, ""),
+ Dependencies =
+ filter_applications(proplists:get_value(applications, Props, [])),
+ Location = filename:absname(filename:dirname(filename:dirname(App))),
+ #plugin{name = Name, version = Version, description = Description,
+ dependencies = Dependencies, location = Location, type = dir};
+ {error, Reason} ->
+ {error, App, {invalid_app, Reason}}
end.
%% Read the .app file from an ez.
diff --git a/src/rabbit_prelaunch.erl b/src/rabbit_prelaunch.erl
index c67404f3ae..e6c7344afe 100644
--- a/src/rabbit_prelaunch.erl
+++ b/src/rabbit_prelaunch.erl
@@ -47,8 +47,7 @@ start() ->
init:get_plain_arguments(),
RootName = UnpackedPluginDir ++ "/rabbit",
- %% Unpack any .ez plugins
- unpack_ez_plugins(EnabledPluginsFile, PluginsDistDir, UnpackedPluginDir),
+ prepare_plugins(EnabledPluginsFile, PluginsDistDir, UnpackedPluginDir),
%% Build a list of required apps based on the fixed set, and any plugins
PluginApps = find_plugins(UnpackedPluginDir),
@@ -148,7 +147,7 @@ delete_recursively(Fn) ->
Error -> Error
end.
-unpack_ez_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) ->
+prepare_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) ->
AllPlugins = rabbit_plugins:find_plugins(PluginsDistDir),
Enabled = rabbit_plugins:read_enabled_plugins(EnabledPluginsFile),
ToUnpack = rabbit_plugins:calculate_required_plugins(Enabled, AllPlugins),
@@ -162,13 +161,15 @@ unpack_ez_plugins(EnabledPluginsFile, PluginsDistDir, DestDir) ->
ok -> ok;
{error, E2} -> terminate("Could not create dir ~s (~p)", [DestDir, E2])
end,
- [unpack_ez_plugin(PluginLocation, DestDir) ||
- #plugin{location = PluginLocation} <-
- rabbit_plugins:lookup_plugins(ToUnpack, AllPlugins)].
-unpack_ez_plugin(PluginFn, PluginDestDir) ->
- zip:unzip(PluginFn, [{cwd, PluginDestDir}]),
- ok.
+ [prepare_plugin(Plugin, DestDir) ||
+ Plugin <- rabbit_plugins:lookup_plugins(ToUnpack, AllPlugins)].
+
+prepare_plugin(#plugin{type = ez, location = Location}, PluginDestDir) ->
+ zip:unzip(Location, [{cwd, PluginDestDir}]);
+prepare_plugin(#plugin{type = dir, name = Name, location = Location},
+ PluginsDestDir) ->
+ file:make_symlink(Location, filename:join([PluginsDestDir, Name])).
find_plugins(PluginDir) ->
[prepare_dir_plugin(PluginName) ||