summaryrefslogtreecommitdiff
path: root/src/rebar_app_utils.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_app_utils.erl')
-rw-r--r--src/rebar_app_utils.erl45
1 files changed, 40 insertions, 5 deletions
diff --git a/src/rebar_app_utils.erl b/src/rebar_app_utils.erl
index dbd085e..7f48ffd 100644
--- a/src/rebar_app_utils.erl
+++ b/src/rebar_app_utils.erl
@@ -27,7 +27,11 @@
-module(rebar_app_utils).
-export([is_app_dir/0, is_app_dir/1,
- load_app_file/1]).
+ app_name/1,
+ app_applications/1,
+ app_vsn/1]).
+
+-export([load_app_file/1]). % TEMPORARY
-include("rebar.hrl").
@@ -47,14 +51,45 @@ is_app_dir(Dir) ->
false
end.
+app_name(AppFile) ->
+ case load_app_file(AppFile) of
+ {ok, AppName, _} ->
+ AppName;
+ {error, Reason} ->
+ ?ABORT("Failed to extract name from ~s: ~p\n",
+ [AppFile, Reason])
+ end.
+
+app_applications(AppFile) ->
+ case load_app_file(AppFile) of
+ {ok, _, AppInfo} ->
+ proplists:get_value(applications, AppInfo);
+ {error, Reason} ->
+ ?ABORT("Failed to extract applications from ~s: ~p\n",
+ [AppFile, Reason])
+ end.
+
+app_vsn(AppFile) ->
+ case load_app_file(AppFile) of
+ {ok, _, AppInfo} ->
+ proplists:get_value(vsn, AppInfo);
+ {error, Reason} ->
+ ?ABORT("Failed to extract vsn from ~s: ~p\n",
+ [AppFile, Reason])
+ end.
+
+
+
+%% ===================================================================
+%% Internal functions
+%% ===================================================================
+
load_app_file(Filename) ->
case file:consult(Filename) of
{ok, [{application, AppName, AppData}]} ->
{ok, AppName, AppData};
{error, Reason} ->
- ?ERROR("Failed to load app file from ~s: ~p\n", [Filename, Reason]),
- ?FAIL;
+ {error, Reason};
Other ->
- ?ERROR("Unexpected terms from app file ~s: ~p\n", [Filename, Other]),
- ?FAIL
+ {error, {unexpected_terms, Other}}
end.