Class: Sprout::FlashPlayerTask
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Sprout::FlashPlayerTask
- Defined in:
- lib/sprout/flash_player_task.rb,
lib/sprout/flash_player_task/version.rb
Defined Under Namespace
Modules: VERSION
Constant Summary collapse
- DEFAULT_VERSION =
'>= 9.60.0'
- EXECUTABLE_NAME =
'flashplayer'
- @@test_result_pre_delimiter =
'<XMLResultPrinter>'
- @@test_result_post_delimiter =
'</XMLResultPrinter>'
- @@home =
nil
- @@trust =
nil
Instance Attribute Summary collapse
-
#name ⇒ Object
Returns the value of attribute name.
-
#swf ⇒ Object
Returns the value of attribute swf.
-
#test_result_file ⇒ Object
Returns the value of attribute test_result_file.
-
#version ⇒ Object
Returns the value of attribute version.
Class Method Summary collapse
- .define_task(args) {|t| ... } ⇒ Object
- .home ⇒ Object
-
.home_paths ⇒ Object
Enumerate the potential locations of the Flash Player Home For each supported Platform, the first existing location will be used.
- .trust ⇒ Object
Instance Method Summary collapse
- #close ⇒ Object
- #define ⇒ Object
- #execute ⇒ Object
-
#initialize(task_name, app) ⇒ FlashPlayerTask
constructor
A new instance of FlashPlayerTask.
- #parse_test_result(line, thread) ⇒ Object
- #read_log(thread, log_file) ⇒ Object
- #run(tool, version, swf) ⇒ Object
- #write_test_result(result) ⇒ Object
Constructor Details
#initialize(task_name, app) ⇒ FlashPlayerTask
Returns a new instance of FlashPlayerTask.
83 84 85 86 87 88 |
# File 'lib/sprout/flash_player_task.rb', line 83 def initialize(task_name, app) super(task_name, app) @version = DEFAULT_VERSION @inside_test_result = false @test_result = '' end |
Instance Attribute Details
#name ⇒ Object
Returns the value of attribute name.
37 38 39 |
# File 'lib/sprout/flash_player_task.rb', line 37 def name @name end |
#swf ⇒ Object
Returns the value of attribute swf.
37 38 39 |
# File 'lib/sprout/flash_player_task.rb', line 37 def swf @swf end |
#test_result_file ⇒ Object
Returns the value of attribute test_result_file.
37 38 39 |
# File 'lib/sprout/flash_player_task.rb', line 37 def test_result_file @test_result_file end |
#version ⇒ Object
Returns the value of attribute version.
37 38 39 |
# File 'lib/sprout/flash_player_task.rb', line 37 def version @version end |
Class Method Details
.define_task(args) {|t| ... } ⇒ Object
42 43 44 45 46 |
# File 'lib/sprout/flash_player_task.rb', line 42 def FlashPlayerTask.define_task(args, &block) t = super yield t if block_given? t.define end |
.home ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/sprout/flash_player_task.rb', line 56 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 |
.home_paths ⇒ Object
Enumerate the potential locations of the Flash Player Home For each supported Platform, the first existing location will be used.
76 77 78 79 80 81 |
# File 'lib/sprout/flash_player_task.rb', line 76 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 |
.trust ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/sprout/flash_player_task.rb', line 48 def FlashPlayerTask.trust if(@@trust) return @@trust end @@trust = File.join(FlashPlayerTask.home, '#Security', 'FlashPlayerTrust', 'sprout.cfg') return @@trust end |
Instance Method Details
#close ⇒ Object
117 118 119 |
# File 'lib/sprout/flash_player_task.rb', line 117 def close Process.kill("SIGALRM", @player_pid) end |
#define ⇒ Object
154 155 156 157 158 159 160 |
# File 'lib/sprout/flash_player_task.rb', line 154 def define task @name => [@swf] if(@test_result_file) CLEAN.add(@test_result_file) end end |
#execute ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/sprout/flash_player_task.rb', line 90 def execute log_file = nil # Don't let trust or log file failures break other features... # begin log_file = FlashPlayerConfig.new().log # FlashPlayerTrust.new(File.dirname(@swf)) if(File.exists?(log_file)) File.open(log_file, 'w') do |f| f.write('') end else FileUtils.mkdir_p(File.dirname(log_file)) FileUtils.touch(log_file) end # rescue # puts '[WARNING] FlashPlayer encountered an error working with the mm.cfg log and/or editing the Trust file' # end @running_process = nil thread = run(EXECUTABLE_NAME, version, swf) read_log(thread, log_file) thread.join end |
#parse_test_result(line, thread) ⇒ Object
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/sprout/flash_player_task.rb', line 187 def parse_test_result(line, thread) if(test_result_file.nil?) return end if(@inside_test_result) if(line.index(@@test_result_post_delimiter)) @inside_test_result = false write_test_result(@test_result) close else @test_result << line end end if(line.index(@@test_result_pre_delimiter)) @inside_test_result = true end end |
#read_log(thread, log_file) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
# File 'lib/sprout/flash_player_task.rb', line 162 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) puts "[trace] #{line}" parse_test_result(line, thread) $stdout.flush lines_put = lines_put + 1 end end end end end |
#run(tool, version, swf) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/sprout/flash_player_task.rb', line 121 def run(tool, version, swf) puts "execute flash player now!" usr = User.new() target = Sprout.get_executable(tool, nil, version) puts "target #{target}" target = User.clean_path(target) @player_pid = nil @swf_pid = nil @parent_pid = nil if(usr.is_a?(OSXUser)) return Thread.new { @player_pid = Process.fork do exec(target) end @swf_pid = Process.fork do exec("open #{swf}") end Process.waitpid(@player_pid) } else return Thread.new { @player_pid = exec("#{target} ./#{swf}") # IO.popen("#{target} ./#{swf}") do |p| # end } end end |
#write_test_result(result) ⇒ Object
207 208 209 210 211 212 |
# File 'lib/sprout/flash_player_task.rb', line 207 def write_test_result(result) FileUtils.makedirs(File.dirname(test_result_file)) File.open(test_result_file, File::CREAT|File::TRUNC|File::RDWR) do |f| f.puts(result) end end |