Lazy load attributes for runners. Get box repackage working.
This commit is contained in:
parent
d9321ed4d4
commit
739d5ffb5f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue