vagrant-plugin-bundler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ # OS-specific
2
+ .DS_Store
3
+
4
+ # Bundler/Rubygems
5
+ *.gem
6
+ .bundle
7
+ pkg/*
8
+ tags
9
+ Gemfile.lock
10
+
11
+ # Vagrant
12
+ .vagrant
13
+ !example_box/Vagrantfile
14
+
15
+ # Berkshelf
16
+ cookbooks
17
+ Berksfile.lock
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/CHANGELOG.md ADDED
@@ -0,0 +1,4 @@
1
+
2
+ # 0.1.0 (unreleased)
3
+
4
+ * Initial release
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ # We depend on Vagrant for development, but we don't add it as a
7
+ # gem dependency because we expect to be installed within the
8
+ # Vagrant environment itself using `vagrant plugin`.
9
+ gem "vagrant", "1.2.2",
10
+ :git => "https://github.com/mitchellh/vagrant.git",
11
+ :ref => "v1.2.2"
12
+ gem "vagrant-omnibus", "1.0.2"
13
+ end
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ The MIT License (MIT)
2
+ Copyright (c) 2013 Mitchell Hashimoto
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
5
+
6
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # Vagrant PluginBundler Plugin
2
+
3
+ This is a [Vagrant](http://www.vagrantup.com) 1.2+ plugin which hooks in before `vagrant up` and `vagrant reload` and ensures that the required vagrant plugins as specified in your Vagrantfile are installed. Think of a minimalist [Bundler](http://gembundler.com) for vagrant plugins.
4
+
5
+ ## Usage
6
+
7
+ Install using standard Vagrant 1.1+ plugin installation methods. After installing, you can specify the required plugin dependencies in your `Vagrantfile` like so:
8
+
9
+ ```ruby
10
+ Vagrant.configure("2") do |config|
11
+
12
+ # require the vagrant-omnibus plugin...
13
+ config.plugin.depend 'vagrant-omnibus', '1.0.2'
14
+
15
+ # ...because we use it here:
16
+ config.omnibus.chef_version = "11.4.4"
17
+
18
+ ...
19
+
20
+ end
21
+ ```
22
+
23
+ Assuming the [vagrant-omnibus](https://github.com/schisamo/vagrant-omnibus) plugin is not installed yet, `vagrant up` will now fail:
24
+ ```
25
+ $ vagrant up
26
+ Bringing machine 'foo' up with 'virtualbox' provider...
27
+ Version 1.0.2 of vagrant-omnibus required. No version found.
28
+
29
+ => run `vagrant plugin install vagrant-omnibus --plugin-version 1.0.2` to fix this
30
+ ```
31
+
32
+ Once you installed the missing plugin via `vagrant plugin install` and thus the required plugin dependencies are met...
33
+ ```
34
+ $ vagrant plugin install vagrant-omnibus --plugin-version 1.0.2
35
+ Installing the 'vagrant-omnibus --version '1.0.2'' plugin. This can take a few minutes...
36
+ Installed the plugin 'vagrant-omnibus (1.0.2)'!
37
+ ```
38
+
39
+ ...you can run `vagrant up` again and it will continue as usual:
40
+ ```
41
+ $ vagrant up
42
+ Bringing machine 'foo' up with 'virtualbox' provider...
43
+ [foo] Setting the name of the VM...
44
+ [foo] Clearing any previously set forwarded ports...
45
+ [foo] Fixed port collision for 22 => 2222. Now on port 2201.
46
+ [foo] Creating shared folders metadata...
47
+ [foo] Clearing any previously set network interfaces...
48
+ [foo] Preparing network interfaces based on configuration...
49
+ [foo] Forwarding ports...
50
+ [foo] -- 22 => 2201 (adapter 1)
51
+ [foo] Booting VM...
52
+ ...
53
+ ```
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'rspec/core/rake_task'
4
+
5
+ # Immediately sync all stdout so that tools like buildbot can
6
+ # immediately load in the output.
7
+ $stdout.sync = true
8
+ $stderr.sync = true
9
+
10
+ # Change to the directory of this file.
11
+ Dir.chdir(File.expand_path("../", __FILE__))
12
+
13
+ # This installs the tasks that help with gem creation and
14
+ # publishing.
15
+ Bundler::GemHelper.install_tasks
16
+
17
+ # Install the `spec` task so that we can run tests.
18
+ RSpec::Core::RakeTask.new
19
+
20
+ # Default task is to run the unit tests
21
+ task :default => "spec"
data/Vagrantfile ADDED
@@ -0,0 +1,24 @@
1
+ # -*- mode: ruby -*-
2
+ # vi: set ft=ruby :
3
+
4
+ # require plugin for testing via bundler
5
+ Vagrant.require_plugin "vagrant-plugin-bundler"
6
+ Vagrant.require_plugin "vagrant-omnibus"
7
+
8
+
9
+ Vagrant.configure("2") do |config|
10
+
11
+ config.plugin.depend 'vagrant-omnibus', '1.0.2'
12
+ # config.plugin.depend 'vagrant-omnibus'
13
+ # config.plugin.depend 'vagrant-foo', '1.0.2'
14
+
15
+ # we require vagrant-omnibus plugin!
16
+ config.omnibus.chef_version = "11.4.4"
17
+
18
+ # sample vm
19
+ config.vm.define :foo do |foo_config|
20
+ foo_config.vm.box = "opscode_ubuntu-13.04_provisionerless"
21
+ foo_config.vm.box_url = "https://opscode-vm.s3.amazonaws.com/vagrant/opscode_ubuntu-13.04_provisionerless.box"
22
+ end
23
+
24
+ end
@@ -0,0 +1,49 @@
1
+
2
+ module VagrantPlugins
3
+ module PluginBundler
4
+ module Action
5
+ # This middleware checks if reqiured plugins are present
6
+ class Check
7
+
8
+ def initialize(app, env)
9
+ @app = app
10
+ @installed_plugins = {}
11
+ end
12
+
13
+ def call(env)
14
+
15
+ # check plugins
16
+ #output = `D:/Repos/_github/bills-kitchen/target/build/tools/vagrant/HashiCorp/Vagrant/bin/vagrant plugin list`
17
+ output = `vagrant plugin list`
18
+
19
+ output.each_line do |line|
20
+ name, version = line.match(/\s*(\S+)\s*\((\S+)\)/).captures
21
+ @installed_plugins[name]=version
22
+ end
23
+
24
+ env[:machine].config.plugin.dependencies.each do |plugin, required_version|
25
+
26
+ installed_version = @installed_plugins[plugin]
27
+
28
+ unless installed_version
29
+ raise Errors::PluginNotFoundError,
30
+ :required_version => required_version,
31
+ :plugin => plugin
32
+ end
33
+
34
+ if required_version != installed_version
35
+ raise Errors::PluginVersionError,
36
+ :required_version => required_version,
37
+ :plugin => plugin,
38
+ :installed_version => installed_version
39
+ end
40
+ end
41
+
42
+ # continue if ok
43
+ @app.call(env)
44
+
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,12 @@
1
+ require "pathname"
2
+ require "vagrant/action/builder"
3
+
4
+ module VagrantPlugins
5
+ module PluginBundler
6
+ module Action
7
+ # The autoload farm
8
+ action_root = Pathname.new(File.expand_path("../action", __FILE__))
9
+ autoload :Check, action_root.join("check")
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,22 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module PluginBundler
5
+ class Config < Vagrant.plugin("2", :config)
6
+
7
+ attr_reader :dependencies
8
+
9
+ def initialize()
10
+ @dependencies = {}
11
+ end
12
+
13
+ def depend(name, version)
14
+ if @dependencies[name]
15
+ # raise early here because our hook has to run BEFORE validation
16
+ raise Errors::DuplicatePluginDefinitionError, :plugin => name
17
+ end
18
+ @dependencies[name] = version
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,23 @@
1
+ require "vagrant"
2
+
3
+ module VagrantPlugins
4
+ module PluginBundler
5
+ module Errors
6
+ class VagrantPluginBundlerError < Vagrant::Errors::VagrantError
7
+ error_namespace("vagrant_plugin_bundler.errors")
8
+ end
9
+
10
+ class PluginNotFoundError < VagrantPluginBundlerError
11
+ error_key(:plugin_not_found)
12
+ end
13
+
14
+ class DuplicatePluginDefinitionError < VagrantPluginBundlerError
15
+ error_key(:duplicate_plugin_definition)
16
+ end
17
+
18
+ class PluginVersionError < VagrantPluginBundlerError
19
+ error_key(:plugin_version_error)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ begin
2
+ require "vagrant"
3
+ rescue LoadError
4
+ raise "The Vagrant PluginBundler plugin must be run within Vagrant."
5
+ end
6
+
7
+ # This is a sanity check to make sure no one is attempting to install
8
+ # this into an early Vagrant version.
9
+ if Vagrant::VERSION < "1.2.0"
10
+ raise "The Vagrant PluginBundler plugin is only compatible with Vagrant 1.2+"
11
+ end
12
+
13
+ module VagrantPlugins
14
+ module PluginBundler
15
+ class Plugin < Vagrant.plugin("2")
16
+ name "PluginBundler"
17
+ description <<-DESC
18
+ This plugin checks a list of requirements against the installed plugins.
19
+ DESC
20
+
21
+ config "plugin" do
22
+ setup_i18n
23
+
24
+ require_relative "config"
25
+ Config
26
+ end
27
+
28
+ # This initializes the internationalization strings.
29
+ def self.setup_i18n
30
+ I18n.load_path << File.expand_path("locales/en.yml", PluginBundler.source_root)
31
+ I18n.reload!
32
+ end
33
+
34
+ check_action_hook = lambda do |hook|
35
+ require_relative 'action/check'
36
+ hook.before Vagrant::Action::Builtin::ConfigValidate, VagrantPlugins::PluginBundler::Action::Check
37
+ end
38
+ action_hook 'check-plugin-dependencies-on-machine-up', :machine_action_up, &check_action_hook
39
+ action_hook 'check-plugin-dependencies-on-machine-reload', :machine_action_reload, &check_action_hook
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ module VagrantPlugins
2
+ module PluginBundler
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ require "pathname"
2
+
3
+ require "vagrant-plugin-bundler/plugin"
4
+
5
+ module VagrantPlugins
6
+ module PluginBundler
7
+ lib_path = Pathname.new(File.expand_path("../vagrant-plugin-bundler", __FILE__))
8
+ autoload :Action, lib_path.join("action")
9
+ autoload :Errors, lib_path.join("errors")
10
+
11
+ # This returns the path to the source of this plugin.
12
+ #
13
+ # @return [Pathname]
14
+ def self.source_root
15
+ @source_root ||= Pathname.new(File.expand_path("../../", __FILE__))
16
+ end
17
+ end
18
+ end
data/locales/en.yml ADDED
@@ -0,0 +1,13 @@
1
+ en:
2
+ vagrant_plugin_bundler:
3
+ errors:
4
+ plugin_not_found: |-
5
+ Version %{required_version} of %{plugin} required. No version found.
6
+
7
+ => run `vagrant plugin install %{plugin} --plugin-version %{required_version}` to fix this
8
+ plugin_version_error: |-
9
+ Version %{required_version} of %{plugin} required. Found %{installed_version}.
10
+
11
+ => run `vagrant plugin install %{plugin} --plugin-version %{required_version}` to fix this
12
+ duplicate_plugin_definition: |-
13
+ Duplicate plugin definition for %{plugin}.
@@ -0,0 +1,61 @@
1
+
2
+ require "vagrant-plugin-bundler/config"
3
+ require "vagrant-plugin-bundler/errors"
4
+
5
+ describe VagrantPlugins::PluginBundler::Config do
6
+ let(:config) { described_class.new }
7
+
8
+ # Ensure tests are not affected by AWS credential environment variables
9
+ before :each do
10
+ ENV.stub(:[] => nil)
11
+ end
12
+
13
+ describe "config.dependencies" do
14
+
15
+ context "when nothing specified" do
16
+ before do
17
+ config.finalize!
18
+ end
19
+ it "should be empty" do
20
+ config.dependencies.should be_empty
21
+ end
22
+ end
23
+
24
+ context "when single plugin specified" do
25
+ before do
26
+ config.depend 'foo', '1.0.0'
27
+ config.finalize!
28
+ end
29
+ it "should contain exactly one plugin" do
30
+ config.dependencies.size.should == 1
31
+ end
32
+ it "should contain the specified plugin" do
33
+ config.dependencies.should == { 'foo' => '1.0.0' }
34
+ end
35
+ end
36
+
37
+ context "when multiple plugins specified" do
38
+ context "with all different plugins" do
39
+ before do
40
+ config.depend 'foo', '1.0.0'
41
+ config.depend 'bar', '1.1.0'
42
+ config.finalize!
43
+ end
44
+ it "should contain all specified plugins" do
45
+ config.dependencies.should == { 'foo' => '1.0.0', 'bar' => '1.1.0' }
46
+ end
47
+ end
48
+ context "with same plugin twice" do
49
+ it "should fail" do
50
+ begin
51
+ config.depend 'foo', '1.0.0'
52
+ config.depend 'foo', '1.1.0'
53
+ fail "it should have raised 'DuplicatePluginDefinitionError'"
54
+ rescue VagrantPlugins::PluginBundler::Errors::DuplicatePluginDefinitionError
55
+ # expected
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+ require "vagrant-plugin-bundler/version"
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = "vagrant-plugin-bundler"
6
+ s.version = VagrantPlugins::PluginBundler::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.authors = "Torben Knerr"
9
+ s.email = "mail@tknerr.de"
10
+ s.homepage = "https://github.com/tknerr/vagrant-plugin-bundler"
11
+ s.summary = "This plugin checks a list of requirements against the installed plugins."
12
+ s.description = "This plugin checks a list of requirements against the installed plugins."
13
+
14
+ s.required_rubygems_version = ">= 1.3.6"
15
+ s.rubyforge_project = "vagrant-plugin-bundler"
16
+
17
+ s.add_development_dependency "rake"
18
+ s.add_development_dependency "rspec-core", "~> 2.12.2"
19
+ s.add_development_dependency "rspec-expectations", "~> 2.12.1"
20
+ s.add_development_dependency "rspec-mocks", "~> 2.12.1"
21
+
22
+ # The following block of code determines the files that should be included
23
+ # in the gem. It does this by reading all the files in the directory where
24
+ # this gemspec is, and parsing out the ignored files from the gitignore.
25
+ # Note that the entire gitignore(5) syntax is not supported, specifically
26
+ # the "!" syntax, but it should mostly work correctly.
27
+ root_path = File.dirname(__FILE__)
28
+ all_files = Dir.chdir(root_path) { Dir.glob("**/{*,.*}") }
29
+ all_files.reject! { |file| [".", ".."].include?(File.basename(file)) }
30
+ gitignore_path = File.join(root_path, ".gitignore")
31
+ gitignore = File.readlines(gitignore_path)
32
+ gitignore.map! { |line| line.chomp.strip }
33
+ gitignore.reject! { |line| line.empty? || line =~ /^(#|!)/ }
34
+
35
+ unignored_files = all_files.reject do |file|
36
+ # Ignore any directories, the gemspec only cares about files
37
+ next true if File.directory?(file)
38
+
39
+ # Ignore any paths that match anything in the gitignore. We do
40
+ # two tests here:
41
+ #
42
+ # - First, test to see if the entire path matches the gitignore.
43
+ # - Second, match if the basename does, this makes it so that things
44
+ # like '.DS_Store' will match sub-directories too (same behavior
45
+ # as git).
46
+ #
47
+ gitignore.any? do |ignore|
48
+ File.fnmatch(ignore, file, File::FNM_PATHNAME) ||
49
+ File.fnmatch(ignore, File.basename(file), File::FNM_PATHNAME)
50
+ end
51
+ end
52
+
53
+ s.files = unignored_files
54
+ s.executables = unignored_files.map { |f| f[/^bin\/(.*)/, 1] }.compact
55
+ s.require_path = 'lib'
56
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vagrant-plugin-bundler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Torben Knerr
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: &28762380 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *28762380
25
+ - !ruby/object:Gem::Dependency
26
+ name: rspec-core
27
+ requirement: &28761888 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 2.12.2
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *28761888
36
+ - !ruby/object:Gem::Dependency
37
+ name: rspec-expectations
38
+ requirement: &28761588 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 2.12.1
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *28761588
47
+ - !ruby/object:Gem::Dependency
48
+ name: rspec-mocks
49
+ requirement: &28761312 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.12.1
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *28761312
58
+ description: This plugin checks a list of requirements against the installed plugins.
59
+ email: mail@tknerr.de
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CHANGELOG.md
65
+ - Gemfile
66
+ - lib/vagrant-plugin-bundler/action/check.rb
67
+ - lib/vagrant-plugin-bundler/action.rb
68
+ - lib/vagrant-plugin-bundler/config.rb
69
+ - lib/vagrant-plugin-bundler/errors.rb
70
+ - lib/vagrant-plugin-bundler/plugin.rb
71
+ - lib/vagrant-plugin-bundler/version.rb
72
+ - lib/vagrant-plugin-bundler.rb
73
+ - LICENSE
74
+ - locales/en.yml
75
+ - Rakefile
76
+ - README.md
77
+ - spec/vagrant-plugin-bundler/config_spec.rb
78
+ - vagrant-plugin-bundler.gemspec
79
+ - Vagrantfile
80
+ - .gitignore
81
+ - .rspec
82
+ homepage: https://github.com/tknerr/vagrant-plugin-bundler
83
+ licenses: []
84
+ post_install_message:
85
+ rdoc_options: []
86
+ require_paths:
87
+ - lib
88
+ required_ruby_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 712217213
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: 1.3.6
103
+ requirements: []
104
+ rubyforge_project: vagrant-plugin-bundler
105
+ rubygems_version: 1.8.16
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: This plugin checks a list of requirements against the installed plugins.
109
+ test_files: []