From 06e1b2f52c4170f048c529d155d304d9ded3da33 Mon Sep 17 00:00:00 2001 From: Chris Roberts Date: Wed, 16 Nov 2016 13:19:43 -0800 Subject: [PATCH] Include installed gem version plugin information. Clean after install and update. --- lib/vagrant/plugin/manager.rb | 24 ++++++++++++++++++++++-- lib/vagrant/plugin/state_file.rb | 11 ++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb index 72b291a3e..4f875fd6f 100644 --- a/lib/vagrant/plugin/manager.rb +++ b/lib/vagrant/plugin/manager.rb @@ -80,9 +80,13 @@ module Vagrant version: opts[:version], require: opts[:require], sources: opts[:sources], - installed_gem_version: result.version + installed_gem_version: result.version.to_s ) + # After install clean plugin gems to remove any cruft. This is useful + # for removing outdated dependencies or other versions of an installed + # plugin if the plugin is upgraded/downgraded + Vagrant::Bundler.instance.clean(installed_plugins) result rescue Gem::GemNotFoundException raise Errors::PluginGemNotFound, name: name @@ -111,7 +115,23 @@ module Vagrant # Updates all or a specific set of plugins. def update_plugins(specific) - Vagrant::Bundler.instance.update(installed_plugins, specific) + result = Vagrant::Bundler.instance.update(installed_plugins, specific) + installed_plugins.each do |name, info| + matching_spec = result.detect{|s| s.name == name} + info = Hash[ + info.map do |key, value| + [key.to_sym, value] + end + ] + if matching_spec + @user_file.add_plugin(name, **info.merge( + version: "> 0", + installed_gem_version: matching_spec.version.to_s + )) + end + end + Vagrant::Bundler.instance.clean(installed_plugins) + result rescue Gem::Exception => e raise Errors::BundlerError, message: e.to_s end diff --git a/lib/vagrant/plugin/state_file.rb b/lib/vagrant/plugin/state_file.rb index c80ee658c..85db50b92 100644 --- a/lib/vagrant/plugin/state_file.rb +++ b/lib/vagrant/plugin/state_file.rb @@ -31,11 +31,12 @@ module Vagrant # @param [String] name The name of the plugin def add_plugin(name, **opts) @data["installed"][name] = { - "ruby_version" => RUBY_VERSION, - "vagrant_version" => Vagrant::VERSION, - "gem_version" => opts[:version] || "", - "require" => opts[:require] || "", - "sources" => opts[:sources] || [], + "ruby_version" => RUBY_VERSION, + "vagrant_version" => Vagrant::VERSION, + "gem_version" => opts[:version] || "", + "require" => opts[:require] || "", + "sources" => opts[:sources] || [], + "installed_gem_version" => opts[:installed_gem_version] } save!