flashsdk_sqe 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (94) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +41 -0
  3. data/POSTINSTALL.rdoc +81 -0
  4. data/README.textile +79 -0
  5. data/VERSION +1 -0
  6. data/bin/flashlog +8 -0
  7. data/bin/flashplayer +9 -0
  8. data/bin/sprout-as3 +9 -0
  9. data/bin/sprout-flex +8 -0
  10. data/ext/CloseFlashPlayerForDumbassOSX.scpt +6 -0
  11. data/ext/OpenFlashPlayerForDumbassOSX.scpt +12 -0
  12. data/flashsdk_sqe.gemspec +25 -0
  13. data/lib/flashplayer.rb +9 -0
  14. data/lib/flashplayer/errors.rb +12 -0
  15. data/lib/flashplayer/executable.rb +142 -0
  16. data/lib/flashplayer/log_file.rb +100 -0
  17. data/lib/flashplayer/mm_config.rb +96 -0
  18. data/lib/flashplayer/module.rb +51 -0
  19. data/lib/flashplayer/specification.rb +45 -0
  20. data/lib/flashplayer/system_mixins.rb +98 -0
  21. data/lib/flashplayer/task.legacy.rb +293 -0
  22. data/lib/flashplayer/task.rb +62 -0
  23. data/lib/flashplayer/trust.rb +45 -0
  24. data/lib/flashsdk.rb +24 -0
  25. data/lib/flashsdk/acompc.rb +29 -0
  26. data/lib/flashsdk/adl.rb +83 -0
  27. data/lib/flashsdk/adt.rb +276 -0
  28. data/lib/flashsdk/amxmlc.rb +28 -0
  29. data/lib/flashsdk/asdoc.rb +164 -0
  30. data/lib/flashsdk/compc.rb +124 -0
  31. data/lib/flashsdk/compiler_base.rb +1131 -0
  32. data/lib/flashsdk/fcsh.rb +173 -0
  33. data/lib/flashsdk/fcsh_socket.rb +167 -0
  34. data/lib/flashsdk/fdb.rb +833 -0
  35. data/lib/flashsdk/generators/class_generator.rb +87 -0
  36. data/lib/flashsdk/generators/flash_helper.rb +234 -0
  37. data/lib/flashsdk/generators/flex_project_generator.rb +30 -0
  38. data/lib/flashsdk/generators/project_generator.rb +31 -0
  39. data/lib/flashsdk/generators/templates/ActionScript3Class.as +9 -0
  40. data/lib/flashsdk/generators/templates/ActionScript3MainClass.as +11 -0
  41. data/lib/flashsdk/generators/templates/ActionScript3RunnerClass.as +19 -0
  42. data/lib/flashsdk/generators/templates/DefaultProjectImage.png +0 -0
  43. data/lib/flashsdk/generators/templates/Flex4Application.mxml +45 -0
  44. data/lib/flashsdk/generators/templates/Flex4Main.css +7 -0
  45. data/lib/flashsdk/generators/templates/Flex4Rakefile.rb +34 -0
  46. data/lib/flashsdk/generators/templates/Flex4RunnerClass.mxml +29 -0
  47. data/lib/flashsdk/generators/templates/FlexTestRunner.mxml +0 -0
  48. data/lib/flashsdk/generators/templates/Gemfile +5 -0
  49. data/lib/flashsdk/generators/templates/rakefile.rb +79 -0
  50. data/lib/flashsdk/module.rb +107 -0
  51. data/lib/flashsdk/mxmlc.rb +160 -0
  52. data/lib/flex3.rb +54 -0
  53. data/lib/flex4.rb +115 -0
  54. data/pkg/flashsdk_sqe-0.0.1.gem +0 -0
  55. data/rakefile.rb +42 -0
  56. data/test/fixtures/acompc/simple/SomeAirFile.as +11 -0
  57. data/test/fixtures/air/simple/SomeProject.apk +1 -0
  58. data/test/fixtures/air/simple/SomeProject.as +11 -0
  59. data/test/fixtures/air/simple/SomeProject.mxml +9 -0
  60. data/test/fixtures/air/simple/SomeProject.pfx +0 -0
  61. data/test/fixtures/air/simple/SomeProject.swf +0 -0
  62. data/test/fixtures/air/simple/SomeProject.xml +13 -0
  63. data/test/fixtures/asdoc/lib/OtherFile.as +17 -0
  64. data/test/fixtures/asdoc/src/SomeFile.as +11 -0
  65. data/test/fixtures/compc/simple/SomeFile.as +11 -0
  66. data/test/fixtures/flashplayer/AsUnit Runner.swf +0 -0
  67. data/test/fixtures/mxmlc/broken/SomeFile.as +10 -0
  68. data/test/fixtures/mxmlc/simple/SomeFile.as +11 -0
  69. data/test/fixtures/sdk/fdb +90 -0
  70. data/test/fixtures/sdk/mxmlc +56 -0
  71. data/test/unit/acompc_test.rb +37 -0
  72. data/test/unit/adl_test.rb +32 -0
  73. data/test/unit/adt_test.rb +185 -0
  74. data/test/unit/amxmlc_test.rb +55 -0
  75. data/test/unit/asdoc_test.rb +45 -0
  76. data/test/unit/class_generator_test.rb +56 -0
  77. data/test/unit/compc_test.rb +37 -0
  78. data/test/unit/fake_flashplayer_system.rb +11 -0
  79. data/test/unit/fcsh_socket_test.rb +53 -0
  80. data/test/unit/fcsh_test.rb +55 -0
  81. data/test/unit/fdb_test.rb +54 -0
  82. data/test/unit/flash_helper_test.rb +43 -0
  83. data/test/unit/flashplayer_executable_test.rb +69 -0
  84. data/test/unit/flashplayer_log_file_test.rb +47 -0
  85. data/test/unit/flashplayer_mm_config_test.rb +74 -0
  86. data/test/unit/flashplayer_module_test.rb +56 -0
  87. data/test/unit/flashplayer_task_test.rb +91 -0
  88. data/test/unit/flashplayer_trust_test.rb +30 -0
  89. data/test/unit/flex_compiler_options_test.rb +213 -0
  90. data/test/unit/flex_generator_test.rb +37 -0
  91. data/test/unit/mxmlc_test.rb +65 -0
  92. data/test/unit/project_generator_test.rb +57 -0
  93. data/test/unit/test_helper.rb +18 -0
  94. metadata +200 -0
