core: Vagrant.require_plugin is gone
This commit is contained in:
parent
5387984e0f
commit
d98868d150
|
@ -172,72 +172,11 @@ module Vagrant
|
||||||
"#{version} #{component}"
|
"#{version} #{component}"
|
||||||
end
|
end
|
||||||
|
|
||||||
# This should be used instead of Ruby's built-in `require` in order to
|
# @deprecated
|
||||||
# load a Vagrant plugin. This will load the given plugin by first doing
|
|
||||||
# a normal `require`, giving a nice error message if things go wrong,
|
|
||||||
# and second by verifying that a Vagrant plugin was actually defined in
|
|
||||||
# the process.
|
|
||||||
#
|
|
||||||
# @param [String] name Name of the plugin to load.
|
|
||||||
def self.require_plugin(name)
|
def self.require_plugin(name)
|
||||||
logger = Log4r::Logger.new("vagrant::root")
|
puts "Vagrant.require_plugin is deprecated and has no effect any longer."
|
||||||
|
puts "Use `vagrant plugin` commands to manage plugins. This warning will"
|
||||||
if ENV["VAGRANT_NO_PLUGINS"]
|
puts "be removed in the next version of Vagrant."
|
||||||
logger.warn("VAGRANT_NO_PLUGINS is set, not loading 3rd party plugin: #{name}")
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
# Redirect stdout/stderr so that we can output it in our own way.
|
|
||||||
previous_stderr = $stderr
|
|
||||||
previous_stdout = $stdout
|
|
||||||
$stderr = StringIO.new
|
|
||||||
$stdout = StringIO.new
|
|
||||||
|
|
||||||
# Attempt the normal require
|
|
||||||
begin
|
|
||||||
require name
|
|
||||||
plugin("2").manager.plugin_required(name)
|
|
||||||
rescue Exception => e
|
|
||||||
# Since this is a rare case, we create a one-time logger here
|
|
||||||
# in order to output the error
|
|
||||||
logger.error("Failed to load plugin: #{name}")
|
|
||||||
logger.error(" -- Error: #{e.inspect}")
|
|
||||||
logger.error(" -- Backtrace:")
|
|
||||||
logger.error(e.backtrace.join("\n"))
|
|
||||||
|
|
||||||
# If it is a LoadError we first try to see if it failed loading
|
|
||||||
# the top-level entrypoint. If so, then we report a different error.
|
|
||||||
if e.is_a?(LoadError)
|
|
||||||
# Parse the message in order to get what failed to load, and
|
|
||||||
# add some extra protection around if the message is different.
|
|
||||||
parts = e.to_s.split(" -- ", 2)
|
|
||||||
if parts.length == 2 && parts[1] == name
|
|
||||||
raise Errors::PluginLoadError, :plugin => name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Get the string data out from the stdout/stderr captures
|
|
||||||
stderr = $stderr.string
|
|
||||||
stdout = $stdout.string
|
|
||||||
if !stderr.empty? || !stdout.empty?
|
|
||||||
raise Errors::PluginLoadFailedWithOutput,
|
|
||||||
:plugin => name,
|
|
||||||
:stderr => stderr,
|
|
||||||
:stdout => stdout
|
|
||||||
end
|
|
||||||
|
|
||||||
# And raise an error itself
|
|
||||||
raise Errors::PluginLoadFailed,
|
|
||||||
:plugin => name
|
|
||||||
end
|
|
||||||
|
|
||||||
# Log plugin version
|
|
||||||
gem = Gem::Specification.find { |spec| spec.name == name }
|
|
||||||
version = gem ? gem.version : "<unknown>"
|
|
||||||
logger.info("Loaded plugin #{name}, version #{version}")
|
|
||||||
ensure
|
|
||||||
$stderr = previous_stderr if previous_stderr
|
|
||||||
$stdout = previous_stdout if previous_stdout
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# This allows a Vagrantfile to specify the version of Vagrant that is
|
# This allows a Vagrantfile to specify the version of Vagrant that is
|
||||||
|
|
|
@ -47,36 +47,6 @@ describe Vagrant do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "requiring plugins" do
|
|
||||||
it "should require the plugin given" do
|
|
||||||
# For now, just require a stdlib
|
|
||||||
expect { described_class.require_plugin "set" }.
|
|
||||||
to_not raise_error
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should add the gem name to plugin manager" do
|
|
||||||
expect(described_class.plugin("2").manager).
|
|
||||||
to receive(:plugin_required).with("set")
|
|
||||||
described_class.require_plugin "set"
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should raise an error if the file doesn't exist" do
|
|
||||||
expect { described_class.require_plugin("i_dont_exist") }.
|
|
||||||
to raise_error(Vagrant::Errors::PluginLoadError)
|
|
||||||
end
|
|
||||||
|
|
||||||
it "should raise an error if the loading failed in some other way" do
|
|
||||||
plugin_dir = temporary_dir
|
|
||||||
plugin_path = plugin_dir.join("test.rb")
|
|
||||||
plugin_path.open("w") do |f|
|
|
||||||
f.write(%Q[require 'I_dont_exist'])
|
|
||||||
end
|
|
||||||
|
|
||||||
expect { described_class.require_plugin(plugin_path.to_s) }.
|
|
||||||
to raise_error(Vagrant::Errors::PluginLoadFailed)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "has_plugin?" do
|
describe "has_plugin?" do
|
||||||
before(:each) do
|
before(:each) do
|
||||||
Class.new(described_class.plugin("2")) do
|
Class.new(described_class.plugin("2")) do
|
||||||
|
|
Loading…
Reference in New Issue