summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/rebar.hrl9
-rw-r--r--priv/templates/otp_lib.template (renamed from priv/templates/otp_lib.template.dtl)0
-rw-r--r--rebar.config11
-rw-r--r--src/rebar_core.erl8
-rw-r--r--src/rebar_erlydtl_compiler.erl18
-rw-r--r--src/rebar_provider.erl162
-rw-r--r--src/rebar_prv_app_discovery.erl18
-rw-r--r--src/rebar_prv_clean.erl18
-rw-r--r--src/rebar_prv_compile.erl18
-rw-r--r--src/rebar_prv_deps.erl18
-rw-r--r--src/rebar_prv_do.erl18
-rw-r--r--src/rebar_prv_help.erl20
-rw-r--r--src/rebar_prv_install_deps.erl18
-rw-r--r--src/rebar_prv_lock.erl18
-rw-r--r--src/rebar_prv_new.erl18
-rw-r--r--src/rebar_prv_packages.erl18
-rw-r--r--src/rebar_prv_release.erl27
-rw-r--r--src/rebar_prv_shell.erl18
-rw-r--r--src/rebar_prv_tar.erl25
-rw-r--r--src/rebar_prv_update.erl18
-rw-r--r--src/rebar_prv_upgrade.erl18
-rw-r--r--src/rebar_prv_version.erl18
-rw-r--r--src/rebar_state.erl33
23 files changed, 200 insertions, 347 deletions
diff --git a/include/rebar.hrl b/include/rebar.hrl
index 7f85892..4263fb9 100644
--- a/include/rebar.hrl
+++ b/include/rebar.hrl
@@ -13,15 +13,6 @@
-define(FMT(Str, Args), lists:flatten(io_lib:format(Str, Args))).
--record(provider, {name :: atom(), % The 'user friendly' name of the task
- provider_impl :: atom(), % The implementation of the task, maybe fun or
- bare :: boolean(), % Indicates whether a build config is needed
- deps :: [atom()], % The list of dependencies
- desc :: string(), % The description for the task
- short_desc :: string(), % A one line short description of the task
- example :: string() | undefined, % An example of the task usage
- opts :: list()}). % The list of options that the task requires/understands
-
-define(DEFAULT_LIB_DIRS, ["apps", "libs", "."]).
-define(DEFAULT_DEPS_DIR, "_deps").
-define(DEFAULT_PLUGINS_DIR, "_plugins").
diff --git a/priv/templates/otp_lib.template.dtl b/priv/templates/otp_lib.template
index 19d7593..19d7593 100644
--- a/priv/templates/otp_lib.template.dtl
+++ b/priv/templates/otp_lib.template
diff --git a/rebar.config b/rebar.config
index acb1fad..bc593ae 100644
--- a/rebar.config
+++ b/rebar.config
@@ -8,7 +8,7 @@
{escript_incl_extra, [{"priv/templates/*", "."}, {"rebar/include/*", "."}]}.
{escript_incl_apps,
- [inets, getopt, erlydtl, erlware_commons, relx, rebar]}.
+ [inets, getopt, erlydtl, erlware_commons, relx, providers, rebar]}.
{escript_top_level_app, rebar}.
{escript_name, rebar3}.
@@ -27,12 +27,13 @@
{platform_define, "^[0-9]+", namespaced_types}
]}.
-{first_files, [rebar_provider]}.
-
-{deps, [{relx, "",
+{deps, [{providers, "",
+ {git, "https://github.com/tsloughter/providers.git",
+ {branch, "master"}}},
+ {relx, "",
{git, "https://github.com/erlware/relx.git",
{branch, "master"}}},
- {getopt, "", {git, "git@github.com:jcomellas/getopt.git", {branch, "master"}}}]}.
+ {getopt, "", {git, "git@github.com:jcomellas/getopt.git", {branch, "master"}}}]}.
{erlydtl_opts, [{doc_root, "priv/templates"},
{compiler_options, [report, return, debug_info]}]}.
diff --git a/src/rebar_core.erl b/src/rebar_core.erl
index 9f2b168..17fc0e2 100644
--- a/src/rebar_core.erl
+++ b/src/rebar_core.erl
@@ -34,17 +34,17 @@
-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}.
process_command(State, Command) ->
%% ? rebar_prv_install_deps:setup_env(State),
-
- TargetProviders = rebar_provider:get_target_providers(Command, State),
+ Providers = rebar_state:providers(State),
+ TargetProviders = providers:get_target_providers(Command, Providers),
do(TargetProviders, State).
-spec do([atom()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do([], State) ->
{ok, State};
do([ProviderName | Rest], State) ->
- Provider = rebar_provider:get_provider(ProviderName
+ Provider = providers:get_provider(ProviderName
,rebar_state:providers(State)),
- case rebar_provider:do(Provider, State) of
+ case providers:do(Provider, State) of
{ok, State1} ->
do(Rest, State1);
{error, Error} ->
diff --git a/src/rebar_erlydtl_compiler.erl b/src/rebar_erlydtl_compiler.erl
index 7d90ada..88ffb96 100644
--- a/src/rebar_erlydtl_compiler.erl
+++ b/src/rebar_erlydtl_compiler.erl
@@ -94,7 +94,7 @@
%% ]}.
-module(rebar_erlydtl_compiler).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -113,14 +113,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar erlydtl compile",
- short_desc = "Compile erlydtl templates.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar erlydtl compile"},
+ {short_desc, "Compile erlydtl templates."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
do(Config) ->
diff --git a/src/rebar_provider.erl b/src/rebar_provider.erl
deleted file mode 100644
index 7d78e3b..0000000
--- a/src/rebar_provider.erl
+++ /dev/null
@@ -1,162 +0,0 @@
--module(rebar_provider).
-
-%% API
--export([create/1,
- new/2,
- do/2,
- impl/1,
- get_provider/2,
- get_target_providers/2,
- help/1,
- format/1]).
-
--export_type([t/0]).
-
--include("rebar.hrl").
-
-%%%===================================================================
-%%% Types
-%%%===================================================================
-
--type t() :: record(provider).
-
--type provider_name() :: atom().
-
--callback init(rebar_state:t()) -> {ok, rebar_state:t()}.
--callback do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
-
-%%%===================================================================
-%%% API
-%%%===================================================================
-
-%% @doc create a new provider object from the specified module. The
-%% module should implement the provider behaviour.
-%%
-%% @param ModuleName The module name.
-%% @param State0 The current state of the system
--spec new(module(), rebar_state:t()) -> {ok, rebar_state:t()}.
-new(ModuleName, State) when is_atom(ModuleName) ->
- case code:which(ModuleName) of
- non_existing ->
- ?ERROR("Module ~p does not exist.", [ModuleName]),
- {ok, State};
- _ ->
- ModuleName:init(State)
- end.
-
--spec create(list()) -> t().
-create(Attrs) ->
- #provider{name=proplists:get_value(name, Attrs, undefined)
- ,provider_impl=proplists:get_value(provider_impl, Attrs, undefined)
- ,bare=proplists:get_value(bare, Attrs, false)
- ,deps=proplists:get_value(deps, Attrs, [])
- ,desc=proplists:get_value(desc, Attrs, "")
- ,short_desc=proplists:get_value(short_desc, Attrs, "")
- ,example=proplists:get_value(example, Attrs, "")
- ,opts=proplists:get_value(opts, Attrs, [])}.
-
-%% @doc Manipulate the state of the system, that new state
-%%
-%% @param Provider the provider object
-%% @param State the current state of the system
--spec do(Provider::t(), rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
-do(Provider, State) ->
- {PreHooks, PostHooks} = rebar_state:hooks(State, Provider#provider.name),
- run_all([PreHooks++Provider | PostHooks], State).
-
--spec run_all([t()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
-run_all([], State) ->
- {ok, State};
-run_all([Provider | Rest], State) ->
- case (Provider#provider.provider_impl):do(State) of
- {ok, State1} ->
- run_all(Rest, State1);
- {error, Error} ->
- {error, Error}
- end.
-
-%%% @doc get the name of the module that implements the provider
-%%% @param Provider the provider object
--spec impl(Provider::t()) -> module().
-impl(Provider) ->
- Provider#provider.name.
-
-help(State) ->
- Providers = rebar_state:providers(State),
- Help = lists:sort([{ec_cnv:to_list(P#provider.name), P#provider.short_desc} || P <- Providers,
- P#provider.bare =/= true]),
- Longest = lists:max([length(X) || {X, _} <- Help]),
-
- lists:foreach(fun({Name, ShortDesc}) ->
- Length = length(Name),
- Spacing = lists:duplicate(Longest - Length + 8, " "),
- io:format("~s~s~s~n", [Name, Spacing, ShortDesc])
- end, Help).
-
-
-%% @doc print the provider module name
-%%
-%% @param T - The provider
-%% @return An iolist describing the provider
--spec format(t()) -> iolist().
-format(#provider{name=Name}) ->
- atom_to_list(Name).
-
-get_target_providers(Target, State) ->
- Providers = rebar_state:providers(State),
- TargetProviders = lists:filter(fun(#provider{name=T}) when T =:= Target->
- true;
- (_) ->
- false
- end, Providers),
- process_deps(TargetProviders, Providers).
-
--spec get_provider(provider_name(), [t()]) -> t().
-get_provider(ProviderName, [Provider = #provider{name = ProviderName} | _]) ->
- Provider;
-get_provider(ProviderName, [_ | Rest]) ->
- get_provider(ProviderName, Rest);
-get_provider(_ProviderName, _) ->
- [].
-
-process_deps([], _Providers) ->
- [];
-process_deps(TargetProviders, Providers) ->
- DepChain = lists:flatmap(fun(Provider) ->
- {DC, _, _} = process_deps(Provider, Providers, []),
- DC
- end, TargetProviders),
- ['NONE' | Rest] =
- reorder_providers(lists:flatten([{'NONE', P#provider.name} || P <- TargetProviders] ++ DepChain)),
- Rest.
-
-process_deps(Provider, Providers, Seen) ->
- case lists:member(Provider, Seen) of
- true ->
- {[], Providers, Seen};
- false ->
- Deps = Provider#provider.deps,
- DepList = lists:map(fun(Dep) ->
- {Dep, Provider#provider.name}
- end, Deps),
- {NewDeps, _, NewSeen} =
- lists:foldl(fun(Arg, Acc) ->
- process_dep(Arg, Acc)
- end,
- {[], Providers, Seen}, Deps),
- {[DepList | NewDeps], Providers, NewSeen}
- end.
-
-process_dep(ProviderName, {Deps, Providers, Seen}) ->
- Provider = get_provider(ProviderName, Providers),
- {NewDeps, _, NewSeen} = process_deps(Provider, Providers, [ProviderName | Seen]),
- {[Deps | NewDeps], Providers, NewSeen}.
-
-%% @doc Reorder the providers according to thier dependency set.
-reorder_providers(OProviderList) ->
- case rebar_topo:sort(OProviderList) of
- {ok, ProviderList} ->
- ProviderList;
- {error, {cycle, _}} ->
- ?ERROR("There was a cycle in the provider list. Unable to complete build!", [])
- end.
diff --git a/src/rebar_prv_app_discovery.erl b/src/rebar_prv_app_discovery.erl
index 630f232..775aa3d 100644
--- a/src/rebar_prv_app_discovery.erl
+++ b/src/rebar_prv_app_discovery.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_app_discovery).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = true,
- deps = ?DEPS,
- example = "",
- short_desc = "",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, ""},
+ {short_desc, ""},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_clean.erl b/src/rebar_prv_clean.erl
index 1ed6241..2f983f3 100644
--- a/src/rebar_prv_clean.erl
+++ b/src/rebar_prv_clean.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_clean).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar clean",
- short_desc = "Remove compiled beam files from apps.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar clean"},
+ {short_desc, "Remove compiled beam files from apps."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 8ec0560..fdeafdd 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -1,6 +1,6 @@
-module(rebar_prv_compile).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1,
@@ -17,14 +17,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar compile",
- short_desc = "Compile apps .app.src and .erl files.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar compile"},
+ {short_desc, "Compile apps .app.src and .erl files."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_deps.erl b/src/rebar_prv_deps.erl
index 4612c52..6ba0d3a 100644
--- a/src/rebar_prv_deps.erl
+++ b/src/rebar_prv_deps.erl
@@ -1,6 +1,6 @@
-module(rebar_prv_deps).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -12,14 +12,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = true,
- deps = ?DEPS,
- example = "rebar deps",
- short_desc = "List dependencies",
- desc = info("List dependencies"),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, "rebar deps"},
+ {short_desc, "List dependencies"},
+ {desc, info("List dependencies")},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_do.erl b/src/rebar_prv_do.erl
index 7216813..4bffd04 100644
--- a/src/rebar_prv_do.erl
+++ b/src/rebar_prv_do.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_do).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar3 do <task1>, <task2>, ...",
- short_desc = "Higher order provider for running multiple tasks in a sequence.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar3 do <task1>, <task2>, ..."},
+ {short_desc, "Higher order provider for running multiple tasks in a sequence."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_help.erl b/src/rebar_prv_help.erl
index efc9c3f..9c9bbde 100644
--- a/src/rebar_prv_help.erl
+++ b/src/rebar_prv_help.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_help).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar help <task>",
- short_desc = "Display a list of tasks or help for a given task or subtask.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar help <task>"},
+ {short_desc, "Display a list of tasks or help for a given task or subtask."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
@@ -43,6 +43,6 @@ help(State) ->
getopt:usage(OptSpecList, "rebar", "", []),
?CONSOLE("~nSeveral tasks are available:~n", []),
- rebar_provider:help(State),
+ providers:help(State),
?CONSOLE("~nRun 'rebar help <TASK>' for details.~n~n", []).
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 7d0d751..8b56ac3 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -26,7 +26,7 @@
%% -------------------------------------------------------------------
-module(rebar_prv_install_deps).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -54,14 +54,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = true,
- deps = ?DEPS,
- example = undefined,
- short_desc = "Install dependencies",
- desc = info("Install dependencies"),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, undefined},
+ {short_desc, "Install dependencies"},
+ {desc, info("Install dependencies")},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl
index 2265265..dfe04cd 100644
--- a/src/rebar_prv_lock.erl
+++ b/src/rebar_prv_lock.erl
@@ -1,6 +1,6 @@
-module(rebar_prv_lock).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -16,14 +16,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = true,
- deps = ?DEPS,
- example = "",
- short_desc = "Locks dependencies.",
- desc = info("Locks dependencies"),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, true},
+ {deps, ?DEPS},
+ {example, ""},
+ {short_desc, "Locks dependencies."},
+ {desc, info("Locks dependencies")},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_new.erl b/src/rebar_prv_new.erl
index 1c796b6..3535061 100644
--- a/src/rebar_prv_new.erl
+++ b/src/rebar_prv_new.erl
@@ -1,6 +1,6 @@
-module(rebar_prv_new).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -16,14 +16,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar new <template>",
- short_desc = "Create new project from templates.",
- desc = info(),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar new <template>"},
+ {short_desc, "Create new project from templates."},
+ {desc, info()},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_packages.erl b/src/rebar_prv_packages.erl
index 3349287..6c0dd3f 100644
--- a/src/rebar_prv_packages.erl
+++ b/src/rebar_prv_packages.erl
@@ -1,6 +1,6 @@
-module(rebar_prv_packages).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -12,14 +12,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar pkgs",
- short_desc = "List available packages.",
- desc = info("List available packages"),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar pkgs"},
+ {short_desc, "List available packages."},
+ {desc, info("List available packages")},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_release.erl b/src/rebar_prv_release.erl
index 2eee367..b151bb5 100644
--- a/src/rebar_prv_release.erl
+++ b/src/rebar_prv_release.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_release).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,17 +19,24 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar release",
- short_desc = "Build release of project.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar release"},
+ {short_desc, "Build release of project."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
- relx:main(["release"]),
+ Options = rebar_state:command_args(State),
+ AllOptions = string:join(["release" | Options], " "),
+ case rebar_state:get(State, relx, []) of
+ [] ->
+ relx:main(AllOptions);
+ Config ->
+ relx:main([{config, Config}], AllOptions)
+ end,
{ok, State}.
diff --git a/src/rebar_prv_shell.erl b/src/rebar_prv_shell.erl
index 4bd0886..e74486d 100644
--- a/src/rebar_prv_shell.erl
+++ b/src/rebar_prv_shell.erl
@@ -28,7 +28,7 @@
-module(rebar_prv_shell).
-author("Kresten Krab Thorup <krab@trifork.com>").
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -44,14 +44,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar shell",
- short_desc = "Run shell with project apps and deps in path.",
- desc = info(),
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar shell"},
+ {short_desc, "Run shell with project apps and deps in path."},
+ {desc, info()},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_tar.erl b/src/rebar_prv_tar.erl
index 8e7fb69..06a4014 100644
--- a/src/rebar_prv_tar.erl
+++ b/src/rebar_prv_tar.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_tar).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,17 +19,22 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar tar",
- short_desc = "Tar archive of release built of project.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar tar"},
+ {short_desc, "Tar archive of release built of project."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
- relx:main(["release tar"]),
+ case rebar_state:get(State, relx, []) of
+ [] ->
+ relx:main(["release tar"]);
+ Config ->
+ relx:main([{config, Config}], ["release tar"])
+ end,
{ok, State}.
diff --git a/src/rebar_prv_update.erl b/src/rebar_prv_update.erl
index e1648e2..53402db 100644
--- a/src/rebar_prv_update.erl
+++ b/src/rebar_prv_update.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_update).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar update",
- short_desc = "Update package index.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar update"},
+ {short_desc, "Update package index."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl
index 6722948..1c6abf7 100644
--- a/src/rebar_prv_upgrade.erl
+++ b/src/rebar_prv_upgrade.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_upgrade).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar upgrade cowboy",
- short_desc = "Upgrade dependency.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar upgrade cowboy"},
+ {short_desc, "Upgrade dependency."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
diff --git a/src/rebar_prv_version.erl b/src/rebar_prv_version.erl
index e88bf39..f158b6d 100644
--- a/src/rebar_prv_version.erl
+++ b/src/rebar_prv_version.erl
@@ -3,7 +3,7 @@
-module(rebar_prv_version).
--behaviour(rebar_provider).
+-behaviour(provider).
-export([init/1,
do/1]).
@@ -19,14 +19,14 @@
-spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
init(State) ->
- State1 = rebar_state:add_provider(State, #provider{name = ?PROVIDER,
- provider_impl = ?MODULE,
- bare = false,
- deps = ?DEPS,
- example = "rebar version",
- short_desc = "Print version for rebar and current Erlang.",
- desc = "",
- opts = []}),
+ State1 = rebar_state:add_provider(State, providers:create([{name, ?PROVIDER},
+ {module, ?MODULE},
+ {bare, false},
+ {deps, ?DEPS},
+ {example, "rebar version"},
+ {short_desc, "Print version for rebar and current Erlang."},
+ {desc, ""},
+ {opts, []}])),
{ok, State1}.
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 6f9b3d3..14b55d2 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -139,28 +139,39 @@ providers(#state_t{providers=Providers}) ->
providers(State, NewProviders) ->
State#state_t{providers=NewProviders}.
--spec add_provider(t(), rebar_provider:t()) -> t().
+-spec add_provider(t(), providers:t()) -> t().
add_provider(State=#state_t{providers=Providers}, Provider) ->
State#state_t{providers=[Provider | Providers]}.
create_logic_providers(ProviderModules, State0) ->
lists:foldl(fun(ProviderMod, Acc) ->
- {ok, State1} = rebar_provider:new(ProviderMod, Acc),
+ {ok, State1} = providers:new(ProviderMod, Acc),
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)]}.
+prepend_hook(State=#state_t{providers=Providers}, Target, Hook) ->
+ State#state_t{providers=add_hook(pre, Providers, Target, Hook)}.
-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)]}.
+append_hook(State=#state_t{providers=Providers}, Target, Hook) ->
+ State#state_t{providers=add_hook(post, Providers, Target, Hook)}.
--spec hooks(t(), atom()) -> {[rebar_provider:t()], [rebar_provider:t()]}.
-hooks(#state_t{hooks=Hooks}, Target) ->
- proplists:get_value(Target, Hooks, {[], []}).
+-spec hooks(t(), atom()) -> {[providers:t()], [providers:t()]}.
+hooks(_State=#state_t{providers=Providers}, Target) ->
+ Provider = providers:get_provider(Target, Providers),
+ providers:hooks(Provider).
%% ===================================================================
%% Internal functions
%% ===================================================================
+
+add_hook(Which, Providers, Target, Hook) ->
+ Provider = providers:get_provider(Target, Providers),
+ Hooks = providers:hooks(Provider),
+ NewHooks = add_hook(Which, Hooks, Hook),
+ NewProvider = providers:hooks(Provider, NewHooks),
+ [NewProvider | lists:delete(Provider, Providers)].
+
+add_hook(pre, {PreHooks, PostHooks}, Hook) ->
+ {[Hook | PreHooks], PostHooks};
+add_hook(post, {PreHooks, PostHooks}, Hook) ->
+ {PreHooks, [Hook | PostHooks]}.