commands/plugin: install version and entrypoints work
This commit is contained in:
parent
9dc1307b7c
commit
8904319beb
|
@ -97,9 +97,19 @@ module Vagrant
|
|||
gemfile.puts(%Q[source "http://gems.hashicorp.com"])
|
||||
gemfile.puts(%Q[gem "vagrant", "= #{Vagrant::VERSION}"])
|
||||
gemfile.puts("group :plugins do")
|
||||
plugins.each do |plugin|
|
||||
gemfile.puts(%Q[gem "#{plugin}"])
|
||||
|
||||
plugins.each do |name, plugin|
|
||||
version = plugin["gem_version"]
|
||||
version = nil if version == ""
|
||||
|
||||
opts = {}
|
||||
if plugin["require"] && plugin["require"] != ""
|
||||
opts[:require] = plugin["require"]
|
||||
end
|
||||
|
||||
gemfile.puts(%Q[gem "#{name}", #{version.inspect}, #{opts.inspect}])
|
||||
end
|
||||
|
||||
gemfile.puts("end")
|
||||
gemfile.close
|
||||
end
|
||||
|
|
|
@ -28,16 +28,23 @@ module Vagrant
|
|||
#
|
||||
# @param [String] name Name of the plugin (gem)
|
||||
# @return [Gem::Specification]
|
||||
def install_plugin(name)
|
||||
def install_plugin(name, **opts)
|
||||
plugins = installed_plugins
|
||||
plugins[name] = {
|
||||
"require" => opts[:require],
|
||||
"gem_version" => opts[:version],
|
||||
}
|
||||
|
||||
result = nil
|
||||
Vagrant::Bundler.instance.install(installed_plugins.push(name)).each do |spec|
|
||||
Vagrant::Bundler.instance.install(plugins).each do |spec|
|
||||
next if spec.name != name
|
||||
next if result && result.version >= spec.version
|
||||
result = spec
|
||||
end
|
||||
|
||||
# Add the plugin to the state file
|
||||
@global_file.add_plugin(result.name)
|
||||
@global_file.add_plugin(
|
||||
result.name, version: opts[:version], require: opts[:require])
|
||||
|
||||
result
|
||||
rescue ::Bundler::GemNotFound
|
||||
|
@ -58,7 +65,7 @@ module Vagrant
|
|||
#
|
||||
# @return [Array<String>]
|
||||
def installed_plugins
|
||||
@global_file.installed_plugins.keys
|
||||
@global_file.installed_plugins
|
||||
end
|
||||
|
||||
# This returns the list of plugins that are installed as
|
||||
|
@ -66,7 +73,7 @@ module Vagrant
|
|||
#
|
||||
# @return [Array<Gem::Specification>]
|
||||
def installed_specs
|
||||
installed = Set.new(installed_plugins)
|
||||
installed = Set.new(installed_plugins.keys)
|
||||
|
||||
# Go through the plugins installed in this environment and
|
||||
# get the latest version of each.
|
||||
|
|
|
@ -27,13 +27,13 @@ module Vagrant
|
|||
# Add a plugin that is installed to the state file.
|
||||
#
|
||||
# @param [String] name The name of the plugin
|
||||
def add_plugin(name)
|
||||
if !@data["installed"].has_key?(name)
|
||||
@data["installed"][name] = {
|
||||
"ruby_version" => RUBY_VERSION,
|
||||
"vagrant_version" => Vagrant::VERSION,
|
||||
}
|
||||
end
|
||||
def add_plugin(name, **opts)
|
||||
@data["installed"][name] = {
|
||||
"ruby_version" => RUBY_VERSION,
|
||||
"vagrant_version" => Vagrant::VERSION,
|
||||
"gem_version" => opts[:version] || "",
|
||||
"require" => opts[:require] || "",
|
||||
}
|
||||
|
||||
save!
|
||||
end
|
||||
|
|
|
@ -22,6 +22,7 @@ module VagrantPlugins
|
|||
end
|
||||
|
||||
def call(env)
|
||||
entrypoint = env[:plugin_entry_point]
|
||||
plugin_name = env[:plugin_name]
|
||||
version = env[:plugin_version]
|
||||
|
||||
|
@ -51,7 +52,8 @@ module VagrantPlugins
|
|||
|
||||
# TODO: support version, pre-release, custom sources
|
||||
manager = Vagrant::Plugin::Manager.instance
|
||||
plugin_spec = manager.install_plugin(plugin_name)
|
||||
plugin_spec = manager.install_plugin(
|
||||
plugin_name, version: version, require: entrypoint)
|
||||
|
||||
# Tell the user
|
||||
env[:ui].success(I18n.t("vagrant.commands.plugin.installed",
|
||||
|
|
|
@ -39,7 +39,9 @@ describe Vagrant::Plugin::Manager do
|
|||
|
||||
describe "#installed_plugins" do
|
||||
it "has the plugins" do
|
||||
expect(subject.installed_plugins).to eql(["foo"])
|
||||
plugins = subject.installed_plugins
|
||||
expect(plugins.length).to eql(1)
|
||||
expect(plugins).to have_key("foo")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -32,6 +32,8 @@ describe Vagrant::Plugin::StateFile do
|
|||
expect(plugins["foo"]).to eql({
|
||||
"ruby_version" => RUBY_VERSION,
|
||||
"vagrant_version" => Vagrant::VERSION,
|
||||
"gem_version" => "",
|
||||
"require" => "",
|
||||
})
|
||||
end
|
||||
|
||||
|
@ -50,6 +52,11 @@ describe Vagrant::Plugin::StateFile do
|
|||
instance = described_class.new(path)
|
||||
expect(instance.installed_plugins.keys).to eql(["foo"])
|
||||
end
|
||||
|
||||
it "should store metadata" do
|
||||
subject.add_plugin("foo", version: "1.2.3")
|
||||
expect(subject.installed_plugins["foo"]["gem_version"]).to eql("1.2.3")
|
||||
end
|
||||
end
|
||||
|
||||
context "with an old-style file" do
|
||||
|
|
Loading…
Reference in New Issue