選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

74 行
3.0 KiB

  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, State),
  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. ProjectPlugins = rebar_state:get(State, project_plugins, []),
  39. PluginsDirs = filelib:wildcard(filename:join(rebar_dir:plugins_dir(State), "*")),
  40. CheckoutsDirs = filelib:wildcard(filename:join(rebar_dir:checkouts_dir(State), "*")),
  41. Apps = rebar_app_discover:find_apps(CheckoutsDirs++PluginsDirs, SrcDirs, all, State),
  42. display_plugins("Local plugins", Apps, Plugins ++ ProjectPlugins),
  43. {ok, State}.
  44. -spec format_error(any()) -> iolist().
  45. format_error(Reason) ->
  46. io_lib:format("~p", [Reason]).
  47. display_plugins(_Header, _Apps, []) ->
  48. ok;
  49. display_plugins(Header, Apps, Plugins) ->
  50. ?CONSOLE("--- ~ts ---", [Header]),
  51. display_plugins(Apps, Plugins),
  52. ?CONSOLE("", []).
  53. display_plugins(Apps, Plugins) ->
  54. lists:foreach(fun(Plugin) ->
  55. Name = if is_atom(Plugin) -> atom_to_binary(Plugin, unicode);
  56. is_tuple(Plugin) -> rebar_utils:to_binary(element(1, Plugin))
  57. end,
  58. case rebar_app_utils:find(Name, Apps) of
  59. {ok, App} ->
  60. ?CONSOLE("~ts (~s)", [Name, rebar_app_info:original_vsn(App)]);
  61. error ->
  62. ?DEBUG("Unable to find plugin ~ts", [Name])
  63. end
  64. end, Plugins).