summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_provider.erl12
-rw-r--r--src/rebar_prv_shell.erl10
-rw-r--r--src/rebar_prv_tar.erl1
-rw-r--r--src/rebar_prv_version.erl1
-rw-r--r--src/rebar_state.erl13
5 files changed, 28 insertions, 9 deletions
diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl
index 3c80a80..e5d7520 100644
--- a/src/rebar_provider.erl
+++ b/src/rebar_provider.erl
@@ -66,7 +66,17 @@ new(ModuleName, State0) when is_atom(ModuleName) ->
-spec do(Provider::t(), rebar_state:t()) ->
{ok, rebar_state:t()}.
do(Provider, State) ->
- (Provider#provider.provider_impl):do(State).
+ {PreHooks, PostHooks} = rebar_state:hooks(State, Provider#provider.name),
+ {ok, State1} = run_hook_plugins(PreHooks, State),
+ {ok, State2} = (Provider#provider.provider_impl):do(State1),
+ run_hook_plugins(PostHooks, State2).
+
+run_hook_plugins(Hooks, State) ->
+ State1 = lists:foldl(fun(Hook, StateAcc) ->
+ {ok, StateAcc1} = rebar_provider:do(Hook, StateAcc),
+ StateAcc1
+ end, State, Hooks),
+ {ok, State1}.
%%% @doc get the name of the module that implements the provider
%%% @param Provider the provider object
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index 06195ec..80f6bcf 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -50,7 +50,7 @@ init(State) ->
deps = ?DEPS,
example = "rebar shell",
short_desc = "Run shell with project apps and deps in path.",
- desc = "",
+ desc = info(),
opts = []}),
{ok, State1}.
@@ -91,12 +91,8 @@ shell() ->
%% this call never returns (until user quits shell)
timer:sleep(infinity).
-info(help, shell) ->
- ?CONSOLE(
- "Start a shell with project and deps preloaded similar to~n"
- "'erl -pa ebin -pa deps/*/ebin'.~n",
- []
- ).
+info() ->
+ "Start a shell with project and deps preloaded similar to~n'erl -pa ebin -pa deps/*/ebin'.~n".
remove_error_handler(0) ->
?WARN("Unable to remove simple error_logger handler~n", []);
diff --git a/src/rebar_prv_tar.erl b/src/rebar_prv_tar.erl
index 607d533..7f5ab4f 100644
--- a/src/rebar_prv_tar.erl
+++ b/src/rebar_prv_tar.erl
@@ -31,6 +31,5 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error().
do(Config) ->
- RelxConfig = rebar_state:get_local(Config, relx, []),
relx:main("release tar"),
{ok, Config}.
diff --git a/src/rebar_prv_version.erl b/src/rebar_prv_version.erl
index ab56802..9197438 100644
--- a/src/rebar_prv_version.erl
+++ b/src/rebar_prv_version.erl
@@ -27,6 +27,7 @@ init(State) ->
short_desc = "Print version for rebar and current Erlang.",
desc = "",
opts = []}),
+
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | relx:error().
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index fa9aa96..706c528 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -14,6 +14,7 @@
binary_deps/1, binary_deps/2,
src_deps/1, src_deps/2,
+ prepend_hook/3, append_hook/3, hooks/2,
providers/1, providers/2, add_provider/2]).
-include("rebar.hrl").
@@ -39,6 +40,7 @@
project_apps = ordsets:new() :: ordsets:ordset(rebar_app_info:t()),
providers = [],
+ hooks = [],
skip_dirs = new_skip_dirs() :: rebar_dict() }).
-export_type([t/0]).
@@ -160,6 +162,17 @@ create_logic_providers(ProviderModules, State0) ->
State1
end, State0, ProviderModules).
+prepend_hook(State=#state_t{hooks=Hooks}, Target, Hook) ->
+ {PreHooks, PostHooks} = proplists:get_value(Target, Hooks, {[], []}),
+ State#state_t{hooks=[{Target, {[Hook | PreHooks], PostHooks}} | proplists:delete(Target, Hooks)]}.
+
+append_hook(State=#state_t{hooks=Hooks}, Target, Hook) ->
+ {PreHooks, PostHooks} = proplists:get_value(Target, Hooks, {[], []}),
+ State#state_t{hooks=[{Target, {PreHooks, [Hook | PostHooks]}} | proplists:delete(Target, Hooks)]}.
+
+hooks(#state_t{hooks=Hooks}, Target) ->
+ proplists:get_value(Target, Hooks, {[], []}).
+
%% ===================================================================
%% Internal functions
%% ===================================================================