Load plugins with the private gem path.

This changed plugin loading semantics a tiny bit, since they are
no longer loaded when Vagrant is loaded but instead when the
Vagrant::Environment is initialized. I'll note this in the CHANGELOG.
This commit is contained in:
Mitchell Hashimoto 2012-02-06 22:39:35 -05:00
parent 261a83d60f
commit 13fddfa6f9
3 changed files with 26 additions and 22 deletions

View File

@ -50,6 +50,9 @@ require 'i18n'
# there are issues with ciphers not being properly loaded. # there are issues with ciphers not being properly loaded.
require 'openssl' require 'openssl'
# Always make the version available
require 'vagrant/version'
module Vagrant module Vagrant
autoload :Action, 'vagrant/action' autoload :Action, 'vagrant/action'
autoload :Box, 'vagrant/box' autoload :Box, 'vagrant/box'
@ -186,7 +189,3 @@ Vagrant.provisioners.register(:shell) { Vagrant::Provisioners::Shell }
Vagrant.config_keys.register(:freebsd) { Vagrant::Guest::FreeBSD::FreeBSDConfig } Vagrant.config_keys.register(:freebsd) { Vagrant::Guest::FreeBSD::FreeBSDConfig }
Vagrant.config_keys.register(:linux) { Vagrant::Guest::Linux::LinuxConfig } Vagrant.config_keys.register(:linux) { Vagrant::Guest::Linux::LinuxConfig }
Vagrant.config_keys.register(:solaris) { Vagrant::Guest::Solaris::SolarisConfig } Vagrant.config_keys.register(:solaris) { Vagrant::Guest::Solaris::SolarisConfig }
# Load the things which must be loaded before anything else.
require 'vagrant/version'
Vagrant::Plugin.load!

View File

@ -88,6 +88,9 @@ module Vagrant
# Setup the default private key # Setup the default private key
@default_private_key_path = @home_path.join("insecure_private_key") @default_private_key_path = @home_path.join("insecure_private_key")
copy_insecure_private_key copy_insecure_private_key
# Load the plugins
load_plugins
end end
#--------------------------------------------------------------- #---------------------------------------------------------------
@ -494,5 +497,17 @@ module Vagrant
nil nil
end end
# Loads the Vagrant plugins by properly setting up RubyGems so that
# our private gem repository is on the path.
def load_plugins
# Add our private gem path to the gem path and reset the paths
# that Rubygems knows about.
ENV["GEM_PATH"] = "#{@gems_path}:#{ENV["GEM_PATH"]}"
::Gem.clear_paths
# Load the plugins
Plugin.load!
end
end end
end end

View File

@ -9,15 +9,9 @@ module Vagrant
# (for debugging), the list of loaded plugins is stored in the {plugins} # (for debugging), the list of loaded plugins is stored in the {plugins}
# array. # array.
class Plugin class Plugin
# The array of loaded plugins. # The array of gem specifications that were loaded as plugins.
@@plugins = [] @@plugins = []
# The gemspec of this plugin. This is an actual gemspec object.
attr_reader :gemspec
# The path to the `vagrant_init.rb` file which was loaded for this plugin.
attr_reader :file
# Loads all the plugins for Vagrant. Plugins are currently # Loads all the plugins for Vagrant. Plugins are currently
# gems which have a "vagrant_init.rb" somewhere on their # gems which have a "vagrant_init.rb" somewhere on their
# load path. This file is loaded to kick off the load sequence # load path. This file is loaded to kick off the load sequence
@ -46,6 +40,11 @@ module Vagrant
specs = Gem::VERSION >= "1.6.0" ? source.latest_specs(true) : source.latest_specs specs = Gem::VERSION >= "1.6.0" ? source.latest_specs(true) : source.latest_specs
specs.each do |spec| specs.each do |spec|
if @@plugins.include?(spec)
logger.debug("Plugin already loaded, not loading again: #{spec.name}")
next
end
# If this gem depends on Vagrant, verify this is a valid release of # If this gem depends on Vagrant, verify this is a valid release of
# Vagrant for this gem to load into. # Vagrant for this gem to load into.
vagrant_dep = spec.dependencies.find { |d| d.name == "vagrant" } vagrant_dep = spec.dependencies.find { |d| d.name == "vagrant" }
@ -65,7 +64,8 @@ module Vagrant
next if !file next if !file
logger.info("Loading plugin: #{spec.name} (#{spec.version})") logger.info("Loading plugin: #{spec.name} (#{spec.version})")
@@plugins << new(spec, file) @@plugins << spec
load file
end end
logger.info("Loaded #{@@plugins.length} plugins.") logger.info("Loaded #{@@plugins.length} plugins.")
@ -77,15 +77,5 @@ module Vagrant
# #
# @return [Array] # @return [Array]
def self.plugins; @@plugins; end def self.plugins; @@plugins; end
# Initializes a new plugin, given a Gemspec and the path to the
# gem's `vagrant_init.rb` file. This should never be called manually.
# Instead {load!} creates all the instances.
def initialize(spec, file)
@gemspec = spec
@file = file
load file
end
end end
end end