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 instead of calling super for testability
|
||||||
alias_method :general_call, :call
|
alias_method :general_call, :call
|
||||||
def call(env)
|
def call(env)
|
||||||
env["package.directory"] = env["box"].directory
|
env["package.directory"] = env["box_directory"]
|
||||||
general_call(env)
|
general_call(env)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Vagrant
|
||||||
def initialize(app, env)
|
def initialize(app, env)
|
||||||
@app = app
|
@app = app
|
||||||
@env = env
|
@env = env
|
||||||
@env["package.output"] ||= env["config"].package.name
|
@env["package.output"] ||= env["global_config"].package.name
|
||||||
@env["package.include"] ||= []
|
@env["package.include"] ||= []
|
||||||
@env["package.vagrantfile"] ||= nil
|
@env["package.vagrantfile"] ||= nil
|
||||||
end
|
end
|
||||||
|
@ -70,7 +70,7 @@ module Vagrant
|
||||||
# the actual box
|
# the actual box
|
||||||
def copy_include_files
|
def copy_include_files
|
||||||
files_to_copy.each do |from, to|
|
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)
|
FileUtils.mkdir_p(to.parent)
|
||||||
|
|
||||||
# Copy direcotry contents recursively.
|
# Copy direcotry contents recursively.
|
||||||
|
@ -84,7 +84,7 @@ module Vagrant
|
||||||
|
|
||||||
# Compress the exported file into a package
|
# Compress the exported file into a package
|
||||||
def compress
|
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|
|
File.open(tar_path, Platform.tar_file_options) do |tar|
|
||||||
Archive::Tar::Minitar::Output.open(tar) do |output|
|
Archive::Tar::Minitar::Output.open(tar) do |output|
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -10,9 +10,10 @@ module Vagrant
|
||||||
class Runner
|
class Runner
|
||||||
@@reported_interrupt = false
|
@@reported_interrupt = false
|
||||||
|
|
||||||
def initialize(registry, globals=nil)
|
def initialize(registry, globals=nil, &block)
|
||||||
@registry = registry
|
@registry = registry
|
||||||
@globals = globals || {}
|
@globals = globals || {}
|
||||||
|
@lazy_globals = block
|
||||||
@logger = Log4r::Logger.new("vagrant::action::runner")
|
@logger = Log4r::Logger.new("vagrant::action::runner")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,6 +26,7 @@ module Vagrant
|
||||||
# Create the initial environment with the options given
|
# Create the initial environment with the options given
|
||||||
environment = Environment.new
|
environment = Environment.new
|
||||||
environment.merge!(@globals)
|
environment.merge!(@globals)
|
||||||
|
environment.merge!(@lazy_globals.call) if @lazy_globals
|
||||||
environment.merge!(options || {})
|
environment.merge!(options || {})
|
||||||
|
|
||||||
# Run the action chain in a busy block, marking the environment as
|
# Run the action chain in a busy block, marking the environment as
|
||||||
|
|
|
@ -31,7 +31,7 @@ module Vagrant
|
||||||
|
|
||||||
# Begins sequence to repackage this box.
|
# Begins sequence to repackage this box.
|
||||||
def repackage(options=nil)
|
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
|
end
|
||||||
|
|
||||||
# Implemented for comparison with other boxes. Comparison is implemented
|
# Implemented for comparison with other boxes. Comparison is implemented
|
||||||
|
|
|
@ -209,9 +209,13 @@ module Vagrant
|
||||||
#
|
#
|
||||||
# @return [Action::Runner]
|
# @return [Action::Runner]
|
||||||
def action_runner
|
def action_runner
|
||||||
@action_runner ||= Action::Runner.new(action_registry,
|
@action_runner ||= Action::Runner.new(action_registry) do |env|
|
||||||
|
{
|
||||||
|
:global_config => config.global,
|
||||||
:tmp_path => tmp_path,
|
:tmp_path => tmp_path,
|
||||||
:ui => @ui)
|
:ui => @ui
|
||||||
|
}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Action registry for registering new actions with this environment.
|
# Action registry for registering new actions with this environment.
|
||||||
|
|
|
@ -51,4 +51,15 @@ describe Vagrant::Action::Runner do
|
||||||
instance.run(callable)
|
instance.run(callable)
|
||||||
result.should == "bar"
|
result.should == "bar"
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -20,4 +20,15 @@ describe Vagrant::Box do
|
||||||
|
|
||||||
instance.destroy
|
instance.destroy
|
||||||
end
|
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
|
end
|
||||||
|
|
Loading…
Reference in New Issue