From 5fe29940054184d74f7195e093cd3069a7067c06 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sun, 5 Jan 2014 20:50:25 -0800 Subject: [PATCH] commands/plugin: convert all actions to use the new classes --- lib/vagrant/plugin/manager.rb | 2 +- plugins/commands/plugin/action.rb | 1 + .../commands/plugin/action/license_plugin.rb | 9 ------ .../commands/plugin/action/list_plugins.rb | 28 ++++--------------- .../plugin/action/plugin_exists_check.rb | 7 ++--- plugins/commands/plugin/command/base.rb | 5 ---- plugins/commands/plugin/plugin.rb | 1 - 7 files changed, 11 insertions(+), 42 deletions(-) diff --git a/lib/vagrant/plugin/manager.rb b/lib/vagrant/plugin/manager.rb index 21672cc1d..b58e2ffd7 100644 --- a/lib/vagrant/plugin/manager.rb +++ b/lib/vagrant/plugin/manager.rb @@ -63,7 +63,7 @@ module Vagrant # This returns the list of plugins that should be enabled. # - # @return [Array] + # @return [Hash] def installed_plugins @global_file.installed_plugins end diff --git a/plugins/commands/plugin/action.rb b/plugins/commands/plugin/action.rb index 04cfa5c9c..89b58e0c2 100644 --- a/plugins/commands/plugin/action.rb +++ b/plugins/commands/plugin/action.rb @@ -15,6 +15,7 @@ module VagrantPlugins # This middleware sequence licenses paid addons. def self.action_license Vagrant::Action::Builder.new.tap do |b| + b.use PluginExistsCheck b.use LicensePlugin end end diff --git a/plugins/commands/plugin/action/license_plugin.rb b/plugins/commands/plugin/action/license_plugin.rb index 518c1824c..f4566c94c 100644 --- a/plugins/commands/plugin/action/license_plugin.rb +++ b/plugins/commands/plugin/action/license_plugin.rb @@ -17,15 +17,6 @@ module VagrantPlugins end def call(env) - # Get the list of installed plugins according to the state file - installed = env[:plugin_state_file].installed_plugins.keys - - # If the plugin we're trying to license doesn't exist in the - # state file, then it is an error. - if !installed.include?(env[:plugin_name]) - raise Vagrant::Errors::PluginNotFound, :name => env[:plugin_name] - end - # Verify the license file exists license_file = Pathname.new(env[:plugin_license_path]) if !license_file.file? diff --git a/plugins/commands/plugin/action/list_plugins.rb b/plugins/commands/plugin/action/list_plugins.rb index 8c173e6b3..76ad5a561 100644 --- a/plugins/commands/plugin/action/list_plugins.rb +++ b/plugins/commands/plugin/action/list_plugins.rb @@ -16,31 +16,15 @@ module VagrantPlugins end def call(env) - # Get the list of installed plugins according to the state file - installed = env[:plugin_state_file].installed_plugins.keys - - # Go through the plugins installed in this environment and - # get the latest version of each. - installed_map = {} - Vagrant::Plugin::Manager.instance.installed_specs.each do |spec| - # Ignore specs that aren't in our installed list - next if !installed.include?(spec.name) - - # If we already have a newer version in our list of installed, - # then ignore it - next if installed_map.has_key?(spec.name) && - installed_map[spec.name].version >= spec.version - - installed_map[spec.name] = spec - end + specs = Vagrant::Plugin::Manager.instance.installed_specs # Output! - if installed_map.empty? + if specs.empty? env[:ui].info(I18n.t("vagrant.commands.plugin.no_plugins")) - else - installed_map.values.each do |spec| - env[:ui].info "#{spec.name} (#{spec.version})" - end + end + + specs.each do |spec| + env[:ui].info "#{spec.name} (#{spec.version})" end @app.call(env) diff --git a/plugins/commands/plugin/action/plugin_exists_check.rb b/plugins/commands/plugin/action/plugin_exists_check.rb index abe8d43cf..6616abf0e 100644 --- a/plugins/commands/plugin/action/plugin_exists_check.rb +++ b/plugins/commands/plugin/action/plugin_exists_check.rb @@ -1,4 +1,4 @@ -require "set" +require "vagrant/plugin/manager" module VagrantPlugins module CommandPlugin @@ -11,9 +11,8 @@ module VagrantPlugins end def call(env) - # Get the list of installed plugins according to the state file - installed = env[:plugin_state_file].installed_plugins.keys - if !installed.include?(env[:plugin_name]) + installed = Vagrant::Plugin::Manager.instance.installed_specs + if !installed.has_key?(env[:plugin_name]) raise Vagrant::Errors::PluginNotInstalled, name: env[:plugin_name] end diff --git a/plugins/commands/plugin/command/base.rb b/plugins/commands/plugin/command/base.rb index 770d71697..5cf522fd2 100644 --- a/plugins/commands/plugin/command/base.rb +++ b/plugins/commands/plugin/command/base.rb @@ -11,11 +11,6 @@ module VagrantPlugins # @param [Object] callable the Middleware callable # @param [Hash] env Extra environment hash that is merged in. def action(callable, env=nil) - env = { - :gem_helper => GemHelper.new(@env.gems_path), - :plugin_state_file => Vagrant::Plugin::StateFile.new(@env.home_path.join("plugins.json")) - }.merge(env || {}) - @env.action_runner.run(callable, env) end end diff --git a/plugins/commands/plugin/plugin.rb b/plugins/commands/plugin/plugin.rb index a738d01f1..0fd05973b 100644 --- a/plugins/commands/plugin/plugin.rb +++ b/plugins/commands/plugin/plugin.rb @@ -16,6 +16,5 @@ DESC end autoload :Action, File.expand_path("../action", __FILE__) - autoload :GemHelper, File.expand_path("../gem_helper", __FILE__) end end