Merge pull request #9808 from chrisroberts/f-vagrant-plugin-loading

Vagrant plugin updates
This commit is contained in:
Chris Roberts 2018-05-09 08:37:04 -07:00 committed by GitHub
commit 0b963a5213
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 30 additions and 18 deletions

View File

@ -37,13 +37,18 @@ argv.each_index do |i|
arg = argv[i]
if !arg.start_with?("-")
if ["plugin", "help"].include?(arg) || (arg == "box" && argv[i+1] == "list")
if arg == "box" && argv[i+1] == "list"
opts[:vagrantfile_name] = ""
ENV['VAGRANT_NO_PLUGINS'] = "1"
end
if arg == "plugin" && argv[i+1] != "list"
ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1"
# Do not load plugins when performing plugin operations
if arg == "plugin"
ENV['VAGRANT_NO_PLUGINS'] = "1"
# Only initialize plugins when listing installed plugins
if argv[i+1] != "list"
ENV['VAGRANT_DISABLE_PLUGIN_INIT'] = "1"
end
end
break

View File

@ -288,7 +288,7 @@ end
if Vagrant.plugins_init?
begin
Vagrant::Bundler.instance.init!(plugins)
rescue Exception => e
rescue StandardError, ScriptError => e
global_logger.error("Plugin initialization error - #{e.class}: #{e}")
e.backtrace.each do |backtrace_line|
global_logger.debug(backtrace_line)
@ -334,18 +334,16 @@ if Vagrant.plugins_enabled?
plugins.each do |plugin_name, plugin_info|
if plugin_info["require"].to_s.empty?
begin
global_logger.debug("Loading plugin `#{plugin_name}` with default require: `#{plugin_name}`")
global_logger.info("Loading plugin `#{plugin_name}` with default require: `#{plugin_name}`")
require plugin_name
rescue LoadError, Gem::LoadError => load_error
rescue LoadError => err
if plugin_name.include?("-")
begin
plugin_slash = plugin_name.gsub("-", "/")
global_logger.debug("Failed to load plugin `#{plugin_name}` with default require.")
global_logger.debug("Loading plugin `#{plugin_name}` with slash require: `#{plugin_slash}`")
require plugin_slash
rescue LoadError, Gem::LoadError
global_logger.warn("Failed to load plugin `#{plugin_name}`. Assuming library and moving on.")
end
plugin_slash = plugin_name.gsub("-", "/")
global_logger.error("Failed to load plugin `#{plugin_name}` with default require. - #{err.class}: #{err}")
global_logger.info("Loading plugin `#{plugin_name}` with slash require: `#{plugin_slash}`")
require plugin_slash
else
raise
end
end
else
@ -358,12 +356,12 @@ if Vagrant.plugins_enabled?
global_logger.debug("Bundler detected in use. Loading `:plugins` group.")
::Bundler.require(:plugins)
end
rescue Exception => e
global_logger.error("Plugin loading error: #{e.class} - #{e}")
e.backtrace.each do |backtrace_line|
rescue ScriptError, StandardError => err
global_logger.error("Plugin loading error: #{err.class} - #{err}")
err.backtrace.each do |backtrace_line|
global_logger.debug(backtrace_line)
end
raise Vagrant::Errors::PluginLoadError, message: e.to_s
raise Vagrant::Errors::PluginLoadError, message: err.to_s
end
else
global_logger.debug("Plugin loading is currently disabled.")

View File

@ -303,6 +303,15 @@ module Vagrant
solution = request_set.resolve(installer_set)
activate_solution(solution)
# Remove gems which are already installed
request_set.sorted_requests.delete_if do |activation_req|
rs_spec = activation_req.spec
if vagrant_internal_specs.detect{|ispec| ispec.name == rs_spec.name && ispec.version == rs_spec.version }
@logger.debug("Removing activation request from install. Already installed. (#{rs_spec.spec.full_name})")
true
end
end
@logger.debug("Installing required gems.")
# Install all remote gems into plugin path. Set the installer to ignore dependencies