summaryrefslogtreecommitdiff
path: root/test/rebar_localfs_resource_v2.erl
diff options
context:
space:
mode:
authorsimonxu72 <simon.xu72@gmail.com>2018-10-16 18:37:28 +0800
committersimonxu72 <simon.xu72@gmail.com>2018-10-16 18:37:28 +0800
commit41d133856bf199034b0eeb0903bedc2071fba7e1 (patch)
tree15135eaf1501e016ec1b91b275356a0cfd92d867 /test/rebar_localfs_resource_v2.erl
parentb81871c61809a9e5c09f54d6c8298908d18a760c (diff)
parent7bfc8110d1736d2cbf61e19d2fc16dc8e854b460 (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'test/rebar_localfs_resource_v2.erl')
-rw-r--r--test/rebar_localfs_resource_v2.erl50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/rebar_localfs_resource_v2.erl b/test/rebar_localfs_resource_v2.erl
new file mode 100644
index 0000000..52af4d4
--- /dev/null
+++ b/test/rebar_localfs_resource_v2.erl
@@ -0,0 +1,50 @@
+%% -*- erlang-indent-level: 4;indent-tabs-mode: nil -*-
+%% ex: ts=4 sw=4 et
+%%
+%% @doc A localfs custom resource (for testing purposes only)
+%%
+%% ```
+%% {deps, [
+%% %% Application files are copied from "/path/to/app_name"
+%% {app_name, {localfs, "/path/to/app_name", undefined}}
+%% ]}.
+%% '''
+-module(rebar_localfs_resource_v2).
+
+-behaviour(rebar_resource_v2).
+
+-export([init/2
+ ,lock/2
+ ,download/4
+ ,needs_update/2
+ ,make_vsn/2]).
+
+-include_lib("eunit/include/eunit.hrl").
+
+-spec init(atom(), rebar_state:t()) -> {ok, term()}.
+init(Type, _State) ->
+ Resource = rebar_resource_v2:new(Type, ?MODULE, #{}),
+ {ok, Resource}.
+
+lock(AppInfo, _) ->
+ case rebar_app_info:source(AppInfo) of
+ {localfs, Path, _Ref} ->
+ {localfs, Path, undefined};
+ {localfs, Path} ->
+ {localfs, Path, undefined}
+ end.
+
+needs_update(_AppInfo, _) ->
+ false.
+
+download(TmpDir, AppInfo, State, _) ->
+ download_(TmpDir, rebar_app_info:source(AppInfo), State).
+
+download_(TmpDir, {localfs, Path, _Ref}, State) ->
+ download_(TmpDir, {localfs, Path}, State);
+download_(TmpDir, {localfs, Path}, _State) ->
+ ok = rebar_file_utils:cp_r(filelib:wildcard(Path ++ "/*"), TmpDir),
+ {ok, undefined}.
+
+make_vsn(_AppInfo, _) ->
+ {plain, "undefined"}.