From d98868d1502bde0bd3a2f2b65a4e89793e90e5f8 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 4 Jan 2014 16:35:28 -0800 Subject: [PATCH] core: Vagrant.require_plugin is gone --- lib/vagrant/init.rb | 69 +++------------------------------------ test/unit/vagrant_test.rb | 30 ----------------- 2 files changed, 4 insertions(+), 95 deletions(-) diff --git a/lib/vagrant/init.rb b/lib/vagrant/init.rb index c4a17be6b..32ef6e4e5 100644 --- a/lib/vagrant/init.rb +++ b/lib/vagrant/init.rb @@ -172,72 +172,11 @@ module Vagrant "#{version} #{component}" end - # This should be used instead of Ruby's built-in `require` in order to - # 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. + # @deprecated def self.require_plugin(name) - logger = Log4r::Logger.new("vagrant::root") - - if ENV["VAGRANT_NO_PLUGINS"] - 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 : "" - logger.info("Loaded plugin #{name}, version #{version}") - ensure - $stderr = previous_stderr if previous_stderr - $stdout = previous_stdout if previous_stdout + puts "Vagrant.require_plugin is deprecated and has no effect any longer." + puts "Use `vagrant plugin` commands to manage plugins. This warning will" + puts "be removed in the next version of Vagrant." end # This allows a Vagrantfile to specify the version of Vagrant that is diff --git a/test/unit/vagrant_test.rb b/test/unit/vagrant_test.rb index 0d143d42b..cb8c0f105 100644 --- a/test/unit/vagrant_test.rb +++ b/test/unit/vagrant_test.rb @@ -47,36 +47,6 @@ describe Vagrant do 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 before(:each) do Class.new(described_class.plugin("2")) do