From 3223737734fe7b57bc5a4c7c5d8403abfa0f4120 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Tue, 17 Jul 2018 14:22:26 -0700 Subject: [PATCH] Use env_local consistently internally --- lib/vagrant/bundler.rb | 1 + lib/vagrant/environment.rb | 2 +- lib/vagrant/plugin/manager.rb | 31 ++++++++++++++----- lib/vagrant/plugin/state_file.rb | 2 +- .../commands/plugin/action/list_plugins.rb | 2 +- .../plugin/action/expunge_plugins_test.rb | 8 ++--- .../plugin/action/install_gem_test.rb | 8 ++--- test/unit/vagrant/plugin/state_file_test.rb | 2 +- 8 files changed, 36 insertions(+), 20 deletions(-) diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 4f1d145d2..c1613f612 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -111,6 +111,7 @@ module Vagrant end Gem::Specification.reset + nil end # Removes any temporary files created by init diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 4d2fb6d56..845036cf7 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -171,7 +171,7 @@ module Vagrant plugins = process_configured_plugins end - # Load any local plugins + # Load any environment local plugins Vagrant::Plugin::Manager.instance.load_plugins(plugins) plugins = Vagrant::Plugin::Manager.instance.globalize! diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb index d5d2d3de8..21b60c575 100644 --- a/lib/vagrant/plugin/manager.rb +++ b/lib/vagrant/plugin/manager.rb @@ -43,6 +43,9 @@ module Vagrant @local_file = nil end + # Enable global plugins + # + # @return [Hash] list of plugins def globalize! @logger.debug("Enabling globalized plugins") if !Vagrant.plugins_init? @@ -55,7 +58,10 @@ module Vagrant plugins end + # Enable environment local plugins + # # @param [Environment] env Vagrant environment + # @return [Hash] list of plugins def localize!(env) if env.local_data_path @logger.debug("Enabling localized plugins") @@ -67,6 +73,10 @@ module Vagrant end end + # Initialize bundler with given plugins + # + # @param [Hash] plugins List of plugins + # @return [nil] def bundler_init(plugins) @logger.info("Plugins:") plugins.each do |plugin_name, plugin_info| @@ -96,7 +106,7 @@ module Vagrant # @param [String] name Name of the plugin (gem) # @return [Gem::Specification] def install_plugin(name, **opts) - if opts[:local] && @local_file.nil? + if opts[:env_local] && @local_file.nil? raise Errors::PluginNoLocalError end @@ -117,7 +127,7 @@ module Vagrant if local_spec.nil? result = nil install_lambda = lambda do - Vagrant::Bundler.instance.install(plugins, opts[:local]).each do |spec| + Vagrant::Bundler.instance.install(plugins, opts[:env_local]).each do |spec| next if spec.name != name next if result && result.version >= spec.version result = spec @@ -133,13 +143,13 @@ module Vagrant result = local_spec end # Add the plugin to the state file - plugin_file = opts[:local] ? @local_file : @user_file + plugin_file = opts[:env_local] ? @local_file : @user_file plugin_file.add_plugin( result.name, version: opts[:version], require: opts[:require], sources: opts[:sources], - local: !!opts[:local], + env_local: !!opts[:env_local], installed_gem_version: result.version.to_s ) @@ -165,11 +175,11 @@ module Vagrant end end - if opts[:local] && @local_file.nil? + if opts[:env_local] && @local_file.nil? raise Errors::PluginNoLocalError end - plugin_file = opts[:local] ? @local_file : @user_file + plugin_file = opts[:env_local] ? @local_file : @user_file if !plugin_file.has_plugin?(name) raise Errors::PluginNotInstalled, @@ -186,11 +196,11 @@ module Vagrant # Updates all or a specific set of plugins. def update_plugins(specific, **opts) - if opts[:local] && @local_file.nil? + if opts[:env_local] && @local_file.nil? raise Errors::PluginNoLocalError end - plugin_file = opts[:local] ? @local_file : @user_file + plugin_file = opts[:env_local] ? @local_file : @user_file result = Vagrant::Bundler.instance.update(plugin_file.installed_plugins, specific) plugin_file.installed_plugins.each do |name, info| @@ -274,6 +284,10 @@ module Vagrant installed_map.values end + # Loads the requested plugins into the Vagrant runtime + # + # @param [Hash] plugins List of plugins to load + # @return [nil] def load_plugins(plugins) if !Vagrant.plugins_enabled? @logger.warn("Plugin loading is disabled") @@ -319,6 +333,7 @@ module Vagrant end raise Vagrant::Errors::PluginLoadError, message: err.to_s end + nil end end end diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb index 2e475a87a..c6872d4fd 100644 --- a/lib/vagrant/plugin/state_file.rb +++ b/lib/vagrant/plugin/state_file.rb @@ -41,7 +41,7 @@ module Vagrant "require" => opts[:require] || "", "sources" => opts[:sources] || [], "installed_gem_version" => opts[:installed_gem_version], - "local" => !!opts[:local] + "env_local" => !!opts[:env_local] } save! diff --git a/plugins/commands/plugin/action/list_plugins.rb b/plugins/commands/plugin/action/list_plugins.rb index 3eb8aeb00..4ab8f3982 100644 --- a/plugins/commands/plugin/action/list_plugins.rb +++ b/plugins/commands/plugin/action/list_plugins.rb @@ -38,7 +38,7 @@ module VagrantPlugins meta = ", global" if plugin meta = ", system" if plugin["system"] - meta = ", local" if plugin["local"] + meta = ", local" if plugin["env_local"] end env[:ui].info "#{spec.name} (#{spec.version}#{meta})" env[:ui].machine("plugin-name", spec.name) diff --git a/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb b/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb index c271eb2b3..a758afbc0 100644 --- a/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb +++ b/test/unit/plugins/commands/plugin/action/expunge_plugins_test.rb @@ -5,13 +5,13 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do let(:home_path){ '/fake/file/path/.vagrant.d' } let(:gems_path){ "#{home_path}/gems" } let(:force){ true } - let(:local){ false } + let(:env_local){ false } let(:env) {{ ui: Vagrant::UI::Silent.new, home_path: home_path, gems_path: gems_path, force: force, - local: local + env_local: env_local }} let(:user_file) { double("user_file", exist?: true, delete: true) } @@ -72,7 +72,7 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do end context "when local option is set" do - let(:local) { true } + let(:env_local) { true } it "should not delete plugins" do expect(user_file).not_to receive(:delete) @@ -94,7 +94,7 @@ describe VagrantPlugins::CommandPlugin::Action::ExpungePlugins do end context "when local option is set" do - let(:local) { true } + let(:env_local) { true } it "should delete local plugins" do expect(local_file).to receive(:delete) diff --git a/test/unit/plugins/commands/plugin/action/install_gem_test.rb b/test/unit/plugins/commands/plugin/action/install_gem_test.rb index 7c88695e9..435595041 100644 --- a/test/unit/plugins/commands/plugin/action/install_gem_test.rb +++ b/test/unit/plugins/commands/plugin/action/install_gem_test.rb @@ -18,7 +18,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should install the plugin" do spec = Gem::Specification.new expect(manager).to receive(:install_plugin).with( - "foo", version: nil, require: nil, sources: nil, verbose: false, local: nil).once.and_return(spec) + "foo", version: nil, require: nil, sources: nil, verbose: false, env_local: nil).once.and_return(spec) expect(app).to receive(:call).with(env).once @@ -29,7 +29,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the version if given" do spec = Gem::Specification.new expect(manager).to receive(:install_plugin).with( - "foo", version: "bar", require: nil, sources: nil, verbose: false, local: nil).once.and_return(spec) + "foo", version: "bar", require: nil, sources: nil, verbose: false, env_local: nil).once.and_return(spec) expect(app).to receive(:call).with(env).once @@ -41,7 +41,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the entrypoint if given" do spec = Gem::Specification.new expect(manager).to receive(:install_plugin).with( - "foo", version: "bar", require: "baz", sources: nil, verbose: false, local: nil).once.and_return(spec) + "foo", version: "bar", require: "baz", sources: nil, verbose: false, env_local: nil).once.and_return(spec) expect(app).to receive(:call).with(env).once @@ -54,7 +54,7 @@ describe VagrantPlugins::CommandPlugin::Action::InstallGem do it "should specify the sources if given" do spec = Gem::Specification.new expect(manager).to receive(:install_plugin).with( - "foo", version: nil, require: nil, sources: ["foo"], verbose: false, local: nil).once.and_return(spec) + "foo", version: nil, require: nil, sources: ["foo"], verbose: false, env_local: nil).once.and_return(spec) expect(app).to receive(:call).with(env).once diff --git a/test/unit/vagrant/plugin/state_file_test.rb b/test/unit/vagrant/plugin/state_file_test.rb index efdd8cbe3..9546db7bc 100644 --- a/test/unit/vagrant/plugin/state_file_test.rb +++ b/test/unit/vagrant/plugin/state_file_test.rb @@ -32,7 +32,7 @@ describe Vagrant::Plugin::StateFile do "require" => "", "sources" => [], "installed_gem_version" => nil, - "local" => false, + "env_local" => false, }) end