diff --git a/bin/vagrant b/bin/vagrant index cd7fbc9d3..aaa6e3afa 100755 --- a/bin/vagrant +++ b/bin/vagrant @@ -105,21 +105,8 @@ begin env = Vagrant::Environment.new(opts) if !Vagrant.in_installer? - warned = false - - # If we're in a bundler environment, we assume it is for plugin - # development and will let the user know that. - if defined?(Bundler) - require 'bundler/shared_helpers' - if Bundler::SharedHelpers.in_bundle? - env.ui.warn(I18n.t("vagrant.general.in_bundler")) - env.ui.warn("") - warned = true - end - end - # If we're not in the installer, warn. - env.ui.warn(I18n.t("vagrant.general.not_in_installer")) if !warned + env.ui.warn(I18n.t("vagrant.general.not_in_installer")) end begin diff --git a/lib/vagrant.rb b/lib/vagrant.rb index e0458add8..2458137e0 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -1,17 +1,29 @@ # This file is load before RubyGems are loaded, and allow us to actually # resolve plugin dependencies and load the proper versions of everything. -if defined?(Vagrant) - raise "vagrant is somehow already loaded. bug." -end - ENV["VAGRANT_INSTALLER_EMBEDDED_DIR"] = "/Applications/Vagrant/embedded" -# Initialize Bundler before we load _any_ RubyGems. -require_relative "vagrant/bundler" -require_relative "vagrant/plugin_manager" -Vagrant::Bundler.instance.init!(Vagrant::PluginManager.plugins) +if defined?(Bundler) + require "bundler/shared_helpers" + if Bundler::SharedHelpers.in_bundle? + puts "Vagrant appears to be running in a Bundler environment. Plugins" + puts "will not be loaded and plugin commands are disabled." + puts + ENV["VAGRANT_NO_PLUGINS"] = "1" + end +end -# Initialize Vagrant first, then load the remaining dependencies +require_relative "vagrant/shared_helpers" + +if Vagrant.plugins_enabled? + # Initialize Bundler before we load _any_ RubyGems. + require_relative "vagrant/bundler" + require_relative "vagrant/plugin_manager" + Vagrant::Bundler.instance.init!(Vagrant::PluginManager.plugins) +end + +# Initialize Vagrant now that our Gem paths are setup require "vagrant/init" -Bundler.require(:default) + +# If we have plugins enabled, then load those +Bundler.require(:default) if Vagrant.plugins_enabled? diff --git a/lib/vagrant/bundler.rb b/lib/vagrant/bundler.rb index 769b30f4e..81c445860 100644 --- a/lib/vagrant/bundler.rb +++ b/lib/vagrant/bundler.rb @@ -1,6 +1,6 @@ require "tempfile" -require_relative "paths" +require_relative "shared_helpers" require_relative "version" module Vagrant @@ -21,7 +21,9 @@ module Vagrant @configfile = Tempfile.new("vagrant-bundler-config") @configfile.close - # Build up the Gemfile for our Bundler context + # Build up the Gemfile for our Bundler context. We make sure to + # lock Vagrant to our current Vagrant version. In addition to that, + # we add all our plugin dependencies. @gemfile = Tempfile.new("vagrant-gemfile") @gemfile.puts(%Q[gem "vagrant", "= #{Vagrant::VERSION}"]) plugins.each do |plugin| diff --git a/lib/vagrant/plugin_manager.rb b/lib/vagrant/plugin_manager.rb index 4379af569..2887dac19 100644 --- a/lib/vagrant/plugin_manager.rb +++ b/lib/vagrant/plugin_manager.rb @@ -1,6 +1,6 @@ require "json" -require_relative "paths" +require_relative "shared_helpers" module Vagrant class PluginManager diff --git a/lib/vagrant/paths.rb b/lib/vagrant/shared_helpers.rb similarity index 70% rename from lib/vagrant/paths.rb rename to lib/vagrant/shared_helpers.rb index 6871e16f0..78cdb4a92 100644 --- a/lib/vagrant/paths.rb +++ b/lib/vagrant/shared_helpers.rb @@ -1,8 +1,16 @@ require "pathname" module Vagrant - # The source root is the path to the root directory of - # the Vagrant gem. + # This returns whether or not 3rd party plugins should be loaded. + # + # @return [Boolean] + def self.plugins_enabled? + !ENV["VAGRANT_NO_PLUGINS"] + end + + # The source root is the path to the root directory of the Vagrant source. + # + # @return [Pathname] def self.source_root @source_root ||= Pathname.new(File.expand_path('../../../', __FILE__)) end diff --git a/templates/locales/en.yml b/templates/locales/en.yml index 154693760..e02c1c30c 100644 --- a/templates/locales/en.yml +++ b/templates/locales/en.yml @@ -139,11 +139,6 @@ en: Old: %{old} New: %{new} - in_bundler: |- - You appear to be running Vagrant in a Bundler environment. Because - Vagrant should be run within installers (outside of Bundler), Vagrant - will assume that you're developing plugins and will change its behavior - in certain ways to better assist plugin development. not_in_installer: |- You appear to be running Vagrant outside of the official installers. Note that the installers are what ensure that Vagrant has all required