From 096c8b284f6cca38996d4732ceda92fb72d663aa Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 2 Jul 2011 09:27:28 -0700 Subject: [PATCH] Do not load a plugin if it depends on invalid version of Vagrant --- CHANGELOG.md | 1 + lib/vagrant/plugin.rb | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d107a699..92b97d15d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ - Touch the network configuration file for RedHat so that the `sed` works with host only networking. [GH-381] - Load prerelease versions of plugins if available. + - Do not load a plugin if it depends on an invalid version of Vagrant. ## 0.7.5 (May 16, 2011) diff --git a/lib/vagrant/plugin.rb b/lib/vagrant/plugin.rb index 600ba50b1..79f597016 100644 --- a/lib/vagrant/plugin.rb +++ b/lib/vagrant/plugin.rb @@ -21,6 +21,9 @@ module Vagrant # load path. This file is loaded to kick off the load sequence # for that plugin. def self.load! + # Our version is used for checking dependencies + our_version = Gem::Version.create(Vagrant::VERSION) + # RubyGems 1.8.0 deprecated `source_index`. Gem::Specification is the # new replacement. For now, we support both, but special-case 1.8.x # so that we avoid deprecation messages. @@ -38,6 +41,12 @@ module Vagrant specs = Gem::VERSION >= "1.6.0" ? source.latest_specs(true) : source.latest_specs specs.each do |spec| + # If this gem depends on Vagrant, verify this is a valid release of + # Vagrant for this gem to load into. + vagrant_dep = spec.dependencies.find { |d| d.name == "vagrant" } + next if vagrant_dep && !vagrant_dep.requirement.satisfied_by?(our_version) + + # Find a vagrant_init.rb to verify if this is a plugin file = nil if Gem::VERSION >= "1.8.0" file = spec.matches_for_glob("**/vagrant_init.rb").first