diff options
author | Matthias Radestock <matthias@rabbitmq.com> | 2012-08-08 15:35:01 +0100 |
---|---|---|
committer | Matthias Radestock <matthias@rabbitmq.com> | 2012-08-08 15:35:01 +0100 |
commit | 8ced925b57549e1f05a2e402c548c7876f6cc234 (patch) | |
tree | bcba2ee59ab5835bd12f9e135839f2da6fb058f3 /src/rabbit_plugins.erl | |
parent | 4640ccec963f4c1f34aa6ee1fcc428601f3ad344 (diff) | |
download | rabbitmq-server-8ced925b57549e1f05a2e402c548c7876f6cc234.tar.gz |
cosmetic refactor
- more informative type signatures
- move the final phase of setup() into prepare_plugins
- ditch the non-erlangesc get_ prefix of get_plugin_info
- vertical alignment
- get rid of some intermediate vars
Diffstat (limited to 'src/rabbit_plugins.erl')
-rw-r--r-- | src/rabbit_plugins.erl | 36 |
1 files changed, 19 insertions, 17 deletions
diff --git a/src/rabbit_plugins.erl b/src/rabbit_plugins.erl index 0320c69f..076ccebc 100644 --- a/src/rabbit_plugins.erl +++ b/src/rabbit_plugins.erl @@ -35,11 +35,14 @@ -ifdef(use_specs). --spec(setup/0 :: () -> [atom()]). --spec(active/0 :: () -> [atom()]). +-type(plugin_name() :: atom()). + +-spec(setup/0 :: () -> [plugin_name()]). +-spec(active/0 :: () -> [plugin_name()]). -spec(list/1 :: (string()) -> [#plugin{}]). --spec(read_enabled/1 :: (file:filename()) -> [atom()]). --spec(dependencies/3 :: (boolean(), [atom()], [#plugin{}]) -> [atom()]). +-spec(read_enabled/1 :: (file:filename()) -> [plugin_name()]). +-spec(dependencies/3 :: (boolean(), [plugin_name()], [#plugin{}]) -> + [plugin_name()]). -endif. @@ -50,9 +53,7 @@ setup() -> {ok, PluginDir} = application:get_env(rabbit, plugins_dir), {ok, ExpandDir} = application:get_env(rabbit, plugins_expand_dir), {ok, EnabledFile} = application:get_env(rabbit, enabled_plugins_file), - prepare_plugins(EnabledFile, PluginDir, ExpandDir), - [prepare_dir_plugin(PluginAppDescPath) || - PluginAppDescPath <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")]. + prepare_plugins(EnabledFile, PluginDir, ExpandDir). %% @doc Lists the plugins which are currently running. active() -> @@ -72,8 +73,7 @@ list(PluginsDir) -> (Plugin = #plugin{}, {Plugins1, Problems1}) -> {[Plugin|Plugins1], Problems1} end, {[], []}, - [get_plugin_info(PluginsDir, Plug) || - Plug <- EZs ++ FreeApps]), + [plugin_info(PluginsDir, Plug) || Plug <- EZs ++ FreeApps]), case Problems of [] -> ok; _ -> io:format("Warning: Problem reading some plugins: ~p~n", @@ -125,9 +125,9 @@ prepare_plugins(EnabledFile, PluginsDistDir, ExpandDir) -> %% Eliminate the contents of the destination directory case delete_recursively(ExpandDir) of - ok -> ok; - {error, E} -> throw({error, {cannot_delete_plugins_expand_dir, - [ExpandDir, E]}}) + ok -> ok; + {error, E1} -> throw({error, {cannot_delete_plugins_expand_dir, + [ExpandDir, E1]}}) end, case filelib:ensure_dir(ExpandDir ++ "/") of ok -> ok; @@ -135,11 +135,13 @@ prepare_plugins(EnabledFile, PluginsDistDir, ExpandDir) -> [ExpandDir, E2]}}) end, - [prepare_plugin(Plugin, ExpandDir) || Plugin <- ToUnpackPlugins]. + [prepare_plugin(Plugin, ExpandDir) || Plugin <- ToUnpackPlugins], + + [prepare_dir_plugin(PluginAppDescPath) || + PluginAppDescPath <- filelib:wildcard(ExpandDir ++ "/*/ebin/*.app")]. prepare_dir_plugin(PluginAppDescPath) -> - PluginEBinDir = filename:dirname(PluginAppDescPath), - code:add_path(PluginEBinDir), + code:add_path(filename:dirname(PluginAppDescPath)), NameTokens = string:tokens(PluginAppDescPath, "/."), list_to_atom(lists:nth(length(NameTokens) - 1, NameTokens)). @@ -158,13 +160,13 @@ prepare_plugin(#plugin{type = dir, name = Name, location = Location}, ExpandDir) -> rabbit_file:recursive_copy(Location, filename:join([ExpandDir, Name])). -get_plugin_info(Base, {ez, EZ0}) -> +plugin_info(Base, {ez, EZ0}) -> EZ = filename:join([Base, EZ0]), case read_app_file(EZ) of {application, Name, Props} -> mkplugin(Name, Props, ez, EZ); {error, Reason} -> {error, EZ, Reason} end; -get_plugin_info(Base, {app, App0}) -> +plugin_info(Base, {app, App0}) -> App = filename:join([Base, App0]), case rabbit_file:read_term_file(App) of {ok, [{application, Name, Props}]} -> |