summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-09 14:24:50 +0100
committerAlexandru Scvortov <alexandru@rabbitmq.com>2011-09-09 14:24:50 +0100
commit96cb9d5c605eefc6901d9d8929d02bd74cc5ea27 (patch)
tree2a312c7a8c3132529d432d3bbdd973ffd1ee4809 /src
parentaaa1c65236c48b856a6c900b74621777a785c18b (diff)
downloadrabbitmq-server-git-96cb9d5c605eefc6901d9d8929d02bd74cc5ea27.tar.gz
read and parse app files from ezs
Diffstat (limited to 'src')
-rw-r--r--src/rabbit_plugin.erl53
1 files changed, 52 insertions, 1 deletions
diff --git a/src/rabbit_plugin.erl b/src/rabbit_plugin.erl
index 9120d47076..2547f7816b 100644
--- a/src/rabbit_plugin.erl
+++ b/src/rabbit_plugin.erl
@@ -21,6 +21,12 @@
-define(FORCE_OPT, "-f").
+-record(plugin, {name, %% atom()
+ version, %% string()
+ description, %% string()
+ dependencies, %% [{atom(), string()}]
+ location}). %% string()
+
%%----------------------------------------------------------------------------
-ifdef(use_specs).
@@ -76,4 +82,49 @@ action(list, [], _Opts, PluginsDir, PluginsDistDir) ->
%%----------------------------------------------------------------------------
find_available_plugins(PluginsDistDir) ->
- filelib:wildcard("*.ez", PluginsDistDir).
+ EZs = filelib:wildcard("*.ez", PluginsDistDir),
+ [get_plugin_info(filename:join([PluginsDistDir, EZ])) || EZ <- EZs].
+
+get_plugin_info(EZ) ->
+ case read_app_file(EZ) of
+ {application, Name, Props} ->
+ Version = proplists:get_value(vsn, Props),
+ Description = proplists:get_value(description, Props, ""),
+ Dependencies = proplists:get_value(applications, Props, []),
+ #plugin{name = Name, version = Version, description = Description,
+ dependencies = Dependencies, location = EZ};
+ {error, _} = Error ->
+ Error
+ end.
+
+%% Read the .app file from an ez.
+read_app_file(EZ) ->
+ case zip:list_dir(EZ) of
+ {ok, [_|ZippedFiles]} ->
+ case find_app_files(ZippedFiles) of
+ [AppPath|_] ->
+ {ok, [{AppPath, AppFile}]} =
+ zip:extract(EZ, [{file_list, [AppPath]}, memory]),
+ parse_binary(AppFile);
+ [] ->
+ {error, no_app_file}
+ end;
+ {error, Reason} ->
+ {error, {invalid_ez, Reason}}
+ end.
+
+%% Return the path of the .app files in ebin/.
+find_app_files(ZippedFiles) ->
+ {ok, RE} = re:compile("^.*/ebin/.*.app$"),
+ [Path || {zip_file, Path, _, _, _, _} <- ZippedFiles,
+ re:run(Path, RE, [{capture, none}]) =:= match].
+
+%% Parse a binary into a term.
+parse_binary(Bin) ->
+ try
+ {ok, Ts, _} = erl_scan:string(binary:bin_to_list(Bin)),
+ {ok, Term} = erl_parse:parse_term(Ts),
+ Term
+ catch
+ Err -> {error, {invalid_app, Err}}
+ end.