2013-02-03 07:52:34 +00:00
|
|
|
require "rubygems"
|
2013-02-03 07:59:48 +00:00
|
|
|
require "set"
|
2013-02-03 07:52:34 +00:00
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module CommandPlugin
|
|
|
|
module Action
|
2013-02-03 07:59:48 +00:00
|
|
|
# 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.
|
2013-02-03 07:52:34 +00:00
|
|
|
class ListPlugins
|
|
|
|
def initialize(app, env)
|
|
|
|
@app = app
|
|
|
|
end
|
|
|
|
|
|
|
|
def call(env)
|
2013-02-03 07:59:48 +00:00
|
|
|
# Get the list of installed plugins according to the state file
|
|
|
|
installed = Set.new(env[:plugin_state_file].installed_plugins)
|
2013-02-03 07:52:34 +00:00
|
|
|
|
2013-03-01 20:14:12 +00:00
|
|
|
# Go through the plugins installed in this environment and
|
|
|
|
# get the latest version of each.
|
2013-02-03 20:59:32 +00:00
|
|
|
installed_map = {}
|
2013-03-01 20:14:12 +00:00
|
|
|
env[:gem_helper].with_environment do
|
|
|
|
Gem::Specification.find_all.each do |spec|
|
|
|
|
# Ignore specs that aren't in our installed list
|
|
|
|
next if !installed.include?(spec.name)
|
2013-02-03 20:59:32 +00:00
|
|
|
|
2013-03-01 20:14:12 +00:00
|
|
|
# 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
|
2013-02-03 20:59:32 +00:00
|
|
|
|
2013-03-01 20:14:12 +00:00
|
|
|
installed_map[spec.name] = spec
|
|
|
|
end
|
2013-02-03 20:59:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Output!
|
2013-02-03 21:13:22 +00:00
|
|
|
if installed_map.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
|
2013-02-03 07:52:34 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
@app.call(env)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|