diff --git a/config/default.rb b/config/default.rb index 661d6fb77..ab0bfe93e 100644 --- a/config/default.rb +++ b/config/default.rb @@ -11,7 +11,7 @@ Vagrant::Config.run do |config| config.ssh.forwarded_port_key = "ssh" config.ssh.max_tries = 10 config.ssh.timeout = 30 - config.ssh.private_key_path = File.join(PROJECT_ROOT, 'keys', 'vagrant') + config.ssh.private_key_path = File.expand_path("keys/vagrant", Vagrant.source_root) config.ssh.forward_agent = false config.vm.auto_port_range = (2200..2250) diff --git a/lib/vagrant.rb b/lib/vagrant.rb index c2b036c94..be0d4e465 100644 --- a/lib/vagrant.rb +++ b/lib/vagrant.rb @@ -1,16 +1,24 @@ -libdir = File.join(File.dirname(__FILE__), "vagrant") -PROJECT_ROOT = File.join(libdir, '..', "..") unless defined?(PROJECT_ROOT) - # First, load the various libs which Vagrant requires %w{tempfile json pathname logger virtualbox net/ssh archive/tar/minitar net/scp fileutils mario}.each do |lib| require lib end +module Vagrant + class << self + # The source root is the path to the root directory of + # the Vagrant gem. + def source_root + File.expand_path('../../', __FILE__) + end + end +end + # Then load the glob loader, which will handle loading everything else -require File.expand_path("util/glob_loader", libdir) +require "vagrant/util/glob_loader" # Load them up +libdir = File.expand_path("lib/vagrant", Vagrant.source_root) Vagrant::GlobLoader.glob_require(libdir, %w{util util/stacked_proc_runner downloaders/base config provisioners/base provisioners/chef systems/base commands/base commands/box action/exception_catcher hosts/base}) diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 32a04fb6a..61f8fc043 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -174,7 +174,7 @@ module Vagrant # to load the Vagrantfile into that context. def load_config! # Prepare load paths for config files and append to config queue - config_queue = [File.join(PROJECT_ROOT, "config", "default.rb")] + config_queue = [File.expand_path("config/default.rb", Vagrant.source_root)] config_queue << File.join(box.directory, ROOTFILE_NAME) if box config_queue << File.join(home_path, ROOTFILE_NAME) if home_path config_queue << File.join(root_path, ROOTFILE_NAME) if root_path diff --git a/lib/vagrant/util/template_renderer.rb b/lib/vagrant/util/template_renderer.rb index abbbe3f59..ce6c19811 100644 --- a/lib/vagrant/util/template_renderer.rb +++ b/lib/vagrant/util/template_renderer.rb @@ -76,7 +76,7 @@ module Vagrant # # @return [String] def full_template_path - File.join(PROJECT_ROOT, 'templates', "#{template}.erb").squeeze("/") + File.join(Vagrant.source_root, 'templates', "#{template}.erb").squeeze("/") end end end diff --git a/lib/vagrant/util/translator.rb b/lib/vagrant/util/translator.rb index 696440d23..ef5072a5f 100644 --- a/lib/vagrant/util/translator.rb +++ b/lib/vagrant/util/translator.rb @@ -18,7 +18,7 @@ module Vagrant # # @return [Hash] def strings - @@strings ||= YAML.load_file(File.join(PROJECT_ROOT, "templates", "strings.yml")) + @@strings ||= YAML.load_file(File.join(Vagrant.source_root, "templates", "strings.yml")) end # Renders the string with the given key and data parameters and returns diff --git a/test/vagrant/environment_test.rb b/test/vagrant/environment_test.rb index a5154500a..fc8d12652 100644 --- a/test/vagrant/environment_test.rb +++ b/test/vagrant/environment_test.rb @@ -314,7 +314,7 @@ class EnvironmentTest < Test::Unit::TestCase end should "load from the project root" do - File.expects(:exist?).with(File.join(PROJECT_ROOT, "config", "default.rb")).once + File.expects(:exist?).with(File.join(Vagrant.source_root, "config", "default.rb")).once @env.load_config! end diff --git a/test/vagrant/util/template_renderer_test.rb b/test/vagrant/util/template_renderer_test.rb index ff5ad46df..20922d5eb 100644 --- a/test/vagrant/util/template_renderer_test.rb +++ b/test/vagrant/util/template_renderer_test.rb @@ -73,13 +73,13 @@ class TemplateRendererUtilTest < Test::Unit::TestCase end should "be the ERB file in the templates directory" do - result = File.join(PROJECT_ROOT, "templates", "#{@template}.erb") + result = File.join(Vagrant.source_root, "templates", "#{@template}.erb") assert_equal result, @r.full_template_path end should "remove duplicate path separators" do @r.template = "foo///bar" - result = File.join(PROJECT_ROOT, "templates", "foo", "bar.erb") + result = File.join(Vagrant.source_root, "templates", "foo", "bar.erb") assert_equal result, @r.full_template_path end end diff --git a/test/vagrant/util/translator_test.rb b/test/vagrant/util/translator_test.rb index 94bfd6056..5c7fbcdd8 100644 --- a/test/vagrant/util/translator_test.rb +++ b/test/vagrant/util/translator_test.rb @@ -14,7 +14,7 @@ class TranslatorUtilTest < Test::Unit::TestCase end should "load the file initially, then never again unless reset" do - YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).once + YAML.expects(:load_file).with(File.join(Vagrant.source_root, "templates", "strings.yml")).once @klass.strings @klass.strings @klass.strings @@ -22,7 +22,7 @@ class TranslatorUtilTest < Test::Unit::TestCase end should "reload if reset! is called" do - YAML.expects(:load_file).with(File.join(PROJECT_ROOT, "templates", "strings.yml")).twice + YAML.expects(:load_file).with(File.join(Vagrant.source_root, "templates", "strings.yml")).twice @klass.strings @klass.reset! @klass.strings