core: load system plugins if they are installed
This commit is contained in:
parent
616bf15df5
commit
7710fd16fa
|
@ -125,14 +125,6 @@ module Vagrant
|
|||
c.register([:"2", :synced_folder]) { Plugin::V2::SyncedFolder }
|
||||
end
|
||||
|
||||
# This returns a true/false showing whether we're running from the
|
||||
# environment setup by the Vagrant installers.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def self.in_installer?
|
||||
!!ENV["VAGRANT_INSTALLER_ENV"]
|
||||
end
|
||||
|
||||
# Configure a Vagrant environment. The version specifies the version
|
||||
# of the configuration that is expected by the block. The block, based
|
||||
# on that version, configures the environment.
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
require "pathname"
|
||||
require "set"
|
||||
|
||||
require_relative "../bundler"
|
||||
|
@ -8,20 +9,31 @@ module Vagrant
|
|||
module Plugin
|
||||
# The Manager helps with installing, listing, and initializing plugins.
|
||||
class Manager
|
||||
# Returns the path to the [StateFile] for global plugins.
|
||||
# Returns the path to the [StateFile] for user plugins.
|
||||
#
|
||||
# @return [Pathname]
|
||||
def self.global_plugins_file
|
||||
def self.user_plugins_file
|
||||
Vagrant.user_data_path.join("plugins.json")
|
||||
end
|
||||
|
||||
def self.instance
|
||||
@instance ||= self.new(global_plugins_file)
|
||||
# Returns the path to the [StateFile] for system plugins.
|
||||
def self.system_plugins_file
|
||||
dir = Vagrant.installer_embedded_dir
|
||||
return nil if !dir
|
||||
Pathname.new(dir).join("plugins.json")
|
||||
end
|
||||
|
||||
# @param [Pathname] global_file
|
||||
def initialize(global_file)
|
||||
@global_file = StateFile.new(global_file)
|
||||
def self.instance
|
||||
@instance ||= self.new(user_plugins_file)
|
||||
end
|
||||
|
||||
# @param [Pathname] user_file
|
||||
def initialize(user_file)
|
||||
@user_file = StateFile.new(user_file)
|
||||
|
||||
system_path = self.class.system_plugins_file
|
||||
@system_file = nil
|
||||
@system_file = StateFile.new(system_path) if system_path && system_path.file?
|
||||
end
|
||||
|
||||
# Installs another plugin into our gem directory.
|
||||
|
@ -65,7 +77,7 @@ module Vagrant
|
|||
opts.delete(:version) if opts[:version] && opts[:version] =~ /^\d/
|
||||
|
||||
# Add the plugin to the state file
|
||||
@global_file.add_plugin(
|
||||
@user_file.add_plugin(
|
||||
result.name,
|
||||
version: opts[:version],
|
||||
require: opts[:require],
|
||||
|
@ -83,7 +95,7 @@ module Vagrant
|
|||
#
|
||||
# @param [String] name
|
||||
def uninstall_plugin(name)
|
||||
@global_file.remove_plugin(name)
|
||||
@user_file.remove_plugin(name)
|
||||
|
||||
# Clean the environment, removing any old plugins
|
||||
Vagrant::Bundler.instance.clean(installed_plugins)
|
||||
|
@ -102,7 +114,8 @@ module Vagrant
|
|||
#
|
||||
# @return [Hash]
|
||||
def installed_plugins
|
||||
@global_file.installed_plugins
|
||||
system = @system_file ? @system_file.installed_plugins : {}
|
||||
system.merge(@user_file.installed_plugins)
|
||||
end
|
||||
|
||||
# This returns the list of plugins that are installed as
|
||||
|
|
|
@ -57,6 +57,13 @@ module Vagrant
|
|||
@data["installed"]
|
||||
end
|
||||
|
||||
# Returns true/false if the plugin is present in this state file.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def has_plugin?(name)
|
||||
@data["installed"].has_key?(name)
|
||||
end
|
||||
|
||||
# Remove a plugin that is installed from the state file.
|
||||
#
|
||||
# @param [String] name The name of the plugin.
|
||||
|
|
|
@ -8,6 +8,14 @@ module Vagrant
|
|||
# @return [String]
|
||||
DEFAULT_SERVER_URL = "https://www.vagrantcloud.com"
|
||||
|
||||
# This returns a true/false showing whether we're running from the
|
||||
# environment setup by the Vagrant installers.
|
||||
#
|
||||
# @return [Boolean]
|
||||
def self.in_installer?
|
||||
!!ENV["VAGRANT_INSTALLER_ENV"]
|
||||
end
|
||||
|
||||
# Returns the path to the embedded directory of the Vagrant installer,
|
||||
# if there is one (if we're running in an installer).
|
||||
#
|
||||
|
|
|
@ -38,6 +38,12 @@ describe Vagrant::Plugin::StateFile do
|
|||
})
|
||||
end
|
||||
|
||||
it "should check for plugins" do
|
||||
expect(subject.has_plugin?("foo")).to be_false
|
||||
subject.add_plugin("foo")
|
||||
expect(subject.has_plugin?("foo")).to be_true
|
||||
end
|
||||
|
||||
it "should remove plugins" do
|
||||
subject.add_plugin("foo")
|
||||
subject.remove_plugin("foo")
|
||||
|
|
|
@ -8,6 +8,20 @@ describe Vagrant do
|
|||
|
||||
subject { described_class }
|
||||
|
||||
describe "#in_installer?" do
|
||||
it "is not if env is not set" do
|
||||
with_temp_env("VAGRANT_INSTALLER_ENV" => nil) do
|
||||
expect(subject.in_installer?).to be_false
|
||||
end
|
||||
end
|
||||
|
||||
it "is if env is set" do
|
||||
with_temp_env("VAGRANT_INSTALLER_ENV" => "/foo") do
|
||||
expect(subject.in_installer?).to be_true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#installer_embedded_dir" do
|
||||
it "returns nil if not in an installer" do
|
||||
Vagrant.stub(in_installer?: false)
|
||||
|
|
Loading…
Reference in New Issue