@@ -0,0 +1,100 @@
1
+
2
+ module FlashPlayer
3
+
4
+ class LogFile
5
+
6
+ attr_accessor :logger
7
+ attr_accessor :player_pid
8
+
9
+ def initialize
10
+ @logger = $stdout
11
+ super
12
+ end
13
+
14
+ def tail(thread = nil, player_pid = nil)
15
+ self.player_pid = player_pid
16
+ tail_path flashlog_path, thread
17
+ end
18
+
19
+ private
20
+
21
+ def tail_path path, thread=nil
22
+ logger.puts ">> Tailing '#{path}', press CTRL+C to quit"
23
+ create_flashlog_at path
24
+ clear_flashlog_at path
25
+ read_flashlog_at path, thread
26
+ end
27
+
28
+ def read_flashlog_at path, thread=nil
29
+ thread ||= fake_thread
30
+ lines_put = 0
31
+
32
+ while thread.alive? do
33
+ lines_put, last_line = read_from_file path, lines_put
34
+ logger.flush
35
+ sleep(0.1)
36
+
37
+ unless last_line.nil?
38
+ thread.kill
39
+ Process.kill('KILL', self.player_pid) if self.player_pid
40
+ end
41
+ end
42
+ end
43
+
44
+ def read_from_file path, lines_put
45
+ last_line = nil
46
+ File.open(path, 'r') do |file|
47
+ lines_read = 0
48
+ file.readlines.each do |line|
49
+ last_line = line if line =~ /ALL TESTS ARE COMPLETED/
50
+ if(lines_read >= lines_put)
51
+ logger.puts "[trace] #{line}"
52
+ logger.flush
53
+ lines_put += 1
54
+ end
55
+ lines_read += 1
56
+ end
57
+ end unless !File.exists?(path)
58
+ [lines_put, last_line]
59
+ end
60
+
61
+ def flashlog_path
62
+ begin
63
+ FlashPlayer.flashlog
64
+ rescue FlashPlayer::PathError
65
+ "/dev/null"
66
+ end
67
+ end
68
+
69
+ def clear_flashlog_at path
70
+ File.open(path, 'w') do |f|
71
+ f.write('')
72
+ end
73
+ end
74
+
75
+ def create_flashlog_at path
76
+ if(!File.exists?(path))
77
+ FileUtils.makedirs(File.dirname(path))
78
+ FileUtils.touch(path)
79
+ end
80
+ end
81
+
82
+ def fake_thread
83
+ Thread.new do
84
+ while true
85
+ sleep(0.2)
86
+ end
87
+ end
88
+ end
89
+
90
+ end
91
+ end
92
+
93
+ desc "Tail the flashlog.txt and block (until CTRL+C)"
94
+ task :flashlog do
95
+ mm_config = FlashPlayer::MMConfig.new
96
+ mm_config.create
97
+ reader = FlashPlayer::LogFile.new
98
+ reader.tail
99
+ end
100
+
@@ -0,0 +1,96 @@
1
+
2
+ module FlashPlayer
3
+
4
+ class MMConfig
5
+ FILE_NAME = 'mm.cfg'
6
+
7
+ attr_accessor :logger
8
+
9
+ def initialize
10
+ @file_name = FILE_NAME
11
+ @logger = $stdout
12
+ end
13
+
14
+ def create
15
+ create_if_necessary_at config_path
16
+ end
17
+
18
+ private
19
+
20
+ def create_if_necessary_at path
21
+ if(File.exists?(File.dirname(path)))
22
+ write_config(path, content(flashlog_path)) if(file_blank?(path))
23
+ end
24
+ end
25
+
26
+ def config_path
27
+ if(flashplayer_home == osx_fp9_dir)
28
+ path = File.join(osx_fp9_dir, @file_name)
29
+ else
30
+ path = File.join(system_home, @file_name)
31
+ end
32
+ end
33
+
34
+ def flashplayer_home
35
+ FlashPlayer.home
36
+ end
37
+
38
+ def flashlog_path
39
+ FlashPlayer.flashlog
40
+ end
41
+
42
+ def file_blank?(file)
43
+ !File.exists?(file) || File.read(file).empty?
44
+ end
45
+
46
+ def write_config(location, content)
47
+ if(user_confirmation?(location))
48
+ FileUtils.makedirs File.dirname(location)
49
+
50
+ File.open(location, 'w') do |f|
51
+ f.write(content)
52
+ end
53
+ logger.puts ">> Created file: " + File.expand_path(location)
54
+ location
55
+ else
56
+ raise FlashPlayer::PathError.new("Unable to create #{location}")
57
+ end
58
+ end
59
+
60
+ def content(flashlog)
61
+ return <<EOF
62
+ ErrorReportingEnable=1
63
+ MaxWarnings=0
64
+ TraceOutputEnable=1
65
+ TraceOutputFileName=#{flashlog}
66
+ EOF
67
+ end
68
+
69
+ def user_confirmation?(location)
70
+ puts <<EOF
71
+
72
+ Correctly configured mm.cfg file not found at: #{location}
73
+
74
+ This file is required in order to capture trace output.
75
+
76
+ Would you like this file created automatically? [Yn]
77
+
78
+ EOF
79
+ answer = $stdin.gets.chomp.downcase
80
+ return (answer == 'y' || answer == '')
81
+ end
82
+
83
+ def osx_fp9_dir
84
+ File.join(system_library, 'Application Support', 'Macromedia')
85
+ end
86
+
87
+ def system_library
88
+ Sprout.current_system.library
89
+ end
90
+
91
+ def system_home
92
+ Sprout.current_system.home
93
+ end
94
+ end
95
+ end
96
+
@@ -0,0 +1,51 @@
1
+
2
+ module FlashPlayer
3
+ NAME = 'flashplayer'
4
+ VERSION = '11.1.102'
5
+
6
+ class << self
7
+
8
+ def home
9
+ # NOTE: Look up the value every time,
10
+ # this way we're not storing state globally
11
+ # and the performance penalty is minimal...
12
+ home_paths.each do |path|
13
+ return path if File.exists?(path)
14
+ end
15
+ raise FlashPlayer::PathError.new('FlashPlayer unable to find home folder for your System')
16
+ end
17
+
18
+ def trust
19
+ File.join home, '#Security', 'FlashPlayerTrust', 'sprout.cfg'
20
+ end
21
+
22
+ def flashlog
23
+ File.join home, 'Logs', 'flashlog.txt'
24
+ end
25
+
26
+ private
27
+
28
+ def system_home
29
+ Sprout.current_system.home
30
+ end
31
+
32
+ def system_library
33
+ Sprout.current_system.library
34
+ end
35
+
36
+ # Collection of the potential locations of the Flash Player Home
37
+ # For each supported Platform, the first existing location
38
+ # will be used.
39
+ def home_paths
40
+ [
41
+ File.join(system_library, 'Preferences', 'Macromedia', 'Flash Player'),
42
+ File.join(system_library, 'Application Support', 'Macromedia'),
43
+ File.join(system_home, 'Application Data', 'Macromedia', 'Flash Player'),
44
+ File.join(system_home, 'AppData', 'Roaming', 'Macromedia', 'Flash Player'),
45
+ File.join(system_home, '.macromedia', 'Flash_Player')
46
+ ]
47
+ end
48
+
49
+ end
50
+ end
51
+
@@ -0,0 +1,45 @@
1
+ require 'flashsdk'
2
+
3
+ ##
4
+ # This is the Flash Player Sprout::Specification and is how
5
+ # we figure out from where to load the Flash Player for the
6
+ # current user system.
7
+ Sprout::Specification.new do |s|
8
+ s.name = FlashPlayer::NAME
9
+ s.version = FlashPlayer::VERSION
10
+
11
+ ##
12
+ # NOTE: The order of these declarations is important, the RubyFeature.load method
13
+ # will search for the first match that is appropriate for the end user system.
14
+ #
15
+ # Current releases of the Ruby One-Click Installer for Windows actually
16
+ # run on top of Mingw, and OSX is a *nix variant, which means that
17
+ # all System types (in Ruby at least) derive from UnixSystem.
18
+ #
19
+ # This means that the Linux/Unix declaration will
20
+ # match everyone, so it is effectively the same as ':universal'
21
+ s.add_remote_file_target do |t|
22
+ t.platform = :windows
23
+ t.archive_type = :exe
24
+ t.url = "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug_32bit.exe"
25
+ t.url = "http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.exe"
26
+ t.md5 = "6fbc96203b878529a5baefe2226a403e"
27
+ t.add_executable :flashplayer, "5f7f4c4246784745b0e1b5593e9bc60f.exe"
28
+ end
29
+
30
+ s.add_remote_file_target do |t|
31
+ t.platform = :osx
32
+ t.archive_type = :zip
33
+ t.url = "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.app.zip"
34
+ t.md5 = "861e7b57ffae780ba391ac6adcb40a0d"
35
+ t.add_executable :flashplayer, "Flash Player Debugger.app"
36
+ end
37
+
38
+ s.add_remote_file_target do |t|
39
+ t.platform = :linux
40
+ t.archive_type = :tgz
41
+ t.url = "http://fpdownload.macromedia.com/pub/flashplayer/updaters/11/flashplayer_11_sa_debug.i386.tar.gz"
42
+ t.md5 = "2d5d0da2bcf4b76afe75f7a113f4f3f1"
43
+ t.add_executable :flashplayer, "flashplayerdebugger"
44
+ end
45
+ end
@@ -0,0 +1,98 @@
1
+
2
+ module Sprout
3
+
4
+ module System
5
+
6
+ class WinSystem
7
+
8
+ def open_flashplayer_with exe, swf
9
+ return Thread.new {
10
+ execute exe, swf
11
+ }
12
+ end
13
+ end
14
+
15
+ class OSXSystem < UnixSystem
16
+
17
+ ##
18
+ # Use AppleScript to open the specified Flash Player
19
+ # because, simply launching the executable does not focus
20
+ # it.
21
+ def open_flashplayer_with exe, swf
22
+ # Clean paths differently for this exectuable,
23
+ # because we're forking out to AppleScript over
24
+ # a new process, and spaces need to be escaped.
25
+ @player_exe = exe.split(' ').join('\ ')
26
+
27
+ wrapper = []
28
+ wrapper << "osascript"
29
+ wrapper << open_flashplayer_script_path
30
+ wrapper << @player_exe
31
+
32
+ # Call the UnixSystem.open_flashplayer_with method:
33
+ super wrapper.join(" "), File.expand_path(swf)
34
+ end
35
+
36
+ private
37
+
38
+ ##
39
+ # Use AppleScript to close the Flash Player
40
+ def close_flashplayer
41
+ closer = []
42
+ closer << "osascript"
43
+ closer << close_flashplayer_script_path
44
+ closer << @player_exe
45
+ `#{closer.join(" ")}`
46
+ end
47
+
48
+ def ext_gem_path
49
+ File.join(File.dirname(__FILE__), '..', '..', 'ext')
50
+ end
51
+
52
+ def close_flashplayer_script_path
53
+ File.expand_path(File.join(ext_gem_path, "CloseFlashPlayerForDumbassOSX.scpt"))
54
+ end
55
+
56
+ def open_flashplayer_script_path
57
+ File.expand_path(File.join(ext_gem_path, "OpenFlashPlayerForDumbassOSX.scpt"))
58
+ end
59
+
60
+ end
61
+
62
+ # All others inherit from this class
63
+ class UnixSystem
64
+
65
+ def open_flashplayer_with exe, swf
66
+ player_open = false
67
+ trap("INT") {
68
+ close_flashplayer
69
+ @player_thread.kill
70
+ }
71
+
72
+ @player_thread = Thread.new {
73
+ require 'open4'
74
+ @player_pid, stdin, stdout, stderr = Open4.popen4("#{exe} #{swf}")
75
+ player_open = true
76
+ stdout.read
77
+ }
78
+
79
+ # Wait until the player process has actually
80
+ # openned...
81
+ while !player_open
82
+ sleep 0.1
83
+ end
84
+
85
+ [@player_thread, @player_pid]
86
+ end
87
+
88
+ private
89
+
90
+ def close_flashplayer
91
+ # Don't need to do anything - created
92
+ # this method to handle belligerent OS X trash.
93
+ end
94
+
95
+ end
96
+ end
97
+ end
98
+
@@ -0,0 +1,293 @@
1
+
2
+ =begin
3
+
4
+ class FlashPlayerTask < Rake::Task
5
+ # This is the opening prelude to a collection of test results. When the
6
+ # task encounters this string in the trace output log file, it will begin
7
+ # collecting trace statements with the expectation that the following
8
+ # strings will be well-formatted XML data matching what JUnit emits for
9
+ # Cruise Control.
10
+ #
11
+ # See the lib/asunit3/asunit.framework.XMLResultPrinter for more information.
12
+ @@test_result_pre_delimiter = '<XMLResultPrinter>'
13
+
14
+ # This is the closing string that will indicate the end of test result XML data
15
+ @@test_result_post_delimiter = '</XMLResultPrinter>'
16
+
17
+ @@home = nil
18
+ @@trust = nil
19
+
20
+ def initialize(task_name, app)
21
+ super(task_name, app)
22
+ @default_gem_name = 'sprout-flashplayer-tool'
23
+ @default_gem_version = '10.22.0'
24
+ @default_result_file = 'AsUnitResults.xml'
25
+ @inside_test_result = false
26
+ end
27
+
28
+ def self.define_task(args, &block)
29
+ t = super
30
+ yield t if block_given?
31
+ t.define
32
+ end
33
+
34
+ # Local system path to the Flash Player Trust file
35
+ def FlashPlayerTask.trust
36
+ if(@@trust)
37
+ return @@trust
38
+ end
39
+ @@trust = File.join(FlashPlayerTask.home, '#Security', 'FlashPlayerTrust', 'sprout.cfg')
40
+ return @@trust
41
+ end
42
+
43
+ # Local system path to where the Flash Player stores trace output logs and trust files
44
+ def FlashPlayerTask.home
45
+ if(@@home)
46
+ return @@home
47
+ end
48
+
49
+ FlashPlayerTask.home_paths.each do |path|
50
+ if(File.exists?(path))
51
+ return @@home = path
52
+ end
53
+ end
54
+
55
+ if(@@home.nil?)
56
+ raise FlashPlayerError.new('FlashPlayer unable to find home folder for your platform')
57
+ end
58
+ return @@home
59
+ end
60
+
61
+ # Collection of the potential locations of the Flash Player Home
62
+ # For each supported Platform, the first existing location
63
+ # will be used.
64
+ def FlashPlayerTask.home_paths
65
+ return [File.join(User.library, 'Preferences', 'Macromedia', 'Flash Player'),
66
+ File.join(User.library, 'Application Support', 'Macromedia'),
67
+ File.join(User.home, 'Application Data', 'Macromedia', 'Flash Player'),
68
+ File.join(User.home, 'AppData', 'Roaming', 'Macromedia', 'Flash Player'),
69
+ File.join(User.home, '.macromedia', 'Flash_Player')]
70
+ end
71
+
72
+ # The swf parameter can be set explicitly in the block sent to this task as in:
73
+ #
74
+ # flashplayer :run do |t|
75
+ # t.swf = 'bin/SomeProject.swf'
76
+ # end
77
+ #
78
+ # Or it can be set implicitly as a rake prerequisite as follows:
79
+ #
80
+ # flashplayer :run => 'bin/SomeProject' do |t|
81
+ # end
82
+ #
83
+ def swf=(swf)
84
+ @swf = swf
85
+ end
86
+
87
+ def swf
88
+ @swf ||= nil
89
+ if(@swf.nil?)
90
+ prerequisites.each do |req|
91
+ if(req.index('.swf'))
92
+ @swf = req.to_s
93
+ break
94
+ end
95
+ end
96
+ end
97
+ return @swf
98
+ end
99
+
100
+ def gem_version=(version)
101
+ @gem_version = version
102
+ end
103
+
104
+ def gem_version
105
+ return @gem_version ||= nil
106
+ end
107
+
108
+ # Full name of the sprout tool gem that this tool task will use.
109
+ # This defaults to sprout-flashplayer-tool
110
+ def gem_name=(name)
111
+ @gem_name = name
112
+ end
113
+
114
+ def gem_name
115
+ return @gem_name ||= @default_gem_name
116
+ end
117
+
118
+ # The File where JUnit test results should be written. This value
119
+ # defaults to 'AsUnitResults.xml'
120
+ #
121
+ def test_result_file=(file)
122
+ @test_result_file = file
123
+ end
124
+
125
+ def test_result_file
126
+ @test_result_file ||= @default_result_file
127
+ end
128
+
129
+ def test_result
130
+ @test_result ||= ''
131
+ end
132
+
133
+ def define
134
+ CLEAN.add(test_result_file)
135
+ end
136
+
137
+ def execute(*args)
138
+ super
139
+ raise FlashPlayerError.new("FlashPlayer task #{name} required field swf is nil") unless swf
140
+
141
+ log_file = nil
142
+
143
+ # Don't let trust or log file failures break other features...
144
+ begin
145
+ config = FlashPlayerConfig.new
146
+ log_file = config.log_file
147
+ FlashPlayerTrust.new(File.expand_path(File.dirname(swf)))
148
+
149
+ if(File.exists?(log_file))
150
+ File.open(log_file, 'w') do |f|
151
+ f.write('')
152
+ end
153
+ else
154
+ FileUtils.makedirs(File.dirname(log_file))
155
+ FileUtils.touch(log_file)
156
+ end
157
+ rescue StandardError => e
158
+ logger.puts '[WARNING] FlashPlayer encountered an error working with the mm.cfg log and/or editing the Trust file'
159
+ end
160
+
161
+ @running_process = nil
162
+ @thread = run(gem_name, gem_version, swf)
163
+ read_log(@thread, log_file) unless log_file.nil?
164
+ @thread.join
165
+ end
166
+
167
+ def run(tool, gem_version, swf)
168
+ path_to_exe = Sprout.get_executable(tool, nil, gem_version)
169
+ target = User.clean_path(path_to_exe)
170
+ @player_pid = nil
171
+
172
+ thread_out = $stdout
173
+ command = "#{target} #{User.clean_path(swf)}"
174
+
175
+ usr = User.new()
176
+ if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser))
177
+ return Thread.new {
178
+ system command
179
+ }
180
+ elsif usr.is_a?(OSXUser)
181
+ require 'clix_flash_player'
182
+ @clix_player = CLIXFlashPlayer.new
183
+ @clix_player.execute(target, swf)
184
+ return @clix_player
185
+ else
186
+ return Thread.new {
187
+ require 'open4'
188
+ @player_pid, stdin, stdout, stderr = Open4.popen4(command)
189
+ stdout.read
190
+ }
191
+ end
192
+ end
193
+
194
+ def close
195
+ usr = User.new
196
+ if(usr.is_a?(WinUser))
197
+ Thread.kill(@thread)
198
+ elsif(usr.is_a?(OSXUser))
199
+ @clix_player.kill unless @clix_player.nil?
200
+ else
201
+ Process.kill("SIGALRM", @player_pid)
202
+ end
203
+ end
204
+
205
+ def read_log(thread, log_file)
206
+ lines_put = 0
207
+
208
+ if(log_file.nil?)
209
+ raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file because the expected location was nil')
210
+ end
211
+
212
+ if(!File.exists?(log_file))
213
+ raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file in the expected location: ' + log_file)
214
+ end
215
+
216
+ while(thread.alive?)
217
+ sleep(0.2)
218
+ lines_read = 0
219
+
220
+ File.open(log_file, 'r') do |file|
221
+ file.readlines.each do |line|
222
+ lines_read = lines_read + 1
223
+ if(lines_read > lines_put)
224
+ if(!parse_test_result(line, thread))
225
+ logger.puts "[trace] #{line}"
226
+ end
227
+ $stdout.flush
228
+ lines_put = lines_put + 1
229
+ end
230
+ end
231
+ end
232
+ end
233
+ end
234
+
235
+ # Returns true if inside of a test result
236
+ def parse_test_result(line, thread)
237
+ if(@inside_test_result)
238
+ if(line.index(@@test_result_post_delimiter))
239
+ @inside_test_result = false
240
+ write_test_result(test_result)
241
+ close
242
+ examine_test_result test_result
243
+ return true
244
+ else
245
+ test_result << line
246
+ end
247
+ end
248
+
249
+ if(line.index(@@test_result_pre_delimiter))
250
+ @inside_test_result = true
251
+ end
252
+
253
+ return @inside_test_result
254
+ end
255
+
256
+ def write_test_result(result)
257
+ FileUtils.makedirs(File.dirname(test_result_file))
258
+ File.open(test_result_file, File::CREAT|File::TRUNC|File::RDWR) do |f|
259
+ f.puts(result)
260
+ end
261
+ end
262
+
263
+ def examine_test_result(result)
264
+ require 'rexml/document'
265
+ doc = nil
266
+ begin
267
+ doc = REXML::Document.new(result)
268
+ rescue REXML::ParseException => e
269
+ puts "[WARNING] Invalid test results encountered"
270
+ return
271
+ end
272
+
273
+ # Handle JUnit Failures
274
+ failures = []
275
+
276
+ doc.elements.each('/testsuites/testsuite/testsuite/testcase/error') do |element|
277
+ failures << element.text
278
+ end
279
+
280
+ doc.elements.each("/testsuites/testsuite/testsuite/testcase/failure") do |element|
281
+ failures << element.text
282
+ end
283
+
284
+ if(failures.size > 0)
285
+ raise AssertionFailure.new("[ERROR] Test Failures Encountered \n#{failures.join("\n")}")
286
+ end
287
+ end
288
+
289
+ end
290
+
291
+ =end
292
+
293
+