Skip to content

Commit

Permalink
Plugins. Documentation coming shortly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchellh committed Sep 15, 2010
1 parent 759bbd0 commit d5fbf29
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,9 @@
## 0.6.0 (unreleased)

- **Plugins** have landed. Plugins are simply gems which have a `vagrant_init.rb`
file somewhere in their load path. Please read the documentation on
vagrantup.com before attempting to create a plugin (which is very easy)
for more information on how it all works and also some guidelines.
- `vagrant package` now takes a `--vagrantfile` option to specify a
Vagrantfile to package. The `--include` approach for including a Vagrantfile
no longer works (previously built boxes will continue to work).
Expand Down
4 changes: 3 additions & 1 deletion lib/vagrant.rb
Expand Up @@ -14,6 +14,7 @@ module Vagrant
autoload :Config, 'vagrant/config'
autoload :DataStore, 'vagrant/data_store'
autoload :Errors, 'vagrant/errors'
autoload :Plugin, 'vagrant/plugin'
autoload :Util, 'vagrant/util'

module Command
Expand Down Expand Up @@ -48,5 +49,6 @@ def self.source_root
downloaders/base provisioners/base provisioners/chef systems/base
hosts/base})

# Initialize the built-in actions
# Initialize the built-in actions and load the plugins.
Vagrant::Action.builtin!
Vagrant::Plugin.load!
40 changes: 40 additions & 0 deletions lib/vagrant/plugin.rb
@@ -0,0 +1,40 @@
require "rubygems"

module Vagrant
class Plugin
# The array of loaded plugins.
@@plugins = []

attr_reader :gemspec
attr_reader :file

# Loads all the plugins for Vagrant. Plugins are currently
# gems which have a "vagrant_init.rb" somewhere on their
# load path. This file is loaded to kick off the load sequence
# for that plugin.
def self.load!
# Look for a vagrant_init.rb in all the gems, but only the
# latest version of the gems.
Gem.source_index.latest_specs.each do |spec|
file = Gem.searcher.matching_files(spec, "vagrant_init.rb").first
next if !file

@@plugins << new(spec, file)
end
end

# Returns the array of plugins which are currently loaded by
# Vagrant.
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
9 changes: 9 additions & 0 deletions test/vagrant/plugin_test.rb
@@ -0,0 +1,9 @@
require "test_helper"

class PluginTest < Test::Unit::TestCase
setup do
@klass = Vagrant::Plugin
end

# This is a pretty tough class to test. TODO.
end

0 comments on commit d5fbf29

Please sign in to comment.