From 6df6f6764fb62b2ed6a36c06d6d9e4beae28f869 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 3 Nov 2012 20:29:34 -0700 Subject: [PATCH] Remove plugin activation. It really isn't necessary. It was only used in a couple places and it isn't necessary since you can do the loading within the actual blocks themselves. --- lib/vagrant/config/v1/loader.rb | 13 ++++----- lib/vagrant/environment.rb | 15 ---------- lib/vagrant/plugin/v1/plugin.rb | 25 ---------------- plugins/guests/fedora/plugin.rb | 3 -- plugins/kernel_v1/plugin.rb | 33 ++++++++++++++-------- test/unit/vagrant/plugin/v1/plugin_test.rb | 28 ------------------ 6 files changed, 27 insertions(+), 90 deletions(-) diff --git a/lib/vagrant/config/v1/loader.rb b/lib/vagrant/config/v1/loader.rb index d914c0ce6..348e3e45f 100644 --- a/lib/vagrant/config/v1/loader.rb +++ b/lib/vagrant/config/v1/loader.rb @@ -59,21 +59,21 @@ module Vagrant old_keys = old_state["keys"] new_keys = new_state["keys"] keys = {} - old_keys.each do |key, old| + old_keys.each do |key, old_value| if new_keys.has_key?(key) # We need to do a merge, which we expect to be available # on the config class itself. - keys[key] = old.merge(new_keys[key]) + keys[key] = old_value.merge(new_keys[key]) else # We just take the old value, but dup it so that we can modify. - keys[key] = old.dup + keys[key] = old_value.dup end end - new_keys.each do |key, new| + new_keys.each do |key, new_value| # Add in the keys that the new class has that we haven't merged. if !keys.has_key?(key) - keys[key] = new.dup + keys[key] = new_value.dup end end @@ -87,9 +87,6 @@ module Vagrant # Get all the registered plugins config_map = {} Vagrant.plugin("1").registered.each do |plugin| - # Activate the plugin since we're about to use it - plugin.activate! - # Get all the available configuration keys and add them to the map plugin.config.each do |key, klass| config_map[key] = klass diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 7be9e476e..148d4e9e5 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -99,9 +99,6 @@ module Vagrant # Load the plugins load_plugins - - # Activate the plugins - activate_plugins end # Return a human-friendly string for pretty printed or inspected @@ -394,10 +391,6 @@ module Vagrant config_loader.set(:vm, subvm.config_procs) end - # We activate plugins here because the files which we're loading - # configuration from may have defined new plugins as well. - activate_plugins - # Execute the configuration stack and store the result as the final # value in the config ivar. config_loader.load @@ -529,14 +522,6 @@ module Vagrant nil end - # This finds all the current plugins and activates them. This is an - # idempotent call so it is safe to call this as much as you need. - def activate_plugins - Vagrant.plugin("1").registered.each do |plugin| - plugin.activate! - end - end - # Loads the Vagrant plugins by properly setting up RubyGems so that # our private gem repository is on the path. def load_plugins diff --git a/lib/vagrant/plugin/v1/plugin.rb b/lib/vagrant/plugin/v1/plugin.rb index 7d0e57b53..101640f8c 100644 --- a/lib/vagrant/plugin/v1/plugin.rb +++ b/lib/vagrant/plugin/v1/plugin.rb @@ -68,19 +68,6 @@ module Vagrant hooks << block end - # The given block will be called when this plugin is activated. The - # activation block should be used to load any of the classes used by - # the plugin other than the plugin definition itself. Vagrant only - # guarantees that the plugin definition will remain backwards - # compatible, but not any other classes (such as command base classes - # or so on). Therefore, to avoid crashing future versions of Vagrant, - # these classes should be placed in separate files and loaded in the - # activation block. - def self.activated(&block) - data[:activation_block] = block if block_given? - data[:activation_block] - end - # Defines additional command line commands available by key. The key # becomes the subcommand, so if you register a command "foo" then # "vagrant foo" becomes available. @@ -225,18 +212,6 @@ module Vagrant data[:provisioners] end - # Activates the current plugin. This shouldn't be called publicly. - def self.activate! - if !data[:activated_called] - LOGGER.info("Activating plugin: #{self.name}") - data[:activated_called] = true - - # Call the activation block - block = activated - block.call if block - end - end - # Registers the plugin. This makes the plugin actually work with # Vagrant. Prior to registering, the plugin is merely a skeleton. # diff --git a/plugins/guests/fedora/plugin.rb b/plugins/guests/fedora/plugin.rb index 19be0ab72..5f6a6b5e8 100644 --- a/plugins/guests/fedora/plugin.rb +++ b/plugins/guests/fedora/plugin.rb @@ -6,9 +6,6 @@ module VagrantPlugins name "Fedora guest" description "Fedora guest support." - activated do - end - guest("fedora") do require File.expand_path("../guest", __FILE__) Guest diff --git a/plugins/kernel_v1/plugin.rb b/plugins/kernel_v1/plugin.rb index 9f87195f8..3b5d69994 100644 --- a/plugins/kernel_v1/plugin.rb +++ b/plugins/kernel_v1/plugin.rb @@ -11,20 +11,31 @@ module VagrantPlugins basic functionality of Vagrant version 1. DESC - activated do + # Core configuration keys provided by the kernel. + config("ssh") do require File.expand_path("../config/ssh", __FILE__) - require File.expand_path("../config/nfs", __FILE__) - require File.expand_path("../config/package", __FILE__) - require File.expand_path("../config/vagrant", __FILE__) - require File.expand_path("../config/vm", __FILE__) + SSHConfig end - # Core configuration keys provided by the kernel. - config("ssh") { SSHConfig } - config("nfs") { NFSConfig } - config("package") { PackageConfig } - config("vagrant") { VagrantConfig } - config("vm") { VMConfig } + config("nfs") do + require File.expand_path("../config/nfs", __FILE__) + NFSConfig + end + + config("package") do + require File.expand_path("../config/package", __FILE__) + PackageConfig + end + + config("vagrant") do + require File.expand_path("../config/vagrant", __FILE__) + VagrantConfig + end + + config("vm") do + require File.expand_path("../config/vm", __FILE__) + VMConfig + end end end end diff --git a/test/unit/vagrant/plugin/v1/plugin_test.rb b/test/unit/vagrant/plugin/v1/plugin_test.rb index df1d5ccc2..9dcf25969 100644 --- a/test/unit/vagrant/plugin/v1/plugin_test.rb +++ b/test/unit/vagrant/plugin/v1/plugin_test.rb @@ -35,34 +35,6 @@ describe Vagrant::Plugin::V1::Plugin do end end - describe "activation block" do - it "should have no activation block by default" do - plugin = Class.new(described_class) - plugin.activated.should be_nil - end - - it "should be able to set and get the activation block" do - plugin = Class.new(described_class) do - activated do - 42 - end - end - - plugin.activated.call.should == 42 - end - - it "should activate when `activate!` is called" do - plugin = Class.new(described_class) do - activated do - raise NotImplementedError - end - end - - expect { plugin.activate! }.to raise_error(NotImplementedError) - expect { plugin.activate! }.to_not raise_error - end - end - describe "commands" do it "should register command classes" do plugin = Class.new(described_class) do