Skip to content

Commit

Permalink
bump
Browse files Browse the repository at this point in the history
  • Loading branch information
Licenser committed Jul 22, 2015
1 parent 40719bd commit 05e7d3e
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
{erl_opts, [{i, ".."}, {i,"deps"}, {parse_transform, lager_transform}, debug_info, warnings_as_errors]}.
{deps,
[
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "1.0.0"}}}
{lager, ".*", {git, "git://github.com/basho/lager.git", {tag, "2.0.0"}}}
]}.
2 changes: 1 addition & 1 deletion src/eplugin.app.src
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{application, eplugin,
[
{description, ""},
{vsn, "0.1.2"},
{vsn, "0.1.3"},
{registered, []},
{applications, [
kernel,
Expand Down
21 changes: 18 additions & 3 deletions src/eplugin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
provide/1,
wait_for_init/0,
is_enabled/1,
disable/1]).
disable/1,
reload/0]).

%% This is a library we don't want xref to spam us with the exported functions.
-ignore_xref([start/0,
Expand All @@ -28,12 +29,13 @@
register/4, register/5,
fold/2,
config/1,
provide/1,
plugins/0,
enable/1,
provide/1,
is_enabled/1,
disable/1]).
wait_for_init/0,
disable/1,
reload/0]).

-export_type([plugin_desc/0]).

Expand Down Expand Up @@ -507,6 +509,19 @@ plugins() ->
provide(What) ->
eplugin_srv:provide(What).

%%--------------------------------------------------------------------
%% @doc
%% Checks the config directory for new plugins (existing plugins are
%% NOT recompiled!
%%
%% @spec reload() -> ok
%% @end
%%--------------------------------------------------------------------

-spec reload() -> ok.

reload() ->
eplugin_srv:reload().

%%%===================================================================
%%% Internal functions
Expand Down
38 changes: 33 additions & 5 deletions src/eplugin_srv.erl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).

-export([provide/1, wait_until_provided/1, register_callbacks/2, register_callback/5]).
-export([provide/1, wait_until_provided/1, register_callbacks/2, register_callback/5, reload/0]).

-define(SERVER, ?MODULE).

Expand All @@ -44,6 +44,12 @@ start_link() ->
provide(What) ->
gen_server:cast(?SERVER, {provide, What}).

-spec reload() ->
ok.
reload() ->
gen_server:cast(?SERVER, reload).


-spec wait_until_provided(What::atom()) -> ok.
wait_until_provided(What) ->
gen_server:call(?SERVER, {wait_until_provided, What}).
Expand Down Expand Up @@ -118,6 +124,27 @@ handle_call(_Request, _From, State) ->
%% {stop, Reason, State}
%% @end
%%--------------------------------------------------------------------
handle_cast(reload, State = #state{pending = Pending}) ->
{ok, Base} = application:get_env(plugin_dir),
WC = filename:join([Base, "*", "plugin.conf"]),
Plugins = eplugin:plugins(),
Configs = filelib:wildcard(WC),
New = lists:foldl(fun(File, Acc) ->
case load_config(File) of
{ok, Path, Name, Modules, Config} ->
case lists:keyfind(Name, 2, Plugins) of
false ->
[{Path, Name, Modules, Config} | Acc];
_ ->
Acc
end;
_ ->
Acc
end
end, [], Configs),
provide(eplugin),
{ok, State#state{pending = Pending ++ New}};

handle_cast({provide, What}, State = #state{pending = Pending,
provided = Provided,
waiting = Waiting}) ->
Expand All @@ -131,12 +158,13 @@ handle_cast({provide, What}, State = #state{pending = Pending,
compile_plugin(Path, Name, Modules, Config)
end, Load),
{Ready, Waiting1} = lists:partition(fun({WaitWhat, _WaitFrom}) ->
WaitWhat =:= What
WaitWhat =:= What
end, Waiting),
lists:foreach(fun({_, WaitFrom}) ->
gen_server:reply(WaitFrom, ok)
gen_server:reply(WaitFrom, ok)
end, Ready),
{noreply, State#state{provided = Provided1, pending = Pending1, waiting = Waiting1}};

handle_cast(_Msg, State) ->
{noreply, State}.

Expand Down Expand Up @@ -209,8 +237,8 @@ load_modules(Name, _Path, []) ->

load_modules(Name, Path, [{M, _RegisterFor} | Modules]) ->
File = filename:join([Path, M]),
% code:delete(M),
% code:purge(M),
% code:delete(M),
% code:purge(M),
case code:load_abs(File) of
{error, Reason} ->
lager:error("[eplugin::~p] Failed to load module ~p(~s): ~p.", [Name, M, File, Reason]),
Expand Down

0 comments on commit 05e7d3e

Please sign in to comment.