diff --git a/plugins/commands/plugin/action/list_plugins.rb b/plugins/commands/plugin/action/list_plugins.rb index 515d39a4c..5123ff0a0 100644 --- a/plugins/commands/plugin/action/list_plugins.rb +++ b/plugins/commands/plugin/action/list_plugins.rb @@ -1,18 +1,36 @@ require "rubygems" +require "set" module VagrantPlugins module CommandPlugin module Action + # This middleware lists all the installed plugins. + # + # This is a bit more complicated than simply listing installed + # gems or what is in the state file as installed. Instead, this + # actually compares installed gems with what the state file claims + # is installed, and outputs the appropriate truly installed + # plugins. class ListPlugins def initialize(app, env) @app = app end def call(env) - env[:gem_helper].with_environment do - specs = Gem::Specification.find_all + # Get the list of installed plugins according to the state file + installed = Set.new(env[:plugin_state_file].installed_plugins) - specs.each do |spec| + # Get the actual specifications of installed gems + specs = env[:gem_helper].with_environment do + Gem::Specification.find_all + end + + # Go through each spec and if it is an installed plugin, then + # output it. This means that both the installed state and + # gem match up. + specs.each do |spec| + if installed.include?(spec.name) + # TODO: Formatting env[:ui].info spec.name end end diff --git a/plugins/commands/plugin/gem_helper.rb b/plugins/commands/plugin/gem_helper.rb index 0ce73efab..ff1eec780 100644 --- a/plugins/commands/plugin/gem_helper.rb +++ b/plugins/commands/plugin/gem_helper.rb @@ -55,7 +55,7 @@ module VagrantPlugins # Clear paths so that it reads the new GEM_HOME setting Gem.clear_paths - yield + return yield ensure # Restore the old GEM_HOME ENV["GEM_HOME"] = old_gem_home diff --git a/plugins/commands/plugin/state_file.rb b/plugins/commands/plugin/state_file.rb index 5282ee480..ce045507f 100644 --- a/plugins/commands/plugin/state_file.rb +++ b/plugins/commands/plugin/state_file.rb @@ -21,6 +21,16 @@ module VagrantPlugins save! end + # This returns a list of installed plugins according to the state + # file. Note that this may _not_ directly match over to actually + # installed gems. + # + # @return [Array] + def installed_plugins + @data["installed"] ||= [] + @data["installed"] + end + # This saves the state back into the state file. def save! @path.open("w+") do |f|