Use env_local consistently internally

This commit is contained in:
Chris Roberts 2018-07-17 14:22:26 -07:00
parent a410b0af51
commit 3223737734
8 changed files with 36 additions and 20 deletions

View File

@ -111,6 +111,7 @@ module Vagrant
end
Gem::Specification.reset
nil
end
# Removes any temporary files created by init

View File

@ -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!

View File

@ -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

View File

@ -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!

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -32,7 +32,7 @@ describe Vagrant::Plugin::StateFile do
"require" => "",
"sources" => [],
"installed_gem_version" => nil,
"local" => false,
"env_local" => false,
})
end