summaryrefslogtreecommitdiff
path: root/src/rebar_resource.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_resource.erl')
-rw-r--r--src/rebar_resource.erl44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/rebar_resource.erl b/src/rebar_resource.erl
index cdce7a8..a3a8edb 100644
--- a/src/rebar_resource.erl
+++ b/src/rebar_resource.erl
@@ -2,23 +2,53 @@
%% ex: ts=4 sw=4 et
-module(rebar_resource).
--export([]).
+-export([new/3,
+ lock/2,
+ download/4,
+ needs_update/2,
+ make_vsn/2]).
--export_type([resource/0
- ,type/0
- ,location/0
- ,ref/0]).
+-export_type([source/0,
+ type/0,
+ location/0,
+ ref/0]).
--type resource() :: {type(), location(), ref()}.
+-include("rebar.hrl").
+
+-type source() :: {type(), location(), ref()} | {type(), location(), ref(), binary()}.
-type type() :: atom().
-type location() :: string().
-type ref() :: any().
-callback lock(file:filename_all(), tuple()) ->
- rebar_resource:resource().
+ source().
-callback download(file:filename_all(), tuple(), rebar_state:t()) ->
{tarball, file:filename_all()} | {ok, any()} | {error, any()}.
-callback needs_update(file:filename_all(), tuple()) ->
boolean().
-callback make_vsn(file:filename_all()) ->
{plain, string()} | {error, string()}.
+
+-spec new(type(), module(), term()) -> rebar_resource_v2:resource().
+new(Type, Module, State) ->
+ #resource{type=Type,
+ module=Module,
+ state=State,
+ implementation=?MODULE}.
+
+lock(Module, AppInfo) ->
+ Module:lock(rebar_app_info:dir(AppInfo), rebar_app_info:source(AppInfo)).
+
+download(Module, TmpDir, AppInfo, State) ->
+ case Module:download(TmpDir, rebar_app_info:source(AppInfo), State) of
+ {ok, _} ->
+ ok;
+ Error ->
+ Error
+ end.
+
+needs_update(Module, AppInfo) ->
+ Module:needs_update(rebar_app_info:dir(AppInfo), rebar_app_info:source(AppInfo)).
+
+make_vsn(Module, AppInfo) ->
+ Module:make_vsn(rebar_app_info:dir(AppInfo)).