From dabf7c66ad8eef7c4ace63045f03eb26ca225c33 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Wed, 26 May 2021 19:15:41 +0200 Subject: [PATCH] fix: external plugin load all Load all apps in external plugins directory this is to allow adding other apps as external plugin's dependency --- src/emqx_plugins.erl | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/emqx_plugins.erl b/src/emqx_plugins.erl index f05da760e..c2de5fe57 100644 --- a/src/emqx_plugins.erl +++ b/src/emqx_plugins.erl @@ -172,7 +172,14 @@ load_ext_plugin(PluginDir) -> error({plugin_app_file_not_found, AppFile}) end, ok = load_plugin_app(AppName, Ebin), - ok = load_plugin_conf(AppName, PluginDir). + try + ok = load_plugin_conf(AppName, PluginDir) + catch + throw : {conf_file_not_found, ConfFile} -> + %% this is maybe a dependency of an external plugin + ?LOG(debug, "config_load_error_ignored for app=~p, path=~s", [AppName, ConfFile]), + ok + end. load_plugin_app(AppName, Ebin) -> _ = code:add_patha(Ebin), @@ -180,8 +187,8 @@ load_plugin_app(AppName, Ebin) -> lists:foreach( fun(BeamFile) -> Module = list_to_atom(filename:basename(BeamFile, ".beam")), - case code:ensure_loaded(Module) of - {module, Module} -> ok; + case code:load_file(Module) of + {module, _} -> ok; {error, Reason} -> error({failed_to_load_plugin_beam, BeamFile, Reason}) end end, Modules), @@ -193,12 +200,12 @@ load_plugin_app(AppName, Ebin) -> load_plugin_conf(AppName, PluginDir) -> Priv = filename:join([PluginDir, "priv"]), Etc = filename:join([PluginDir, "etc"]), - Schema = filelib:wildcard(filename:join([Priv, "*.schema"])), ConfFile = filename:join([Etc, atom_to_list(AppName) ++ ".conf"]), Conf = case filelib:is_file(ConfFile) of true -> cuttlefish_conf:file(ConfFile); - false -> error({conf_file_not_found, ConfFile}) + false -> throw({conf_file_not_found, ConfFile}) end, + Schema = filelib:wildcard(filename:join([Priv, "*.schema"])), ?LOG(debug, "loading_extra_plugin_config conf=~s, schema=~s", [ConfFile, Schema]), AppsEnv = cuttlefish_generator:map(cuttlefish_schema:files(Schema), Conf), lists:foreach(fun({AppName1, Envs}) ->