lukebayes-clix_flash_player 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ == 0.1.0 14/5/2009
2
+
3
+ * 1 major improvement
4
+ * Created and built the solution
5
+ * Explored different strategies for solving the problem
data/Manifest.txt ADDED
@@ -0,0 +1,11 @@
1
+ Manifest.txt
2
+ History.txt
3
+ rakefile.rb
4
+ README.rdoc
5
+ lib/clix_flash_player.rb
6
+ lib/clix_wrapper.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/clix_flash_player_test.rb
11
+ test/test_helper.rb
data/README.rdoc ADDED
@@ -0,0 +1,57 @@
1
+ = CLIX Flash Player
2
+
3
+ == DESCRIPTION:
4
+
5
+ This is a Command Line interface to the Flash Player for OS X.
6
+
7
+ This project was created because unlike the modern distributions of the desktop debug Flash Player on Windows and Linux, the OS X distribution does not behave properly when executed by another process.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ We need to be able to execute and focus a specific instance of the Flash Player along with a specific SWF file. The Flash Player execution thread should block until the user selects File >> Quit (or hits CMD+Q), or until the parent application is interrupted (SIGINT) using CTRL+C.
12
+
13
+ The Flash Player should be focused and still terminate whether or not a runtime exception occurs in the first frame (or any frame) of the loaded SWF file.
14
+
15
+ Our solution should work each revision of the Flash Player, from 9.0.115 and greater.
16
+
17
+ == SYNOPSIS:
18
+
19
+ You can use this application by targeting a specific, downloaded instance of the Flash Player and a SWF file as follows:
20
+
21
+ flash_player = "Flash Player.app/Content/MacOS/Flash Player"
22
+ swf = "bin/SomeProject.swf"
23
+
24
+ player = CLIXFlashPlayer.new
25
+ player.execute(flash_player, swf)
26
+
27
+
28
+ == REQUIREMENTS:
29
+
30
+ Simply executing the Flash Player on OS X does not give us the ability to focus it, or continue to control or kill it when an uncaught runtime exception is encountered.
31
+
32
+ The CLIXFlashPlayer provides full control over the process that represents the Flash Player.
33
+
34
+ == LICENSE:
35
+
36
+ (The MIT License)
37
+
38
+ Copyright (c) 2009 Pattern Park, Inc.
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ 'Software'), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,72 @@
1
+ require 'rubygems'
2
+ require 'open4'
3
+
4
+ $:.unshift(File.dirname(__FILE__)) unless
5
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
6
+
7
+ class CLIXFlashPlayerError < StandardError; end
8
+
9
+ class CLIXFlashPlayer
10
+ VERSION = '0.1.0'
11
+
12
+ def initialize
13
+ @activate_pid = nil
14
+ @player_pid = nil
15
+ @thread = nil
16
+ end
17
+
18
+ def execute(player, swf)
19
+ cleanup
20
+ validate(player, swf)
21
+ player = File.expand_path(File.join(player, 'Contents', 'MacOS', 'Flash Player'))
22
+ swf = File.expand_path(swf)
23
+ setup_trap
24
+ @thread = Thread.new {
25
+ @player_pid = open4.popen4("#{player.split(' ').join('\ ')}")[0]
26
+ wrapper = File.expand_path(File.dirname(__FILE__) + '/clix_wrapper.rb')
27
+ command = "ruby #{wrapper} '#{player}' '#{swf}'"
28
+ @activate_pid = open4.popen4(command)[0]
29
+ Process.wait(@player_pid)
30
+ }
31
+ end
32
+
33
+ def kill
34
+ system("kill -9 #{@player_pid}")
35
+ end
36
+
37
+ def join
38
+ @thread.join
39
+ end
40
+
41
+ def alive?
42
+ return @thread.alive?
43
+ end
44
+
45
+ private
46
+
47
+ def cleanup
48
+ if(@thread && @thread.alive?)
49
+ kill
50
+ @thread.join
51
+ end
52
+ end
53
+
54
+ def validate(player, swf)
55
+ raise CLIXFlashPlayerError.new("Player must not be nil") if(player.nil? || player == '')
56
+ raise CLIXFlashPlayerError.new("Player cannot be found: '#{player}'") if(!File.exists?(player))
57
+ raise CLIXFlashPlayerError.new("SWF must not be nil") if(swf.nil? || swf == '')
58
+ raise CLIXFlashPlayerError.new("SWF cannot be found: '#{swf}'") if(!File.exists?(swf))
59
+ end
60
+
61
+ def setup_trap
62
+ # Trap the CTRL+C Interrupt signal
63
+ # Which prevents nasty exception messages
64
+ Kernel.trap('INT') do
65
+ if(@thread.alive?)
66
+ @thread.kill
67
+ end
68
+ end
69
+ end
70
+
71
+ end
72
+
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/ruby
2
+ require 'rubygems'
3
+ require 'appscript'
4
+
5
+ # player9 = "/Users/lbayes/Projects/CLIXFlashPlayer/exploration/fixtures/9.0.151/Flash Player.app/Contents/MacOS/Flash Player"
6
+ # player10 = "/Users/lbayes/Projects/CLIXFlashPlayer/exploration/fixtures/10.0.22.87/Flash Player.app/Contents/MacOS/Flash Player"
7
+
8
+ # player = player10
9
+
10
+ # good_swf = '/Users/lbayes/Projects/CLIXFlashPlayer/exploration/fixtures/SomeProject.swf'
11
+ # bad_swf = '/Users/lbayes/Projects/CLIXFlashPlayer/exploration/fixtures/InstantRuntimeException.swf'
12
+
13
+ # swf = good_swf
14
+
15
+ player = ARGV[0]
16
+ swf = ARGV[1]
17
+
18
+ puts "argv 0: #{player}"
19
+ puts "argv 1: #{swf}"
20
+
21
+ if(player.nil?)
22
+ raise "CLIXWrapper requires 'player' argument like:\nruby clix_wrapper [player] [swf]"
23
+ end
24
+
25
+ if(swf.nil?)
26
+ raise "CLIXWrapper requires 'swf' argument like:\nruby clix_wrapper [player] [swf]"
27
+ end
28
+
29
+ # player = File.expand_path(player).split(' ').join('\ ')
30
+ # swf = File.expand_path(swf).split(' ').join('\ ')
31
+
32
+
33
+ # Give the player focus:
34
+ Appscript.app(player).activate
35
+ puts "activate succeeded"
36
+ # Open the SWF:
37
+ Appscript.app(player).open(MacTypes::Alias.path(swf))
38
+ puts "open succeeded"
39
+
data/rakefile.rb ADDED
@@ -0,0 +1,26 @@
1
+ %w[rubygems rake rake/clean fileutils newgem rubigen].each { |f| require f }
2
+ require File.dirname(__FILE__) + '/lib/clix_flash_player'
3
+
4
+ # Generate all the Rake tasks
5
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
6
+ $hoe = Hoe.new('clix_flash_player', CLIXFlashPlayer::VERSION) do |p|
7
+ p.developer('Luke Bayes', 'lbayes@patternpark.com')
8
+ p.rubyforge_name = p.name
9
+ p.extra_deps = [
10
+ ['open4','>= 0.9.6'],
11
+ ]
12
+ p.extra_dev_deps = [
13
+ ['newgem', ">= #{::Newgem::VERSION}"]
14
+ ]
15
+ p.test_globs = ['test/*_test.rb']
16
+ p.clean_globs |= %w[**/.DS_Store tmp *.log]
17
+ path = (p.rubyforge_name == p.name) ? p.rubyforge_name : "\#{p.rubyforge_name}/\#{p.name}"
18
+ p.remote_rdoc_dir = File.join(path.gsub(/^#{p.rubyforge_name}\/?/,''), 'rdoc')
19
+ p.rsync_args = '-av --delete --ignore-errors'
20
+ end
21
+
22
+ require 'newgem/tasks' # load /tasks/*.rake
23
+ Dir['tasks/**/*.rake'].each { |t| load t }
24
+
25
+ # TODO - want other tests/tasks run by default? Add them to the list
26
+ # task :default => [:spec, :features]
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/clix_flash_player.rb'}"
9
+ puts "Loading clix_flash_player gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/test_helper'
2
+
3
+ class CLIXFlashPlayerTest < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @fixtures = File.join(File.dirname(__FILE__) + '/../', 'exploration', 'fixtures')
7
+ @flash_player10 = File.join(@fixtures, '10.0.22.87', 'Flash Player.app')
8
+ @flash_player9 = File.join(@fixtures, '9.0.151', 'Flash Player.app')
9
+
10
+ @good_swf = File.join(@fixtures, 'SomeProject.swf')
11
+ @bad_swf = File.join(@fixtures, 'InstantRuntimeException.swf')
12
+ end
13
+
14
+ def teardown
15
+ super
16
+ end
17
+
18
+ def test_nil_player
19
+ player = CLIXFlashPlayer.new
20
+ assert_raise CLIXFlashPlayerError do
21
+ player.execute(nil, @good_swf)
22
+ end
23
+ end
24
+
25
+ def test_bad_player_target
26
+ player = CLIXFlashPlayer.new
27
+ assert_raise CLIXFlashPlayerError do
28
+ player.execute('foo', @good_swf)
29
+ end
30
+ end
31
+
32
+ def test_nil_swf
33
+ player = CLIXFlashPlayer.new
34
+ assert_raise CLIXFlashPlayerError do
35
+ player.execute(@flash_player9, nil)
36
+ end
37
+ end
38
+
39
+ def test_bad_swf_target
40
+ player = CLIXFlashPlayer.new
41
+ assert_raise CLIXFlashPlayerError do
42
+ player.execute(@flash_player9, 'foo')
43
+ end
44
+ end
45
+
46
+ def test_second_execute
47
+ player = CLIXFlashPlayer.new
48
+ player.execute(@flash_player9, @good_swf)
49
+ sleep(4.0)
50
+ player.execute(@flash_player10, @good_swf)
51
+ sleep(4.0)
52
+ player.kill
53
+ player.join
54
+ end
55
+
56
+ def test_good_swf
57
+ player = CLIXFlashPlayer.new
58
+ player.execute(@flash_player9, @good_swf)
59
+ sleep(4.0)
60
+ player.kill
61
+ player.join
62
+ end
63
+
64
+ def test_bad_swf
65
+ player = CLIXFlashPlayer.new
66
+ player.execute(@flash_player9, @bad_swf)
67
+ sleep(4.0)
68
+ player.kill
69
+ player.join
70
+ end
71
+
72
+ end
@@ -0,0 +1,5 @@
1
+ require 'test/unit'
2
+ $:.push(File.dirname(__FILE__) + '/../lib')
3
+ $:.push(File.dirname(__FILE__))
4
+
5
+ require 'clix_flash_player'
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lukebayes-clix_flash_player
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Luke Bayes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-16 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: open4
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 0.9.6
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: newgem
27
+ type: :development
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.0
34
+ version:
35
+ - !ruby/object:Gem::Dependency
36
+ name: hoe
37
+ type: :development
38
+ version_requirement:
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 1.8.0
44
+ version:
45
+ description: This is a Command Line interface to the Flash Player for OS X. This project was created because unlike the modern distributions of the desktop debug Flash Player on Windows and Linux, the OS X distribution does not behave properly when executed by another process.
46
+ email:
47
+ - lbayes@patternpark.com
48
+ executables: []
49
+
50
+ extensions: []
51
+
52
+ extra_rdoc_files:
53
+ - Manifest.txt
54
+ - History.txt
55
+ - README.rdoc
56
+ files:
57
+ - Manifest.txt
58
+ - History.txt
59
+ - rakefile.rb
60
+ - README.rdoc
61
+ - lib/clix_flash_player.rb
62
+ - lib/clix_wrapper.rb
63
+ - script/console
64
+ - script/destroy
65
+ - script/generate
66
+ - test/clix_flash_player_test.rb
67
+ - test/test_helper.rb
68
+ has_rdoc: false
69
+ homepage:
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.rdoc
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ version:
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ requirements: []
89
+
90
+ rubyforge_project: clix_flash_player
91
+ rubygems_version: 1.2.0
92
+ signing_key:
93
+ specification_version: 3
94
+ summary: This is a Command Line interface to the Flash Player for OS X
95
+ test_files:
96
+ - test/clix_flash_player_test.rb