sprout-as3-bundle 0.2.3 → 0.2.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,474 @@
1
+
2
+ module Sprout #:nodoc:
3
+
4
+ class FDBTaskError < StandardError #:nodoc:
5
+ end
6
+
7
+ # The FDBTask provides a procedural rake front end to the FDB command line tool
8
+ #
9
+ # Here is a decent tutorial on using FDB with SWF or HTML content:
10
+ # http://installingcats.wordpress.com/tag/adobe-flex/
11
+ #
12
+ # You can send the fdb task some debug commands directly or simply
13
+ # execute the rake task and interact with the debugger manually.
14
+ #
15
+ # The FDBTask requires that you have a debug Flash Player installed
16
+ # on your system as the default execution application for SWF files.
17
+ #
18
+ # Following is an example of setting up a breakpoint in
19
+ # SomeFile at line 23
20
+ # fdb :debug do |t|
21
+ # t.file = 'bin/SomeProject-debug.swf'
22
+ # t.run
23
+ # t.break = 'SomeFile:23'
24
+ # t.continue
25
+ # end
26
+ #
27
+ # You can also point the FDBTask at HTML pages. These pages will be
28
+ # launched in your default browswer. You will need to manually install
29
+ # a debug Flash Player in that particular browser.
30
+ # To use a browser instead of the desktop Flash Player, simply point
31
+ # file argument at an HTML document or remote URL. The SWF file loaded
32
+ # must be compiled using the -debug flag in order to connect to the
33
+ # debugger.
34
+ # fdb :debug do |t|
35
+ # t.file = 'bin/SomeProject-debug.html'
36
+ # t.run
37
+ # t.continue
38
+ # end
39
+ #
40
+ class FDBTask < ToolTask
41
+ # The SWF file to debug.
42
+ attr_accessor :swf
43
+
44
+ def initialize_task # :nodoc:
45
+ @default_gem_name = 'sprout-flex3sdk-tool'
46
+ @default_gem_path = 'bin/fdb'
47
+ @queue = []
48
+ end
49
+
50
+ def define # :nodoc:
51
+ self
52
+ end
53
+
54
+ def stdout=(out) # :nodoc:
55
+ @stdout = out
56
+ end
57
+
58
+ def stdout # :nodoc:
59
+ @stdout ||= $stdout
60
+ end
61
+
62
+ def execute(*args) # :nodoc:
63
+ # TODO: First check the SWF file to ensure that debugging is enabled!
64
+ buffer = FDBBuffer.new(get_executable, stdout)
65
+ buffer.wait_for_prompt
66
+
67
+ @queue.each do |command|
68
+ handle_command(buffer, command)
69
+ end
70
+
71
+ buffer.join
72
+ self
73
+ end
74
+
75
+ def handle_command(buffer, command) # :nodoc:
76
+ parts = command.split(' ')
77
+ name = parts.shift
78
+ value = parts.shift
79
+ case name
80
+ when "sleep"
81
+ buffer.sleep_until value
82
+ when "terminate"
83
+ buffer.kill
84
+ else
85
+ buffer.write command
86
+ end
87
+ end
88
+
89
+ def get_executable # :nodoc:
90
+ exe = Sprout.get_executable(gem_name, gem_path, gem_version)
91
+ User.clean_path(exe)
92
+ end
93
+
94
+ def command_queue # :nodoc:
95
+ @queue
96
+ end
97
+
98
+ # Print backtrace of all stack frames
99
+ def bt
100
+ @queue << "bt"
101
+ end
102
+
103
+ # Set breakpoint at specified line or function
104
+ def break=(point)
105
+ @queue << "break #{point}"
106
+ end
107
+
108
+ # Display the name and number of the current file
109
+ def cf
110
+ @queue << "cf"
111
+ end
112
+
113
+ # Clear breakpoint at specified line or function
114
+ def clear=(point)
115
+ @queue << "clear #{point}"
116
+ end
117
+
118
+ # Apply/remove conditional expression to a breakpoint
119
+ def condition=(cond)
120
+ @queue << "condition #{cond}"
121
+ end
122
+
123
+ # Continue execution after stopping at breakpoint
124
+ def continue
125
+ @queue << "continue"
126
+ end
127
+
128
+ # Alias for continue
129
+ def c
130
+ @queue << "continue"
131
+ end
132
+
133
+ # Sets commands to execute when breakpoint hit
134
+ def commands=(cmd)
135
+ @queue << "com #{cmd}"
136
+ end
137
+
138
+ # Delete breakpoints or auto-display expressions
139
+ def delete
140
+ @queue << "delete"
141
+ end
142
+
143
+ # Add a directory to the search path for source files
144
+ def directory=(dir)
145
+ @queue << "directory #{dir}"
146
+ end
147
+
148
+ # Disable breakpoints or auto-display expressions
149
+ def disable
150
+ @queue << "disable"
151
+ end
152
+
153
+ # Disassemble source lines or functions
154
+ def disassemble
155
+ @queue << "dissassemble"
156
+ end
157
+
158
+ # Add an auto-display expressions
159
+ def display=(disp)
160
+ @queue << "disp #{disp}"
161
+ end
162
+
163
+ # Enable breakpoints or auto-display expressions
164
+ def enable
165
+ @queue << "enable"
166
+ end
167
+
168
+ # Enable breakpoints or auto-display expressions
169
+ def e
170
+ @queue << "enable"
171
+ end
172
+
173
+ # Specify application to be debugged.
174
+ def file=(file)
175
+ @prerequisites << file
176
+ @queue << "file #{file}"
177
+ end
178
+
179
+ # Execute until current function returns
180
+ def finish
181
+ @queue << "finish"
182
+ end
183
+
184
+ # Specify how to handle a fault
185
+ def handle
186
+ @queue << "handle"
187
+ end
188
+
189
+ # Set listing location to where execution is halted
190
+ def home
191
+ @queue << "home"
192
+ end
193
+
194
+ # Display information about the program being debugged
195
+ def info
196
+ @queue << "info"
197
+ end
198
+
199
+ # Argument variables of current stack frame
200
+ def info_arguments
201
+ @queue << "i a"
202
+ end
203
+
204
+ # Status of user-settable breakpoints
205
+ def info_breakpoints
206
+ @queue << "i b"
207
+ end
208
+
209
+ # Display list of auto-display expressions
210
+ def info_display
211
+ @queue << "i d"
212
+ end
213
+
214
+ # Names of targets and files being debugged
215
+ def info_files
216
+ @queue << "i f"
217
+ end
218
+
219
+ # All function names
220
+ def info_functions=(value)
221
+ @queue << "i fu #{value}"
222
+ end
223
+
224
+ # How to handle a fault
225
+ def info_handle
226
+ @queue << "i h"
227
+ end
228
+
229
+ # Local variables of current stack frame
230
+ def info_locals
231
+ @queue << "i l"
232
+ end
233
+
234
+ # Scope chain of current stack frame
235
+ def info_scopechain
236
+ @queue << "i sc"
237
+ end
238
+
239
+ # Source files in the program
240
+ def info_sources
241
+ @queue << "i so"
242
+ end
243
+
244
+ # Backtrace of the stack
245
+ def info_stack
246
+ @queue << "i s"
247
+ end
248
+
249
+ # List of swfs in this session
250
+ def info_swfs
251
+ @queue << "i sw"
252
+ end
253
+
254
+ # Application being debugged
255
+ def info_targets
256
+ @queue << "i t"
257
+ end
258
+
259
+ # All global and static variable names
260
+ def info_variables
261
+ @queue << "i v"
262
+ end
263
+
264
+ # Kill execution of program being debugged
265
+ def kill
266
+ @queue << "kill"
267
+ end
268
+
269
+ # List specified function or line
270
+ def list
271
+ @queue << "list"
272
+ end
273
+
274
+ # Step program
275
+ def next
276
+ @queue << "next"
277
+ end
278
+
279
+ # Print value of variable EXP
280
+ def print=(msg)
281
+ @queue << "print #{msg}"
282
+ end
283
+
284
+ # Print working directory
285
+ def pwd
286
+ @queue << "pwd"
287
+ end
288
+
289
+ # Exit fdb
290
+ def quit
291
+ @queue << "quit"
292
+ @queue << "y"
293
+ @queue << "terminate"
294
+ end
295
+
296
+ # Start debugged program
297
+ def run
298
+ @queue << "run"
299
+ end
300
+
301
+ # Set the value of a variable
302
+ def set=(value)
303
+ @queue << "set #{value}"
304
+ end
305
+
306
+ # Sleep until some 'str' String is sent to the output
307
+ def sleep_until(str)
308
+ @queue << "sleep #{str}"
309
+ end
310
+
311
+ # Read fdb commands from a file
312
+ def source=(file)
313
+ @queue << "source #{file}"
314
+ end
315
+
316
+ # Step program until it reaches a different source line
317
+ def step
318
+ @queue << "step"
319
+ end
320
+
321
+ # Force the Flash Debugger and running SWF to close
322
+ def terminate
323
+ @queue << "terminate"
324
+ end
325
+
326
+ # Remove an auto-display expression
327
+ def undisplay
328
+ @queue << "undisplay"
329
+ end
330
+
331
+ # Set or clear filter for file listing based on swf
332
+ def viewswf
333
+ @queue << "viewswf"
334
+ end
335
+
336
+ # Displays the context of a variable
337
+ def what=(value)
338
+ @queue << "what #{value}"
339
+ end
340
+
341
+ # Same as bt
342
+ def where
343
+ @queue << "bt"
344
+ end
345
+
346
+ end
347
+
348
+ # A buffer that provides clean blocking support for the fdb command shell
349
+ class FDBBuffer #:nodoc:
350
+ PLAYER_TERMINATED = 'Player session terminated'
351
+ EXIT_PROMPT = 'The program is running. Exit anyway? (y or n)'
352
+ PROMPT = '(fdb) '
353
+ QUIT = 'quit'
354
+
355
+ # The constructor expects a buffered input and output
356
+ def initialize(exe, output, user_input=nil)
357
+ @output = output
358
+ @prompted = false
359
+ @faulted = false
360
+ @user_input = user_input
361
+ @found_search = false
362
+ @pending_expression = nil
363
+ listen exe
364
+ end
365
+
366
+ def user_input
367
+ @user_input ||= $stdin
368
+ end
369
+
370
+ def create_input(exe)
371
+ ProcessRunner.new("#{exe}")
372
+ end
373
+
374
+ def sleep_until(str)
375
+ @found_search = false
376
+ @pending_expression = str
377
+ while !@found_search do
378
+ sleep(0.2)
379
+ end
380
+ end
381
+
382
+ # Listen for messages from the input process
383
+ def listen(exe)
384
+ @input = nil
385
+ @listener = Thread.new do
386
+ @input = create_input(exe)
387
+ def puts(msg)
388
+ $stdout.puts msg
389
+ end
390
+
391
+ char = ''
392
+ line = ''
393
+ while true do
394
+ begin
395
+ char = @input.readpartial 1
396
+ rescue EOFError => e
397
+ puts "End of File - Exiting Now"
398
+ @prompted = true
399
+ break
400
+ end
401
+
402
+ if(char == "\n")
403
+ line = ''
404
+ else
405
+ line << char
406
+ end
407
+
408
+ @output.print char
409
+ @output.flush
410
+
411
+ if(line == PROMPT || line.match(/\(y or n\) $/))
412
+ @prompted = true
413
+ line = ''
414
+ elsif(@pending_expression && line.match(/#{@pending_expression}/))
415
+ @found_search = true
416
+ @pending_expression = nil
417
+ elsif(line == PLAYER_TERMINATED)
418
+ puts ""
419
+ puts "Closed SWF Connection - Exiting Now"
420
+ @prompted = true
421
+ break
422
+ end
423
+ end
424
+ end
425
+
426
+ end
427
+
428
+ # Block for the life of the input process
429
+ def join
430
+ puts ">> Entering FDB interactive mode, type 'help' for more info."
431
+ print PROMPT
432
+ $stdout.flush
433
+
434
+ Thread.new do
435
+ while true do
436
+ msg = user_input.gets.chomp!
437
+ @input.puts msg
438
+ wait_for_prompt
439
+ end
440
+ end
441
+
442
+ @listener.join
443
+ end
444
+
445
+ # Block until prompted returns true
446
+ def wait_for_prompt
447
+ while !@prompted do
448
+ sleep(0.2)
449
+ end
450
+ end
451
+
452
+ # Kill the buffer
453
+ def kill
454
+ @listener.kill
455
+ end
456
+
457
+ # Send a message to the buffer input and reset the prompted flag to false
458
+ def write(msg)
459
+ @prompted = false
460
+ @input.puts msg
461
+ print msg + "\n"
462
+ $stdout.flush
463
+ if(msg != "c" && msg != "continue")
464
+ wait_for_prompt
465
+ end
466
+ end
467
+
468
+ end
469
+ end
470
+
471
+ def fdb(args, &block)
472
+ Sprout::FDBTask.define_task(args, &block)
473
+ end
474
+
@@ -1,11 +1,26 @@
1
1
 
2
2
  module Sprout # :nodoc:
3
- class MXMLCDebug < MXMLCHelper # :nodoc:
3
+
4
+ # The MXMLCDebug helper wraps up the flashplayer and mxmlc tasks by
5
+ # using either a Singleton or provided ProjectModel instance.
6
+ #
7
+ # The simple case that uses a Singleton ProjectModel:
8
+ # debug :debug
9
+ #
10
+ # Using a ProjectModel instance:
11
+ # project_model :model
12
+ #
13
+ # debug :debug => :model
14
+ #
15
+ # Configuring the proxied Sprout::MXMLCTask
16
+ # debug :debug do |t|
17
+ # t.link_report = 'LinkReport.rpt'
18
+ # end
19
+ #
20
+ class MXMLCDebug < MXMLCHelper
4
21
 
5
22
  def initialize(args, &block)
6
23
  super
7
- t = define_outer_task
8
- t.prerequisites << player_task_name
9
24
 
10
25
  mxmlc output do |t|
11
26
  configure_mxmlc t
@@ -14,7 +29,10 @@ module Sprout # :nodoc:
14
29
  end
15
30
 
16
31
  define_player
17
- return output
32
+
33
+ t = define_outer_task
34
+ t.prerequisites << output
35
+ t.prerequisites << player_task_name
18
36
  end
19
37
 
20
38
  end
@@ -1,6 +1,26 @@
1
1
 
2
- module Sprout
3
- class MXMLCDeploy < MXMLCHelper # :nodoc:
2
+ module Sprout # :nodoc:
3
+
4
+ # The MXMLCDeploy helper wraps up an mxmlc task by
5
+ # using either a Singleton or provided ProjectModel instance.
6
+ #
7
+ # This helper turns off debugging and turns on optimization for
8
+ # the compiled SWF file.
9
+ #
10
+ # The simple case that uses a Singleton ProjectModel:
11
+ # deploy :deploy
12
+ #
13
+ # Using a ProjectModel instance:
14
+ # project_model :model
15
+ #
16
+ # deploy :deploy => :model
17
+ #
18
+ # Configuring the proxy Sprout::MXMLCTask
19
+ # deploy :deploy do |t|
20
+ # t.link_report = 'LinkReport.rpt'
21
+ # end
22
+ #
23
+ class MXMLCDeploy < MXMLCHelper
4
24
 
5
25
  def initialize(args, &block)
6
26
  super
@@ -1,25 +1,39 @@
1
1
 
2
2
  module Sprout # :nodoc:
3
- class MXMLCDocument < MXMLCHelper # :nodoc:
3
+
4
+ # The MXMLCDocument helper wraps up the asdoc task
5
+ # using either a Singleton or provided ProjectModel instance.
6
+ #
7
+ # The simple case that uses a Singleton ProjectModel:
8
+ # document :asdoc
9
+ #
10
+ # Using a ProjectModel instance:
11
+ # project_model :model
12
+ #
13
+ # document :asdoc => :model
14
+ #
15
+ # Configuring the proxy ASDocTask
16
+ # document :asdoc do |t|
17
+ # t.link_report = 'LinkReport.rpt'
18
+ # end
19
+ #
20
+ class MXMLCDocument < MXMLCHelper
4
21
 
5
22
  def initialize(args, &block)
6
23
  super
7
- outer = define_outer_task
8
24
 
9
- asdoc output => input do |t|
10
- t.output = 'doc'
25
+ asdoc task_name do |t|
26
+ configure_mxmlc(t, true)
27
+ t.output = model.doc_dir
28
+ t.doc_classes = input
29
+ t.main_title = model.project_name
11
30
  yield t if block_given?
12
31
  end
13
32
 
14
- outer.prerequisites << output
15
33
  end
16
34
 
17
- def create_output
18
- return File.join(model.doc_dir, 'index.html')
19
- end
20
-
21
35
  def create_input
22
- return "#{create_output_base}.swf"
36
+ return File.basename(super).split('.')[0]
23
37
  end
24
38
 
25
39
  end