summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Radestock <matthias@lshift.net>2009-07-24 18:42:25 +0100
committerMatthias Radestock <matthias@lshift.net>2009-07-24 18:42:25 +0100
commitc8ef29dcc896a30ab30ca9e14adfb3923d5bc389 (patch)
treeede90566c07ce9386e5f0f588d4ff531a9a0063b
parent33c5fd5352d992adc20e7c92fb13856f297d5cba (diff)
downloadrabbitmq-server-c8ef29dcc896a30ab30ca9e14adfb3923d5bc389.tar.gz
cosmetic
-rw-r--r--src/rabbit_plugin_activator.erl254
1 files changed, 126 insertions, 128 deletions
diff --git a/src/rabbit_plugin_activator.erl b/src/rabbit_plugin_activator.erl
index 34df9c48..a7311882 100644
--- a/src/rabbit_plugin_activator.erl
+++ b/src/rabbit_plugin_activator.erl
@@ -37,91 +37,88 @@
-define(DefaultUnpackedPluginDir, "priv/plugins").
-define(DefaultRabbitEBin, "ebin").
-define(BaseApps, [rabbit]).
--ifdef(enable_debug).
--define(Debug(F, V), io:format("DEBUG: " ++ F, V)).
--endif.
--ifndef(enable_debug).
--define(Debug(_F, _V), ok).
--endif.
-define(Error(F, V), io:format("ERROR: " ++ F, V)).
%%----------------------------------------------------------------------------
start() ->
- % Ensure Rabbit is loaded so we can access it's environment
- application:load(rabbit),
-
- % Determine our various directories
- PluginDir = get_env_or_default(plugins_dir, ?DefaultPluginDir),
- UnpackedPluginDir = get_env_or_default(plugins_expand_dir, ?DefaultUnpackedPluginDir),
- RabbitEBin = get_env_or_default(rabbit_ebin, ?DefaultRabbitEBin),
- ?Debug("Got Plugin Dir ~p~n", [PluginDir]),
- ?Debug("Got Unpacked Plugin Dir ~p~n", [UnpackedPluginDir]),
- ?Debug("Got Rabbit EBin Dir ~p~n", [RabbitEBin]),
-
- % Unpack any .ez plugins
- unpack_ez_plugins(PluginDir, UnpackedPluginDir),
-
- % Build a list of required apps based on the fixed set, and any plugins
- RequiredApps = ?BaseApps ++ find_plugins(PluginDir) ++ find_plugins(UnpackedPluginDir),
-
- % Build the entire set of dependencies - this will load the applications along the way
- AllApps = case catch sets:to_list(expand_dependencies(RequiredApps)) of
- {unknown_app, _} ->
- ?Error("Failed to expand dependencies.~n", []),
- halt(1);
- AppList ->
- AppList
- end,
- AppVersions = [determine_version(App) || App <- AllApps],
- {value, {rabbit, RabbitVersion}} = lists:keysearch(rabbit, 1, AppVersions),
-
- % Build the overall release descriptor
- RDesc = {release,
- {"rabbit", RabbitVersion},
- {erts, erlang:system_info(version)},
- AppVersions},
-
- % Write it out to ebin/rabbit.rel
- ?Debug("Generated rabbit.rel: ~p.~n", [RDesc]),
- file:write_file(RabbitEBin ++ "/rabbit.rel", io_lib:format("~p.~n", [RDesc])),
-
- % Compile the script
- case systools:make_script(RabbitEBin ++ "/rabbit", [local, silent]) of
- {ok, Module, Warnings} ->
- % This gets lots of spurious no-source warnings when we have .ez files, so we want to supress them to prevent
- % hiding real issues.
- WarningStr = Module:format_warning([W || W <- Warnings,
- case W of
- {warning, {source_not_found, _}} -> false;
- _ -> true
- end]),
- case length(WarningStr) of
- 0 -> ok;
- _ -> io:format("~s", [WarningStr])
- end,
- ok;
- {error, Module, Error} ->
- io:format("Boot file generation failed: ~s~n", [Module:format_error(Error)]),
- halt(1)
- end,
- halt(),
- ok.
-
+ %% Ensure Rabbit is loaded so we can access it's environment
+ application:load(rabbit),
+
+ %% Determine our various directories
+ PluginDir = get_env(plugins_dir, ?DefaultPluginDir),
+ UnpackedPluginDir = get_env(plugins_expand_dir, ?DefaultUnpackedPluginDir),
+ RabbitEBin = get_env(rabbit_ebin, ?DefaultRabbitEBin),
+
+ %% Unpack any .ez plugins
+ unpack_ez_plugins(PluginDir, UnpackedPluginDir),
+
+ %% Build a list of required apps based on the fixed set, and any plugins
+ RequiredApps = ?BaseApps ++
+ find_plugins(PluginDir) ++
+ find_plugins(UnpackedPluginDir),
+
+ %% Build the entire set of dependencies - this will load the
+ %% applications along the way
+ AllApps = case catch sets:to_list(expand_dependencies(RequiredApps)) of
+ {unknown_app, _} ->
+ ?Error("Failed to expand dependencies.~n", []),
+ halt(1);
+ AppList ->
+ AppList
+ end,
+ AppVersions = [determine_version(App) || App <- AllApps],
+ {value, {rabbit, RabbitVersion}} = lists:keysearch(rabbit, 1, AppVersions),
+
+ %% Build the overall release descriptor
+ RDesc = {release,
+ {"rabbit", RabbitVersion},
+ {erts, erlang:system_info(version)},
+ AppVersions},
+
+ %% Write it out to ebin/rabbit.rel
+ file:write_file(RabbitEBin ++ "/rabbit.rel",
+ io_lib:format("~p.~n", [RDesc])),
+
+ %% Compile the script
+ case systools:make_script(RabbitEBin ++ "/rabbit", [local, silent]) of
+ {ok, Module, Warnings} ->
+ %% This gets lots of spurious no-source warnings when we
+ %% have .ez files, so we want to supress them to prevent
+ %% hiding real issues.
+ WarningStr = Module:format_warning(
+ [W || W <- Warnings,
+ case W of
+ {warning, {source_not_found, _}} -> false;
+ _ -> true
+ end]),
+ case length(WarningStr) of
+ 0 -> ok;
+ _ -> io:format("~s", [WarningStr])
+ end,
+ ok;
+ {error, Module, Error} ->
+ io:format("Boot file generation failed: ~s~n",
+ [Module:format_error(Error)]),
+ halt(1)
+ end,
+ halt(),
+ ok.
+
stop() ->
- ok.
-
-get_env_or_default(Key, Default) ->
- case application:get_env(rabbit, Key) of
- {ok, V} -> V;
- _ -> Default
- end.
-
+ ok.
+
+get_env(Key, Default) ->
+ case application:get_env(rabbit, Key) of
+ {ok, V} -> V;
+ _ -> Default
+ end.
+
determine_version(App) ->
- application:load(App),
- {ok, Vsn} = application:get_key(App, vsn),
- {App, Vsn}.
-
+ application:load(App),
+ {ok, Vsn} = application:get_key(App, vsn),
+ {App, Vsn}.
+
assert_dir(Dir) ->
case filelib:is_dir(Dir) of
true -> ok;
@@ -130,63 +127,64 @@ assert_dir(Dir) ->
ok = file:make_dir(Dir)
end.
delete_dir(Dir) ->
- case filelib:is_dir(Dir) of
- true ->
- case file:list_dir(Dir) of
- {ok, Files} ->
- Paths = [Dir ++ "/" ++ F || F <- Files],
- [delete_dir(F) || F <- Paths, filelib:is_dir(F)],
- [file:delete(F) || F <- Paths, filelib:is_file(F)]
- end,
- ok = file:del_dir(Dir);
- false ->
- ok
- end.
+ case filelib:is_dir(Dir) of
+ true ->
+ case file:list_dir(Dir) of
+ {ok, Files} ->
+ Paths = [Dir ++ "/" ++ F || F <- Files],
+ [delete_dir(F) || F <- Paths, filelib:is_dir(F)],
+ [file:delete(F) || F <- Paths, filelib:is_file(F)]
+ end,
+ ok = file:del_dir(Dir);
+ false ->
+ ok
+ end.
unpack_ez_plugins(PluginSrcDir, PluginDestDir) ->
- % Eliminate the contents of the destination directory
- delete_dir(PluginDestDir),
-
- assert_dir(PluginDestDir),
- [unpack_ez_plugin(PluginName, PluginDestDir) || PluginName <- filelib:wildcard(PluginSrcDir ++ "/*.ez")].
-
-unpack_ez_plugin(PluginFn, PluginDestDir) ->
- zip:unzip(PluginFn, [{cwd, PluginDestDir}]),
- ok.
+ %% Eliminate the contents of the destination directory
+ delete_dir(PluginDestDir),
+ assert_dir(PluginDestDir),
+ [unpack_ez_plugin(PluginName, PluginDestDir) ||
+ PluginName <- filelib:wildcard(PluginSrcDir ++ "/*.ez")].
+
+unpack_ez_plugin(PluginFn, PluginDestDir) ->
+ zip:unzip(PluginFn, [{cwd, PluginDestDir}]),
+ ok.
find_plugins(PluginDir) ->
- [prepare_dir_plugin(PluginName) || PluginName <- filelib:wildcard(PluginDir ++ "/*/ebin/*.app")].
-
+ [prepare_dir_plugin(PluginName) ||
+ PluginName <- filelib:wildcard(PluginDir ++ "/*/ebin/*.app")].
+
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).
+ %% 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).
expand_dependencies(Pending) ->
- expand_dependencies(sets:new(), Pending).
+ expand_dependencies(sets:new(), Pending).
expand_dependencies(Current, []) ->
- Current;
+ Current;
expand_dependencies(Current, [Next|Rest]) ->
- case sets:is_element(Next, Current) of
- true ->
- expand_dependencies(Current, Rest);
- false ->
- case application:load(Next) of
- ok ->
- ok;
- {error, {already_loaded, _}} ->
- ok;
- X ->
- ?Error("Failed to load ~s: ~p~n", [Next, X]),
- throw({unknown_app, Next})
- end,
- {ok, Required} = application:get_key(Next, applications),
- Unique = [A || A <- Required, not(sets:is_element(A, Current))],
- expand_dependencies(sets:add_element(Next, Current), Rest ++ Unique)
- end.
+ case sets:is_element(Next, Current) of
+ true ->
+ expand_dependencies(Current, Rest);
+ false ->
+ case application:load(Next) of
+ ok ->
+ ok;
+ {error, {already_loaded, _}} ->
+ ok;
+ X ->
+ ?Error("Failed to load ~s: ~p~n", [Next, X]),
+ throw({unknown_app, Next})
+ end,
+ {ok, Required} = application:get_key(Next, applications),
+ Unique = [A || A <- Required, not(sets:is_element(A, Current))],
+ expand_dependencies(sets:add_element(Next, Current), Rest ++ Unique)
+ end.