Merge pull request #80 from hyperthunk/plugin-hooks

Allow plugins to run before/after a rebar command.
This commit is contained in:
Dave Smith 2011-06-06 08:02:50 -07:00
commit ab116276b7

View file

@ -148,8 +148,16 @@ process_dir(Dir, ParentConfig, Command, DirSet) ->
%% in preprocess. %% in preprocess.
{ok, PluginModules} = plugin_modules(Config), {ok, PluginModules} = plugin_modules(Config),
%% Execute any before_command plugins on this directory
execute_pre(Command, PluginModules,
Config, ModuleSetFile),
%% Execute the current command on this directory %% Execute the current command on this directory
execute(Command, Modules ++ PluginModules, execute(Command, Modules ++ PluginModules,
Config, ModuleSetFile),
%% Execute any after_command plugins on this directory
execute_post(Command, PluginModules,
Config, ModuleSetFile) Config, ModuleSetFile)
end, end,
@ -215,6 +223,17 @@ is_dir_type(rel_dir, Dir) ->
is_dir_type(_, _) -> is_dir_type(_, _) ->
false. false.
execute_pre(Command, Modules, Config, ModuleFile) ->
execute_plugin_hook("pre_", Command, Modules,
Config, ModuleFile).
execute_post(Command, Modules, Config, ModuleFile) ->
execute_plugin_hook("post_", Command, Modules,
Config, ModuleFile).
execute_plugin_hook(Hook, Command, Modules, Config, ModuleFile) ->
HookFunction = list_to_atom(Hook ++ atom_to_list(Command)),
execute(HookFunction, Modules, Config, ModuleFile).
%% %%
%% Execute a command across all applicable modules %% Execute a command across all applicable modules