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.
This commit is contained in:
Mitchell Hashimoto 2012-11-03 20:29:34 -07:00
parent 5cf737d4fc
commit 6df6f6764f
6 changed files with 27 additions and 90 deletions

View File

@ -59,21 +59,21 @@ module Vagrant
old_keys = old_state["keys"] old_keys = old_state["keys"]
new_keys = new_state["keys"] new_keys = new_state["keys"]
keys = {} keys = {}
old_keys.each do |key, old| old_keys.each do |key, old_value|
if new_keys.has_key?(key) if new_keys.has_key?(key)
# We need to do a merge, which we expect to be available # We need to do a merge, which we expect to be available
# on the config class itself. # on the config class itself.
keys[key] = old.merge(new_keys[key]) keys[key] = old_value.merge(new_keys[key])
else else
# We just take the old value, but dup it so that we can modify. # 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
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. # Add in the keys that the new class has that we haven't merged.
if !keys.has_key?(key) if !keys.has_key?(key)
keys[key] = new.dup keys[key] = new_value.dup
end end
end end
@ -87,9 +87,6 @@ module Vagrant
# Get all the registered plugins # Get all the registered plugins
config_map = {} config_map = {}
Vagrant.plugin("1").registered.each do |plugin| 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 # Get all the available configuration keys and add them to the map
plugin.config.each do |key, klass| plugin.config.each do |key, klass|
config_map[key] = klass config_map[key] = klass

View File

@ -99,9 +99,6 @@ module Vagrant
# Load the plugins # Load the plugins
load_plugins load_plugins
# Activate the plugins
activate_plugins
end end
# Return a human-friendly string for pretty printed or inspected # Return a human-friendly string for pretty printed or inspected
@ -394,10 +391,6 @@ module Vagrant
config_loader.set(:vm, subvm.config_procs) config_loader.set(:vm, subvm.config_procs)
end 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 # Execute the configuration stack and store the result as the final
# value in the config ivar. # value in the config ivar.
config_loader.load config_loader.load
@ -529,14 +522,6 @@ module Vagrant
nil nil
end 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 # Loads the Vagrant plugins by properly setting up RubyGems so that
# our private gem repository is on the path. # our private gem repository is on the path.
def load_plugins def load_plugins

View File

@ -68,19 +68,6 @@ module Vagrant
hooks << block hooks << block
end 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 # Defines additional command line commands available by key. The key
# becomes the subcommand, so if you register a command "foo" then # becomes the subcommand, so if you register a command "foo" then
# "vagrant foo" becomes available. # "vagrant foo" becomes available.
@ -225,18 +212,6 @@ module Vagrant
data[:provisioners] data[:provisioners]
end 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 # Registers the plugin. This makes the plugin actually work with
# Vagrant. Prior to registering, the plugin is merely a skeleton. # Vagrant. Prior to registering, the plugin is merely a skeleton.
# #

View File

@ -6,9 +6,6 @@ module VagrantPlugins
name "Fedora guest" name "Fedora guest"
description "Fedora guest support." description "Fedora guest support."
activated do
end
guest("fedora") do guest("fedora") do
require File.expand_path("../guest", __FILE__) require File.expand_path("../guest", __FILE__)
Guest Guest

View File

@ -11,20 +11,31 @@ module VagrantPlugins
basic functionality of Vagrant version 1. basic functionality of Vagrant version 1.
DESC 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/ssh", __FILE__)
require File.expand_path("../config/nfs", __FILE__) SSHConfig
require File.expand_path("../config/package", __FILE__)
require File.expand_path("../config/vagrant", __FILE__)
require File.expand_path("../config/vm", __FILE__)
end end
# Core configuration keys provided by the kernel. config("nfs") do
config("ssh") { SSHConfig } require File.expand_path("../config/nfs", __FILE__)
config("nfs") { NFSConfig } NFSConfig
config("package") { PackageConfig } end
config("vagrant") { VagrantConfig }
config("vm") { VMConfig } 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 end
end end

View File

@ -35,34 +35,6 @@ describe Vagrant::Plugin::V1::Plugin do
end end
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 describe "commands" do
it "should register command classes" do it "should register command classes" do
plugin = Class.new(described_class) do plugin = Class.new(described_class) do