commands/plugin: list uses PluginManager
This commit is contained in:
parent
279b171339
commit
1eef75a715
|
@ -19,7 +19,7 @@ if Vagrant.plugins_enabled?
|
|||
# Initialize Bundler before we load _any_ RubyGems.
|
||||
require_relative "vagrant/bundler"
|
||||
require_relative "vagrant/plugin_manager"
|
||||
Vagrant::Bundler.instance.init!(Vagrant::PluginManager.plugins)
|
||||
Vagrant::Bundler.instance.init!(Vagrant::Plugin::Manager.instance.installed_plugins)
|
||||
end
|
||||
|
||||
# Initialize Vagrant now that our Gem paths are setup
|
||||
|
|
|
@ -2,6 +2,7 @@ module Vagrant
|
|||
module Plugin
|
||||
autoload :V1, "vagrant/plugin/v1"
|
||||
autoload :V2, "vagrant/plugin/v2"
|
||||
autoload :Manager, "vagrant/plugin/manager"
|
||||
autoload :StateFile, "vagrant/plugin/state_file"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
require_relative "../shared_helpers"
|
||||
|
||||
module Vagrant
|
||||
module Plugin
|
||||
# The Manager helps with installing, listing, and initializing plugins.
|
||||
class Manager
|
||||
# Returns the path to the [StateFile] for global plugins.
|
||||
#
|
||||
# @return [Pathname]
|
||||
def self.global_plugins_file
|
||||
Vagrant.user_data_path.join("plugins.json")
|
||||
end
|
||||
|
||||
def self.instance
|
||||
@instance ||= self.new(global_plugins_file)
|
||||
end
|
||||
|
||||
# @param [Pathname] global_file
|
||||
def initialize(global_file)
|
||||
@global_file = StateFile.new(global_file)
|
||||
end
|
||||
|
||||
# This returns the list of plugins that should be enabled.
|
||||
#
|
||||
# @return [Array<String>]
|
||||
def installed_plugins
|
||||
@global_file.installed_plugins.keys
|
||||
end
|
||||
|
||||
# This returns the list of plugins that are installed as
|
||||
# Gem::Specifications.
|
||||
#
|
||||
# @return [Array<Gem::Specification>]
|
||||
def installed_specs
|
||||
::Bundler.load.specs
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,16 +0,0 @@
|
|||
require "json"
|
||||
|
||||
require_relative "shared_helpers"
|
||||
|
||||
module Vagrant
|
||||
class PluginManager
|
||||
def self.global_plugins_file
|
||||
Vagrant.user_data_path.join("plugins.json")
|
||||
end
|
||||
|
||||
def self.plugins
|
||||
plugins = JSON.parse(global_plugins_file.read)
|
||||
plugins["installed"].keys
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,3 +1,5 @@
|
|||
require "vagrant/plugin/manager"
|
||||
|
||||
module VagrantPlugins
|
||||
module CommandPlugin
|
||||
module Action
|
||||
|
@ -20,7 +22,7 @@ module VagrantPlugins
|
|||
# Go through the plugins installed in this environment and
|
||||
# get the latest version of each.
|
||||
installed_map = {}
|
||||
Bundler.load.specs.each do |spec|
|
||||
Vagrant::Plugin::Manager.instance.installed_specs.each do |spec|
|
||||
# Ignore specs that aren't in our installed list
|
||||
next if !installed.include?(spec.name)
|
||||
|
||||
|
|
|
@ -0,0 +1,56 @@
|
|||
require "json"
|
||||
require "pathname"
|
||||
|
||||
require "vagrant/plugin"
|
||||
require "vagrant/plugin/manager"
|
||||
require "vagrant/plugin/state_file"
|
||||
|
||||
require File.expand_path("../../../base", __FILE__)
|
||||
|
||||
describe Vagrant::Plugin::Manager do
|
||||
let(:path) do
|
||||
f = Tempfile.new("vagrant")
|
||||
p = f.path
|
||||
f.close
|
||||
f.unlink
|
||||
Pathname.new(p)
|
||||
end
|
||||
|
||||
after do
|
||||
path.unlink if path.file?
|
||||
end
|
||||
|
||||
subject { described_class.new(path) }
|
||||
|
||||
context "without state" do
|
||||
describe "#installed_plugins" do
|
||||
it "is empty initially" do
|
||||
expect(subject.installed_plugins).to be_empty
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
context "with state" do
|
||||
before do
|
||||
sf = Vagrant::Plugin::StateFile.new(path)
|
||||
sf.add_plugin("foo")
|
||||
end
|
||||
|
||||
describe "#installed_plugins" do
|
||||
it "has the plugins" do
|
||||
expect(subject.installed_plugins).to eql(["foo"])
|
||||
end
|
||||
end
|
||||
|
||||
describe "#installed_specs" do
|
||||
it "has the plugins" do
|
||||
runtime = double("runtime")
|
||||
runtime.stub(specs: ["foo"])
|
||||
::Bundler.stub(:load => runtime)
|
||||
|
||||
expect(subject.installed_specs).to eql(["foo"])
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue