Remove bundler where no longer required

This commit is contained in:
Chris Roberts 2016-11-07 20:00:38 -08:00
parent 36d21f3c3f
commit 1f5dd35d16
7 changed files with 49 additions and 70 deletions

View File

@ -44,54 +44,6 @@ if argv.include?("--debug")
ENV["VAGRANT_LOG"] = "debug"
end
# Setup our dependencies by initializing Bundler. If we're using plugins,
# then also initialize the paths to the plugins.
begin
require "bundler"
rescue Errno::EINVAL
# Bundler can generate the EINVAL error during initial require, which means
# nothing has yet been setup (so no access to I18n). Note that vagrant has
# failed early and copy information related to problem and possible solution.
$stderr.puts "Vagrant failed to initialize at a very early stage:\n\n"
$stderr.puts "Vagrant received an \"EINVAL\" error while attempting to set some"
$stderr.puts "environment variables. This is usually caused by the total size of your"
$stderr.puts "environment variables being too large. Vagrant sets a handful of"
$stderr.puts "environment variables to function and requires this to work. Please"
$stderr.puts "delete some environment variables prior to executing Vagrant to"
$stderr.puts "fix this."
exit 255
end
if(defined?(Bundler))
begin
$vagrant_bundler_runtime = Bundler.setup(:default, :plugins)
rescue Bundler::GemNotFound
$stderr.puts "Bundler, the underlying system used to manage Vagrant plugins,"
$stderr.puts "is reporting that a plugin or its dependency can't be found."
$stderr.puts "This is usually caused by manual tampering with the 'plugins.json'"
$stderr.puts "file in the Vagrant home directory. To fix this error, please"
$stderr.puts "remove that file and reinstall all your plugins using `vagrant"
$stderr.puts "plugin install`."
rescue Bundler::VersionConflict => e
$stderr.puts "Vagrant experienced a version conflict with some installed plugins!"
$stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the"
$stderr.puts "upgrade process, some existing plugins are no longer compatible with"
$stderr.puts "this version of Vagrant. The recommended way to fix this is to remove"
$stderr.puts "your existing plugins and reinstall them one-by-one. To remove all"
$stderr.puts "plugins:"
$stderr.puts ""
$stderr.puts " rm -r ~/.vagrant.d/plugins.json ~/.vagrant.d/gems"
$stderr.puts ""
$stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable"
$stderr.puts "set, the folders above will be in that directory rather than your"
$stderr.puts "user's home directory."
$stderr.puts ""
$stderr.puts "The error message is shown below:\n\n"
$stderr.puts e.message
exit 1
end
end
# Stdout/stderr should not buffer output
$stdout.sync = true
$stderr.sync = true

View File

@ -1,12 +1,5 @@
require "vagrant/shared_helpers"
if Vagrant.plugins_enabled? && !defined?(Bundler)
puts "It appears that Vagrant was not properly loaded. Specifically,"
puts "the bundler context Vagrant requires was not setup. Please execute"
puts "vagrant using only the `vagrant` executable."
abort
end
require 'rubygems'
require 'log4r'
@ -72,10 +65,6 @@ global_logger.info("RubyGems version: #{Gem::VERSION}")
ENV.each do |k, v|
global_logger.info("#{k}=#{v.inspect}") if k =~ /^VAGRANT_/
end
global_logger.info("Plugins:")
Bundler.definition.specs_for([:plugins]).each do |spec|
global_logger.info(" - #{spec.name} = #{spec.version}")
end
# We need these components always so instead of an autoload we
# just require them explicitly here.
@ -256,7 +245,34 @@ end
# Setup the plugin manager and load any defined plugins
require_relative "vagrant/plugin/manager"
plugins = Vagrant::Plugin::Manager.instance.installed_plugins
Vagrant::Bundler.instance.init!(plugins) unless ENV['VAGRANT_DISABLE_PLUGIN_INIT'] == "1"
global_logger.info("Plugins:")
plugins.each do |plugin_name, plugin_info|
global_logger.info(" - #{plugin_name} = #{plugin_info[:version]}")
end
if Vagrant.plugins_init?
begin
Vagrant::Bundler.instance.init!(plugins)
rescue Gem::ConflictError, Gem::DependencyError => e
$stderr.puts "Vagrant experienced a version conflict with some installed plugins!"
$stderr.puts "This usually happens if you recently upgraded Vagrant. As part of the"
$stderr.puts "upgrade process, some existing plugins are no longer compatible with"
$stderr.puts "this version of Vagrant. The recommended way to fix this is to remove"
$stderr.puts "your existing plugins and reinstall them one-by-one. To remove all"
$stderr.puts "plugins:"
$stderr.puts ""
$stderr.puts " vagrant expunge"
$stderr.puts ""
$stderr.puts "Note if you have an alternate VAGRANT_HOME environmental variable"
$stderr.puts "set, the folders above will be in that directory rather than your"
$stderr.puts "user's home directory."
$stderr.puts ""
$stderr.puts "The error message is shown below:\n\n"
$stderr.puts e.message
exit 1
end
end
# A lambda that knows how to load plugins from a single directory.
plugin_load_proc = lambda do |directory|

