h4oflashsdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. data/Gemfile +3 -0
  2. data/Gemfile.lock +41 -0
  3. data/POSTINSTALL.rdoc +79 -0
  4. data/README.textile +79 -0
  5. data/VERSION +1 -0
  6. data/bin/flashlog +8 -0
  7. data/bin/flashplayer +9 -0
  8. data/bin/sprout-as3 +9 -0
  9. data/bin/sprout-flex +8 -0
  10. data/ext/CloseFlashPlayerForDumbassOSX.scpt +6 -0
  11. data/ext/OpenFlashPlayerForDumbassOSX.scpt +12 -0
  12. data/flashsdk.gemspec +25 -0
  13. data/flashsdk.komodoproject +4 -0
  14. data/lib/flashplayer/errors.rb +12 -0
  15. data/lib/flashplayer/executable.rb +143 -0
  16. data/lib/flashplayer/log_file.rb +94 -0
  17. data/lib/flashplayer/mm_config.rb +96 -0
  18. data/lib/flashplayer/module.rb +51 -0
  19. data/lib/flashplayer/specification.rb +45 -0
  20. data/lib/flashplayer/system_mixins.rb +98 -0
  21. data/lib/flashplayer/task.legacy.rb +293 -0
  22. data/lib/flashplayer/task.rb +62 -0
  23. data/lib/flashplayer/trust.rb +45 -0
  24. data/lib/flashplayer.rb +9 -0
  25. data/lib/flashsdk/acompc.rb +29 -0
  26. data/lib/flashsdk/adl.rb +83 -0
  27. data/lib/flashsdk/adt.rb +276 -0
  28. data/lib/flashsdk/amxmlc.rb +28 -0
  29. data/lib/flashsdk/asdoc.rb +164 -0
  30. data/lib/flashsdk/compc.rb +124 -0
  31. data/lib/flashsdk/compiler_base.rb +1131 -0
  32. data/lib/flashsdk/fcsh.rb +173 -0
  33. data/lib/flashsdk/fcsh_socket.rb +167 -0
  34. data/lib/flashsdk/fdb.rb +833 -0
  35. data/lib/flashsdk/generators/class_generator.rb +87 -0
  36. data/lib/flashsdk/generators/flash_helper.rb +234 -0
  37. data/lib/flashsdk/generators/flex_project_generator.rb +30 -0
  38. data/lib/flashsdk/generators/project_generator.rb +31 -0
  39. data/lib/flashsdk/generators/templates/ActionScript3Class.as +9 -0
  40. data/lib/flashsdk/generators/templates/ActionScript3MainClass.as +11 -0
  41. data/lib/flashsdk/generators/templates/ActionScript3RunnerClass.as +19 -0
  42. data/lib/flashsdk/generators/templates/DefaultProjectImage.png +0 -0
  43. data/lib/flashsdk/generators/templates/Flex4Application.mxml +45 -0
  44. data/lib/flashsdk/generators/templates/Flex4Main.css +7 -0
  45. data/lib/flashsdk/generators/templates/Flex4Rakefile.rb +34 -0
  46. data/lib/flashsdk/generators/templates/Flex4RunnerClass.mxml +29 -0
  47. data/lib/flashsdk/generators/templates/FlexTestRunner.mxml +0 -0
  48. data/lib/flashsdk/generators/templates/Gemfile +5 -0
  49. data/lib/flashsdk/generators/templates/rakefile.rb +79 -0
  50. data/lib/flashsdk/module.rb +107 -0
  51. data/lib/flashsdk/mxmlc.rb +160 -0
  52. data/lib/flashsdk.rb +24 -0
  53. data/lib/flex3.rb +54 -0
  54. data/lib/flex4.rb +115 -0
  55. data/rakefile.rb +42 -0
  56. data/test/fixtures/acompc/simple/SomeAirFile.as +11 -0
  57. data/test/fixtures/air/simple/SomeProject.apk +1 -0
  58. data/test/fixtures/air/simple/SomeProject.as +11 -0
  59. data/test/fixtures/air/simple/SomeProject.mxml +9 -0
  60. data/test/fixtures/air/simple/SomeProject.pfx +0 -0
  61. data/test/fixtures/air/simple/SomeProject.swf +0 -0
  62. data/test/fixtures/air/simple/SomeProject.xml +13 -0
  63. data/test/fixtures/asdoc/lib/OtherFile.as +17 -0
  64. data/test/fixtures/asdoc/src/SomeFile.as +11 -0
  65. data/test/fixtures/compc/simple/SomeFile.as +11 -0
  66. data/test/fixtures/flashplayer/AsUnit Runner.swf +0 -0
  67. data/test/fixtures/mxmlc/broken/SomeFile.as +10 -0
  68. data/test/fixtures/mxmlc/simple/SomeFile.as +11 -0
  69. data/test/fixtures/sdk/fdb +90 -0
  70. data/test/fixtures/sdk/mxmlc +56 -0
  71. data/test/unit/acompc_test.rb +37 -0
  72. data/test/unit/adl_test.rb +32 -0
  73. data/test/unit/adt_test.rb +185 -0
  74. data/test/unit/amxmlc_test.rb +55 -0
  75. data/test/unit/asdoc_test.rb +45 -0
  76. data/test/unit/class_generator_test.rb +56 -0
  77. data/test/unit/compc_test.rb +37 -0
  78. data/test/unit/fake_flashplayer_system.rb +11 -0
  79. data/test/unit/fcsh_socket_test.rb +53 -0
  80. data/test/unit/fcsh_test.rb +55 -0
  81. data/test/unit/fdb_test.rb +54 -0
  82. data/test/unit/flash_helper_test.rb +43 -0
  83. data/test/unit/flashplayer_executable_test.rb +69 -0
  84. data/test/unit/flashplayer_log_file_test.rb +47 -0
  85. data/test/unit/flashplayer_mm_config_test.rb +74 -0
  86. data/test/unit/flashplayer_module_test.rb +56 -0
  87. data/test/unit/flashplayer_task_test.rb +91 -0
  88. data/test/unit/flashplayer_trust_test.rb +30 -0
  89. data/test/unit/flex_compiler_options_test.rb +213 -0
  90. data/test/unit/flex_generator_test.rb +37 -0
  91. data/test/unit/mxmlc_test.rb +65 -0
  92. data/test/unit/project_generator_test.rb +57 -0
  93. data/test/unit/test_helper.rb +18 -0
  94. metadata +284 -0
@@ -0,0 +1,173 @@
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
+
@@ -0,0 +1,167 @@
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
+