Get the plugins list through -emqx_plugin module attributes
This commit is contained in:
parent
b79bf13ae7
commit
865ef864db
|
@ -60,14 +60,15 @@ load() ->
|
|||
load_expand_plugins() ->
|
||||
case emqx_config:get_env(expand_plugins_dir) of
|
||||
undefined -> ok;
|
||||
Dir ->
|
||||
PluginsDir = filelib:wildcard("*", Dir),
|
||||
lists:foreach(fun(PluginDir) ->
|
||||
case filelib:is_dir(Dir ++ PluginDir) of
|
||||
true -> load_expand_plugin(Dir ++ PluginDir);
|
||||
ExpandPluginsDir ->
|
||||
Plugins = filelib:wildcard("*", ExpandPluginsDir),
|
||||
lists:foreach(fun(Plugin) ->
|
||||
PluginDir = filename:join(ExpandPluginsDir, Plugin),
|
||||
case filelib:is_dir(PluginDir) of
|
||||
true -> load_expand_plugin(PluginDir);
|
||||
false -> ok
|
||||
end
|
||||
end, PluginsDir)
|
||||
end, Plugins)
|
||||
end.
|
||||
|
||||
load_expand_plugin(PluginDir) ->
|
||||
|
@ -98,25 +99,6 @@ init_expand_plugin_config(PluginDir) ->
|
|||
[application:set_env(AppName, Par, Val) || {Par, Val} <- Envs]
|
||||
end, AppsEnv).
|
||||
|
||||
get_expand_plugin_config() ->
|
||||
case emqx_config:get_env(expand_plugins_dir) of
|
||||
undefined -> ok;
|
||||
Dir ->
|
||||
PluginsDir = filelib:wildcard("*", Dir),
|
||||
lists:foldl(fun(PluginDir, Acc) ->
|
||||
case filelib:is_dir(Dir ++ PluginDir) of
|
||||
true ->
|
||||
Etc = Dir ++ PluginDir ++ "/etc",
|
||||
case filelib:wildcard("*.{conf,config}", Etc) of
|
||||
[] -> Acc;
|
||||
[Conf] -> [Conf | Acc]
|
||||
end;
|
||||
false ->
|
||||
Acc
|
||||
end
|
||||
end, [], PluginsDir)
|
||||
end.
|
||||
|
||||
ensure_file(File) ->
|
||||
case filelib:is_file(File) of false -> write_loaded([]); true -> ok end.
|
||||
|
||||
|
@ -155,23 +137,16 @@ stop_plugins(Names) ->
|
|||
%% @doc List all available plugins
|
||||
-spec(list() -> [emqx_types:plugin()]).
|
||||
list() ->
|
||||
case emqx_config:get_env(plugins_etc_dir) of
|
||||
undefined ->
|
||||
[];
|
||||
PluginsEtc ->
|
||||
CfgFiles = filelib:wildcard("*.{conf,config}", PluginsEtc) ++ get_expand_plugin_config(),
|
||||
Plugins = [plugin(CfgFile) || CfgFile <- CfgFiles],
|
||||
StartedApps = names(started_app),
|
||||
lists:map(fun(Plugin = #plugin{name = Name}) ->
|
||||
case lists:member(Name, StartedApps) of
|
||||
true -> Plugin#plugin{active = true};
|
||||
false -> Plugin
|
||||
end
|
||||
end, Plugins)
|
||||
end.
|
||||
StartedApps = names(started_app),
|
||||
lists:map(fun({Name, _, _}) ->
|
||||
Plugin = plugin(Name),
|
||||
case lists:member(Name, StartedApps) of
|
||||
true -> Plugin#plugin{active = true};
|
||||
false -> Plugin
|
||||
end
|
||||
end, ekka_boot:all_module_attributes(emqx_plugin)).
|
||||
|
||||
plugin(CfgFile) ->
|
||||
AppName = app_name(CfgFile),
|
||||
plugin(AppName) ->
|
||||
case application:get_all_key(AppName) of
|
||||
{ok, Attrs} ->
|
||||
Ver = proplists:get_value(vsn, Attrs, "0"),
|
||||
|
@ -268,10 +243,6 @@ stop_app(App) ->
|
|||
%%--------------------------------------------------------------------
|
||||
%% Internal functions
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
app_name(File) ->
|
||||
[AppName | _] = string:tokens(File, "."), list_to_atom(AppName).
|
||||
|
||||
names(plugin) ->
|
||||
names(list());
|
||||
|
||||
|
|
Loading…
Reference in New Issue