| Class | Sprout::FlashPlayerTask |
| In: |
bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb
|
| Parent: | Rake::Task |
The FlashPlayerTask will download, unpack, configure and launch the debug Flash Player for OS X, Windows and Linux.
Simply send the rake task the swf you‘d like to launch either indirectly as a rake dependency or directly as the swf property of this task.
flashplayer :run => 'bin/SomeProject.swf'
Or you could:
flashplayer :run do |t|
t.swf = 'bin/SomeProject.swf'
end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 73 def self.define_task(args, &block) t = super yield t if block_given? t.define end
Local system path to where the Flash Player stores trace output logs and trust files
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 89 def FlashPlayerTask.home if(@@home) return @@home end FlashPlayerTask.home_paths.each do |path| if(File.exists?(path)) return @@home = path end end if(@@home.nil?) raise FlashPlayerError.new('FlashPlayer unable to find home folder for your platform') end return @@home end
Collection of the potential locations of the Flash Player Home For each supported Platform, the first existing location will be used.
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 109 def FlashPlayerTask.home_paths return [File.join(User.library, 'Preferences', 'Macromedia', 'Flash Player'), File.join(User.library, 'Application Support', 'Macromedia'), File.join(User.home, 'Application Data', 'Macromedia', 'Flash Player'), File.join(User.home, '.macromedia', 'Flash_Player')] end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 65 def initialize(task_name, app) super(task_name, app) @default_gem_name = 'sprout-flashplayer-tool' @default_gem_version = '10.22.0' @default_result_file = 'AsUnitResults.xml' @inside_test_result = false end
Local system path to the Flash Player Trust file
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 80 def FlashPlayerTask.trust if(@@trust) return @@trust end @@trust = File.join(FlashPlayerTask.home, '#Security', 'FlashPlayerTrust', 'sprout.cfg') return @@trust end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 268 def close usr = User.new if(usr.is_a?(WinUser)) Thread.kill(@thread) elsif(usr.is_a?(OSXUser)) @clix_player.kill else Process.kill("SIGALRM", @player_pid) end end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 156 def do_not_focus @do_not_focus ||= nil end
By default, the Flash Player should be given focus after being launched. Unfortunately, this doesn‘t work properly on OS X, so we needed to do some hackery in order to make it happen. This in turn can lead to multiple instances of the Player being instantiated. In the case of running a test harness, this is absolutely not desirable, so we had expose a parameter that allows us to prevent auto-focus of the player.
This feature is deprecated in current versions of the FlashPlayerTask
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 151 def do_not_focus=(focus) @do_not_focus = focus puts "[WARNING] Thanks to fixes in the FlashPlayer task, do_not_focus is deprecated and no longer needs to be used" end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 333 def examine_test_result(result) require 'rexml/document' doc = nil begin doc = REXML::Document.new(result) rescue REXML::ParseException => e puts "[WARNING] Invalid test results encountered" return end # Handle JUnit Failures failures = [] doc.elements.each('/testsuites/testsuite/testsuite/testcase/error') do |element| failures << element.text end doc.elements.each("/testsuites/testsuite/testsuite/testcase/failure") do |element| failures << element.text end if(failures.size > 0) raise AssertionFailure.new("[ERROR] Test Failures Encountered \n#{failures.join("\n")}") end end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 212 def execute(*args) super raise FlashPlayerError.new("FlashPlayer task #{name} required field swf is nil") unless swf log_file = nil # Don't let trust or log file failures break other features... begin log_file = FlashPlayerConfig.new().log FlashPlayerTrust.new(File.expand_path(File.dirname(swf))) if(File.exists?(log_file)) File.open(log_file, 'w') do |f| f.write('') end else FileUtils.makedirs(File.dirname(log_file)) FileUtils.touch(log_file) end rescue StandardError => e puts '[WARNING] FlashPlayer encountered an error working with the mm.cfg log and/or editing the Trust file' end @running_process = nil @thread = run(gem_name, gem_version, swf) read_log(@thread, log_file) @thread.join end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 189 def gem_name return @gem_name ||= @default_gem_name end
Full name of the sprout tool gem that this tool task will use. This defaults to sprout-flashplayer-tool
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 185 def gem_name=(name) @gem_name = name end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 179 def gem_version return @gem_version ||= nil end
The gem version of the sprout-flashplayer-tool RubyGem to download.
It‘s important to note that this version number will differ slightly from the actual player version in that the final revision (the last of three numbers), is the gem version, while the first two describe the player version being downloaded. The exact gem version that you would like the ToolTask to execute. By default this value should be nil and will download the latest version of the gem that is available unless there is a version already installed on your system.
This attribute could be an easy way to update your local gem to the latest version without leaving your build file, but it‘s primary purpose is to allow you to specify very specific versions of the tools that your project depends on. This way your team can rest assured that they are all working with the same tools.
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 175 def gem_version=(version) @gem_version = version end
Returns true if inside of a test result
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 306 def parse_test_result(line, thread) if(@inside_test_result) if(line.index(@@test_result_post_delimiter)) @inside_test_result = false write_test_result(test_result) close examine_test_result test_result return true else test_result << line end end if(line.index(@@test_result_pre_delimiter)) @inside_test_result = true end return @inside_test_result end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 279 def read_log(thread, log_file) lines_put = 0 if(!File.exists?(log_file)) raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file in the expected location: ' + log_file) end while(thread.alive?) sleep(0.2) lines_read = 0 File.open(log_file, 'r') do |file| file.readlines.each do |line| lines_read = lines_read + 1 if(lines_read > lines_put) if(!parse_test_result(line, thread)) puts "[trace] #{line}" end $stdout.flush lines_put = lines_put + 1 end end end end end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 241 def run(tool, gem_version, swf) path_to_exe = Sprout.get_executable(tool, nil, gem_version) target = User.clean_path(path_to_exe) @player_pid = nil thread_out = $stdout command = "#{target} #{User.clean_path(swf)}" usr = User.new() if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser)) return Thread.new { system command } elsif usr.is_a?(OSXUser) require 'clix_flash_player' @clix_player = CLIXFlashPlayer.new @clix_player.execute(target, swf) return @clix_player else return Thread.new { require 'open4' @player_pid, stdin, stdout, stderr = Open4.popen4(command) stdout.read } end end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 131 def swf @swf ||= nil if(@swf.nil?) prerequisites.each do |req| if(req.index('.swf')) @swf = req.to_s break end end end return @swf end
The swf parameter can be set explicitly in the block sent to this task as in:
flashplayer :run do |t|
t.swf = 'bin/SomeProject.swf'
end
Or it can be set implicitly as a rake prerequisite as follows:
flashplayer :run => 'bin/SomeProject' do |t| end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 127 def swf=(swf) @swf = swf end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 204 def test_result @test_result ||= '' end
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 200 def test_result_file @test_result_file ||= @default_result_file end
The File where JUnit test results should be written. This value defaults to ‘AsUnitResults.xml‘
# File bundles/flashplayer/lib/sprout/tasks/flashplayer_task.rb, line 196 def test_result_file=(file) @test_result_file = file end