flashplayer 9.115.0 → 10.1.1.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +9 -0
- data/VERSION +1 -0
- data/flashplayer.gemspec +22 -0
- data/lib/flashplayer.rb +13 -0
- data/lib/flashplayer/clix_flash_player.rb +92 -0
- data/lib/flashplayer/clix_wrapper.rb +22 -0
- data/lib/flashplayer/errors.rb +12 -0
- data/lib/flashplayer/log_file.rb +79 -0
- data/lib/flashplayer/mm_config.rb +88 -0
- data/lib/flashplayer/module.rb +52 -0
- data/lib/flashplayer/specification.rb +31 -0
- data/lib/flashplayer/task.rb +408 -0
- data/lib/flashplayer/trust.rb +44 -0
- data/rakefile.rb +20 -0
- data/test/fixtures/AsUnit4.swf +0 -0
- data/test/unit/flashplayer_test.rb +56 -0
- data/test/unit/log_file_test.rb +36 -0
- data/test/unit/mm_config_test.rb +47 -0
- data/test/unit/task_test.rb +36 -0
- data/test/unit/test_helper.rb +16 -0
- data/test/unit/trust_test.rb +31 -0
- metadata +118 -52
- data/LICENSE +0 -83
- data/bin/flashplayer +0 -11
- data/lib/sprout.spec +0 -20
- data/lib/sprout/flash_player/version.rb +0 -12
data/Gemfile
ADDED
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
10.1.1.pre
|
data/flashplayer.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path File.dirname(__FILE__), 'lib'
|
3
|
+
$:.unshift lib unless $:.include?(lib)
|
4
|
+
|
5
|
+
require 'bundler'
|
6
|
+
Bundler.setup
|
7
|
+
|
8
|
+
require 'flashplayer'
|
9
|
+
|
10
|
+
Gem::Specification.new do |s|
|
11
|
+
s.name = FlashPlayer::NAME
|
12
|
+
s.version = FlashPlayer::VERSION
|
13
|
+
s.author = "Luke Bayes"
|
14
|
+
s.email = "projectsprouts@googlegroups.com"
|
15
|
+
s.homepage = "http://www.adobe.com/products/flex"
|
16
|
+
s.summary = "Adobe Flash Player"
|
17
|
+
s.description = "The Adobe Flash Player"
|
18
|
+
s.files = FileList['**/**/*'].exclude /.git|.svn|.DS_Store/
|
19
|
+
s.add_bundler_dependencies
|
20
|
+
s.require_paths << 'lib'
|
21
|
+
end
|
22
|
+
|
data/lib/flashplayer.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'sprout'
|
2
|
+
|
3
|
+
lib = File.expand_path File.dirname(__FILE__)
|
4
|
+
$:.unshift lib unless $:.include?(lib)
|
5
|
+
|
6
|
+
require 'flashplayer/errors'
|
7
|
+
require 'flashplayer/module'
|
8
|
+
require 'flashplayer/mm_config'
|
9
|
+
require 'flashplayer/trust'
|
10
|
+
require 'flashplayer/log_file'
|
11
|
+
require 'flashplayer/task'
|
12
|
+
require 'flashplayer/specification'
|
13
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'open4'
|
3
|
+
|
4
|
+
$CLIX_WRAPPER_TARGET = File.join(File.expand_path(File.dirname(__FILE__)), 'clix_wrapper.rb')
|
5
|
+
|
6
|
+
class CLIXFlashPlayerError < StandardError; end
|
7
|
+
|
8
|
+
class CLIXFlashPlayer
|
9
|
+
VERSION = '0.1.0'
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@activate_pid = nil
|
13
|
+
@player_pid = nil
|
14
|
+
@thread = nil
|
15
|
+
end
|
16
|
+
|
17
|
+
def execute(player, swf)
|
18
|
+
cleanup
|
19
|
+
player = clean_path(player)
|
20
|
+
swf = clean_path(swf)
|
21
|
+
validate(player, swf)
|
22
|
+
|
23
|
+
if(!player.match('Contents/MacOS'))
|
24
|
+
player = File.join(player, 'Contents', 'MacOS', 'Flash Player')
|
25
|
+
end
|
26
|
+
|
27
|
+
setup_trap
|
28
|
+
|
29
|
+
@thread = Thread.new {
|
30
|
+
@player_pid = open4.popen4("#{player.split(' ').join('\ ')}")[0]
|
31
|
+
begin
|
32
|
+
raise "clix_wrapper.rb could not be found at: #{wrapper}" if !File.exists?($CLIX_WRAPPER_TARGET)
|
33
|
+
command = "ruby #{$CLIX_WRAPPER_TARGET} '#{player}' '#{swf}'"
|
34
|
+
@activate_pid, stdin, stdout, stderr = open4.popen4(command)
|
35
|
+
$stdout.puts stdout.read
|
36
|
+
error = stderr.read
|
37
|
+
raise error if !error.nil? && error != ''
|
38
|
+
Process.wait(@player_pid)
|
39
|
+
rescue StandardError => e
|
40
|
+
$stdout.puts e.to_s
|
41
|
+
kill
|
42
|
+
raise e
|
43
|
+
end
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def kill
|
48
|
+
system("kill -9 #{@player_pid}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def join
|
52
|
+
if(@thread.alive?)
|
53
|
+
@thread.join
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def alive?
|
58
|
+
return @thread.alive?
|
59
|
+
end
|
60
|
+
|
61
|
+
private
|
62
|
+
|
63
|
+
def clean_path(path)
|
64
|
+
File.expand_path(path.gsub("'", '').gsub("\\", ''))
|
65
|
+
end
|
66
|
+
|
67
|
+
def cleanup
|
68
|
+
if(@thread && @thread.alive?)
|
69
|
+
kill
|
70
|
+
@thread.join
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def validate(player, swf)
|
75
|
+
raise CLIXFlashPlayerError.new("Player must not be nil") if(player.nil? || player == '')
|
76
|
+
raise CLIXFlashPlayerError.new("Player cannot be found: '#{player}'") if(!File.exists?(player))
|
77
|
+
raise CLIXFlashPlayerError.new("SWF must not be nil") if(swf.nil? || swf == '')
|
78
|
+
raise CLIXFlashPlayerError.new("SWF cannot be found: '#{swf}'") if(!File.exists?(swf))
|
79
|
+
end
|
80
|
+
|
81
|
+
def setup_trap
|
82
|
+
# Trap the CTRL+C Interrupt signal
|
83
|
+
# Which prevents nasty exception messages
|
84
|
+
Kernel.trap('INT') do
|
85
|
+
if(@thread.alive?)
|
86
|
+
@thread.kill
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
require 'rubygems'
|
3
|
+
|
4
|
+
player = ARGV[0]
|
5
|
+
swf = ARGV[1]
|
6
|
+
|
7
|
+
raise "CLIXWrapper requires 'player' argument like:\nruby clix_wrapper [player] [swf]" if(player.nil?)
|
8
|
+
raise "CLIXWrapper could not find player at '#{player}'" if !File.exists?(player)
|
9
|
+
|
10
|
+
raise "CLIXWrapper requires 'swf' argument like:\nruby clix_wrapper [player] [swf]" if(swf.nil?)
|
11
|
+
raise "CLIXWrapper could not find swf at '#{swf}'" if !File.exists?(swf)
|
12
|
+
|
13
|
+
begin
|
14
|
+
require 'appscript'
|
15
|
+
# Give the player focus:
|
16
|
+
Appscript.app(player).activate
|
17
|
+
# Open the SWF:
|
18
|
+
Appscript.app(player).open(MacTypes::Alias.path(swf))
|
19
|
+
rescue LoadError => e
|
20
|
+
raise "\n\n[ERROR] You must install the rb-appscript gem to use the desktop debug Flash Player, you do this by running:\n\nsudo gem install rb-appscript"
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,79 @@
|
|
1
|
+
|
2
|
+
module FlashPlayer
|
3
|
+
|
4
|
+
class LogFile
|
5
|
+
|
6
|
+
attr_accessor :logger
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@config = MMConfig.new
|
10
|
+
@logger = $stdout
|
11
|
+
end
|
12
|
+
|
13
|
+
def tail thread
|
14
|
+
@config.create
|
15
|
+
tail_path flashlog_path, thread
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def tail_path path, thread=nil
|
21
|
+
logger.puts ">> Tailing '#{path}', press CTRL+C to quit"
|
22
|
+
create_flashlog_at path
|
23
|
+
clear_flashlog_at path
|
24
|
+
read_flashlog_at path, thread
|
25
|
+
end
|
26
|
+
|
27
|
+
def read_flashlog_at path, thread=nil
|
28
|
+
thread ||= Thread.new{}
|
29
|
+
lines_put = 0
|
30
|
+
|
31
|
+
trap("INT") { thread.kill }
|
32
|
+
|
33
|
+
while thread.alive? do
|
34
|
+
File.open(path, 'r') do |file|
|
35
|
+
lines_read = 0
|
36
|
+
file.readlines.each do |line|
|
37
|
+
if(lines_read >= lines_put)
|
38
|
+
logger.puts "[trace] #{line}"
|
39
|
+
logger.flush
|
40
|
+
lines_put += 1
|
41
|
+
end
|
42
|
+
lines_read += 1
|
43
|
+
end
|
44
|
+
end
|
45
|
+
logger.flush
|
46
|
+
sleep(0.2)
|
47
|
+
end
|
48
|
+
|
49
|
+
logger.puts ""
|
50
|
+
logger.puts ">> Exiting from tailing '#{path}' at user request"
|
51
|
+
end
|
52
|
+
|
53
|
+
def flashlog_path
|
54
|
+
File.join(FlashPlayer.home, 'Logs', 'flashlog.txt')
|
55
|
+
end
|
56
|
+
|
57
|
+
def clear_flashlog_at path
|
58
|
+
File.open(path, 'w') do |f|
|
59
|
+
f.write('')
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def create_flashlog_at path
|
64
|
+
if(!File.exists?(path))
|
65
|
+
FileUtils.makedirs(File.dirname(path))
|
66
|
+
FileUtils.touch(path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
desc "Tail the flashlog.txt and block"
|
74
|
+
def flashlog args
|
75
|
+
task args do
|
76
|
+
reader = FlashPlayer::LogFile.new
|
77
|
+
reader.tail
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,88 @@
|
|
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
|
+
write_config(path, content(path)) if(file_blank?(path))
|
22
|
+
end
|
23
|
+
|
24
|
+
def flashplayer_home
|
25
|
+
FlashPlayer.home
|
26
|
+
end
|
27
|
+
|
28
|
+
def config_path
|
29
|
+
if(flashplayer_home == osx_fp9_dir)
|
30
|
+
path = File.join(osx_fp9_dir, @file_name)
|
31
|
+
else
|
32
|
+
path = File.join(system_home, @file_name)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def file_blank?(file)
|
37
|
+
!File.exists?(file) || File.read(file).empty?
|
38
|
+
end
|
39
|
+
|
40
|
+
def write_config(location, content)
|
41
|
+
if(user_confirmation?(location))
|
42
|
+
File.open(location, 'w') do |f|
|
43
|
+
f.write(content)
|
44
|
+
end
|
45
|
+
logger.puts ">> Created file: " + File.expand_path(location)
|
46
|
+
location
|
47
|
+
else
|
48
|
+
raise FlashPlayer::PathError.new("Unable to create #{file_name} at: #{location}")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def content(file)
|
53
|
+
return <<EOF
|
54
|
+
ErrorReportingEnable=1
|
55
|
+
MaxWarnings=0
|
56
|
+
TraceOutputEnable=1
|
57
|
+
TraceOutputFileName=#{file}
|
58
|
+
EOF
|
59
|
+
end
|
60
|
+
|
61
|
+
def user_confirmation?(location)
|
62
|
+
puts <<EOF
|
63
|
+
|
64
|
+
Correctly configured mm.cfg file not found at: #{location}
|
65
|
+
|
66
|
+
This file is required in order to capture trace output.
|
67
|
+
|
68
|
+
Would you like this file created automatically? [Yn]
|
69
|
+
|
70
|
+
EOF
|
71
|
+
answer = $stdin.gets.chomp.downcase
|
72
|
+
return (answer == 'y' || answer == '')
|
73
|
+
end
|
74
|
+
|
75
|
+
def osx_fp9_dir
|
76
|
+
File.join(system_library, 'Application Support', 'Macromedia')
|
77
|
+
end
|
78
|
+
|
79
|
+
def system_library
|
80
|
+
Sprout.current_system.library
|
81
|
+
end
|
82
|
+
|
83
|
+
def system_home
|
84
|
+
Sprout.current_system.home
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
|
2
|
+
module FlashPlayer
|
3
|
+
NAME = 'flashplayer'
|
4
|
+
|
5
|
+
# Do this craptastic, otherwise we get a carriage return
|
6
|
+
# after our version, and that poops on our archive folder
|
7
|
+
# after downloading...
|
8
|
+
version_file = File.join(File.dirname(__FILE__), '..', '..', 'VERSION')
|
9
|
+
VERSION = File.read(version_file).gsub("\n", '')
|
10
|
+
|
11
|
+
class << self
|
12
|
+
|
13
|
+
def home
|
14
|
+
# NOTE: Look up the value every time,
|
15
|
+
# this way we're not storing state globally
|
16
|
+
# and the performance penalty is minimal...
|
17
|
+
home_paths.each do |path|
|
18
|
+
return path if File.exists?(path)
|
19
|
+
end
|
20
|
+
raise FlashPlayer::PathError.new('FlashPlayer unable to find home folder for your System')
|
21
|
+
end
|
22
|
+
|
23
|
+
def trust
|
24
|
+
File.join(home, '#Security', 'FlashPlayerTrust', 'sprout.cfg')
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def system_home
|
30
|
+
Sprout.current_system.home
|
31
|
+
end
|
32
|
+
|
33
|
+
def system_library
|
34
|
+
Sprout.current_system.library
|
35
|
+
end
|
36
|
+
|
37
|
+
# Collection of the potential locations of the Flash Player Home
|
38
|
+
# For each supported Platform, the first existing location
|
39
|
+
# will be used.
|
40
|
+
def home_paths
|
41
|
+
[
|
42
|
+
File.join(system_library, 'Preferences', 'Macromedia', 'Flash Player'),
|
43
|
+
File.join(system_library, 'Application Support', 'Macromedia'),
|
44
|
+
File.join(system_home, 'Application Data', 'Macromedia', 'Flash Player'),
|
45
|
+
File.join(system_home, 'AppData', 'Roaming', 'Macromedia', 'Flash Player'),
|
46
|
+
File.join(system_home, '.macromedia', 'Flash_Player')
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,31 @@
|
|
1
|
+
|
2
|
+
Sprout::Specification.new do |s|
|
3
|
+
s.name = FlashPlayer::NAME
|
4
|
+
s.version = FlashPlayer::VERSION
|
5
|
+
|
6
|
+
s.add_remote_file_target do |t|
|
7
|
+
t.platform = :osx
|
8
|
+
t.archive_type = :zip
|
9
|
+
t.url = "http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.app.zip"
|
10
|
+
t.md5 = "ff6824b7fd676dd1b613204221f5b5b9"
|
11
|
+
t.add_executable :flashplayer, "Flash Player Debugger.app/Contents/MacOS/Flash Player Debugger"
|
12
|
+
end
|
13
|
+
=begin
|
14
|
+
s.add_remote_file_target do |t|
|
15
|
+
t.platform = :win32
|
16
|
+
t.archive_type = :exe
|
17
|
+
t.url = "http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.exe"
|
18
|
+
t.md5 = "4d8d58d72709f44421b2ea4e89cc30be"
|
19
|
+
t.add_executable :flashplayer, "flashplayer_10_sa_debug.exe"
|
20
|
+
end
|
21
|
+
|
22
|
+
s.add_remote_file_target do |t|
|
23
|
+
t.platform = :linux
|
24
|
+
t.archive_type = :tgz
|
25
|
+
t.url = "http://download.macromedia.com/pub/flashplayer/updaters/10/flashplayer_10_sa_debug.tar.gz"
|
26
|
+
t.md5 = "6cabe6038343374b547043d29de14417"
|
27
|
+
t.add_executable :flashplayer, "flash_player_10_linux_dev/standalone/debugger/flashplayer"
|
28
|
+
end
|
29
|
+
=end
|
30
|
+
end
|
31
|
+
|
@@ -0,0 +1,408 @@
|
|
1
|
+
|
2
|
+
module FlashPlayer
|
3
|
+
|
4
|
+
class Task
|
5
|
+
|
6
|
+
attr_accessor :input
|
7
|
+
|
8
|
+
attr_accessor :pkg_name
|
9
|
+
attr_accessor :pkg_version
|
10
|
+
|
11
|
+
def initialize
|
12
|
+
@logger = $stdout
|
13
|
+
@mm_config = MMConfig.new
|
14
|
+
@reader = LogFile.new
|
15
|
+
@trust_config = Trust.new
|
16
|
+
@process = nil
|
17
|
+
|
18
|
+
@pkg_name = FlashPlayer::NAME
|
19
|
+
@pkg_version = FlashPlayer::VERSION
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute swf
|
23
|
+
update_mm_config
|
24
|
+
update_trust_config_with swf
|
25
|
+
player_thread = launch_player_with swf
|
26
|
+
tail_flashlog player_thread
|
27
|
+
end
|
28
|
+
|
29
|
+
def logger=(logger)
|
30
|
+
@logger = logger
|
31
|
+
@mm_config.logger = logger
|
32
|
+
@reader.logger = logger
|
33
|
+
@trust_config.logger = logger
|
34
|
+
end
|
35
|
+
|
36
|
+
def logger
|
37
|
+
@logger
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def update_mm_config
|
43
|
+
@mm_config.create
|
44
|
+
end
|
45
|
+
|
46
|
+
def update_trust_config_with swf
|
47
|
+
@trust_config.add File.dirname(swf)
|
48
|
+
end
|
49
|
+
|
50
|
+
def clean_path path
|
51
|
+
current_system.clean_path path
|
52
|
+
end
|
53
|
+
|
54
|
+
def current_system
|
55
|
+
@current_system ||= Sprout.current_system
|
56
|
+
end
|
57
|
+
|
58
|
+
def launch_player_with swf
|
59
|
+
player = Sprout::Executable.load(:flashplayer, pkg_name, pkg_version).path
|
60
|
+
swf = clean_path swf
|
61
|
+
current_system.open_flashplayer_with player, swf
|
62
|
+
end
|
63
|
+
|
64
|
+
def tail_flashlog player_thread
|
65
|
+
@reader.tail player_thread
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
##
|
71
|
+
# Update the native System instances
|
72
|
+
# to handle FlashPlayer launching in
|
73
|
+
# order to overcome non-cli limitations.
|
74
|
+
#
|
75
|
+
module Sprout
|
76
|
+
module System
|
77
|
+
|
78
|
+
class WinSystem
|
79
|
+
def open_flashplayer_with exe, swf
|
80
|
+
return Thread.new {
|
81
|
+
system command
|
82
|
+
}
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
class OSXSystem
|
87
|
+
def open_flashplayer_with exe, swf
|
88
|
+
require 'flashplayer/clix_flash_player'
|
89
|
+
@clix_player = CLIXFlashPlayer.new
|
90
|
+
@clix_player.execute(exe, swf)
|
91
|
+
return @clix_player
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
class UnixSystem
|
96
|
+
def open_flashplayer_with exe, swf
|
97
|
+
return Thread.new {
|
98
|
+
require 'open4'
|
99
|
+
@player_pid, stdin, stdout, stderr = Open4.popen4(command)
|
100
|
+
stdout.read
|
101
|
+
}
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def flashplayer args
|
108
|
+
# TODO:
|
109
|
+
# This shouldn't take over the SWF task name
|
110
|
+
# but instead should be assigned a SWF.
|
111
|
+
task args do
|
112
|
+
player = FlashPlayer::Task.new
|
113
|
+
player.execute args
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
=begin
|
118
|
+
|
119
|
+
class FlashPlayerTask < Rake::Task
|
120
|
+
# This is the opening prelude to a collection of test results. When the
|
121
|
+
# task encounters this string in the trace output log file, it will begin
|
122
|
+
# collecting trace statements with the expectation that the following
|
123
|
+
# strings will be well-formatted XML data matching what JUnit emits for
|
124
|
+
# Cruise Control.
|
125
|
+
#
|
126
|
+
# See the lib/asunit3/asunit.framework.XMLResultPrinter for more information.
|
127
|
+
@@test_result_pre_delimiter = '<XMLResultPrinter>'
|
128
|
+
|
129
|
+
# This is the closing string that will indicate the end of test result XML data
|
130
|
+
@@test_result_post_delimiter = '</XMLResultPrinter>'
|
131
|
+
|
132
|
+
@@home = nil
|
133
|
+
@@trust = nil
|
134
|
+
|
135
|
+
def initialize(task_name, app)
|
136
|
+
super(task_name, app)
|
137
|
+
@default_gem_name = 'sprout-flashplayer-tool'
|
138
|
+
@default_gem_version = '10.22.0'
|
139
|
+
@default_result_file = 'AsUnitResults.xml'
|
140
|
+
@inside_test_result = false
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.define_task(args, &block)
|
144
|
+
t = super
|
145
|
+
yield t if block_given?
|
146
|
+
t.define
|
147
|
+
end
|
148
|
+
|
149
|
+
# Local system path to the Flash Player Trust file
|
150
|
+
def FlashPlayerTask.trust
|
151
|
+
if(@@trust)
|
152
|
+
return @@trust
|
153
|
+
end
|
154
|
+
@@trust = File.join(FlashPlayerTask.home, '#Security', 'FlashPlayerTrust', 'sprout.cfg')
|
155
|
+
return @@trust
|
156
|
+
end
|
157
|
+
|
158
|
+
# Local system path to where the Flash Player stores trace output logs and trust files
|
159
|
+
def FlashPlayerTask.home
|
160
|
+
if(@@home)
|
161
|
+
return @@home
|
162
|
+
end
|
163
|
+
|
164
|
+
FlashPlayerTask.home_paths.each do |path|
|
165
|
+
if(File.exists?(path))
|
166
|
+
return @@home = path
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
if(@@home.nil?)
|
171
|
+
raise FlashPlayerError.new('FlashPlayer unable to find home folder for your platform')
|
172
|
+
end
|
173
|
+
return @@home
|
174
|
+
end
|
175
|
+
|
176
|
+
# Collection of the potential locations of the Flash Player Home
|
177
|
+
# For each supported Platform, the first existing location
|
178
|
+
# will be used.
|
179
|
+
def FlashPlayerTask.home_paths
|
180
|
+
return [File.join(User.library, 'Preferences', 'Macromedia', 'Flash Player'),
|
181
|
+
File.join(User.library, 'Application Support', 'Macromedia'),
|
182
|
+
File.join(User.home, 'Application Data', 'Macromedia', 'Flash Player'),
|
183
|
+
File.join(User.home, 'AppData', 'Roaming', 'Macromedia', 'Flash Player'),
|
184
|
+
File.join(User.home, '.macromedia', 'Flash_Player')]
|
185
|
+
end
|
186
|
+
|
187
|
+
# The swf parameter can be set explicitly in the block sent to this task as in:
|
188
|
+
#
|
189
|
+
# flashplayer :run do |t|
|
190
|
+
# t.swf = 'bin/SomeProject.swf'
|
191
|
+
# end
|
192
|
+
#
|
193
|
+
# Or it can be set implicitly as a rake prerequisite as follows:
|
194
|
+
#
|
195
|
+
# flashplayer :run => 'bin/SomeProject' do |t|
|
196
|
+
# end
|
197
|
+
#
|
198
|
+
def swf=(swf)
|
199
|
+
@swf = swf
|
200
|
+
end
|
201
|
+
|
202
|
+
def swf
|
203
|
+
@swf ||= nil
|
204
|
+
if(@swf.nil?)
|
205
|
+
prerequisites.each do |req|
|
206
|
+
if(req.index('.swf'))
|
207
|
+
@swf = req.to_s
|
208
|
+
break
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
return @swf
|
213
|
+
end
|
214
|
+
|
215
|
+
def gem_version=(version)
|
216
|
+
@gem_version = version
|
217
|
+
end
|
218
|
+
|
219
|
+
def gem_version
|
220
|
+
return @gem_version ||= nil
|
221
|
+
end
|
222
|
+
|
223
|
+
# Full name of the sprout tool gem that this tool task will use.
|
224
|
+
# This defaults to sprout-flashplayer-tool
|
225
|
+
def gem_name=(name)
|
226
|
+
@gem_name = name
|
227
|
+
end
|
228
|
+
|
229
|
+
def gem_name
|
230
|
+
return @gem_name ||= @default_gem_name
|
231
|
+
end
|
232
|
+
|
233
|
+
# The File where JUnit test results should be written. This value
|
234
|
+
# defaults to 'AsUnitResults.xml'
|
235
|
+
#
|
236
|
+
def test_result_file=(file)
|
237
|
+
@test_result_file = file
|
238
|
+
end
|
239
|
+
|
240
|
+
def test_result_file
|
241
|
+
@test_result_file ||= @default_result_file
|
242
|
+
end
|
243
|
+
|
244
|
+
def test_result
|
245
|
+
@test_result ||= ''
|
246
|
+
end
|
247
|
+
|
248
|
+
def define # :nodoc:
|
249
|
+
CLEAN.add(test_result_file)
|
250
|
+
end
|
251
|
+
|
252
|
+
def execute(*args)
|
253
|
+
super
|
254
|
+
raise FlashPlayerError.new("FlashPlayer task #{name} required field swf is nil") unless swf
|
255
|
+
|
256
|
+
log_file = nil
|
257
|
+
|
258
|
+
# Don't let trust or log file failures break other features...
|
259
|
+
begin
|
260
|
+
config = FlashPlayerConfig.new
|
261
|
+
log_file = config.log_file
|
262
|
+
FlashPlayerTrust.new(File.expand_path(File.dirname(swf)))
|
263
|
+
|
264
|
+
if(File.exists?(log_file))
|
265
|
+
File.open(log_file, 'w') do |f|
|
266
|
+
f.write('')
|
267
|
+
end
|
268
|
+
else
|
269
|
+
FileUtils.makedirs(File.dirname(log_file))
|
270
|
+
FileUtils.touch(log_file)
|
271
|
+
end
|
272
|
+
rescue StandardError => e
|
273
|
+
puts '[WARNING] FlashPlayer encountered an error working with the mm.cfg log and/or editing the Trust file'
|
274
|
+
end
|
275
|
+
|
276
|
+
@running_process = nil
|
277
|
+
@thread = run(gem_name, gem_version, swf)
|
278
|
+
read_log(@thread, log_file) unless log_file.nil?
|
279
|
+
@thread.join
|
280
|
+
end
|
281
|
+
|
282
|
+
def run(tool, gem_version, swf)
|
283
|
+
path_to_exe = Sprout.get_executable(tool, nil, gem_version)
|
284
|
+
target = User.clean_path(path_to_exe)
|
285
|
+
@player_pid = nil
|
286
|
+
|
287
|
+
thread_out = $stdout
|
288
|
+
command = "#{target} #{User.clean_path(swf)}"
|
289
|
+
|
290
|
+
usr = User.new()
|
291
|
+
if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser))
|
292
|
+
return Thread.new {
|
293
|
+
system command
|
294
|
+
}
|
295
|
+
elsif usr.is_a?(OSXUser)
|
296
|
+
require 'clix_flash_player'
|
297
|
+
@clix_player = CLIXFlashPlayer.new
|
298
|
+
@clix_player.execute(target, swf)
|
299
|
+
return @clix_player
|
300
|
+
else
|
301
|
+
return Thread.new {
|
302
|
+
require 'open4'
|
303
|
+
@player_pid, stdin, stdout, stderr = Open4.popen4(command)
|
304
|
+
stdout.read
|
305
|
+
}
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
def close
|
310
|
+
usr = User.new
|
311
|
+
if(usr.is_a?(WinUser))
|
312
|
+
Thread.kill(@thread)
|
313
|
+
elsif(usr.is_a?(OSXUser))
|
314
|
+
@clix_player.kill unless @clix_player.nil?
|
315
|
+
else
|
316
|
+
Process.kill("SIGALRM", @player_pid)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
def read_log(thread, log_file)
|
321
|
+
lines_put = 0
|
322
|
+
|
323
|
+
if(log_file.nil?)
|
324
|
+
raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file because the expected location was nil')
|
325
|
+
end
|
326
|
+
|
327
|
+
if(!File.exists?(log_file))
|
328
|
+
raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file in the expected location: ' + log_file)
|
329
|
+
end
|
330
|
+
|
331
|
+
while(thread.alive?)
|
332
|
+
sleep(0.2)
|
333
|
+
lines_read = 0
|
334
|
+
|
335
|
+
File.open(log_file, 'r') do |file|
|
336
|
+
file.readlines.each do |line|
|
337
|
+
lines_read = lines_read + 1
|
338
|
+
if(lines_read > lines_put)
|
339
|
+
if(!parse_test_result(line, thread))
|
340
|
+
puts "[trace] #{line}"
|
341
|
+
end
|
342
|
+
$stdout.flush
|
343
|
+
lines_put = lines_put + 1
|
344
|
+
end
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end
|
349
|
+
|
350
|
+
# Returns true if inside of a test result
|
351
|
+
def parse_test_result(line, thread)
|
352
|
+
if(@inside_test_result)
|
353
|
+
if(line.index(@@test_result_post_delimiter))
|
354
|
+
@inside_test_result = false
|
355
|
+
write_test_result(test_result)
|
356
|
+
close
|
357
|
+
examine_test_result test_result
|
358
|
+
return true
|
359
|
+
else
|
360
|
+
test_result << line
|
361
|
+
end
|
362
|
+
end
|
363
|
+
|
364
|
+
if(line.index(@@test_result_pre_delimiter))
|
365
|
+
@inside_test_result = true
|
366
|
+
end
|
367
|
+
|
368
|
+
return @inside_test_result
|
369
|
+
end
|
370
|
+
|
371
|
+
def write_test_result(result)
|
372
|
+
FileUtils.makedirs(File.dirname(test_result_file))
|
373
|
+
File.open(test_result_file, File::CREAT|File::TRUNC|File::RDWR) do |f|
|
374
|
+
f.puts(result)
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
378
|
+
def examine_test_result(result)
|
379
|
+
require 'rexml/document'
|
380
|
+
doc = nil
|
381
|
+
begin
|
382
|
+
doc = REXML::Document.new(result)
|
383
|
+
rescue REXML::ParseException => e
|
384
|
+
puts "[WARNING] Invalid test results encountered"
|
385
|
+
return
|
386
|
+
end
|
387
|
+
|
388
|
+
# Handle JUnit Failures
|
389
|
+
failures = []
|
390
|
+
|
391
|
+
doc.elements.each('/testsuites/testsuite/testsuite/testcase/error') do |element|
|
392
|
+
failures << element.text
|
393
|
+
end
|
394
|
+
|
395
|
+
doc.elements.each("/testsuites/testsuite/testsuite/testcase/failure") do |element|
|
396
|
+
failures << element.text
|
397
|
+
end
|
398
|
+
|
399
|
+
if(failures.size > 0)
|
400
|
+
raise AssertionFailure.new("[ERROR] Test Failures Encountered \n#{failures.join("\n")}")
|
401
|
+
end
|
402
|
+
end
|
403
|
+
|
404
|
+
end
|
405
|
+
|
406
|
+
=end
|
407
|
+
|
408
|
+
|