diff --git a/lib/vagrant/action/box/package.rb b/lib/vagrant/action/box/package.rb index a513b28e8..68b1dab96 100644 --- a/lib/vagrant/action/box/package.rb +++ b/lib/vagrant/action/box/package.rb @@ -10,7 +10,7 @@ module Vagrant # Alias instead of calling super for testability alias_method :general_call, :call def call(env) - env["package.directory"] = env["box"].directory + env["package.directory"] = env["box_directory"] general_call(env) end end diff --git a/lib/vagrant/action/general/package.rb b/lib/vagrant/action/general/package.rb index 90522a6a9..83fcf7c53 100644 --- a/lib/vagrant/action/general/package.rb +++ b/lib/vagrant/action/general/package.rb @@ -20,7 +20,7 @@ module Vagrant def initialize(app, env) @app = app @env = env - @env["package.output"] ||= env["config"].package.name + @env["package.output"] ||= env["global_config"].package.name @env["package.include"] ||= [] @env["package.vagrantfile"] ||= nil end @@ -70,7 +70,7 @@ module Vagrant # the actual box def copy_include_files files_to_copy.each do |from, to| - @env.ui.info I18n.t("vagrant.actions.general.package.packaging", :file => from) + @env[:ui].info I18n.t("vagrant.actions.general.package.packaging", :file => from) FileUtils.mkdir_p(to.parent) # Copy direcotry contents recursively. @@ -84,7 +84,7 @@ module Vagrant # Compress the exported file into a package def compress - @env.ui.info I18n.t("vagrant.actions.general.package.compressing", :tar_path => tar_path) + @env[:ui].info I18n.t("vagrant.actions.general.package.compressing", :tar_path => tar_path) File.open(tar_path, Platform.tar_file_options) do |tar| Archive::Tar::Minitar::Output.open(tar) do |output| begin diff --git a/lib/vagrant/action/runner.rb b/lib/vagrant/action/runner.rb index fa530cc36..aa667e009 100644 --- a/lib/vagrant/action/runner.rb +++ b/lib/vagrant/action/runner.rb @@ -10,10 +10,11 @@ module Vagrant class Runner @@reported_interrupt = false - def initialize(registry, globals=nil) - @registry = registry - @globals = globals || {} - @logger = Log4r::Logger.new("vagrant::action::runner") + def initialize(registry, globals=nil, &block) + @registry = registry + @globals = globals || {} + @lazy_globals = block + @logger = Log4r::Logger.new("vagrant::action::runner") end def run(callable_id, options=nil) @@ -25,6 +26,7 @@ module Vagrant # Create the initial environment with the options given environment = Environment.new environment.merge!(@globals) + environment.merge!(@lazy_globals.call) if @lazy_globals environment.merge!(options || {}) # Run the action chain in a busy block, marking the environment as diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 81fd0492f..816dfcdc9 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -31,7 +31,7 @@ module Vagrant # Begins sequence to repackage this box. def repackage(options=nil) - env.actions.run(:box_repackage, { "box" => self, "validate" => false }.merge(options || {})) + @action_runner.run(:box_repackage, { :box_name => @name, :box_directory => @directory }) end # Implemented for comparison with other boxes. Comparison is implemented diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index c0101c501..732fdac1b 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -209,9 +209,13 @@ module Vagrant # # @return [Action::Runner] def action_runner - @action_runner ||= Action::Runner.new(action_registry, - :tmp_path => tmp_path, - :ui => @ui) + @action_runner ||= Action::Runner.new(action_registry) do |env| + { + :global_config => config.global, + :tmp_path => tmp_path, + :ui => @ui + } + end end # Action registry for registering new actions with this environment. diff --git a/test/unit/vagrant/action/runner_test.rb b/test/unit/vagrant/action/runner_test.rb index 2a3e1d4cd..fedd89fc4 100644 --- a/test/unit/vagrant/action/runner_test.rb +++ b/test/unit/vagrant/action/runner_test.rb @@ -51,4 +51,15 @@ describe Vagrant::Action::Runner do instance.run(callable) result.should == "bar" end + + it "should yield the block passed to the init method to get lazy loaded globals" do + result = nil + callable = lambda do |env| + result = env["data"] + end + + instance = described_class.new(registry) { { "data" => "bar" } } + instance.run(callable) + result.should == "bar" + end end diff --git a/test/unit/vagrant/box_test.rb b/test/unit/vagrant/box_test.rb index 0fa5babf3..a2dbfbfb0 100644 --- a/test/unit/vagrant/box_test.rb +++ b/test/unit/vagrant/box_test.rb @@ -20,4 +20,15 @@ describe Vagrant::Box do instance.destroy end + + it "can repackage itself" do + # Simply test the messages to the action runner + options = { + :box_name => name, + :box_directory => directory + } + action_runner.should_receive(:run).with(:box_repackage, options) + + instance.repackage + end end