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