View File

@ -81,9 +81,9 @@ module Vagrant
)
result
rescue ::Bundler::GemNotFound
rescue Gem::GemNotFoundException
raise Errors::PluginGemNotFound, name: name
rescue ::Bundler::BundlerError => e
rescue Gem::Exception => e
raise Errors::BundlerError, message: e.to_s
end
@ -102,14 +102,14 @@ module Vagrant
# Clean the environment, removing any old plugins
Vagrant::Bundler.instance.clean(installed_plugins)
rescue ::Bundler::BundlerError => e
rescue Gem::Exception => e
raise Errors::BundlerError, message: e.to_s
end
# Updates all or a specific set of plugins.
def update_plugins(specific)
Vagrant::Bundler.instance.update(installed_plugins, specific)
rescue ::Bundler::BundlerError => e
rescue Gem::Exception => e
raise Errors::BundlerError, message: e.to_s
end

View File

@ -38,6 +38,13 @@ module Vagrant
ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"]
end
# Should the plugin system be initialized
#
# @return [Boolean]
def self.plugins_init?
!ENV['VAGRANT_DISABLE_PLUGIN_INIT']
end
# This returns whether or not 3rd party plugins should and can be loaded.
#
# @return [Boolean]

View File

@ -5,7 +5,9 @@ module Vagrant
class Env
def self.with_original_env
original_env = ENV.to_hash
ENV.replace(::Bundler::ORIGINAL_ENV) if defined?(::Bundler::ORIGINAL_ENV)
if defined?(::Bundler) && defined?(::Bundler::ORIGINAL_ENV)
ENV.replace(::Bundler::ORIGINAL_ENV)
end
ENV.update(Vagrant.original_env)
yield
ensure

View File

@ -297,7 +297,9 @@ module Vagrant
def jailbreak(env = {})
return if ENV.key?("VAGRANT_SKIP_SUBPROCESS_JAILBREAK")
env.replace(::Bundler::ORIGINAL_ENV) if defined?(::Bundler::ORIGINAL_ENV)
if defined?(::Bundler) && defined?(::Bundler::ORIGINAL_ENV)
env.replace(::Bundler::ORIGINAL_ENV)
end
env.merge!(Vagrant.original_env)
# Bundler does this, so I guess we should as well, since I think it

View File

@ -45,14 +45,14 @@ describe Vagrant::Plugin::Manager do
end
it "masks GemNotFound with our error" do
expect(bundler).to receive(:install).and_raise(Bundler::GemNotFound)
expect(bundler).to receive(:install).and_raise(Gem::GemNotFoundException)
expect { subject.install_plugin("foo") }.
to raise_error(Vagrant::Errors::PluginGemNotFound)
end
it "masks bundler errors with our own error" do
expect(bundler).to receive(:install).and_raise(Bundler::InstallError)
expect(bundler).to receive(:install).and_raise(Gem::InstallError)
expect { subject.install_plugin("foo") }.
to raise_error(Vagrant::Errors::BundlerError)
@ -140,7 +140,7 @@ describe Vagrant::Plugin::Manager do
end
it "masks bundler errors with our own error" do
expect(bundler).to receive(:clean).and_raise(Bundler::InstallError)
expect(bundler).to receive(:clean).and_raise(Gem::InstallError)
expect { subject.uninstall_plugin("foo") }.
to raise_error(Vagrant::Errors::BundlerError)
@ -182,7 +182,7 @@ describe Vagrant::Plugin::Manager do
describe "#update_plugins" do
it "masks bundler errors with our own error" do
expect(bundler).to receive(:update).and_raise(Bundler::InstallError)
expect(bundler).to receive(:update).and_raise(Gem::InstallError)
expect { subject.update_plugins([]) }.
to raise_error(Vagrant::Errors::BundlerError)