Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

78 строки
3.2 KiB

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
  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. %% use `checkouts_dir' and not `checkouts_out_dir'. Since we use `all' in `find_apps'
  41. %% so it doesn't need to be built and the apps in `checkouts_dir' could be old
  42. %% because the user removing from `_checkouts/' doesn't cause removal of the output
  43. CheckoutsDirs = filelib:wildcard(filename:join(rebar_dir:checkouts_dir(State), "*")),
  44. Apps = rebar_app_discover:find_apps(CheckoutsDirs++PluginsDirs, SrcDirs, all, State),
  45. display_plugins("Local plugins", Apps, Plugins ++ ProjectPlugins),
  46. {ok, State}.
  47. -spec format_error(any()) -> iolist().
  48. format_error(Reason) ->
  49. io_lib:format("~p", [Reason]).
  50. display_plugins(_Header, _Apps, []) ->
  51. ok;
  52. display_plugins(Header, Apps, Plugins) ->
  53. ?CONSOLE("--- ~ts ---", [Header]),
  54. display_plugins(Apps, Plugins),
  55. ?CONSOLE("", []).
  56. display_plugins(Apps, Plugins) ->
  57. lists:foreach(fun(Plugin) ->
  58. Name = if is_atom(Plugin) -> atom_to_binary(Plugin, unicode);
  59. is_tuple(Plugin) -> rebar_utils:to_binary(element(1, Plugin))
  60. end,
  61. case rebar_app_utils:find(Name, Apps) of
  62. {ok, App} ->
  63. ?CONSOLE("~ts (~s)", [Name, rebar_app_info:original_vsn(App)]);
  64. error ->
  65. ?DEBUG("Unable to find plugin ~ts", [Name])
  66. end
  67. end, Plugins).