summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar.app.src4
-rw-r--r--src/rebar3.erl10
-rw-r--r--src/rebar_fetch.erl43
-rw-r--r--src/rebar_prv_deps.erl6
-rw-r--r--src/rebar_prv_install_deps.erl6
-rw-r--r--src/rebar_prv_lock.erl2
-rw-r--r--src/rebar_state.erl13
-rw-r--r--test/rebar_resource_SUITE.erl8
8 files changed, 56 insertions, 36 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src
index ee4bfd7..eada93b 100644
--- a/src/rebar.app.src
+++ b/src/rebar.app.src
@@ -23,6 +23,10 @@
%% Default log level
{log_level, warn},
+ {resources, [{git, rebar_git_resource},
+ {pkg, rebar_pkg_resource},
+ {hg, rebar_hg_resource}]},
+
{providers, [rebar_prv_app_discovery,
rebar_prv_as,
rebar_prv_clean,
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 87258aa..f853411 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -124,16 +124,18 @@ run_aux(State, GlobalPluginProviders, RawArgs) ->
filename:join(filename:absname(rebar_state:dir(State2)), BaseDir)),
{ok, Providers} = application:get_env(rebar, providers),
- {ok, PluginProviders, State4} = rebar_plugins:install(State3),
+ {ok, Resources} = application:get_env(rebar, resources),
+ State4 = rebar_state:resources(State3, Resources),
+ {ok, PluginProviders, State5} = rebar_plugins:install(State4),
%% Providers can modify profiles stored in opts, so set default after initializing providers
AllProviders = Providers++PluginProviders++GlobalPluginProviders,
- State5 = rebar_state:create_logic_providers(AllProviders, State4),
- State6 = rebar_state:default(State5, rebar_state:opts(State5)),
+ State6 = rebar_state:create_logic_providers(AllProviders, State5),
+ State7 = rebar_state:default(State6, rebar_state:opts(State6)),
{Task, Args} = parse_args(RawArgs),
- rebar_core:init_command(rebar_state:command_args(State6, Args), Task).
+ rebar_core:init_command(rebar_state:command_args(State7, Args), Task).
init_config() ->
%% Initialize logging system
diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl
index b2ad211..20bf46b 100644
--- a/src/rebar_fetch.erl
+++ b/src/rebar_fetch.erl
@@ -7,30 +7,28 @@
%% -------------------------------------------------------------------
-module(rebar_fetch).
--export([lock_source/2,
+-export([lock_source/3,
download_source/3,
- needs_update/2]).
+ needs_update/3]).
-export([format_error/1]).
-include("rebar.hrl").
-include_lib("providers/include/providers.hrl").
-%% map short versions of resources to module names
--define(RESOURCES, [{git, rebar_git_resource}, {pkg, rebar_pkg_resource},
- {hg, rebar_hg_resource}]).
-
--spec lock_source(file:filename_all(), rebar_resource:resource()) ->
+-spec lock_source(file:filename_all(), rebar_resource:resource(), rebar_state:t()) ->
rebar_resource:resource() | {error, string()}.
-lock_source(AppDir, Source) ->
- Module = get_resource_type(Source),
+lock_source(AppDir, Source, State) ->
+ Resources = rebar_state:resources(State),
+ Module = get_resource_type(Source, Resources),
Module:lock(AppDir, Source).
-spec download_source(file:filename_all(), rebar_resource:resource(), rebar_state:t()) ->
true | {error, any()}.
download_source(AppDir, Source, State) ->
try
- Module = get_resource_type(Source),
+ Resources = rebar_state:resources(State),
+ Module = get_resource_type(Source, Resources),
TmpDir = ec_file:insecure_mkdtemp(),
AppDir1 = ec_cnv:to_list(AppDir),
case Module:download(TmpDir, Source, State) of
@@ -64,9 +62,10 @@ download_source(AppDir, Source, State) ->
throw(?PRV_ERROR({fetch_fail, Source}))
end.
--spec needs_update(file:filename_all(), rebar_resource:resource()) -> boolean() | {error, string()}.
-needs_update(AppDir, Source) ->
- Module = get_resource_type(Source),
+-spec needs_update(file:filename_all(), rebar_resource:resource(), rebar_state:t()) -> boolean() | {error, string()}.
+needs_update(AppDir, Source, State) ->
+ Resources = rebar_state:resources(State),
+ Module = get_resource_type(Source, Resources),
try
Module:needs_update(AppDir, Source)
catch
@@ -77,17 +76,17 @@ needs_update(AppDir, Source) ->
format_error({fetch_fail, Source}) ->
io_lib:format("Failed to fetch and copy dep: ~p", [Source]).
-get_resource_type({Type, Location}) ->
- find_resource_module(Type, Location);
-get_resource_type({Type, Location, _}) ->
- find_resource_module(Type, Location);
-get_resource_type({Type, _, _, Location}) ->
- find_resource_module(Type, Location);
-get_resource_type(_) ->
+get_resource_type({Type, Location}, Resources) ->
+ find_resource_module(Type, Location, Resources);
+get_resource_type({Type, Location, _}, Resources) ->
+ find_resource_module(Type, Location, Resources);
+get_resource_type({Type, _, _, Location}, Resources) ->
+ find_resource_module(Type, Location, Resources);
+get_resource_type(_, _) ->
rebar_pkg_resource.
-find_resource_module(Type, Location) ->
- case lists:keyfind(Type, 1, ?RESOURCES) of
+find_resource_module(Type, Location, Resources) ->
+ case lists:keyfind(Type, 1, Resources) of
false ->
case code:which(Type) of
non_existing ->
diff --git a/src/rebar_prv_deps.erl b/src/rebar_prv_deps.erl
index f1697b6..3627e91 100644
--- a/src/rebar_prv_deps.erl
+++ b/src/rebar_prv_deps.erl
@@ -77,7 +77,7 @@ display_dep(_State, {Name, _Vsn, Source, _Opts}) when is_tuple(Source) ->
display_dep(State, {Name, Source={pkg, _, Vsn}, Level}) when is_integer(Level) ->
DepsDir = rebar_dir:deps_dir(State),
AppDir = filename:join([DepsDir, ec_cnv:to_binary(Name)]),
- NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source) of
+ NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source, State) of
true -> "*";
false -> ""
end,
@@ -85,7 +85,7 @@ display_dep(State, {Name, Source={pkg, _, Vsn}, Level}) when is_integer(Level) -
display_dep(State, {Name, Source, Level}) when is_tuple(Source), is_integer(Level), element(1, Source) =:= git ->
DepsDir = rebar_dir:deps_dir(State),
AppDir = filename:join([DepsDir, ec_cnv:to_binary(Name)]),
- NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source) of
+ NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source, State) of
true -> "*";
false -> ""
end,
@@ -93,7 +93,7 @@ display_dep(State, {Name, Source, Level}) when is_tuple(Source), is_integer(Leve
display_dep(State, {Name, Source, Level}) when is_tuple(Source), is_integer(Level) ->
DepsDir = rebar_dir:deps_dir(State),
AppDir = filename:join([DepsDir, ec_cnv:to_binary(Name)]),
- NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source) of
+ NeedsUpdate = case rebar_fetch:needs_update(AppDir, Source, State) of
true -> "*";
false -> ""
end,
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 8d07cd3..851cbf2 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -510,12 +510,12 @@ fetch_app(AppInfo, AppDir, State) ->
Result
end.
-maybe_upgrade(AppInfo, AppDir, false, _State) ->
+maybe_upgrade(AppInfo, AppDir, false, State) ->
Source = rebar_app_info:source(AppInfo),
- rebar_fetch:needs_update(AppDir, Source);
+ rebar_fetch:needs_update(AppDir, Source, State);
maybe_upgrade(AppInfo, AppDir, true, State) ->
Source = rebar_app_info:source(AppInfo),
- case rebar_fetch:needs_update(AppDir, Source) of
+ case rebar_fetch:needs_update(AppDir, Source, State) of
true ->
?INFO("Updating ~s", [rebar_app_info:name(AppInfo)]),
case rebar_fetch:download_source(AppDir, Source, State) of
diff --git a/src/rebar_prv_lock.erl b/src/rebar_prv_lock.erl
index e839168..5536ec9 100644
--- a/src/rebar_prv_lock.erl
+++ b/src/rebar_prv_lock.erl
@@ -37,7 +37,7 @@ do(State) ->
%% If source is tuple it is a source dep
%% e.g. {git, "git://github.com/ninenines/cowboy.git", "master"}
{rebar_app_info:name(Dep)
- ,rebar_fetch:lock_source(Dir, Source)
+ ,rebar_fetch:lock_source(Dir, Source, State)
,rebar_app_info:dep_level(Dep)}
end || Dep <- AllDeps, not(rebar_app_info:is_checkout(Dep))],
Dir = rebar_state:dir(State),
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index cd127c0..af481bf 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -30,6 +30,7 @@
overrides/1, overrides/2,
apply_overrides/2,
+ resources/1, resources/2, add_resource/2,
providers/1, providers/2, add_provider/2]).
-include("rebar.hrl").
@@ -51,6 +52,7 @@
all_deps = [] :: [rebar_app_info:t()],
overrides = [],
+ resources = [],
providers = []}).
-export_type([t/0]).
@@ -296,6 +298,16 @@ namespace(#state_t{namespace=Namespace}) ->
namespace(State=#state_t{}, Namespace) ->
State#state_t{namespace=Namespace}.
+resources(#state_t{resources=Resources}) ->
+ Resources.
+
+resources(State, NewResources) ->
+ State#state_t{resources=NewResources}.
+
+-spec add_resource(t(), rebar_resource:resource()) -> t().
+add_resource(State=#state_t{resources=Resources}, Resource) ->
+ State#state_t{resources=[Resource | Resources]}.
+
providers(#state_t{providers=Providers}) ->
Providers.
@@ -425,4 +437,3 @@ umerge([], Olds, Merged, CmpMerged, Cmp) when CmpMerged == Cmp ->
lists:reverse(Olds, Merged);
umerge([], Olds, Merged, _CmpMerged, Cmp) ->
lists:reverse(Olds, [Cmp | Merged]).
-
diff --git a/test/rebar_resource_SUITE.erl b/test/rebar_resource_SUITE.erl
index 95263c7..15f14db 100644
--- a/test/rebar_resource_SUITE.erl
+++ b/test/rebar_resource_SUITE.erl
@@ -12,7 +12,10 @@ groups() ->
{hg, [], [{group, all}]}].
init_per_group(all, Config) ->
- Config;
+ State = rebar_state:resources(rebar_state:new(), [{git, rebar_git_resource},
+ {pkg, rebar_pkg_resource},
+ {hg, rebar_hg_resource}]),
+ [{state, State} | Config];
init_per_group(Name, Config) ->
[{type, Name},
{resource, {Name, "https://example.org/user/app", "vsn"}} | Config].
@@ -33,4 +36,5 @@ end_per_testcase(_, Config) ->
change_type_upgrade(Config) ->
?assert(rebar_fetch:needs_update(?config(path, Config),
- ?config(resource, Config))).
+ ?config(resource, Config),
+ ?config(state, Config))).