> EXITING NOW!\n"
84 | exit! 0
85 | end
86 |
87 | end
88 |
89 | fake_fdb = FakeFDB.new
90 |
91 |
--------------------------------------------------------------------------------
/test/unit/flashplayer_mm_config_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class MMConfigTest < Test::Unit::TestCase
4 | include Sprout::TestHelper
5 |
6 | context "An MMConfig" do
7 |
8 | setup do
9 | @home = File.join(fixtures, 'home')
10 | @osx_fp = File.join(@home, 'Application Support', 'Macromedia')
11 | @linux_fp = File.join(@home, '.macromedia', 'Flash_Player')
12 |
13 | FileUtils.mkdir_p @home
14 |
15 | @mm_config = FlashPlayer::MMConfig.new
16 | @mm_config.stubs(:user_confirmation?).returns true
17 | @mm_config.logger = StringIO.new
18 | end
19 |
20 | teardown do
21 | remove_file @home
22 | end
23 |
24 | should "ignore failure if flashplayer has never run" do
25 | # No creation of expected FlashPlayer folders...
26 |
27 | as_a_mac_system do
28 | @mm_config.stubs(:system_library).returns @home
29 | @mm_config.stubs(:flashplayer_home).returns @osx_fp
30 | @mm_config.create
31 | end
32 | end
33 |
34 | should "create a config file on OS X with FP 9" do
35 | FileUtils.mkdir_p @osx_fp
36 | flashlog = File.expand_path(File.join(@osx_fp, 'Logs', 'flashlog.txt'))
37 |
38 | as_a_mac_system do
39 | @mm_config.stubs(:system_library).returns @home
40 | @mm_config.stubs(:flashplayer_home).returns @osx_fp
41 | @mm_config.stubs(:flashlog_path).returns flashlog
42 | @mm_config.create
43 | mm_cfg = File.join(@osx_fp, mm_config_file)
44 | assert_file mm_cfg do |content|
45 | assert_matches /#{@flashlog}/, content
46 | end
47 | end
48 | end
49 |
50 | should "create a config file on linux" do
51 | FileUtils.mkdir_p @linux_fp
52 | flashlog = File.expand_path(File.join(@linux_fp, 'Logs', 'flashlog.txt'))
53 |
54 | as_a_unix_system do
55 | @mm_config.stubs(:system_library).returns @home
56 | @mm_config.stubs(:system_home).returns @home
57 | @mm_config.stubs(:flashlog_path).returns flashlog
58 | @mm_config.stubs(:flashplayer_home).returns @linux_fp
59 | @mm_config.create
60 | mm_cfg = File.join(@home, mm_config_file)
61 | assert_file mm_cfg do |content|
62 | assert_matches /#{flashlog}/, content
63 | end
64 | end
65 | end
66 | end
67 |
68 | private
69 |
70 | def mm_config_file
71 | FlashPlayer::MMConfig::FILE_NAME
72 | end
73 | end
74 |
75 |
--------------------------------------------------------------------------------
/lib/flashplayer/system_mixins.rb:
--------------------------------------------------------------------------------
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
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 |
99 |
--------------------------------------------------------------------------------
/lib/flashsdk/generators/class_generator.rb:
--------------------------------------------------------------------------------
1 |
2 | module FlashSDK
3 |
4 | ##
5 | # This Generator will create a new ActionScript class
6 | # based on the +ActionScript3Class.as+ template.
7 | #
8 | # This Generator should only be executed from within
9 | # a project that has a Gemfile. If your Gemfile
10 | # loads the "asunit4" gem, a test case and test suite
11 | # will also be created whenever this generator is run.
12 | #
13 | # You can run this generator as follows:
14 | #
15 | # $ sprout-class utils.MathUtil
16 | #
17 | # You can prevent the creation of a test case and test
18 | # suite by sending in the +--no-test+ parameter as follows:
19 | #
20 | # $ sprout-class utils.MathUtil --no-test
21 | #
22 | class ClassGenerator < Sprout::Generator::Base
23 | include FlashHelper
24 |
25 | ##
26 | # @return [String] The default package to use.
27 | add_param :package, String, { :default => ""}
28 |
29 | ##
30 | # @return [String] The path where assets will be created.
31 | add_param :assets, String, { :default => 'assets' }
32 |
33 | ##
34 | # @return [String] The path where skins will be created.
35 | add_param :skins, String, { :default => 'skins' }
36 |
37 | ##
38 | # @return [String] The path where test cases should be created.
39 | add_param :test, String, { :default => 'test' }
40 |
41 | ##
42 | # @return [String] The path where libraries should be added.
43 | add_param :lib, String, { :default => 'lib' }
44 |
45 | ##
46 | # @return [String] The path where binaries should be created.
47 | add_param :bin, String, { :default => 'bin' }
48 |
49 | ##
50 | # @return [String] The path where source files should be created.
51 | add_param :src, String, { :default => 'src' }
52 |
53 | ##
54 | # @return [String] The path where documentation should be created.
55 | add_param :doc, String, { :default => 'doc' }
56 |
57 | ##
58 | # @return [Boolean] Call the TestClassGenerator after creating class.
59 | add_param :test_class, Boolean, { :default => true }
60 |
61 | def manifest
62 | if(!input.match(/Test$/))
63 | directory class_directory do
64 | template "#{class_name}.as", 'ActionScript3Class.as'
65 | end
66 | end
67 |
68 | if test_class
69 | generator :test_class, :input => "#{fully_qualified_class_name}Test"
70 | end
71 | end
72 |
73 | end
74 | end
75 |
76 | module FlashSDK
77 | ##
78 | # This is a null Generator, if you add a test library
79 | # to your Gemfile, it should have it's own TestClassGenerator
80 | # that supercedes this one.
81 | class TestClassGenerator < Sprout::Generator::Base
82 |
83 | def manifest
84 | end
85 | end
86 | end
87 |
88 |
--------------------------------------------------------------------------------
/README.textile:
--------------------------------------------------------------------------------
1 |
2 | h1. The Flash SDK Sprout Gem
3 |
4 | h3. Installation
5 |
6 | # "Install Ruby":http://www.ruby-lang.org/en/downloads/ _(>= v 1.8.7)_
7 | # "Install RubyGems":http://rubyforge.org/frs/?group_id=126 _(>= v 1.3.6)_
8 | # Install the Flash SDK prerelease gem:
9 |
10 | gem install flashsdk --pre
11 |
12 | h3. Getting Started
13 |
14 | Open a terminal and enter the following commands:
15 |
16 | Create a new ActionScript 3 project and move into it:
17 |
18 | sprout-as3 SomeProject
19 | cd SomeProject
20 |
21 |
22 | Resolve all dependencies, compile and launch the SWF:
23 |
24 | rake
25 |
26 | Generate a new class, test case and test suite:
27 |
28 | sprout-class utils.MathUtil
29 |
30 | Compile and launch the test harness:
31 |
32 | rake test
33 |
34 | Compile a SWC file:
35 |
36 | rake swc
37 |
38 | Generate documentation using "AsDoc":http://labs.adobe.com/wiki/index.php/ASDoc:
39 |
40 | rake asdoc
41 |
42 | Execute the test harness, emit a JUnit-compatible test results document, and close the Flash Player when complete or after encountering an uncaught exception:
43 |
44 | rake ci
45 |
46 | Display all available Rake tasks:
47 |
48 | rake -T
49 |
50 | h3. Some Links
51 |
52 | * "Web Site":http://projectsprouts.org
53 | * "See the Documentation":http://projectsprouts.org/rdoc
54 | * "Meet the Community":http://groups.google.com/group/projectsprouts
55 |
56 | h3. MIT License
57 |
58 |
59 | Copyright (c) 2007-2010 Pattern Park
60 |
61 | Permission is hereby granted, free of charge, to any person obtaining
62 | a copy of this software and associated documentation files (the
63 | "Software"), to deal in the Software without restriction, including
64 | without limitation the rights to use, copy, modify, merge, publish,
65 | distribute, sublicense, and/or sell copies of the Software, and to
66 | permit persons to whom the Software is furnished to do so, subject to
67 | the following conditions:
68 |
69 | The above copyright notice and this permission notice shall be
70 | included in all copies or substantial portions of the Software.
71 |
72 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
73 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
74 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
75 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
76 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
77 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
78 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
79 |
80 |
--------------------------------------------------------------------------------
/test/unit/flashplayer_task_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 | require 'fake_flashplayer_system'
3 |
4 | class TaskTest < Test::Unit::TestCase
5 | include Sprout::TestHelper
6 |
7 | context "A FlashPlayerTask" do
8 |
9 | setup do
10 | # Force reload of the Specification on each
11 | # test method b/c Sprout::TestHelper calls
12 | # Executable.clear_entities! but 'require'
13 | # only runs once per VM run...
14 | load 'flashplayer/specification.rb'
15 | @swf = File.join(fixtures, 'flashplayer', 'AsUnit Runner.swf')
16 | @missing_home = File.join(fixtures, 'missing_folder')
17 | @config_path = File.join(@missing_home, 'fp_config', 'mm.cfg')
18 |
19 | #Sprout.stdout = $stdout
20 | #Sprout.stderr = $stderr
21 | end
22 |
23 | teardown do
24 | remove_file @missing_home
25 | ENV['USE_FDB'] = 'false'
26 | end
27 |
28 | ## THIS METHOD WAS COMMENTED OUT....
29 | =begin
30 | should "wait for SWF even if clean system" do
31 | # No creation of expected FlashPlayer folders...
32 |
33 | FlashPlayer.stubs(:home).returns @missing_home
34 | FlashPlayer::MMConfig.any_instance.stubs(:system_home).returns @missing_home
35 | FlashPlayer::MMConfig.any_instance.stubs(:config_path).returns @config_path
36 | FlashPlayer::MMConfig.any_instance.stubs(:user_confirmation?).returns false
37 |
38 | ENV['USE_FDB'] = 'true'
39 |
40 | as_a_mac_system do
41 | t = flashplayer @swf
42 | t.invoke
43 | end
44 | end
45 | =end
46 |
47 | should "work with swf as task name" do
48 | t = flashplayer @swf
49 | configure_task t
50 | t.invoke
51 | end
52 |
53 | should "work with swf in block" do
54 | t = flashplayer :run do |t|
55 | t.input = @swf
56 | end
57 | Rake::FileTask.define_task @swf
58 | configure_task t
59 | t.invoke
60 | assert_equal @swf, t.input
61 | end
62 |
63 | should "work with swf as prerequisite" do
64 | t = flashplayer :run => @swf
65 | Rake::FileTask.define_task @swf
66 | configure_task t
67 | t.invoke
68 | assert_equal @swf, t.input
69 | end
70 |
71 | should "fire when declared as a dependency" do
72 | t = flashplayer :run => @swf
73 | Rake::FileTask.define_task @swf
74 | configure_task t
75 | other = Rake::Task.define_task :parent => :run
76 | other.invoke
77 | end
78 | end
79 |
80 | private
81 |
82 | def configure_task t
83 | t.logger = StringIO.new
84 |
85 | # Comment following lines to really launch the player:
86 | sys = FakeFlashPlayerSystem.new
87 | FlashPlayer::Executable.any_instance.stubs(:current_system).returns sys
88 | sys.expects(:open_flashplayer_with).returns Thread.new{}
89 | end
90 | end
91 |
92 |
--------------------------------------------------------------------------------
/lib/flashsdk/module.rb:
--------------------------------------------------------------------------------
1 | ##
2 | #
3 | # The FlashSDK is a collection of project and file generators,
4 | # automated build tasks, external libraries, executables,
5 | # and runtimes that make it possible to create SWF and AIR content.
6 | #
7 | # If you're just getting started with the FlashSDK, you'll probably
8 | # want to read more about the following topics.
9 | #
10 | # = Generators
11 | #
12 | # The FlashSDK comes with a handful of standard generators. These
13 | # generators should be installed into your system $PATH when you
14 | # install the FlashSDK gem. In general, Sprout generators fall
15 | # into one of two categories: a) Application Generators, or b) File
16 | # Generators.
17 | #
18 | # Application Generators can be run from any directory on your system
19 | # and will usually create a new folder and place a large number of
20 | # files into that folder. These generators usually don't have any
21 | # prerequisites in terms of where they're run.
22 | #
23 | # File Generators usually expect to be run within an existing project
24 | # directory, and often have dependencies related to the type of
25 | # project they're run in. For example, most Class generators expect
26 | # to find a Gemfile in the same directory where they're run.
27 | #
28 | # If you're interested in creating your own Generators, please see
29 | # the {Sprout::Generator} documentation.
30 | #
31 | # == See Also:
32 | #
33 | # {FlashSDK::ClassGenerator},
34 | # {FlashSDK::FlexProjectGenerator},
35 | # {FlashSDK::ProjectGenerator}
36 | #
37 | # = Rake Tasks
38 | #
39 | # The FlashSDK includes a number of automated build tasks that work with
40 | # the Rake build system.
41 | #
42 | # If you're not familiar with Rake, you should
43 | # stop right now and read Martin Fowler's essay introducing it to the
44 | # world: http://martinfowler.com/articles/rake.html
45 | #
46 | # == See Also:
47 | #
48 | # {FlashSDK::MXMLC},
49 | # {FlashSDK::COMPC},
50 | # {FlashSDK::FDB},
51 | # {FlashSDK::ADL},
52 | # {FlashSDK::ADT},
53 | # {FlashPlayer::Task}
54 | #
55 | # = Libraries
56 | #
57 | # There is a growing collection of libraries that have been made available
58 | # to Sprouts users. The first of these projects is the automated
59 | # unit test framework, AsUnit[http://asunit.org].
60 | #
61 | # To include a new Sprout Library into your project, you'll need to take the
62 | # following steps:
63 | #
64 | # * Add it to your Gemfile like:
65 | #
66 | # gem "asunit4", ">= 4.0.0.pre"
67 | #
68 | # * Add it to your Rakefile like:
69 | #
70 | # library :asunit4
71 | #
72 | # * Add it to your Rake Task like:
73 | #
74 | # mxmlc 'bin/SomeProjectRunner.swf' => :asunit4 do |t|
75 | # ...
76 | # end
77 | #
78 | # * From your project root, run:
79 | #
80 | # bundle install
81 | #
82 | # If you're interested in learning more about how to _create_ new libraries,
83 | # check out the {Sprout::Library} documentation.
84 | #
85 | # = Executables / Runtimes
86 | #
87 | # The FlasSDK also includes a number of tools that help us compile and run
88 | # ActionScript (or AIR) applications.
89 | #
90 | # These executables are usually accessed via Rake, and shouldn't require
91 | # any manual intervention, but some of you are interested in
92 | # where these applications live and how to change how they're accessed.
93 | #
94 | # Following are the {Sprout::Specification}s that are included with the FlashSDK:
95 | #
96 | # * {file:flashsdk/lib/flashplayer/specification.rb}
97 | # * {file:flashsdk/lib/flex3.rb}
98 | # * {file:flashsdk/lib/flex4.rb}
99 | #
100 | module FlashSDK
101 | # Do this strip, otherwise we get a carriage return
102 | # after our version, and that poops on our archive folder
103 | # after downloading...
104 | version_file = File.join(File.dirname(__FILE__), '..', '..', 'VERSION')
105 | VERSION = File.read(version_file).strip
106 | end
107 |
108 |
--------------------------------------------------------------------------------
/lib/flashsdk/fcsh.rb:
--------------------------------------------------------------------------------
1 |
2 | module FlashSDK
3 |
4 | class FCSH < Sprout::Executable::Session
5 |
6 | ##
7 | # The the Ruby file that will load the expected
8 | # Sprout::Specification.
9 | #
10 | # Default value is 'flex4'
11 | set :pkg_name, 'flex4'
12 |
13 | ##
14 | # The default pkg version
15 | #
16 | set :pkg_version, ">= #{FlashSDK::VERSION}"
17 |
18 | ##
19 | # The default executable target.
20 | #
21 | set :executable, :fcsh
22 |
23 | ##
24 | # Set the default prompt that should be presented
25 | # on stdout when fcsh is ready for input.
26 | set :prompt, /^\(fcsh\) /
27 |
28 | ##
29 | # Clear the saved compilation target
30 | # from memory.
31 | #
32 | # @param id [Integer]
33 | #
34 | add_action :clear
35 |
36 | ##
37 | # Perform compilation using COMPC and the
38 | # provided arguments.
39 | #
40 | # @param options [String]
41 | #
42 | add_action :compc
43 |
44 | ##
45 | # Execute a saved compilation from the provided
46 | # id number.
47 | #
48 | # @param id [Integer]
49 | #
50 | add_action :compile
51 |
52 | ##
53 | # Perform compilation using MXMLC and the
54 | # provided arguments.
55 | #
56 | # @param options [String]
57 | #
58 | add_action :mxmlc
59 |
60 | ##
61 | # Exit FCSH
62 | add_action :quit
63 |
64 |
65 | def system_execute binary, params
66 | params ||= ''
67 | ##
68 | # Combine stdout and stderr for FCSH
69 | # so that they both arrive on stdout
70 | params << ' 2<&1'
71 | super binary, params
72 | end
73 |
74 | end
75 | end
76 |
77 | ##
78 | # Rake task that will make any subsequent
79 | # mxmlc or compc tasks use the FCSH compiler.
80 | #
81 | # You can use this task by inserting it
82 | # before the task you're calling on the
83 | # command line like:
84 | #
85 | # rake fcsh test
86 | #
87 | # or:
88 | #
89 | # rake fcsh debug
90 | #
91 | # Or you can add this task as a prerequisite
92 | # to your build tasks directly like:
93 | #
94 | # mxmlc 'bin/SomeProject.swf' => :fcsh do |t|
95 | # ...
96 | # end
97 | #
98 | desc "Make subsequent MXMLC or COMPC tasks use FCSH"
99 | task :fcsh do
100 | ENV['USE_FCSH'] = 'true'
101 | end
102 |
103 | ##
104 | # Rake task that will make any subsequent
105 | # mxmlc or compc tasks use the FCSH compiler.
106 | #
107 | # You can use this task by inserting it
108 | # before the task you're calling on the
109 | # command line like:
110 | #
111 | # rake fcsh test
112 | #
113 | # or:
114 | #
115 | # rake fcsh debug
116 | #
117 | # Or you can add this task as a prerequisite
118 | # to your build tasks directly like:
119 | #
120 | # mxmlc 'bin/SomeProject.swf' => :fcsh do |t|
121 | # ...
122 | # end
123 | #
124 | desc "Make subsequent MXMLC or COMPC tasks use FCSH"
125 | task :fcsh do
126 | ENV['USE_FCSH'] = 'true'
127 | end
128 | ##
129 | # Rake task that will make any subsequent
130 | # mxmlc or compc tasks use the FCSH compiler.
131 | #
132 | # You can use this task by inserting it
133 | # before the task you're calling on the
134 | # command line like:
135 | #
136 | # rake fcsh test
137 | #
138 | # or:
139 | #
140 | # rake fcsh debug
141 | #
142 | # Or you can add this task as a prerequisite
143 | # to your build tasks directly like:
144 | #
145 | # mxmlc 'bin/SomeProject.swf' => :fcsh do |t|
146 | # ...
147 | # end
148 | #
149 | desc "Make subsequent MXMLC or COMPC tasks use FCSH"
150 | task :fcsh do
151 | ENV['USE_FCSH'] = 'true'
152 | end
153 |
154 | namespace :fcsh do
155 | desc "Start the FCSH server"
156 | task :start do
157 | server = FlashSDK::FCSHSocket.new
158 | server.listen ENV['FCSH_PKG_NAME'], ENV['FCSH_PKG_VERSION'], ENV['FCSH_PORT']
159 | end
160 |
161 | desc "Clear the cached compilation data"
162 | task :clear do
163 | client = FlashSDK::FCSHSocket.new
164 | client.execute "clear", ENV['FCSH_PORT']
165 | end
166 |
167 | desc "Quit the fcsh server"
168 | task :quit do
169 | client = FlashSDK::FCSHSocket.new
170 | client.execute "quit", ENV['FCSH_PORT']
171 | end
172 | end
173 |
174 |
--------------------------------------------------------------------------------
/lib/flashplayer/executable.rb:
--------------------------------------------------------------------------------
1 |
2 | module FlashPlayer
3 |
4 | class Executable < Sprout::Executable::Base
5 |
6 | attr_accessor :stdout
7 | attr_accessor :stderr
8 |
9 | ##
10 | # The file that the Flash Player should launch.
11 | #
12 | # flashplayer bin/SomeProject.swf
13 | #
14 | add_param :input, String, { :hidden_name => true, :required => true }
15 |
16 | ##
17 | # Drop into FDB after launching the Player.
18 | #
19 | # flashplayer --fdb bin/SomeProject.swf
20 | #
21 | add_param :fdb, Boolean, { :hidden_value => true }
22 |
23 | ##
24 | # The Flash Player version to use.
25 | add_param :version, String, { :default => FlashPlayer::VERSION }
26 |
27 | def initialize
28 | super
29 | @mm_config = MMConfig.new
30 | @reader = LogFile.new
31 | @trust_config = Trust.new
32 | @process = nil
33 | @stdout = $stdout
34 | @stderr = $stderr
35 | @logger = $stdout
36 | self.pkg_name = FlashPlayer::NAME
37 | self.pkg_version = FlashPlayer::VERSION
38 | end
39 |
40 | def execute *args
41 | execute_safely do
42 | update_mm_config
43 | update_trust_config_with input
44 | end
45 |
46 | if use_fdb?
47 | launch_fdb_and_player_with input
48 | else
49 | player_thread = launch_player_with input
50 | tail_flashlog player_thread
51 | end
52 | end
53 |
54 | def use_fdb?
55 | # Check as string b/c this is
56 | # how the boolean value comes
57 | # accross the command line input.
58 | fdb || ENV['USE_FDB'].to_s == 'true'
59 | end
60 |
61 | def logger=(logger)
62 | @logger = logger
63 | @mm_config.logger = logger
64 | @reader.logger = logger
65 | @trust_config.logger = logger
66 | end
67 |
68 | def logger
69 | @logger
70 | end
71 |
72 | private
73 |
74 | def launch_fdb_and_player_with input
75 | # Keep getting a fatal lock error which I believe
76 | # is being caused by the FlashPlayer and FDB attempting
77 | # to write to stdout simultaneously.
78 | # Trying to give fdb a fake stream until after the
79 | # player is launched...
80 | fake_out = Sprout::OutputBuffer.new
81 | fake_err = Sprout::OutputBuffer.new
82 |
83 | fdb_instance = FlashSDK::FDB.new
84 | fdb_instance.stdout = fake_out
85 | fdb_instance.stderr = fake_err
86 | fdb_instance.execute false
87 | fdb_instance.run
88 | player_thread = launch_player_with input
89 |
90 | # Emit whatever messages have been passed:
91 | stdout.puts fake_out.read
92 | stdout.flush
93 | stderr.puts fake_err.read
94 | stdout.flush
95 | # Replace the fdb instance streams with
96 | # the real ones:
97 | fdb_instance.stdout = stdout
98 | fdb_instance.stderr = stderr
99 |
100 | # Let the user interact with fdb:
101 | fdb_instance.handle_user_input
102 |
103 | fdb_instance.wait
104 | player_thread.join if player_thread.alive?
105 | end
106 |
107 | def execute_safely
108 | begin
109 | Thread.abort_on_exception = true
110 | yield if block_given?
111 | rescue FlashPlayer::PathError => e
112 | logger.puts ">> [WARNING] It seems this was the first time FlashPlayer was launched on this system and as a result, the expected folders were not found. Please close the Player and run again - this message should only ever be displayed once."
113 | end
114 | end
115 |
116 | def update_mm_config
117 | @mm_config.create
118 | end
119 |
120 | def update_trust_config_with swf
121 | @trust_config.add File.dirname(swf)
122 | end
123 |
124 | def clean_path path
125 | current_system.clean_path path
126 | end
127 |
128 | def current_system
129 | @current_system ||= Sprout.current_system
130 | end
131 |
132 | def launch_player_with swf
133 | player = Sprout::Executable.load(:flashplayer, pkg_name, pkg_version).path
134 | current_system.open_flashplayer_with player, clean_path(swf)
135 | end
136 |
137 | def tail_flashlog player_thread
138 | @reader.tail player_thread
139 | end
140 |
141 | end
142 | end
143 |
144 |
--------------------------------------------------------------------------------
/lib/flashsdk/asdoc.rb:
--------------------------------------------------------------------------------
1 | module FlashSDK
2 |
3 | ##
4 | # The AsDoc executable is a wrapper around the Flex SDK binary of the same name.
5 | #
6 | # Following is a simple example of the asdoc Rake task:
7 | #
8 | # desc "Generate documentation at <%= doc %>/"
9 | # asdoc 'doc' do |t|
10 | # t.doc_sources << 'src'
11 | #
12 | # # Exclude test main file
13 | # t.exclude_sources << 'src/SomeProjectRunner.as'
14 | # end
15 | #
16 | # @see CompilerBase
17 | #
18 | class AsDoc < CompilerBase
19 |
20 | ##
21 | # The default prefix for shell params.
22 | set :default_prefix, '-'
23 |
24 | ##
25 | # The the Ruby file that will load the expected
26 | # Sprout::Specification.
27 | #
28 | # Default value is 'flex4'
29 | #
30 | set :pkg_name, 'flex4'
31 |
32 | ##
33 | # The default pkg version
34 | #
35 | set :pkg_version, ">= #{FlashSDK::VERSION}"
36 |
37 | ##
38 | # The default executable target.
39 | #
40 | set :executable, :asdoc
41 |
42 | ##
43 | # Boolean specifies whether to include the date in the footer.
44 | add_param :date_in_footer, Boolean
45 |
46 | ##
47 | # List of source file to include in the documentation.
48 | add_param :doc_sources, Files
49 | add_param_alias :ds, :doc_sources
50 |
51 | ##
52 | # List of classes to include in the documentation.
53 | add_param :doc_classes, Strings
54 |
55 | ##
56 | # List of namespaces to include in the documentation.
57 | add_param :doc_namespaces, Strings
58 |
59 | ##
60 | # Path to look for the example files.
61 | add_param :examples_path, Paths
62 |
63 | ##
64 | # Classes to exclude from documentation.
65 | add_param :exclude_classes, Strings
66 |
67 | ##
68 | # Boolean specifying whether to exclude dependencies.
69 | add_param :exclude_dependencies, Boolean
70 |
71 | ##
72 | # List of source files to exclude form the documentation.
73 | add_param :exclude_sources, Files
74 |
75 | ##
76 | # Footer string to be displayed in the documentation.
77 | add_param :footer, String
78 |
79 | add_param :include_all_for_asdoc, Boolean
80 |
81 | ##
82 | # If true, manifest entries with lookupOnly=true are included in SWC
83 | # catalog. Default is false. (advanced)
84 | add_param :include_lookup_only, Boolean, { :default => false }
85 |
86 | ##
87 | # Width of the left frame.
88 | add_param :left_frameset_width, Number
89 |
90 | ##
91 | # Report well-formed HTML errors as warnings.
92 | add_param :lenient, Boolean
93 |
94 | ##
95 | # Title to be displayed in the title bar.
96 | add_param :main_title, String
97 |
98 | ##
99 | # File containing description for packages.
100 | add_param :package_description_file, Files
101 |
102 | ##
103 | # Specifies a description for a package name.
104 | add_param :package, Strings, { :delimiter => ' ' }
105 |
106 | ##
107 | # Path for custom templates.
108 | add_param :templates_path, Path
109 |
110 | ##
111 | # Title to be displayed in the browser window.
112 | add_param :window_title, String
113 |
114 | # TODO: Possibly remove the following from the CompilerBase
115 | #
116 | # include_resource_bundles
117 |
118 | def execute
119 | # Never use fcsh for asdoc
120 | # (overused inheritance smell)
121 | self.use_fcsh = false
122 | duration = Benchmark.measure { super }
123 | Sprout.stdout.puts "[ASDOC] Creation complete in #{duration} seconds."
124 | end
125 |
126 | protected
127 |
128 | ##
129 | # Override the default behavior that creates a file task,
130 | # and create a 'task' instead. This will force the docs
131 | # to get recreated with every run, instead of failing to
132 | # create when the outer folder still exists.
133 | def create_outer_task *args
134 | Rake::Task.define_task *args do
135 | execute
136 | end
137 | end
138 | end
139 | end
140 |
141 | ##
142 | # Create a new Rake::File task that will execute {FlashSDK::AsDoc}.
143 | #
144 | # @return [FlashSDK::AsDoc]
145 | #
146 | # @example The following is a simple AsDoc task:
147 | #
148 | # desc "Compile the SWF"
149 | # mxmlc 'bin/SomeProject.swf' do |t|
150 | # t.library_path << 'lib/corelib.swc'
151 | # t.input = 'src/SomeProject.as'
152 | # end
153 | #
154 | # desc "Generate documentation"
155 | # asdoc 'docs/' do |t|
156 | # t.doc_sources << 'src'
157 | # end
158 | #
159 | def asdoc args, &block
160 | exe = FlashSDK::AsDoc.new
161 | exe.to_rake args, &block
162 | exe
163 | end
164 |
165 |
--------------------------------------------------------------------------------
/lib/flashsdk/fcsh_socket.rb:
--------------------------------------------------------------------------------
1 | require 'socket'
2 |
3 | module FlashSDK
4 |
5 | ##
6 | # This is a client to the long-running FCSH process.
7 | #
8 | # The server side of this connection should be
9 | # started before starting the client.
10 | #
11 | # To do this, just open a new terminal, cd into your
12 | # project directory, and run:
13 | #
14 | # rake fcsh:start
15 | #
16 | class FCSHSocket
17 |
18 | ##
19 | # The default TCP port that FCSH will use
20 | # to connect.
21 | DEFAULT_PORT = 12321
22 |
23 | attr_accessor :port
24 |
25 | attr_reader :requests
26 |
27 | ##
28 | # Create a new FCSHClient
29 | def initialize
30 | @port = DEFAULT_PORT
31 | @requests = {}
32 | end
33 |
34 | def listen pkg_name=nil, pkg_version=nil, port=nil
35 | port = port || @port
36 | # Instantiate FCSH:
37 | fcsh = FlashSDK::FCSH.new
38 | fcsh.pkg_name = pkg_name unless pkg_name.nil?
39 | fcsh.pkg_version = pkg_version unless pkg_version.nil?
40 |
41 | # Notify the outer shell that we're ready:
42 | Sprout.stdout.puts "FCSH socket open with: #{fcsh.pkg_name} and #{fcsh.pkg_version}, waiting for connections on port #{port}"
43 | Sprout.stdout.puts ""
44 |
45 | # Start up the FCSH Session:
46 | fcsh.execute false
47 |
48 | # Create a readable IO pipe:
49 | output = Sprout::OutputBuffer.new
50 | # Associate the IO pipe with our
51 | # outputs so that FCSH will write
52 | # to it.
53 | Sprout.stdout = output
54 | Sprout.stderr = output
55 |
56 | server = TCPServer.new 'localhost', port
57 |
58 | # Create a thread that will exit
59 | # when FCSH exits.
60 | t = Thread.new do
61 | fcsh.wait
62 | end
63 |
64 | while t.alive? do
65 | Sprout.stdout.puts ""
66 | session = server.accept
67 | rendered = render_request session.gets
68 | parts = rendered.split(" ")
69 | method = parts.shift.strip
70 | if parts.size > 0
71 | fcsh.send method, parts.join(" ")
72 | else
73 | fcsh.send method
74 | end
75 |
76 | fcsh.wait_for_prompt
77 |
78 | if method == "clear"
79 | clear_requests
80 | end
81 |
82 | response = "#{rendered}\n"
83 | response << output.read.gsub(rendered, '')
84 | session.puts response.gsub(fcsh.prompt, "\n")
85 | session.flush
86 | session.close
87 | end
88 | end
89 |
90 | def execute command, port=nil
91 | duration = Benchmark.measure do
92 | port = port || @port
93 | begin
94 | #Sprout.stdout.puts "[FCSH] #{command}"
95 | session = TCPSocket.new 'localhost', port
96 | session.puts command
97 | response = session.read
98 | if response.match /Error/
99 | raise Sprout::Errors::UsageError.new "[FCSH] #{response}"
100 | else
101 | Sprout.stdout.puts "[FCSH] #{response}"
102 | end
103 | response
104 | rescue Errno::ECONNREFUSED => e
105 | message = "[ERROR] "
106 | message << e.message
107 | message << ": Could not connect to an FCSH server on port: #{port} at: #{Dir.pwd}.\n\n"
108 | message << "This is probably because one has not been started. To start a new FCSH server, open a new "
109 | message << "terminal and run the following:\n\n"
110 | message << "cd #{Dir.pwd}\n"
111 | message << "rake fcsh:start\n"
112 | raise Sprout::Errors::UsageError.new message
113 | ensure
114 | if !session.nil? && !session.closed?
115 | session.flush
116 | session.close
117 | end
118 | end
119 | end
120 |
121 | if command.match /^mxmlc|^compc/
122 | Sprout.stdout.puts "[FCSH] complete in #{duration} seconds."
123 | end
124 | end
125 |
126 | private
127 |
128 | def render_request request
129 | if request.match /^mxmlc|^compc/
130 | hash = Digest::MD5.hexdigest request
131 |
132 | if requests[hash].nil?
133 | requests[hash] = next_compiler_index
134 | request
135 | else
136 | "compile #{requests[hash]}"
137 | end
138 | else
139 | request
140 | end
141 | end
142 |
143 | def next_compiler_index
144 | index = 1
145 | @requests.each do |key, value|
146 | value += 1
147 | index = [index, value].max
148 | end
149 | index
150 | end
151 |
152 | def clear_requests
153 | # Clear the cached requests,
154 | # but leave them in place, the underlying
155 | # FCSH implementation continues incrementing
156 | # indices.
157 |
158 | new_requests = {}
159 | @requests.each do |key, value|
160 | new_requests["removed-item"] = value
161 | end
162 | @requests = new_requests
163 | end
164 |
165 | end
166 | end
167 |
168 |
--------------------------------------------------------------------------------
/lib/flashsdk/compc.rb:
--------------------------------------------------------------------------------
1 | module FlashSDK
2 |
3 | ##
4 | # The COMPC compiler is a tool that creates SWC libraries from source code.
5 | #
6 | # Following is an example of the creation of a simple SWC file:
7 | #
8 | # compc 'bin/SomeProject.swc' do |t|
9 | # t.include_classes << 'SomeProject'
10 | # t.source_path << 'src'
11 | # end
12 | #
13 | # desc 'Compile the SWC'
14 | # task :swc => 'bin/SomeProject.swc'
15 | #
16 | class COMPC < CompilerBase
17 |
18 | ##
19 | # Outputs the SWC content as a SWF into an open directory format rather than a SWC file.
20 | #
21 | # This is especially useful for creating Runtime Shared Libraries.
22 | #
23 | # compc "bin/rsls/foo" do |t|
24 | # t.directory = true
25 | # t.include_sources = 'src'
26 | # end
27 | #
28 | # @see Sprout::COMPC#include_sources
29 | #
30 | add_param :directory, Boolean
31 |
32 | ##
33 | # Specifies classes to include in the SWC file. You provide the class name (for example, MyClass) rather than the file name (for example, MyClass.as) to the file for this option. As a result, all classes specified with this option must be in the compiler's source path. You specify this by using the source-path compiler option.
34 | #
35 | # You can use packaged and unpackaged classes. To use components in namespaces, use the include-namespaces option.
36 | #
37 | # If the components are in packages, ensure that you use dot-notation rather than slashes to separate package levels.
38 | #
39 | # This is the default option for the component compiler.
40 | #
41 | add_param :include_classes, Strings
42 |
43 | add_param_alias :ic, :include_classes
44 |
45 |
46 | ##
47 | # Adds the file to the SWC file. This option does not embed files inside the library.swf file. This is useful for skinning and theming, where you want to add non-compiled files that can be referenced in a style sheet or embedded as assets in MXML files.
48 | #
49 | # If you use the [Embed] syntax to add a resource to your application, you are not required to use this option to also link it into the SWC file.
50 | #
51 | # For more information, see Adding nonsource classes (http://livedocs.adobe.com/flex/201/html/compilers_123_39.html#158900).
52 | #
53 | add_param :include_file, Files
54 |
55 | add_param :include_lookup_only, Boolean
56 |
57 | ##
58 | # Specifies namespace-style components in the SWC file. You specify a list of URIs to include in the SWC file. The uri argument must already be defined with the namespace option.
59 | #
60 | # To use components in packages, use the include-classes option.
61 | #
62 | add_param :include_namespaces, Strings
63 |
64 | ##
65 | # Specifies the resource bundles to include in this SWC file. All resource bundles specified with this option must be in the compiler's source path. You specify this using the source-path compiler option.
66 | #
67 | # For more information on using resource bundles, see Localizing Flex Applications (http://livedocs.adobe.com/flex/201/html/l10n_076_1.html#129288) in Flex 2 Developer's Guide.
68 | #
69 | add_param :include_resource_bundles, Files
70 |
71 | ##
72 | # Specifies classes or directories to add to the SWC file. When specifying classes, you specify the path to the class file (for example, MyClass.as) rather than the class name itself (for example, MyClass). This lets you add classes to the SWC file that are not in the source path. In general, though, use the include-classes option, which lets you add classes that are in the source path.
73 | #
74 | # If you specify a directory, this option includes all files with an MXML or AS extension, and ignores all other files.
75 | #
76 | # compc "bin/SomeProject.swc" do |t|
77 | # t.include_sources << 'src'
78 | # t.library_path << 'lib/somelib.swc'
79 | # end
80 | #
81 | # You'll need to be sure your source path and library path are both set up properly for this work.
82 | #
83 | add_param :include_sources, Paths
84 |
85 | ##
86 | # Defines the mapping between your namespaces and the manifest.xml file describing the classes in that namespace.
87 | #
88 | # compc "bin/SomeProject.swc" do |t|
89 | # t.namespace = 'http://sprouts.org/ui sprouts-manifest.xml'
90 | # end
91 | add_param :namespace, String
92 |
93 | ##
94 | # Main source Class to send compiler.
95 | # If used, this should be the last item in the list
96 | add_param :input_class, String, { :hidden_name => true }
97 |
98 |
99 | ##
100 | # The the Ruby file that will load the expected
101 | # Sprout::Specification.
102 | #
103 | # Default value is 'flex4'
104 | #
105 | set :pkg_name, 'flex4'
106 |
107 | ##
108 | # The default pkg version
109 | #
110 | set :pkg_version, ">= #{FlashSDK::VERSION}"
111 |
112 | ##
113 | # The default executable target.
114 | #
115 | set :executable, :compc
116 | end
117 | end
118 |
119 | def compc args, &block
120 | exe = FlashSDK::COMPC.new
121 | exe.to_rake(args, &block)
122 | exe
123 | end
124 |
125 |
--------------------------------------------------------------------------------
/lib/flashsdk/mxmlc.rb:
--------------------------------------------------------------------------------
1 | module FlashSDK
2 |
3 | ##
4 | # The MXMLC task provides a rake front end to the Flex MXMLC command line compiler.
5 | # This task is integrated with the LibraryTask so that if any dependencies are
6 | # library tasks, they will be automatically added to the library_path or source_path
7 | # depending on whether they provide a swc or sources.
8 | #
9 | # The entire MXMLC advanced interface has been provided here. All parameter names should be
10 | # identical to what is available on the regular compiler except dashes have been replaced
11 | # by underscores.
12 | #
13 | # The following example can be pasted in a file named 'rakefile.rb' which should be placed in the same folder as an ActionScript 3.0 class named 'SomeProject.as' that extends flash.display.Sprite.
14 | #
15 | # # Create a remote library dependency on the corelib swc.
16 | # library :corelib
17 | #
18 | # # Alias the compilation task with one that is easier to type
19 | # task :compile => 'SomeProject.swf'
20 | #
21 | # # Create an MXMLC named for the output file that it creates. This task depends on the
22 | # # corelib library and will automatically add the corelib.swc to it's library_path
23 | # mxmlc 'bin/SomeProject.swf' => :corelib do |t|
24 | # t.input = 'src/SomeProject.as'
25 | # t.default_size = '800,600'
26 | # t.default_background_color = "#FFFFFF"
27 | # t.library_path << 'lib/SomeLibrary.swc'
28 | # t.source_path << 'lib/otherlib'
29 | # end
30 | #
31 | # Remember that Rake files are really just regular Ruby code, so if you want to have some configuration information shared by multiple build tasks, just define a method like:
32 | #
33 | # def configure_tasks t
34 | # t.library_path << 'lib/SomeLibrary.swc'
35 | # t.source_path << 'lib/otherlib'
36 | # end
37 | #
38 | # desc "Compile the project"
39 | # mxmlc 'bin/SomeProject.swf' do |t|
40 | # configure_tasks t
41 | # t.input = 'src/SomeProject.as'
42 | # end
43 | #
44 | # desc "Compile the test harness"
45 | # mxmlc 'bin/SomeProjectRunner.swf' => :asunit4 do |t|
46 | # configure_tasks t
47 | # t.input = 'src/SomeProjectRunner.as'
48 | # end
49 | #
50 | # == FCSH
51 | #
52 | # Building with MXMLC can be quite slow. If you'd like
53 | # to measure your build times in fractions of a second
54 | # rather than minutes, you can use the Flex Compiler
55 | # SHell (FCSH).
56 | #
57 | # Sprouts makes it incredibly easy to
58 | # use FCSH, following are some simple instructions:
59 | #
60 | # Open up a new terminal, cd into your project
61 | # directory and run:
62 | #
63 | # rake fcsh:start
64 | #
65 | # Open up a new terminal, cd into your project
66 | # directory and run whatever Rake task depends
67 | # on at least one MXMLC task, and call the
68 | # +fcsh+ task first. This can be done on the
69 | # terminal like this:
70 | #
71 | # rake fcsh test
72 | #
73 | # More information about FCSH can be found on the {Project Sprouts Blog}[http://projectsprouts.org/2011/01/18/using-fcsh.html].
74 | #
75 | # == Flex Debugger (FDB)
76 | #
77 | # Like FCSH, the Flex Debugger can be initiated
78 | # by calling (or depending on) the +fdb+ Rake task.
79 | #
80 | # rake fdb test
81 | #
82 | # This will drop you into the Flex Debugger shell
83 | # environment, you can type +help+ at anytime to
84 | # learn more about what commands are available.
85 | #
86 | # You can also type +quit+ or hit CTRL+C to exit
87 | # FDB.
88 | #
89 | # @see FlashSDK::CompilerBase
90 | # @see Sprout::Executable
91 | #
92 | class MXMLC < CompilerBase
93 |
94 | ##
95 | # Main source file to send compiler.
96 | # This must be the last item in this list
97 | add_param :input, File, { :required => true, :hidden_name => true }
98 |
99 | ##
100 | # Specifies the resource bundles to include when compiling a locale SWF. All resource bundles specified with this option must be in the compiler's source path. You specify this using the source-path compiler option.
101 | #
102 | # For more information on using resource bundles, see Localizing Flex Applications (http://livedocs.adobe.com/flex/201/html/l10n_076_1.html#129288) in Flex 2 Developer's Guide.
103 | #
104 | add_param :include_resource_bundles, Files
105 |
106 | ##
107 | # The default prefix for shell params.
108 | set :default_prefix, '-'
109 |
110 | ##
111 | # The the Ruby file that will load the expected
112 | # Sprout::Specification.
113 | #
114 | # Default value is 'flex4'
115 | #
116 | set :pkg_name, 'flex4'
117 |
118 | ##
119 | # The default pkg version
120 | #
121 | set :pkg_version, ">= #{FlashSDK::VERSION}"
122 |
123 | ##
124 | # The default executable target.
125 | #
126 | set :executable, :mxmlc
127 |
128 | def execute
129 | duration = Benchmark.measure { super }
130 | Sprout.stdout.puts "[MXMLC] Compilation complete in #{duration.real} seconds." unless use_fcsh?
131 | end
132 |
133 | def use_fcsh?
134 | # Check as string b/c this is
135 | # how the boolean value comes
136 | # accross the command line input.
137 | ENV['USE_FCSH'].to_s == 'true'
138 | end
139 |
140 | end
141 | end
142 |
143 | ##
144 | # Create a new Rake::File task that will execute {FlashSDK::MXMLC}.
145 | #
146 | # @return [FlashSDK::MXMLC]
147 | #
148 | # @example The following is a simple MXMLC task:
149 | #
150 | # desc "Compile the project"
151 | # mxmlc 'bin/SomeProject.swf' do |t|
152 | # t.input = 'src/SomeProject.as'
153 | # end
154 | #
155 | def mxmlc args, &block
156 | exe = FlashSDK::MXMLC.new
157 | exe.to_rake args, &block
158 | exe
159 | end
160 |
161 |
--------------------------------------------------------------------------------
/lib/flex4.rb:
--------------------------------------------------------------------------------
1 |
2 | Sprout::Specification.new do |s|
3 | # This is the Specification that loads the Flex 4 SDK,
4 | # To use the Flex 4 SDK from your build tasks, you can
5 | # simply update the pkg_name parameter of your build
6 | # task as follows:
7 | #
8 | # mxmlc 'bin/SomeProject.swf' do |t|
9 | # t.input = 'src/SomeProject.as'
10 | # t.pkg_name = 'flex4'
11 | # end
12 | #
13 | # If you'd like to consume any of the libraries that
14 | # are included with the Flex SDK, you can embed them
15 | # from your Rakefile as follows:
16 | #
17 | # library :f_textlayout
18 | #
19 | # mxmlc 'bin/SomeProject.swf' => :f_textlayout do |t|
20 | # t.input = 'src/SomeProject.as'
21 | # end
22 | #
23 | # If you'd like to consume one of the localized frameworks
24 | # you can set that up as follows:
25 | #
26 | # library 'flex_4_es_ES'
27 | #
28 | # mxmlc 'bin/SomeProject.swf' => 'flex_4_es_ES' do |t|
29 | # t.input = 'src/SomeProject.as'
30 | # end
31 | #
32 | s.name = 'flex4'
33 | s.version = '4.6.0.23201'
34 |
35 | s.add_remote_file_target do |t|
36 | t.platform = :universal
37 | t.archive_type = :zip
38 | t.url = "http://download.macromedia.com/pub/flex/sdk/flex_sdk_4.6.zip"
39 | t.md5 = "202bca98ee7b8db9cda3af01e99c688e"
40 |
41 | # Executables: (add .exe suffix if it was passed in)
42 | t.add_executable :aasdoc, "bin/aasdoc"
43 | t.add_executable :acompc, "bin/acompc"
44 | t.add_executable :adl, "bin/adl"
45 | t.add_executable :adt, "bin/adt"
46 | t.add_executable :amxmlc, "bin/amxmlc"
47 | t.add_executable :asdoc, "bin/asdoc"
48 | t.add_executable :compc, "bin/compc"
49 | t.add_executable :copylocale, "bin/copylocale"
50 | t.add_executable :digest, "bin/digest"
51 | t.add_executable :fcsh, "bin/fcsh"
52 | t.add_executable :fdb, "bin/fdb"
53 | t.add_executable :mxmlc, "bin/mxmlc"
54 | t.add_executable :optimizer, "bin/optimizer"
55 |
56 | # Flex framework SWCs:
57 | t.add_library :advancedgrids, "frameworks/libs/advancedgrids.swc"
58 | t.add_library :aircore, "frameworks/libs/air/aircore.swc"
59 | t.add_library :airframework, "frameworks/libs/air/airframework.swc"
60 | t.add_library :airglobal, "frameworks/libs/air/airglobal.swc"
61 | t.add_library :airspark, "frameworks/libs/air/airspark.swc"
62 | t.add_library :applicationupdater, "frameworks/libs/air/applicationupdater.swc"
63 | t.add_library :applicationupdater_ui, "frameworks/libs/air/applicationupdater_ui.swc"
64 | t.add_library :automation, "frameworks/libs/automation/automation.swc"
65 | t.add_library :automation_agent, "frameworks/libs/automation/automation_agent.swc"
66 | t.add_library :automation_air, "frameworks/libs/automation/automation_air.swc"
67 | t.add_library :automation_airspark, "frameworks/libs/automation/automation_airspark.swc"
68 | t.add_library :automation_dmv, "frameworks/libs/automation/automation_dmv.swc"
69 | t.add_library :automation_flashflexkit, "frameworks/libs/automation/automation_flashflexkit.swc"
70 | t.add_library :automation_spark, "frameworks/libs/automation/automation_spark.swc"
71 | t.add_library :qtp, "frameworks/libs/automation/qtp.swc"
72 | t.add_library :qtp_air, "frameworks/libs/automation/qtp_air.swc"
73 | t.add_library :servicemonitor, "frameworks/libs/air/servicemonitor.swc"
74 | t.add_library :authoringsupport, "frameworks/libs/authoringsupport.swc"
75 | t.add_library :charts, "frameworks/libs/charts.swc"
76 | t.add_library :core, "frameworks/libs/core.swc"
77 | t.add_library :flash_integration, "frameworks/libs/flash-integration.swc"
78 | t.add_library :framework, "frameworks/libs/framework.swc"
79 | t.add_library :mobilecomponents, "frameworks/libs/mobile/mobilecomponents.swc"
80 | t.add_library :mx, "frameworks/libs/mx/mx.swc"
81 | t.add_library :osmf, "frameworks/libs/osmf.swc"
82 | t.add_library :playerglobal_11, "frameworks/libs/player/11.1/playerglobal.swc"
83 | t.add_library :rpc, "frameworks/libs/rpc.swc"
84 | t.add_library :spark, "frameworks/libs/spark.swc"
85 | t.add_library :spark_dmv, "frameworks/libs/spark_dmv.swc"
86 | t.add_library :sparkskins, "frameworks/libs/sparkskins.swc"
87 | t.add_library :textLayout, "frameworks/libs/textLayout.swc"
88 |
89 | # AsDoc templates:
90 | t.add_library :asdoc_templates, "asdoc/templates"
91 |
92 | # Locale-Specific Flex SWCs:
93 | [
94 | 'da_DK', 'de_DE', 'en_US', 'es_ES', 'fi_FL', 'fr_FR', 'it_IT', 'ja_JP',
95 | 'ko_KR', 'nb_NO', 'nl_NL', 'pt_BR', 'ru_RU', 'sv_SE', 'zh_CN', 'zh_TW'
96 | ].each do |locale|
97 | t.add_library "advancedgrids_#{locale}".to_sym, "frameworks/locale/#{locale}/advancedgrids_rb.swc"
98 | t.add_library "airframework_#{locale}".to_sym, "frameworks/locale/#{locale}/airframework_rb.swc"
99 | t.add_library "airspark_#{locale}".to_sym, "frameworks/locale/#{locale}/airspark_rb.swc"
100 | t.add_library "automation_agent_#{locale}".to_sym, "frameworks/locale/#{locale}/automation_agent_rb.swc"
101 | t.add_library "automation_#{locale}".to_sym, "frameworks/locale/#{locale}/automation_rb.swc"
102 | t.add_library "charts_#{locale}".to_sym, "frameworks/locale/#{locale}/charts_rb.swc"
103 | t.add_library "flash_integration_#{locale}".to_sym, "frameworks/locale/#{locale}/flash-integration_rb.swc"
104 | t.add_library "framework_#{locale}".to_sym, "frameworks/locale/#{locale}/framework_rb.swc"
105 | t.add_library "mobilecomponents_#{locale}".to_sym, "frameworks/locale/#{locale}/mobilecomponents_rb.swc"
106 | t.add_library "mx_#{locale}".to_sym, "frameworks/locale/#{locale}/mx_rb.swc"
107 | t.add_library "osmf_#{locale}".to_sym, "frameworks/locale/#{locale}/osmf_rb.swc"
108 | t.add_library "playerglobal_#{locale}".to_sym, "frameworks/locale/#{locale}/playerglobal_rb.swc"
109 | t.add_library "qtp_air_#{locale}".to_sym, "frameworks/locale/#{locale}/qtp_air_rb.swc"
110 | t.add_library "rpc_#{locale}".to_sym, "frameworks/locale/#{locale}/rpc_rb.swc"
111 | t.add_library "spark_#{locale}".to_sym, "frameworks/locale/#{locale}/spark_rb.swc"
112 | t.add_library "textLayout_#{locale}".to_sym, "frameworks/locale/#{locale}/textLayout_rb.swc"
113 | end
114 | end
115 | end
116 |
--------------------------------------------------------------------------------
/test/unit/adt_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class ADTTest < Test::Unit::TestCase
4 | include Sprout::TestHelper
5 |
6 | context "An ADT tool" do
7 |
8 | setup do
9 | @fixture = File.join 'test', 'fixtures', 'air', 'simple'
10 | @application_xml = File.join @fixture, 'SomeProject.xml'
11 | @expected_output = File.join @fixture, 'SomeProject.air'
12 | @apk_input = File.join @fixture, 'SomeProject.apk'
13 | @ipa_output = File.join @fixture, 'SomeProject.ipa'
14 | @swf_input = File.join @fixture, 'SomeProject.swf'
15 | @swf_main = File.join @fixture, 'SomeProject.mxml'
16 | @certificate = File.join @fixture, 'SomeProject.pfx'
17 | @ipa_cert = File.join @fixture, 'SomeProject.p12'
18 | @provisioning_profile = File.join @fixture, 'Profile.mobileprovision'
19 | @platform = 'android'
20 | @target = 'apk-debug'
21 | @appid = 'com.foo.bar.SomeProject'
22 | @cert_password = 'samplePassword'
23 | end
24 |
25 | teardown do
26 | clear_tasks
27 | remove_file @expected_output
28 | end
29 |
30 | should "package a SWF with an application.xml" do
31 | as_a_unix_system do
32 | t = adt @expected_output do |t|
33 | t.package = true
34 | t.target = @target
35 | t.package_input = @application_xml
36 | t.package_output = @expected_output
37 | t.storetype = 'PKCS12'
38 | t.keystore = @certificate
39 | t.storepass = @cert_password
40 | t.included_files << @swf_input
41 | end
42 |
43 | assert_equal "-package -storetype PKCS12 -keystore #{@certificate} " +
44 | "-storepass #{@cert_password} -target #{@target} " +
45 | "test/fixtures/air/simple/SomeProject.air " +
46 | "test/fixtures/air/simple/SomeProject.xml " +
47 | "test/fixtures/air/simple/SomeProject.swf", t.to_shell
48 |
49 | # Uncomment to actually run adt (much slower)
50 | #t.execute
51 | #assert_file @expected_output
52 | end
53 | end
54 |
55 | should "package a SWF and complex assets with an application.xml" do
56 | as_a_unix_system do
57 | t = adt @expected_output do |t|
58 | t.package = true
59 | t.target = @target
60 | t.package_input = @application_xml
61 | t.package_output = @expected_output
62 | t.storetype = 'PKCS12'
63 | t.keystore = @certificate
64 | t.storepass = @cert_password
65 | t.included_files << @swf_input
66 | t.file_options << 'bin path/to/asset.xml'
67 | end
68 |
69 | assert_equal "-package -storetype PKCS12 -keystore #{@certificate} " +
70 | "-storepass #{@cert_password} -target #{@target} " +
71 | "test/fixtures/air/simple/SomeProject.air " +
72 | "test/fixtures/air/simple/SomeProject.xml " +
73 | "test/fixtures/air/simple/SomeProject.swf " +
74 | "-C bin path/to/asset.xml", t.to_shell
75 |
76 | # Uncomment to actually run adt (much slower)
77 | #t.execute
78 | #assert_file @expected_output
79 | end
80 | end
81 |
82 | should "package an iOS swf with a provisioning profile" do
83 | as_a_unix_system do
84 | t = adt @ipa_output do |t|
85 | t.package = true
86 | t.target = 'ipa-test'
87 | t.package_input = @application_xml
88 | t.package_output = @ipa_output
89 | t.storetype = 'PKCS12'
90 | t.keystore = @ipa_cert
91 | t.storepass = @cert_password
92 | t.provisioning_profile = @provisioning_profile
93 | t.included_files << @swf_input
94 | end
95 |
96 | assert_equal "-package -storetype PKCS12 -keystore #{@ipa_cert} " +
97 | "-storepass #{@cert_password} -provisioning-profile " +
98 | "#{@provisioning_profile} -target ipa-test " +
99 | "test/fixtures/air/simple/SomeProject.ipa " +
100 | "test/fixtures/air/simple/SomeProject.xml " +
101 | "test/fixtures/air/simple/SomeProject.swf", t.to_shell
102 |
103 | # Uncomment to actually run adt (much slower)
104 | #t.execute
105 | #assert_file @expected_output
106 | end
107 | end
108 |
109 | should "install an APK" do
110 | as_a_unix_system do
111 | t = adt @expected_output do |t|
112 | t.installApp = true
113 | t.platform = @platform
114 | t.package = true
115 | t.package_input = @apk_input
116 | end
117 |
118 | assert_equal "-installApp -platform #{@platform} -package #{@apk_input}", t.to_shell
119 |
120 | # Uncomment to actually run adt (much slower)
121 | #t.execute
122 | #assert_file @expected_output
123 | end
124 | end
125 |
126 | should "uninstall an APK" do
127 | as_a_unix_system do
128 | t = adt @expected_output do |t|
129 | t.uninstallApp = true
130 | t.platform = @platform
131 | t.appid = @appid
132 | end
133 |
134 | assert_equal "-uninstallApp -platform #{@platform} -appid #{@appid}", t.to_shell
135 |
136 | # Uncomment to actually run adt (much slower)
137 | #t.execute
138 | #assert_file @expected_output
139 | end
140 | end
141 |
142 | should "launch an app" do
143 | as_a_unix_system do
144 | t = adt @expected_output do |t|
145 | t.launchApp = true
146 | t.platform = @platform
147 | t.appid = @appid
148 | end
149 |
150 | assert_equal "-launchApp -platform #{@platform} -appid #{@appid}", t.to_shell
151 |
152 | # Uncomment to actually run adt (much slower)
153 | #t.execute
154 | #assert_file @expected_output
155 | end
156 | end
157 |
158 | should "create a self-signed certificate" do
159 | as_a_unix_system do
160 | t = adt(@certificate) do |t|
161 | t.certificate = true
162 | t.cn = 'SelfCertificate'
163 | t.key_type = '2048-RSA'
164 | t.pfx_file = @certificate
165 | t.password = @cert_password
166 | end
167 |
168 | assert_equal '-certificate -cn SelfCertificate 2048-RSA test/fixtures/air/simple/SomeProject.pfx samplePassword', t.to_shell
169 |
170 | # Uncomment to actually run adt (much slower)
171 | #t.execute
172 | #assert_file @certificate
173 | end
174 | end
175 |
176 | # USE THIS METHOD TO CREATE THE INPUT SWF:
177 | #should "create an input swf" do
178 | #t = amxmlc @swf_input do |t|
179 | #t.input = @swf_main
180 | #end
181 | #t.execute
182 | #end
183 | end
184 | end
185 |
186 |
--------------------------------------------------------------------------------
/lib/flashsdk/generators/flash_helper.rb:
--------------------------------------------------------------------------------
1 |
2 | module FlashSDK
3 |
4 | ##
5 | # The FlashHelper is a module that can be included into any {Sprout::Generator}
6 | # in order to provide support for many common features.
7 | #
8 | # @example An example of how to use this helper:
9 | #
10 | # require 'flashsdk'
11 | #
12 | # class BigFatGenerator < Sprout::Generator::Base
13 | # include FlashSDK::FlashHelper
14 | #
15 | # ...
16 | # end
17 | #
18 | module FlashHelper
19 |
20 | protected
21 |
22 | ##
23 | # @return [String] The directory of the package based on the +input+ string.
24 | def package_directory
25 | if package.include?('/')
26 | remove_slashes package
27 | end
28 | split_package package
29 | end
30 |
31 | ##
32 | # @param [String] A directory or path on disk with slashes like ('/')
33 | # @return [String] The provided value with slashes replaced by dots.
34 | def remove_slashes(value)
35 | if value.include?('/')
36 | value = value.split('/').join('.')
37 | end
38 | return value
39 | end
40 |
41 | ##
42 | # @param value [String] A fully-qualified package or class name (com.example.project.SomeClass)
43 | # @return [Array] The provided package or class name split on the period.
44 | # split on dots.
45 | def split_package(value)
46 | value.split('.')
47 | end
48 |
49 | ##
50 | # @return [String] The directory for test cases that are related to the class provided by +input+
51 | def test_class_directory
52 | parts = input_in_parts
53 | if parts.size > 1
54 | parts.pop
55 | return File.join test, *parts
56 | end
57 | return test
58 | end
59 |
60 | ##
61 | # @return [String] Glob that is used to search for test cases and build
62 | # up the test suites.
63 | def test_glob
64 | return @test_glob ||= File.join(path, test, '**', '?*Test.as')
65 | end
66 |
67 | # @return [String] The provided or default glob.
68 | def test_glob= glob
69 | @test_glob = glob
70 | end
71 |
72 | ##
73 | # @return [Array] Collection of all test case files either assigned or found
74 | # using the test_glob as provided.
75 | def test_cases
76 | @test_cases ||= Dir.glob(test_glob)
77 | end
78 |
79 | ##
80 | # @param [Array] Set the collection of test cases as Files on disk.
81 | # @return [Array] Collection of all test case files that were assigned or found.
82 | def test_cases= collection
83 | @test_cases = collection
84 | end
85 |
86 | ##
87 | # @return [Array] Get the list of test_cases (which are files) as a
88 | # list of fully qualified class names.
89 | def test_case_classes
90 | classes = self.test_cases.dup
91 | classes.collect do |file|
92 | actionscript_file_to_class_name(file)
93 | end
94 | end
95 |
96 | ##
97 | # Transform a file name in the source or test path
98 | # into a fully-qualified class name.
99 | #
100 | # @param file [File] The path to a file on disk that is in the +src+ or +test+ folder.
101 | # @return [String] The fully-qualified class name.
102 | def actionscript_file_to_class_name file
103 | name = file.dup
104 | name.gsub!(/^#{path}\//, '') if respond_to? :path
105 | name.gsub!(/^#{test}\//, '') if respond_to? :test
106 | name.gsub!(/^#{src}\//, '') if respond_to? :src
107 | name.gsub!(/.as$/, '')
108 | name.gsub!(/#{File::SEPARATOR}/, '.')
109 | return name
110 | end
111 |
112 | ##
113 | # @return [String] The directory that contains the +input+ class.
114 | def class_directory
115 | parts = input_in_parts
116 | if parts.size > 1
117 | parts.pop
118 | return File.join src, *parts
119 | end
120 | return src
121 | end
122 |
123 | ##
124 | # @return [String] The package that provided on the command line at +--package+
125 | def default_package_name
126 | remove_slashes package
127 | end
128 |
129 | ##
130 | # @return [String] The package that was provided on the command line at +--input+
131 | def package_name
132 | parts = input_in_parts
133 | if parts.size > 1
134 | parts.pop
135 | return "#{parts.join('.')} "
136 | end
137 | return ""
138 | end
139 |
140 | ##
141 | # @return [String] The fully-qualified class name provided on the command line at +--input+.
142 | def class_name
143 | parts = input_in_parts
144 | name = parts.pop.camel_case
145 | if(name.match(/Test$/))
146 | return name.gsub(/Test$/, '')
147 | end
148 | name
149 | end
150 |
151 | ##
152 | # @return [String] The fully-qualified test class name based on the +--input+
153 | # argument provided on the command line.
154 | def test_class_name
155 | source = class_name
156 | if(!source.match(/Test$/))
157 | return "#{source}Test"
158 | end
159 | source
160 | end
161 |
162 | ##
163 | # @return [String] The project name provided as +--input+ on the command line.
164 | # This is probably only helpful for project generators.
165 | def project_name
166 | input.camel_case
167 | end
168 |
169 | ##
170 | # @return [String] Currently returns hard-coded 'instance'.
171 | def instance_name
172 | # TODO: should uncapitalize class_name
173 | # (not the same as lowercase)
174 | # If the name is > 12 character, just
175 | # use 'instance' instead.
176 | 'instance'
177 | end
178 |
179 | ##
180 | # @param value [String] If no value is provided, will use +--input+ instead.
181 | # @return [Array] An Array of the provided string split on slahes
182 | # or dots with the file extension removed.
183 | def input_in_parts(value=nil)
184 | provided_input = value || input.dup
185 | provided_input.gsub! /^#{src}\//, '' if respond_to? :src
186 | provided_input = provided_input.split('/').join('.')
187 |
188 | remove_file_extensions(provided_input).split('.')
189 | end
190 |
191 | ##
192 | # @return [String] The fully qualified class name version of whatever was +input+.
193 | def fully_qualified_class_name
194 | remove_slashes remove_file_extensions(input)
195 | end
196 |
197 | ##
198 | # @param value [String] A string that may have a file extension.
199 | # @return [String] A new String with common file extensions
200 | # (.as, .mxml, .xml) removed from the provided value.
201 | def remove_file_extensions value
202 | value = value.dup
203 | value.gsub!(/\.as$/, '')
204 | value.gsub!(/\.mxml$/, '')
205 | value.gsub!(/\.xml$/, '')
206 | return value
207 | end
208 |
209 | ##
210 | # @return [String] The +class_name+ with '.swf' appended.
211 | def deploy_swf_name
212 | "#{class_name}.swf"
213 | end
214 |
215 | ##
216 | # @return [String] The +class_name+ with '-debug.swf' appended.
217 | def debug_swf_name
218 | "#{class_name}-debug.swf"
219 | end
220 |
221 | ##
222 | # @return [String] The +class_name+ with '-test.swf' appendend.
223 | def test_swf_name
224 | "#{class_name}-test.swf"
225 | end
226 |
227 | ##
228 | # @return [String] The +class_name+ with 'Runner.swf' appended.
229 | def test_runner_name
230 | "#{class_name}Runner"
231 | end
232 |
233 | end
234 | end
235 |
--------------------------------------------------------------------------------
/lib/flashsdk/adt.rb:
--------------------------------------------------------------------------------
1 | module FlashSDK
2 |
3 | ##
4 | # Creates AIR certificates and compiles AIR packages for distribution.
5 | #
6 | # Following is an example of how this tool might be used to create
7 | # a certificate and AIR package:
8 | #
9 | # mxmlc 'bin/SomeProject.swf' do |t|
10 | # t.input = 'src/SomeProject.as'
11 | # end
12 | #
13 | # adt 'cert/SomeProject.pfx' do |t|
14 | # t.certificate = true
15 | # t.cn = 'SelfCertificate'
16 | # t.key_type = '2048-RSA'
17 | # t.pfx_file = 'cert/SomeProject.pfx'
18 | # # Don't check the .password file into version control:
19 | # t.password = File.read('cert/.password')
20 | # end
21 | #
22 | # adt 'bin/SomeProject.air' => ['bin/SomeProject.swf', 'cert/SomeProject.pfx'] do |t|
23 | # t.package = true
24 | # t.package_input = 'SomeProject.xml'
25 | # t.package_output = 'bin/SomeProject.air'
26 | # t.storetype = 'PKCS12'
27 | # t.keystore = 'cert/SomeProject.pfx'
28 | # # Don't check the .password file into version control:
29 | # t.storepass = File.read('cert/.password')
30 | # t.included_files << 'bin/SomeProject.swf'
31 | # end
32 | #
33 | # desc "Compile, certify and package the AIR application"
34 | # task package => 'bin/SomeProject.air'
35 | #
36 | class ADT < Sprout::Executable::Base
37 | #NOTE:
38 | # The order of these parameters is important!
39 | # Please do not alphabetize or rearrange unless you're
40 | # fixing a bug related to how ADT actually expects
41 | # the arguments...
42 |
43 | ##
44 | # Install an app on a device
45 | #
46 | add_param :installApp, Boolean, { :hidden_value => true }
47 |
48 | ##
49 | # Uninstall an app from a device
50 | #
51 | add_param :uninstallApp, Boolean, { :hidden_value => true }
52 |
53 | ##
54 | # Launch an app on a device
55 | #
56 | add_param :launchApp, Boolean, { :hidden_value => true }
57 |
58 | ##
59 | # The platform to use (ex: android)
60 | #
61 | add_param :platform, String, { :delimiter => ' ' }
62 |
63 | ##
64 | # The appid of the app being installed/uninstalled (ex: com.foo.Bar)
65 | #
66 | add_param :appid, String, { :delimiter => ' ' }
67 |
68 | ##
69 | # Create an AIR package.
70 | #
71 | add_param :package, Boolean, { :hidden_value => true }
72 |
73 | ##
74 | # Set true to create a certificate.
75 | #
76 | # If this value is true, you can optionally set org_unit, org_name and country.
77 | #
78 | # If this value is true, you MUST set +cn+, +key_type+, and +pfx_file+.
79 | #
80 | # adt 'cert/SampleCert.pfx' do |t|
81 | # t.certificate = true
82 | # t.cn = 'SelfCertificate'
83 | # t.key_type = '1024-RSA'
84 | # t.pfx_file = 'cert/SampleCert.pfx'
85 | # t.password = 'samplepassword'
86 | # end
87 | #
88 | add_param :certificate, Boolean, { :hidden_value => true }
89 |
90 | ##
91 | # A Signing Option
92 | #
93 | add_param :storetype, String, { :delimiter => ' ' }
94 |
95 |
96 | ##
97 | # A Signing Option
98 | #
99 | add_param :keystore, String, { :delimiter => ' ' }
100 |
101 | ##
102 | # Provide the password directly to the ADT task
103 | # so that it doesn't attempt to prompt.
104 | #
105 | add_param :storepass, String, { :delimiter => ' ' }
106 |
107 |
108 | ##
109 | # A Signing Option
110 | #
111 | add_param :keypass, String, { :delimiter => ' ' }
112 |
113 |
114 | ##
115 | # A Signing Option
116 | #
117 | add_param :providername, String, { :delimiter => ' ' }
118 |
119 |
120 | ##
121 | # A Signing Option
122 | #
123 | add_param :tsa, String
124 |
125 | ##
126 | # Check Store Signing options
127 | #
128 | add_param :checkstore, String
129 |
130 | ##
131 | # Provisioning profile for iOS apps
132 | #
133 | add_param :provisioning_profile, String, { :delimiter => ' ' }
134 |
135 | ##
136 | # Expects two files:
137 | #
138 | # 1) The Airi file (?)
139 | # 2) The application description
140 | #add_param :prepare, Files
141 |
142 | ##
143 | # Expects two files:
144 | #
145 | # 1) The Airi file (?)
146 | # 2) The Air file
147 | add_param :sign, Files, { :delimiter => ' ' }
148 |
149 |
150 | ##
151 | # The AIR runtime version to use.
152 | add_param :version, String, { :delimiter => ' ' }
153 |
154 |
155 | ##
156 | # Use a specific target, like apk-debug for Android or ipa-debug for iOS
157 | #
158 | add_param :target, String, { :delimiter => ' ' }
159 |
160 | ##
161 | # The AIR file that should be created
162 | # after packaging is complete.
163 | #
164 | add_param :package_output, String, { :hidden_name => true }
165 |
166 | ##
167 | # The XML application descriptor that
168 | # should be used to create an AIR
169 | # application.
170 | #
171 | add_param :package_input, File, { :hidden_name => true }
172 |
173 | ##
174 | # Organization unit, follows certificate.
175 | #
176 | add_param :org_unit, String
177 |
178 | ##
179 | # Organization name, follows certificate.
180 | #
181 | add_param :org_name, String
182 |
183 | ##
184 | # Country, follows certificate.
185 | #
186 | add_param :country, String
187 |
188 | ##
189 | # The Certificate name.
190 | #
191 | add_param :cn, String, { :delimiter => ' ' }
192 |
193 | ##
194 | # Key Type, follows certificate.
195 | #
196 | add_param :key_type, String, { :hidden_name => true }
197 |
198 | ##
199 | # PFX File
200 | #
201 | add_param :pfx_file, String, { :hidden_name => true }
202 |
203 | ##
204 | # When creating a certificate, this is the file
205 | # where the password can be found.
206 | #
207 | add_param :password, String, { :hidden_name => true, :delimiter => ' ' }
208 |
209 | ##
210 | # Expects Signing Options, plus
211 | # two files:
212 | #
213 | # 1) The Air file in
214 | # 2) The Air file out
215 | #
216 | add_param :migrate, Files
217 |
218 | ##
219 | # A list of files to include in the
220 | #
221 | add_param :included_files, Files, { :hidden_name => true }
222 |
223 | ##
224 | # A list of paths (directories) to search
225 | # for contents that will be included in the
226 | # packaged AIR application.
227 | #
228 | # If files are hidden from the file system,
229 | # they will not be included.
230 | #
231 | add_param :included_paths, Paths, { :hidden_name => true }
232 |
233 | ##
234 | # Allows file options in the form of -C +
235 | #
236 | # For example if you defined:
237 | #
238 | # t.file_options << 'dir path/to/asset.xml'
239 | #
240 | # In your adt task defintion, then:
241 | #
242 | # -C dir path/to/asset.xml
243 | #
244 | # Would be appended to your arguments.
245 | #
246 | add_param :file_options, Strings, { :shell_name => '-C', :delimiter => ' ' }
247 |
248 | ##
249 | # The the Ruby file that will load the expected
250 | # Sprout::Specification.
251 | #
252 | # Default value is 'flex4'
253 | #
254 | set :pkg_name, 'flex4'
255 |
256 | ##
257 | # The default pkg version
258 | #
259 | set :pkg_version, ">= #{FlashSDK::VERSION}"
260 |
261 | ##
262 | # The default executable target.
263 | #
264 | set :executable, :adt
265 |
266 | ##
267 | # Ensure the default prefix is '-'
268 | set :default_prefix, '-'
269 | end
270 | end
271 |
272 | def adt *args, &block
273 | exe = FlashSDK::ADT.new
274 | exe.to_rake(*args, &block)
275 | exe
276 | end
277 |
--------------------------------------------------------------------------------
/test/unit/flex_compiler_options_test.rb:
--------------------------------------------------------------------------------
1 | require 'test_helper'
2 |
3 | class FlexCompilerOptionsTest < Test::Unit::TestCase
4 | include Sprout::TestHelper
5 |
6 | # formal tests for a variety of Flex compiler options and how they should appear on the CLI based on true/false settings
7 | context "A Flex compiler's options" do
8 |
9 | setup do
10 | @mxmlc = FlashSDK::MXMLC.new
11 | end
12 |
13 | teardown do
14 | end
15 |
16 | # -as3
17 | should "default to as3=true" do
18 | assert_equal true, @mxmlc.as3
19 | end
20 |
21 | should "not include a -as3 flag if :as3 is set to true" do
22 | @mxmlc.as3 = true
23 | assert_no_match /-as3/, @mxmlc.to_shell
24 | end
25 |
26 | should "include -as3=false flag if :as3 is set to false" do
27 | @mxmlc.as3 = false
28 | assert_equal '-as3=false', @mxmlc.to_shell
29 | end
30 |
31 | # -benchmark
32 | should "default to benchmark=true" do
33 | assert_equal true, @mxmlc.benchmark
34 | end
35 |
36 | should "not include a -benchmark flag if :benchmark is set to true" do
37 | @mxmlc.benchmark = true
38 | assert_no_match /-benchmark/, @mxmlc.to_shell
39 | end
40 |
41 | should "include -benchmark=false flag if :benchmark is set to false" do
42 | @mxmlc.benchmark = false
43 | assert_equal '-benchmark=false', @mxmlc.to_shell
44 | end
45 |
46 | # -debug
47 | should "default to debug=false" do
48 | assert_equal false, @mxmlc.debug
49 | end
50 |
51 | should "not include a -debug flag if :debug is set to false" do
52 | assert_no_match /-debug/, @mxmlc.to_shell
53 | end
54 |
55 | should "include -debug flag if :debug is set to true" do
56 | @mxmlc.debug = true
57 | assert_equal '-debug', @mxmlc.to_shell
58 | end
59 |
60 | # -use-network
61 | should "default to use_network=false" do
62 | assert_equal true, @mxmlc.use_network
63 | end
64 |
65 | should "not include a -use-network flag if :use_network is set to true" do
66 | @mxmlc.use_network = true
67 | assert_no_match /-use-network/, @mxmlc.to_shell
68 | end
69 |
70 | should "include -use-network=false flag if :use_network is set to false" do
71 | @mxmlc.use_network = false
72 | assert_equal '-use-network=false', @mxmlc.to_shell
73 | end
74 |
75 | # -optimize
76 | should "default to optimize=true" do
77 | assert_equal true, @mxmlc.optimize
78 | end
79 |
80 | should "not include a -optimize flag if :optimize is set to true" do
81 | @mxmlc.optimize = true
82 | assert_no_match /-optimize/, @mxmlc.to_shell
83 | end
84 |
85 | should "include -optimize=false flag if :optimize is set to false" do
86 | @mxmlc.optimize = false
87 | assert_equal '-optimize=false', @mxmlc.to_shell
88 | end
89 |
90 | # -show-actionscript-warnings
91 | should "default to show-actionscript-warnings=true" do
92 | assert_equal true, @mxmlc.show_actionscript_warnings
93 | end
94 |
95 | should "not include a -show-actionscript-warnings flag if :show-actionscript-warnings is set to true" do
96 | @mxmlc.show_actionscript_warnings = true
97 | assert_no_match /-show-actionscript-warnings/, @mxmlc.to_shell
98 | end
99 |
100 | should "include -show-actionscript-warnings=false flag if :show-actionscript-warnings is set to false" do
101 | @mxmlc.show_actionscript_warnings = false
102 | assert_equal '-show-actionscript-warnings=false', @mxmlc.to_shell
103 | end
104 |
105 | # -show-binding-warnings
106 | should "default to show-binding-warnings=true" do
107 | assert_equal true, @mxmlc.show_binding_warnings
108 | end
109 |
110 | should "not include a -show-binding-warnings flag if :show-binding-warnings is set to true" do
111 | @mxmlc.show_binding_warnings = true
112 | assert_no_match /-show-binding-warnings/, @mxmlc.to_shell
113 | end
114 |
115 | should "include -show-binding-warnings=false flag if :show-binding-warnings is set to false" do
116 | @mxmlc.show_binding_warnings = false
117 | assert_equal '-show-binding-warnings=false', @mxmlc.to_shell
118 | end
119 |
120 | # -show-shadowed-device-font-warnings
121 | should "default to show-shadowed-device-font-warnings=true" do
122 | assert_equal true, @mxmlc.show_shadowed_device_font_warnings
123 | end
124 |
125 | should "not include a -show-shadowed-device-font-warnings flag if :show-shadowed-device-font-warnings is set to true" do
126 | @mxmlc.show_shadowed_device_font_warnings = true
127 | assert_no_match /-show-shadowed-device-font-warnings/, @mxmlc.to_shell
128 | end
129 |
130 | should "include -show-shadowed-device-font-warnings=false flag if :show-shadowed-device-font-warnings is set to false" do
131 | @mxmlc.show_shadowed_device_font_warnings = false
132 | assert_equal '-show-shadowed-device-font-warnings=false', @mxmlc.to_shell
133 | end
134 |
135 | # -show-unused-type-selector-warnings
136 | should "default to show-unused-type-selector-warnings=true" do
137 | assert_equal true, @mxmlc.show_unused_type_selector_warnings
138 | end
139 |
140 | should "not include a -show-unused-type-selector-warnings flag if :show-unused-type-selector-warnings is set to true" do
141 | @mxmlc.show_unused_type_selector_warnings = true
142 | assert_no_match /-show-unused-type-selector-warnings/, @mxmlc.to_shell
143 | end
144 |
145 | should "include -show-unused-type-selector-warnings=false flag if :show-unused-type-selector-warnings is set to false" do
146 | @mxmlc.show_unused_type_selector_warnings = false
147 | assert_equal '-show-unused-type-selector-warnings=false', @mxmlc.to_shell
148 | end
149 |
150 | # -static-link-runtime-shared-libraries
151 | should "default to static-link-runtime-shared-libraries=false" do
152 | assert_equal false, @mxmlc.static_link_runtime_shared_libraries
153 | end
154 |
155 | should "include a -static-link-runtime-shared-libraries=true flag if :static-link-runtime-shared-libraries is set to true" do
156 | @mxmlc.static_link_runtime_shared_libraries = true
157 | assert_equal '-static-link-runtime-shared-libraries=true', @mxmlc.to_shell
158 | end
159 |
160 | should "not include -static-link-runtime-shared-libraries=false flag if :static-link-runtime-shared-libraries is set to false" do
161 | @mxmlc.static_link_runtime_shared_libraries = false
162 | assert_no_match /-static-link-runtime-shared-libraries/, @mxmlc.to_shell
163 | end
164 |
165 | # -strict
166 | should "default to strict=true" do
167 | assert_equal true, @mxmlc.strict
168 | end
169 |
170 | should "not include a -strict flag if :strict is set to true" do
171 | @mxmlc.strict = true
172 | assert_no_match /-strict/, @mxmlc.to_shell
173 | end
174 |
175 | should "include -strict=false flag if :strict is set to false" do
176 | @mxmlc.strict = false
177 | assert_equal '-strict=false', @mxmlc.to_shell
178 | end
179 |
180 | # -use-resource-bundle-metadata
181 | should "default to use-resource-bundle-metadata=true" do
182 | assert_equal true, @mxmlc.use_resource_bundle_metadata
183 | end
184 |
185 | should "not include a -use-resource-bundle-metadata flag if :use-resource-bundle-metadata is set to true" do
186 | @mxmlc.use_resource_bundle_metadata = true
187 | assert_no_match /-use-resource-bundle-metadata/, @mxmlc.to_shell
188 | end
189 |
190 | should "include -use-resource-bundle-metadata=false flag if :use-resource-bundle-metadata is set to false" do
191 | @mxmlc.use_resource_bundle_metadata = false
192 | assert_equal '-use-resource-bundle-metadata=false', @mxmlc.to_shell
193 | end
194 |
195 | # -warnings
196 | should "default to warnings=true" do
197 | assert_equal true, @mxmlc.warnings
198 | end
199 |
200 | should "not include a -warnings flag if :warnings is set to true" do
201 | @mxmlc.warnings = true
202 | assert_no_match /-warnings/, @mxmlc.to_shell
203 | end
204 |
205 | should "include -warnings=false flag if :warnings is set to false" do
206 | @mxmlc.warnings = false
207 | assert_equal '-warnings=false', @mxmlc.to_shell
208 | end
209 |
210 |
211 | end
212 | end
213 |
214 |
--------------------------------------------------------------------------------
/lib/flashplayer/task.legacy.rb:
--------------------------------------------------------------------------------
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 = ''
13 |
14 | # This is the closing string that will indicate the end of test result XML data
15 | @@test_result_post_delimiter = ''
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 |
294 |
--------------------------------------------------------------------------------
/lib/flashsdk/fdb.rb:
--------------------------------------------------------------------------------
1 |
2 | module FlashSDK
3 |
4 | ##
5 | # The FDB task provides an interface to the Flash Debugger.
6 | #
7 | # In order to use this tool, you'll need to compile a SWF
8 | # file with +--debug=true+, and be prepared to open it
9 | # in a debug Flash Player. You can open the SWF using
10 | # the desktop debug Flash Player for your platform using
11 | # the FlashSDK::FlashPlayer task, or you can open the
12 | # SWF manually on the desktop or the browser - as long
13 | # as you run it in a Debug Flash Player.
14 | #
15 | class FDB < Sprout::Executable::Session
16 |
17 | ##
18 | # Path to the file where test results should be written.
19 | #
20 | # @default 'TestResults.xml'
21 | # @see :test_result_prefix
22 | # @see :test_result_suffix
23 | attr_accessor :test_result_file
24 |
25 | ##
26 | # Regular expression that will match the preamble that is sent
27 | # by your test framework to indicate the beginning of structured
28 | # test output.
29 | #
30 | # @default //
31 | # @see :test_result_file
32 | # @see :test_result_suffix
33 | attr_accessor :test_result_prefix
34 |
35 | ##
36 | # Regular expression that will match the suffix that is sent
37 | # by your test framework to indicate the end of structured
38 | # test output.
39 | #
40 | # @default /<\/TestResults>/
41 | # @see :test_result_file
42 | # @see :test_result_prefix
43 | attr_accessor :test_result_suffix
44 |
45 | def initialize
46 | super
47 | @test_result = ''
48 | @inside_test_result = false
49 | @test_result_file = 'TestResults.xml'
50 | @test_result_prefix = //
51 | @test_result_suffix = /<\/TestResults>/
52 | end
53 |
54 | set :default_prefix, '-'
55 |
56 | ##
57 | # The default gem name
58 | set :pkg_name, 'flex4'
59 |
60 | ##
61 | # The default gem version
62 | set :pkg_version, '>= 4.1.0.pre'
63 |
64 | ##
65 | # The default executable target
66 | set :executable, :fdb
67 |
68 | set :prompt, /^\(fdb\) |\(y or n\) |Waiting for Player to connect/
69 |
70 | ##
71 | # Print a backtrace of all stack frames
72 | add_action :backtrace
73 | add_action_alias :bt, :backtrace
74 | add_action_alias :where, :backtrace
75 |
76 | ##
77 | # Set a breakpoint at specified line or function
78 | #
79 | # @example Sets a breakpoint at line 87 of the current file.
80 | # break 87
81 | #
82 | # @example Sets a breakpoint at line 56 of myapp.mxml
83 | # break myapp.mxml:56
84 | #
85 | # @example Sets a breakpoint at line 29 of file #3
86 | # break #3:29
87 | #
88 | # @example Sets a breakpoint at function doThis() in the current file
89 | # break doThis
90 | #
91 | # @example Sets a breakpoint at function doThat() in file myapp.mxml
92 | # break myapp.mxml:doThat
93 | #
94 | # @example Sets a breakpoint at function doOther() in file #3
95 | # break #3:doOther
96 | #
97 | # @example Sets a breakpoint at the current execution address in the
98 | # current stack frame. This is useful for breaking on return
99 | # to a stack frame.
100 | # break
101 | #
102 | # To see file names and numbers, do 'info sources' or 'info files'.
103 | # To see function names, do 'info functions'.
104 | # Abbreviated file names and function names are accepted if unambiguous.
105 | # If line number is specified, break at start of code for that line.
106 | # If function is specified, break at start of code for that function.
107 | # See 'commands' and 'condition' for further breakpoint control.
108 | add_action :break, Strings
109 |
110 | ##
111 | # Halt when an exception is thrown. This only affects caught
112 | # exceptions -- that is, exceptions that are going to be handled
113 | # by a "catch" block. Uncaught exceptions always halt in the
114 | # debugger.
115 | #
116 | # Use the "delete" command to delete a catchpoint.
117 | #
118 | # Examples:
119 | #
120 | # catch *
121 | #
122 | # Halts when any exception is thrown.
123 | #
124 | # catch ReferenceError
125 | #
126 | # Halts whenever a ReferenceError is thrown
127 | #
128 | add_action :catch, String
129 | add_action_alias :ca, :catch
130 |
131 | ##
132 | #
133 | # Display the name and number of the current file
134 | # or change the current file.
135 | # Examples:
136 | #
137 | # cf
138 | #
139 | # Displays the name and number of the current file.
140 | #
141 | # cf myapp.mxml
142 | #
143 | # Changes the current file to myapp.mxml.
144 | #
145 | # cf #29
146 | #
147 | # Changes the current file to file #29.
148 | # To see file names and numbers, do 'info sources' or 'info files'.
149 | # Abbreviated file names are accepted if unambiguous.
150 | # Listing a file with 'list' also makes that file the current file.
151 | #
152 | add_action :cf, String
153 |
154 | ##
155 | # Clear breakpoint at specified line or function.
156 | # Examples:
157 | #
158 | # clear 87
159 | #
160 | # Clears the breakpoint at line 87 of the current file.
161 | #
162 | # clear myapp.mxml:56
163 | #
164 | # Clears the breakpoint at line 56 of myapp.mxml.
165 | #
166 | # clear #3:29
167 | #
168 | # Clears the breakpoint at line 29 of file #3.
169 | #
170 | # clear doThis
171 | #
172 | # Clears the breakpoint at function doThis() in the current file.
173 | #
174 | # clear myapp.mxml:doThat
175 | #
176 | # Clears the breakpoint at function doThat() in file myapp.mxml.
177 | #
178 | # clear #3:doOther
179 | #
180 | # Clears the breakpoint at function doOther() in file #3.
181 | #
182 | # clear
183 | #
184 | # Clears breakpoint of the current line in the current file.
185 | # To see file names and numbers, do 'info sources' or 'info files'.
186 | # To see function names, do 'info functions'.
187 | # Abbreviated file names and function names are accepted if unambiguous.
188 | # If line number is specified, all breakpoints in that line are cleared.
189 | # If function is specified, breakpoints at beginning of function are cleared.
190 | add_action :clear, Strings
191 | add_action_alias :cl, :clear
192 |
193 | ##
194 | # Continue execution after stopping at a breakpoint
195 | # Specify breakpoint number N to break only if COND is true.
196 | # Usage is `condition N COND', where N is an integer and COND is an
197 | # expression to be evaluated whenever breakpoint N is reached.
198 | add_action :condition, String
199 |
200 | ##
201 | # Provide an affirmative response to a confirmation screen.
202 | #
203 | # See also: unconfirm
204 | add_action :confirm
205 |
206 | ##
207 | # Continue execution after stopping at breakpoint.
208 | # This command takes no arguments.
209 | add_action :continue
210 | add_action_alias :c, :continue
211 |
212 | ##
213 | # Set commands to be executed when a breakpoint is hit.
214 | # Give breakpoint number as argument after `commands`.
215 | # With no argument, the targeted breakpoint is the last one set.
216 | # The commands themselves follow starting on the next line.
217 | # Type a line containing "end" to indicate the end of them.
218 | # Give "silent" as the first line to make the breakpoint silent;
219 | # then no output is printed when it is hit, except what the commands print.
220 | #
221 | # Example:
222 | #
223 | # (fdb) commands
224 | # Type commands for when breakpoint 1 is hit, one per line.
225 | # End with a line saying just 'end'.
226 | # >w
227 | # >end
228 | add_action :commands, String
229 |
230 | ##
231 | # Delete one or more breakpoints.
232 | #
233 | # Examples:
234 | #
235 | # delete
236 | #
237 | # Deletes all breakpoints.
238 | #
239 | # delete 2 5
240 | #
241 | # Deletes breakpoints #2 and #5.
242 | #
243 | # To see breakpoint numbers, do 'info breakpoints'.
244 | add_action :delete, Strings
245 | add_action_alias :d, :delete
246 |
247 | ##
248 | # Modify the list of directories in which fdb searches for source files.
249 | #
250 | # Examples:
251 | #
252 | # directory
253 | #
254 | # Restores list to the default, which is the directory in which the source
255 | # file was compiled into object code, followed by the current working
256 | # directory.
257 | #
258 | # directory C:\MySource (Windows)
259 | # directory /MySource (Mac)
260 | #
261 | # Adds the specified directory to the beginning of the list of directories
262 | # which will be searched for source. When looking for the source for class
263 | # mypackage.MyClass, for example, the debugger would look for both
264 | # C:\MySource\mypackage\MyClass.as and C:\MySource\MyClass.as.
265 | #
266 | # directory C:\Dir1;C:\Dir2 (Windows -- use ';' as separator)
267 | # directory /Dir1:/Dir2 (Mac -- use ':' as separator)
268 | #
269 | # Adds several directories to the beginning of the list of directories
270 | # which will be searched for source.
271 | #
272 | # To see the current list, do 'show directories'.
273 | add_action :directory, Path
274 | add_action_alias :dir, :directory
275 |
276 | ##
277 | # Disable one or more breakpoints or auto-display expressions.
278 | #
279 | # Examples:
280 | #
281 | # disable
282 | #
283 | # disable breakpoints
284 | #
285 | # Disables all breakpoints.
286 | #
287 | # disable 2 5
288 | #
289 | # disable breakpoints 2 5
290 | #
291 | # Disables breakpoints #2 and #5.
292 | #
293 | # disable display
294 | #
295 | # Disables all auto-display expressions.
296 | #
297 | # disable display 1 3
298 | #
299 | # Disables auto-display expressions #1 and #3.
300 | #
301 | # To see breakpoint numbers, do 'info breakpoints'.
302 | # To see auto-display expression numbers, do 'info display'.
303 | add_action :disable, String
304 | add_action_alias :disab, :disable
305 |
306 | ##
307 | # (ActionScript 2 only; not supported when debugging ActionScript 3)
308 | #
309 | # Disassemble a specified portion of source code.
310 | # The default is the current listing line.
311 | # Arguments supported are the same as with the list command
312 | #
313 | # Examples:
314 | #
315 | # disassemble 87
316 | #
317 | # Disassembles line 87 in the current file.
318 | #
319 | # disassemble 87 102
320 | # disassembles lines 87 to 102 in current file.
321 | # disassemble doThis
322 | #
323 | # Disassembles the function doThis() in the current file.
324 | #
325 | # In addition to using simple line numbers as above, you can specify lines
326 | # in additional ways:
327 | #
328 | # myapp.mxml
329 | # Line 1 in myapp.mxml.
330 | # myapp.mxml:doThat
331 | # The first line of function doThat() in myapp.mxml.
332 | # myapp.mxml:56
333 | # Line 56 in myapp.mxml.
334 | # #3
335 | # Line 1 in file #3.
336 | # #3:doOther
337 | # The line in file #3 where the function doOther() begins.
338 | # #3:29
339 | # Line 29 in file #3.
340 | add_action :disassemble, String
341 | add_action_alias :disas, :disassemble
342 |
343 | ##
344 | # Add an auto-display expression
345 | # Add an expression to the list of auto-display expressions.
346 | #
347 | # Example:
348 | #
349 | # display employee.name
350 | #
351 | # Add 'employee.name' to the list of auto-display expressions.
352 | # Every time fdb stops, the value of employee.name will be displayed.
353 | # The argument for this command is similar to that for 'print'.
354 | # To see the list of auto-display expressions and their numbers,
355 | # do 'info display'.
356 | #
357 | # NOTE: Removed because the base class adds this param for some reason.
358 | # Investigate duplicate add_action calls.
359 | #add_action :display, String
360 | #add_action_alias :disp, :display
361 |
362 | ##
363 | # Enable breakpoints or auto-display expressions
364 | add_action :enable
365 | add_action_alias :e, :enable
366 |
367 | ##
368 | # Specify an application to be debugged, without starting it.
369 | #
370 | # Examples:
371 | #
372 | # file http://www.mysite.com/myapp.mxml
373 | #
374 | # Specify an MXML application to be debugged.
375 | #
376 | # file myapp.swf
377 | #
378 | # Specify a local SWF file to be debugged, in the current directory.
379 | # In this case myapp.swd (the file containing the debugging information)
380 | # must also exist in the current directory.
381 | #
382 | # This command does not actually cause the application to start;
383 | # use the 'run' command with no argument to start debugging the application.
384 | #
385 | # Instead of using 'file ' and then 'run', you can simply specify the
386 | # application to be debugged as an argument of 'run':
387 | #
388 | # run http://mysite.com/myapp.mxml
389 | # run myapp.swf
390 | #
391 | # You can also specify the application to be debugged
392 | # as a command-line argument when you start fdb:
393 | #
394 | # fdb http://www.mysite.com/myapp.mxml
395 | #
396 | # fdb myapp.swf
397 | #
398 | # In this case you do not need to use either 'file' or 'run'.
399 | # If you 'run' without specifying an application to debug,
400 | # (fdb)
401 | #
402 | # will wait for any application to connect to it.
403 | add_action :file, File, { :hidden_name => true }
404 | add_action_alias :fil, :file
405 |
406 | ##
407 | # Execute until current function returns.
408 | # This command takes no arguments.
409 | add_action :finish
410 | add_action_alias :f, :finish
411 |
412 | ##
413 | # Specify how fdb should handle a fault in the Flash Player.
414 | #
415 | # Examples:
416 | #
417 | # handle recursion_limit stop
418 | #
419 | # When a recursion_limit fault occurs, display message in fdb
420 | # and stop as if at breakpoint.
421 | #
422 | # handle all print nostop
423 | #
424 | # When any kind of fault occurs, display message in fdb but don't stop.
425 | # First argument is a fault name or 'all'.
426 | # Additional arguments are actions that apply to that fault.
427 | # To see fault names, do 'info handle'.
428 | #
429 | # Actions are print/noprint and stop/nostop.
430 | # 'print' means print a message if this fault happens.
431 | # 'stop' means reenter debugger if this fault happens. Implies 'print'.
432 | add_action :handle, String
433 | add_action_alias :han, :handle
434 |
435 | ##
436 | # Display help on FDB commands
437 | # New to fdb? Do 'tutorial' for basic info.
438 | # List of fdb commands:
439 | # bt (bt) Print backtrace of all stack frames
440 | # break (b) Set breakpoint at specified line or function
441 | # catch (ca) Halt when an exception is thrown
442 | # cf (cf) Display the name and number of the current file
443 | # clear (cl) Clear breakpoint at specified line or function
444 | # condition (cond) Apply/remove conditional expression to a breakpoint
445 | # continue (c) Continue execution after stopping at breakpoint
446 | # commands (com) Sets commands to execute when breakpoint hit
447 | # delete (d) Delete breakpoints or auto-display expressions
448 | # directory (dir) Add a directory to the search path for source files
449 | # disable (disab) Disable breakpoints or auto-display expressions
450 | # disassemble (disas) Disassemble source lines or functions
451 | # display (disp) Add an auto-display expressions
452 | # enable (e) Enable breakpoints or auto-display expressions
453 | # file (fil) Specify application to be debugged.
454 | # finish (f) Execute until current function returns
455 | # handle (han) Specify how to handle a fault
456 | # help (h) Display help on fdb commands
457 | # home (ho) Set listing location to where execution is halted
458 | # info (i) Display information about the program being debugged
459 | # kill (k) Kill execution of program being debugged
460 | # list (l) List specified function or line
461 | # next (n) Step program
462 | # print (p) Print value of variable EXP
463 | # pwd (pw) Print working directory
464 | # quit (q) Exit fdb
465 | # run (r) Start debugged program
466 | # set (se) Set the value of a variable
467 | # source (so) Read fdb commands from a file
468 | # step (s) Step program until it reaches a different source line
469 | # tutorial (t) Display a tutorial on how to use fdb
470 | # undisplay (u) Remove an auto-display expression
471 | # viewswf (v) Set or clear filter for file listing based on swf
472 | # watch (wa) Add a watchpoint on a given variable
473 | # what (wh) Displays the context of a variable
474 | # where (w) Same as bt
475 | # Type 'help' followed by command name for full documentation.
476 | add_action :help
477 | add_action_alias :h, :help
478 |
479 | ##
480 | # Set listing location to where execution is halted
481 | add_action :home, Path
482 | add_action_alias :ho, :home
483 |
484 | ##
485 | # Generic command for showing things about the program being debugged.
486 | # List of info subcommands:
487 | # info arguments (i a) Argument variables of current stack frame
488 | # info breakpoints (i b) Status of user-settable breakpoints
489 | # info display (i d) Display list of auto-display expressions
490 | # info files (i f) Names of targets and files being debugged
491 | # info functions (i fu) All function names
492 | # info handle (i h) How to handle a fault
493 | # info locals (i l) Local variables of current stack frame
494 | # info scopechain (i sc) Scope chain of current stack frame
495 | # info sources (i so) Source files in the program
496 | # info stack (i s) Backtrace of the stack
497 | # info swfs (i sw) List of swfs in this session
498 | # info targets(i t) Application being debugged
499 | # info variables (i v) All global and static variable names
500 | # Type 'help info' followed by info subcommand name for full documentation.
501 | add_action :info, String
502 | add_action_alias :i, :info
503 |
504 | ##
505 | # Kill execution of program being debugged
506 | # This command takes no arguments.
507 | add_action :kill
508 | add_action_alias :k, :kill
509 |
510 | ##
511 | # List lines of code in a source file.
512 | #
513 | # Examples:
514 | #
515 | # list
516 | #
517 | # Lists ten more lines in current file after or around previous listing.
518 | #
519 | # list -
520 | #
521 | # Lists the ten lines in current file before a previous listing.
522 | #
523 | # list 87
524 | #
525 | # Lists ten lines in current file around line 87.
526 | #
527 | # list 87 102
528 | #
529 | # Lists lines 87 to 102 in current file.
530 | #
531 | # In addition to using simple line numbers as above, you can specify lines
532 | # in seven additional ways:
533 | #
534 | # doThis
535 | #
536 | # The first line of function doThis() in the current file.
537 | #
538 | # myapp.mxml
539 | #
540 | # Line 1 in myapp.mxml.
541 | #
542 | # myapp.mxml:doThat
543 | #
544 | # The first line of function doThat() in myapp.mxml.
545 | #
546 | # myapp.mxml:56
547 | #
548 | # Line 56 in myapp.mxml.
549 | #
550 | # #3
551 | #
552 | # Line 1 in file #3.
553 | #
554 | # #3:doOther
555 | #
556 | # The line in file #3 where the function doOther() begins.
557 | #
558 | # #3:29
559 | #
560 | # Line 29 in file #3.
561 | #
562 | # To see file names and numbers, do 'info sources' or 'info files'.
563 | # To see function names, do 'info functions'.
564 | # Abbreviated file names and function names are accepted if unambiguous.
565 | # Listing a file makes that file the current file. (See 'cf' command.)
566 | add_action :list, String
567 | add_action_alias :l, :list
568 |
569 | ##
570 | # Step program, proceeding through subroutine calls.
571 | #
572 | # next
573 | #
574 | # Step once.
575 | #
576 | # next 3
577 | #
578 | # Step 3 times, or until the program stops for another reason.
579 | #
580 | # Like the 'step' command as long as subroutine calls do not happen;
581 | # when they do, the call is treated as one instruction.
582 | add_action :next, String
583 | add_action_alias :n, :next
584 |
585 | ##
586 | # Print value of variable or expression.
587 | #
588 | # Examples:
589 | #
590 | # print i
591 | #
592 | # Print the value of 'i'.
593 | #
594 | # print employee.name
595 | #
596 | # Print the value of 'employee.name'.
597 | #
598 | # print employee
599 | #
600 | # Print the value of the 'employee' Object.
601 | #
602 | # This may simplay display something like [Object 10378].
603 | #
604 | # print employee.
605 | #
606 | # Print the values of all the properties of the 'employee' Object.
607 | #
608 | # print *employee
609 | #
610 | # Print the values of all the properties of the 'employee' Object.
611 | # The prefix * operator is the prefix alternative to the postfix . operator.
612 | #
613 | # print #10378.
614 | #
615 | # Print the values of all the properties of Object #10378.
616 | # Variables accessible are those of the lexical environment of the selected
617 | # stack frame, plus all those whose scope is global or an entire file.
618 | add_action :print, String
619 | add_action_alias :p, :print
620 |
621 | ##
622 | # Print the current working directory.
623 | # This is the directory from which fdb was launched; it cannot be
624 | # changed within fdb. The argument for 'run' and 'source' can be
625 | # specified relative to this directory.
626 | # This command takes no arguments.
627 | add_action :pwd
628 | add_action_alias :pw, :pwd
629 |
630 | ##
631 | # Exit FDB
632 | add_action :quit
633 | add_action_alias :q, :quit
634 |
635 | ##
636 | # Start a debugging session.
637 | #
638 | # Examples:
639 | #
640 | # run http://www.mysite.com/myapp.mxml
641 | #
642 | # Runs the specified MXML application.
643 | #
644 | # run myapp.swf
645 | # run mydir\myapp.swf
646 | # run c:\mydir\myapp.swf
647 | #
648 | # Runs the local SWF file myapp.swf, which can be specified
649 | # either relative to the current directory (see 'pwd' command)
650 | # or using an absolute path. In these cases, myapp.swd
651 | # (the file containing the debugging information) must also
652 | # exist in the same directory as myapp.swf.
653 | #
654 | # run
655 | #
656 | # Run the application previously specified by the 'file' command.
657 | # If no application has been specified, fdb will wait for one
658 | # to connect to it, and time out if none does so.
659 | # 'run' will start the application in a browser or standalone Flash Player.
660 | # As soon as the application starts, it will break into fdb so that you can
661 | # set breakpoints, etc.
662 | #
663 | # On the Macintosh, the only supported form of the command is 'run' with no
664 | # arguments. You must then manually launch the Flash player.
665 | add_action :run, String
666 | add_action_alias :r, :run
667 |
668 | ##
669 | # Set the value of a variable or a convenience variable.
670 | # Convenience variables are variables that exist entirely
671 | # within fdb; they are not part of your program.
672 | # Convenience variables are prefixed with '$' and can
673 | # be any name that does not conflict with any existing
674 | # variable. For example, $myVar. Convenience variables
675 | # are also used to control various aspects of fdb.
676 | #
677 | # The following convenience variables are used by fdb.
678 | # $listsize - number of source lines to display for 'list'
679 | # $columnwrap - column number on which output will wrap
680 | # $infostackshowthis - if 0, does not display 'this' in stack backtrace
681 | # $invokegetters - if 0, prevents fdb from firing getter functions
682 | # $bpnum - the last defined breakpoint number
683 | # $displayattributes - if 1, 'print var.' displays all attributes of members
684 | # of 'var' (e.g. private, static)
685 | #
686 | # Examples:
687 | #
688 | # set i = 3
689 | #
690 | # Sets the variable 'i' to the number 3.
691 | #
692 | # set employee.name = "Susan"
693 | #
694 | # Sets the variable 'employee.name' to the string "Susan".
695 | #
696 | # set $myVar = 20
697 | #
698 | # Sets the convenience variable '$myVar' to the number 20
699 | add_action :set, String
700 | add_action_alias :se, :set
701 |
702 | ##
703 | # Read fdb commands from a file and execute them.
704 | #
705 | # source mycommands.txt
706 | # source mydir\mycommands.txt
707 | # source c:\mydir\mycommands.txt
708 | #
709 | # Reads mycommands.txt and executes the fdb commands in it.
710 | # The file containing the commands can be specified either
711 | # relative to the current directory (see 'pwd' command)
712 | # or using an absolute path.
713 | #
714 | # The file .fdbinit is read automatically in this way when fdb is started.
715 | # Only the current directory is searched for .fdbinit. This means that
716 | # you can have set up multiple .fdbinit files for different projects.
717 | add_action :source, File
718 | add_action_alias :so, :source
719 |
720 | ##
721 | # Step program until it reaches a different source line.
722 | #
723 | # Examples:
724 | #
725 | # step
726 | #
727 | # Step once.
728 | #
729 | # step 3
730 | #
731 | # Step 3 times, or until the program stops for another reason.
732 | add_action :step, Number
733 | add_action_alias :s, :step
734 |
735 | ##
736 | # Display a tutorial on how to use fdb.
737 | # This command takes no arguments.
738 | add_action :tutorial
739 | add_action_alias :t, :tutorial
740 |
741 | ##
742 | # Provide a negative response to a confirmation screen.
743 | #
744 | # See also: confirm
745 | add_action :unconfirm
746 |
747 | ##
748 | # Remove one or more auto-display expressions.
749 | #
750 | # Examples:
751 | #
752 | # undisplay
753 | #
754 | # Remove all auto-display expressions.
755 | #
756 | # undisplay 2 7
757 | #
758 | # Remove auto-display expressions #2 and #7.
759 | #
760 | # To see the list of auto-display expressions and their numbers,
761 | # do 'info display'.
762 | add_action :undisplay, String
763 | add_action_alias :u, :undisplay
764 |
765 | ##
766 | # Set or clear a filter for file listing based on SWF
767 | add_action :viewswf
768 | add_action_alias :v, :viewswf
769 |
770 | ##
771 | # Add a watchpoint on a given variable. The debugger will halt
772 | # execution when the variable's value changes.
773 | #
774 | # Example:
775 | #
776 | # watch foo
777 | #
778 | add_action :watch, String
779 | add_action_alias :wa, :watch
780 |
781 | ##
782 | # Displays the context in which a variable is resolved.
783 | add_action :what
784 | add_action_alias :wh, :what
785 |
786 | def system_execute binary, params
787 | super do |message|
788 | if message.match test_result_suffix
789 | write_test_result
790 | end
791 | if @inside_test_result
792 | @test_result << message
793 | end
794 | if message.match test_result_prefix
795 | @inside_test_result = true
796 | end
797 | end
798 | end
799 |
800 | private
801 |
802 | def write_test_result
803 | File.open test_result_file, 'w+' do |f|
804 | f.write @test_result
805 | end
806 | @test_result = ''
807 | @inside_test_result = false
808 | end
809 |
810 | end
811 | end
812 |
813 | ##
814 | # Rake task helper that delegates to
815 | # the FDB executable.
816 | #
817 | # fdb 'bin/SomeProject.swf' do |t|
818 | # t.break << 'com/foo/bar/SomeClass.as:23'
819 | # t.continue
820 | # t.run
821 | # end
822 | #
823 | def fdb *args, &block
824 | fdb_tool = FlashSDK::FDB.new
825 | fdb_tool.to_rake *args, &block
826 | fdb_tool
827 | end
828 |
829 | desc "Make subsequent FlashPlayer task(s) use FDB"
830 | task :fdb do
831 | ENV['USE_FDB'] = 'true'
832 | end
833 |
834 |
--------------------------------------------------------------------------------