Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

73 řádky
2.8 KiB

před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
před 10 roky
  1. -module(rebar_prv_plugins).
  2. -behaviour(provider).
  3. -export([init/1,
  4. do/1,
  5. format_error/1]).
  6. -include("rebar.hrl").
  7. -include_lib("providers/include/providers.hrl").
  8. -define(PROVIDER, list).
  9. -define(NAMESPACE, plugins).
  10. -define(DEPS, []).
  11. -spec init(rebar_state:t()) -> {ok, rebar_state:t()}.
  12. init(State) ->
  13. State1 = rebar_state:add_provider(
  14. State,
  15. providers:create([
  16. {name, ?PROVIDER},
  17. {module, ?MODULE},
  18. {namespace, ?NAMESPACE},
  19. {bare, true},
  20. {deps, ?DEPS},
  21. {example, "rebar3 plugins list"},
  22. {short_desc, "List local and global plugins for this project"},
  23. {desc, "List local and global plugins for this project"},
  24. {opts, []}])),
  25. {ok, State1}.
  26. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
  27. do(State) ->
  28. GlobalConfigFile = rebar_dir:global_config(),
  29. GlobalConfig = rebar_state:new(rebar_config:consult_file(GlobalConfigFile)),
  30. GlobalPlugins = rebar_state:get(GlobalConfig, plugins, []),
  31. GlobalSrcDirs = rebar_state:get(GlobalConfig, src_dirs, ["src"]),
  32. GlobalPluginsDir = filename:join([rebar_dir:global_cache_dir(rebar_state:opts(State)), "plugins", "*"]),
  33. GlobalApps = rebar_app_discover:find_apps([GlobalPluginsDir], GlobalSrcDirs, all),
  34. display_plugins("Global plugins", GlobalApps, GlobalPlugins),
  35. RebarOpts = rebar_state:opts(State),
  36. SrcDirs = rebar_dir:src_dirs(RebarOpts, ["src"]),
  37. Plugins = rebar_state:get(State, plugins, []),
  38. PluginsDirs = filelib:wildcard(filename:join(rebar_dir:plugins_dir(State), "*")),
  39. CheckoutsDirs = filelib:wildcard(filename:join(rebar_dir:checkouts_dir(State), "*")),
  40. Apps = rebar_app_discover:find_apps(CheckoutsDirs++PluginsDirs, SrcDirs, all),
  41. display_plugins("Local plugins", Apps, Plugins),
  42. {ok, State}.
  43. -spec format_error(any()) -> iolist().
  44. format_error(Reason) ->
  45. io_lib:format("~p", [Reason]).
  46. display_plugins(_Header, _Apps, []) ->
  47. ok;
  48. display_plugins(Header, Apps, Plugins) ->
  49. ?CONSOLE("--- ~ts ---", [Header]),
  50. display_plugins(Apps, Plugins),
  51. ?CONSOLE("", []).
  52. display_plugins(Apps, Plugins) ->
  53. lists:foreach(fun(Plugin) ->
  54. Name = if is_atom(Plugin) -> atom_to_binary(Plugin, unicode);
  55. is_tuple(Plugin) -> rebar_utils:to_binary(element(1, Plugin))
  56. end,
  57. case rebar_app_utils:find(Name, Apps) of
  58. {ok, _App} ->
  59. ?CONSOLE("~ts", [Name]);
  60. error ->
  61. ?DEBUG("Unable to find plugin ~ts", [Name])
  62. end
  63. end, Plugins).