diff options
Diffstat (limited to 'src/rebar_plugins.erl')
-rw-r--r-- | src/rebar_plugins.erl | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index 5a0ca3c..a9550ff 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -3,7 +3,7 @@ -module(rebar_plugins). --export([install/1]). +-export([install/1, handle_plugins/2]). -include("rebar.hrl"). @@ -11,34 +11,45 @@ %% Public API %% =================================================================== +-spec install(rebar_state:t()) -> rebar_state:t(). install(State) -> - %% Set deps_dir to a different dir for plugin so they don't collide - OldDepsDir = rebar_state:get(State, deps_dir, ?DEFAULT_DEPS_DIR), - State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR), - DepsDir = rebar_dir:deps_dir(State1), - expand_plugins(DepsDir), - Plugins = rebar_state:get(State1, plugins, []), - PluginProviders = lists:flatten(rebar_utils:filtermap(fun(Plugin) -> - handle_plugin(Plugin, State1) - end, Plugins)), + DepsDir = rebar_dir:deps_dir(State), + Plugins = rebar_state:get(State, plugins, []), - State2 = rebar_state:set(State1, deps_dir, OldDepsDir), - {ok, PluginProviders, State2}. + ProjectApps = rebar_state:project_apps(State), + DepApps = rebar_app_discover:find_apps([DepsDir], all), + + OtherPlugins = lists:flatmap(fun(App) -> + AppDir = rebar_app_info:dir(App), + C = rebar_config:consult(AppDir), + S = rebar_state:new(rebar_state:new(), C, AppDir), + rebar_state:get(S, plugins, []) + end, ProjectApps++DepApps), + + handle_plugins(Plugins++OtherPlugins, State). + +-spec handle_plugins([rebar_prv_install_deps:dep()], rebar_state:t()) -> rebar_state:t(). +handle_plugins(Plugins, State) -> + PluginProviders = lists:flatmap(fun(Plugin) -> + handle_plugin(Plugin, State) + end, Plugins), + rebar_state:create_logic_providers(PluginProviders, State). --spec handle_plugin(rebar_prv_install_deps:dep(), rebar_state:t()) -> {true, any()} | false. handle_plugin(Plugin, State) -> try - {ok, _, State1} = rebar_prv_install_deps:handle_deps(default, State, [Plugin]), + %% Set deps dir to plugins dir so apps are installed there + State1 = rebar_state:set(State, deps_dir, ?DEFAULT_PLUGINS_DIR), + {ok, _, State2} = rebar_prv_install_deps:handle_deps(default, State1, [Plugin]), - Apps = rebar_state:all_deps(State1), + Apps = rebar_state:all_deps(State2), ToBuild = lists:dropwhile(fun rebar_app_info:valid/1, Apps), [build_plugin(AppInfo) || AppInfo <- ToBuild], plugin_providers(Plugin) catch C:T -> ?DEBUG("~p ~p", [C, T]), - ?WARN("Plugin ~p not available. It will not be used.~n", [Plugin]), - false + ?WARN("Plugin ~p not available. It will not be used.", [Plugin]), + [] end. build_plugin(AppInfo) -> @@ -56,21 +67,17 @@ plugin_providers(Plugin) when is_atom(Plugin) -> validate_plugin(Plugin). validate_plugin(Plugin) -> - ok = application:load(Plugin), + _ = application:load(Plugin), case application:get_env(Plugin, providers) of {ok, Providers} -> - {true, Providers}; + Providers; undefined -> Exports = Plugin:module_info(exports), case lists:member({init,1}, Exports) of false -> - ?WARN("Plugin ~p does not export init/1. It will not be used.~n", [Plugin]), - false; + ?WARN("Plugin ~p does not export init/1. It will not be used.", [Plugin]), + []; true -> - {true, Plugin} + [Plugin] end end. - -expand_plugins(Dir) -> - Apps = filelib:wildcard(filename:join([Dir, "*", "ebin"])), - ok = code:add_pathsa(Apps). |