Do not re-write plugin state file
Maintain existing structure for backwards compatibility and isolate new plugin information which can be ignored when using previous versions.
This commit is contained in:
parent
8952168480
commit
db249d58ac
|
@ -24,53 +24,18 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
upgrade_v0! if !@data["version"]
|
upgrade_v0! if !@data["version"]
|
||||||
upgrade_v1! if @data["version"].to_s == "1"
|
|
||||||
end
|
end
|
||||||
|
|
||||||
@data["version"] ||= "2"
|
@data["version"] ||= "1"
|
||||||
@data["ruby"] ||= {"installed" => {}}
|
@data["installed"] ||= {}
|
||||||
@data["go_plugin"] ||= {}
|
@data["go_plugin"] ||= {}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a go plugin that is installed to the state file.
|
|
||||||
#
|
|
||||||
# @param [String] name The name of the plugin
|
|
||||||
def add_go_plugin(name, **opts)
|
|
||||||
@data["go_plugin"][name] = {
|
|
||||||
"source" => opts[:source]
|
|
||||||
}
|
|
||||||
|
|
||||||
save!
|
|
||||||
end
|
|
||||||
|
|
||||||
# Remove a plugin that is installed from the state file.
|
|
||||||
#
|
|
||||||
# @param [String] name The name of the plugin
|
|
||||||
def remove_go_plugin(name)
|
|
||||||
@data["go_plugin"].delete(name)
|
|
||||||
|
|
||||||
save!
|
|
||||||
end
|
|
||||||
|
|
||||||
# @return [Boolean] go plugin is present in this state file
|
|
||||||
def has_go_plugin?(name)
|
|
||||||
@data["go_plugin"].key?(name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# This returns a hash of installed go plugins according to the state
|
|
||||||
# file. Note that this may _not_ directly match over to actually
|
|
||||||
# installed plugins.
|
|
||||||
#
|
|
||||||
# @return [Hash]
|
|
||||||
def installed_go_plugins
|
|
||||||
@data["go_plugin"]
|
|
||||||
end
|
|
||||||
|
|
||||||
# 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, **opts)
|
def add_plugin(name, **opts)
|
||||||
@data["ruby"]["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] || "",
|
"gem_version" => opts[:version] || "",
|
||||||
|
@ -83,12 +48,49 @@ module Vagrant
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add a go plugin that is installed to the state file
|
||||||
|
#
|
||||||
|
# @param [String, Symbol] name Plugin name
|
||||||
|
def add_go_plugin(name, **opts)
|
||||||
|
@data["go_plugin"][name] = {
|
||||||
|
"source" => opts[:source]
|
||||||
|
}
|
||||||
|
|
||||||
|
save!
|
||||||
|
end
|
||||||
|
|
||||||
|
# Remove a go plugin that is installed from the state file
|
||||||
|
#
|
||||||
|
# @param [String, Symbol] name Name of the plugin
|
||||||
|
def remove_go_plugin(name)
|
||||||
|
@data["go_plugin"].delete(name.to_s)
|
||||||
|
|
||||||
|
save!
|
||||||
|
end
|
||||||
|
|
||||||
|
# Check if go plugin is installed from the state file
|
||||||
|
#
|
||||||
|
# @param [String, Symbol] name Plugin name
|
||||||
|
# @return [Boolean]
|
||||||
|
def has_go_plugin?(name)
|
||||||
|
@data["go_plugin"].key?(name.to_s)
|
||||||
|
end
|
||||||
|
|
||||||
|
# This returns a hash of installed go plugins according to the state
|
||||||
|
# file. Note that this may _not_ directly match over to actually
|
||||||
|
# installed plugins
|
||||||
|
#
|
||||||
|
# @return [Hash]
|
||||||
|
def installed_go_plugins
|
||||||
|
@data["go_plugin"]
|
||||||
|
end
|
||||||
|
|
||||||
# Adds a RubyGems index source to look up gems.
|
# Adds a RubyGems index source to look up gems.
|
||||||
#
|
#
|
||||||
# @param [String] url URL of the source.
|
# @param [String] url URL of the source.
|
||||||
def add_source(url)
|
def add_source(url)
|
||||||
@data["ruby"]["sources"] ||= []
|
@data["sources"] ||= []
|
||||||
@data["ruby"]["sources"] |= [url]
|
@data["sources"] << url if !@data["sources"].include?(url)
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -98,21 +100,21 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @return [Hash]
|
# @return [Hash]
|
||||||
def installed_plugins
|
def installed_plugins
|
||||||
@data["ruby"]["installed"]
|
@data["installed"]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns true/false if the plugin is present in this state file.
|
# Returns true/false if the plugin is present in this state file.
|
||||||
#
|
#
|
||||||
# @return [Boolean]
|
# @return [Boolean]
|
||||||
def has_plugin?(name)
|
def has_plugin?(name)
|
||||||
@data["ruby"]["installed"].key?(name)
|
@data["installed"].key?(name)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove a plugin that is installed from the state file.
|
# Remove a plugin that is installed from the state file.
|
||||||
#
|
#
|
||||||
# @param [String] name The name of the plugin.
|
# @param [String] name The name of the plugin.
|
||||||
def remove_plugin(name)
|
def remove_plugin(name)
|
||||||
@data["ruby"]["installed"].delete(name)
|
@data["installed"].delete(name)
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -120,8 +122,8 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @param [String] url URL of the source
|
# @param [String] url URL of the source
|
||||||
def remove_source(url)
|
def remove_source(url)
|
||||||
@data["ruby"]["sources"] ||= []
|
@data["sources"] ||= []
|
||||||
@data["ruby"]["sources"].delete(url)
|
@data["sources"].delete(url)
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -130,7 +132,7 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @return [Array<String>]
|
# @return [Array<String>]
|
||||||
def sources
|
def sources
|
||||||
@data["ruby"]["sources"] || []
|
@data["sources"] || []
|
||||||
end
|
end
|
||||||
|
|
||||||
# This saves the state back into the state file.
|
# This saves the state back into the state file.
|
||||||
|
@ -164,18 +166,6 @@ module Vagrant
|
||||||
|
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
# This upgrades the internal data representation from V1 to V2
|
|
||||||
def upgrade_v1!
|
|
||||||
@data.delete("version")
|
|
||||||
new_data = {
|
|
||||||
"version" => "2",
|
|
||||||
"ruby" => @data,
|
|
||||||
"go_plugin" => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
save!
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -118,4 +118,56 @@ describe Vagrant::Plugin::StateFile do
|
||||||
to raise_error(Vagrant::Errors::PluginStateFileParseError)
|
to raise_error(Vagrant::Errors::PluginStateFileParseError)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "go plugin usage" do
|
||||||
|
describe "#add_go_plugin" do
|
||||||
|
it "should add plugin to list of installed go plugins" do
|
||||||
|
subject.add_go_plugin("foo", source: "http://localhost/foo.zip")
|
||||||
|
expect(subject.installed_go_plugins).to include("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should update source when added again" do
|
||||||
|
subject.add_go_plugin("foo", source: "http://localhost/foo.zip")
|
||||||
|
expect(subject.installed_go_plugins["foo"]["source"]).to eq("http://localhost/foo.zip")
|
||||||
|
subject.add_go_plugin("foo", source: "http://localhost/foo1.zip")
|
||||||
|
expect(subject.installed_go_plugins["foo"]["source"]).to eq("http://localhost/foo1.zip")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#remove_go_plugin" do
|
||||||
|
before do
|
||||||
|
subject.add_go_plugin("foo", source: "http://localhost/foo.zip")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should remove the installed plugin" do
|
||||||
|
subject.remove_go_plugin("foo")
|
||||||
|
expect(subject.installed_go_plugins).not_to include("foo")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should remove plugin not installed" do
|
||||||
|
subject.remove_go_plugin("foo")
|
||||||
|
expect(subject.installed_go_plugins).not_to include("foo")
|
||||||
|
subject.remove_go_plugin("foo")
|
||||||
|
expect(subject.installed_go_plugins).not_to include("foo")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "#has_go_plugin?" do
|
||||||
|
before do
|
||||||
|
subject.add_go_plugin("foo", source: "http://localhost/foo.zip")
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return true when plugin is installed" do
|
||||||
|
expect(subject.has_go_plugin?("foo")).to be_truthy
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should return false when plugin is not installed" do
|
||||||
|
expect(subject.has_go_plugin?("fee")).to be_falsey
|
||||||
|
end
|
||||||
|
|
||||||
|
it "should allow symbol names" do
|
||||||
|
expect(subject.has_go_plugin?(:foo)).to be_truthy
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue