List actually compares state with gems
This commit is contained in:
parent
8ac7b62075
commit
f257d1211f
|
@ -1,18 +1,36 @@
|
||||||
require "rubygems"
|
require "rubygems"
|
||||||
|
require "set"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module CommandPlugin
|
module CommandPlugin
|
||||||
module Action
|
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
|
class ListPlugins
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
end
|
end
|
||||||
|
|
||||||
def call(env)
|
def call(env)
|
||||||
env[:gem_helper].with_environment do
|
# Get the list of installed plugins according to the state file
|
||||||
specs = Gem::Specification.find_all
|
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
|
env[:ui].info spec.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -55,7 +55,7 @@ module VagrantPlugins
|
||||||
# Clear paths so that it reads the new GEM_HOME setting
|
# Clear paths so that it reads the new GEM_HOME setting
|
||||||
Gem.clear_paths
|
Gem.clear_paths
|
||||||
|
|
||||||
yield
|
return yield
|
||||||
ensure
|
ensure
|
||||||
# Restore the old GEM_HOME
|
# Restore the old GEM_HOME
|
||||||
ENV["GEM_HOME"] = old_gem_home
|
ENV["GEM_HOME"] = old_gem_home
|
||||||
|
|
|
@ -21,6 +21,16 @@ module VagrantPlugins
|
||||||
save!
|
save!
|
||||||
end
|
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<String>]
|
||||||
|
def installed_plugins
|
||||||
|
@data["installed"] ||= []
|
||||||
|
@data["installed"]
|
||||||
|
end
|
||||||
|
|
||||||
# This saves the state back into the state file.
|
# This saves the state back into the state file.
|
||||||
def save!
|
def save!
|
||||||
@path.open("w+") do |f|
|
@path.open("w+") do |f|
|
||||||
|
|
Loading…
Reference in New Issue