2016-11-02 17:37:29 +00:00
|
|
|
require "vagrant/plugin/manager"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPlugin
|
|
|
|
module Action
|
|
|
|
# This middleware attempts to repair installed plugins.
|
|
|
|
#
|
|
|
|
# In general, if plugins are failing to properly load the
|
|
|
|
# core issue will likely be one of two issues:
|
|
|
|
# 1. manual modifications within ~/.vagrant.d/
|
|
|
|
# 2. vagrant upgrade
|
|
|
|
# Running an install on configured plugin set will most
|
|
|
|
# likely fix these issues, which is all this action does.
|
|
|
|
class RepairPlugins
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
2016-11-23 01:54:44 +00:00
|
|
|
@logger = Log4r::Logger.new("vagrant::plugins::plugincommand::repair")
|
2016-11-02 17:37:29 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.repairing"))
|
2018-07-18 20:46:17 +00:00
|
|
|
plugins = Vagrant::Plugin::Manager.instance.globalize!
|
2016-11-23 01:54:44 +00:00
|
|
|
begin
|
2018-07-18 20:46:17 +00:00
|
|
|
ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = nil
|
2016-11-23 01:54:44 +00:00
|
|
|
Vagrant::Bundler.instance.init!(plugins, :repair)
|
2018-07-18 20:46:17 +00:00
|
|
|
ENV["VAGRANT_DISABLE_PLUGIN_INIT"] = "1"
|
2016-11-23 01:54:44 +00:00
|
|
|
env[:ui].info(I18n.t("vagrant.commands.plugin.repair_complete"))
|
2018-07-18 20:46:17 +00:00
|
|
|
rescue => e
|
2016-11-23 01:54:44 +00:00
|
|
|
@logger.error("Failed to repair user installed plugins: #{e.class} - #{e}")
|
|
|
|
e.backtrace.each do |backtrace_line|
|
|
|
|
@logger.debug(backtrace_line)
|
|
|
|
end
|
|
|
|
env[:ui].error(I18n.t("vagrant.commands.plugin.repair_failed", message: e.message))
|
|
|
|
end
|
2016-11-02 17:37:29 +00:00
|
|
|
# Continue
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
2018-07-18 20:46:17 +00:00
|
|
|
|
|
|
|
class RepairPluginsLocal
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
@logger = Log4r::Logger.new("vagrant::plugins::plugincommand::repair_local")
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
|
|
|
Vagrant::Plugin::Manager.instance.localize!(env[:env]).each_pair do |pname, pinfo|
|
|
|
|
env[:env].action_runner.run(Action.action_install,
|
|
|
|
plugin_name: pname,
|
|
|
|
plugin_entry_point: pinfo["require"],
|
|
|
|
plugin_sources: pinfo["sources"],
|
|
|
|
plugin_version: pinfo["gem_version"],
|
|
|
|
plugin_env_local: true
|
|
|
|
)
|
|
|
|
end
|
|
|
|
# Continue
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
2016-11-02 17:37:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|