flashplayer-task 0.1.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.
- data/lib/sprout/flash_player_task.rb +319 -0
- data/lib/sprout/flash_player_task/version.rb +12 -0
- data/sample/bin/SomeProject.swf +0 -0
- data/sample/rakefile.rb +24 -0
- metadata +60 -0
@@ -0,0 +1,319 @@
|
|
1
|
+
=begin
|
2
|
+
Copyright (c) 2007 Pattern Park
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
a copy of this software and associated documentation files (the
|
6
|
+
"Software"), to deal in the Software without restriction, including
|
7
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
19
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
20
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
21
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
=end
|
23
|
+
require 'sprout'
|
24
|
+
|
25
|
+
module Sprout
|
26
|
+
class FlashPlayerError < StandardError; end
|
27
|
+
|
28
|
+
class FlashPlayerTask < Rake::Task
|
29
|
+
DEFAULT_VERSION = '>= 9.60.0'
|
30
|
+
EXECUTABLE_NAME = 'flashplayer'
|
31
|
+
|
32
|
+
@@test_result_pre_delimiter = '<XMLResultPrinter>'
|
33
|
+
@@test_result_post_delimiter = '</XMLResultPrinter>'
|
34
|
+
@@home = nil
|
35
|
+
@@trust = nil
|
36
|
+
|
37
|
+
attr_accessor :version,
|
38
|
+
:name,
|
39
|
+
:swf,
|
40
|
+
:test_result_file
|
41
|
+
|
42
|
+
def FlashPlayerTask.define_task(args, &block)
|
43
|
+
t = super
|
44
|
+
yield t if block_given?
|
45
|
+
t.define
|
46
|
+
end
|
47
|
+
|
48
|
+
def FlashPlayerTask.trust
|
49
|
+
if(@@trust)
|
50
|
+
return @@trust
|
51
|
+
end
|
52
|
+
@@trust = File.join(FlashPlayerTask.home, '#Security', 'FlashPlayerTrust', 'sprout.cfg')
|
53
|
+
return @@trust
|
54
|
+
end
|
55
|
+
|
56
|
+
def FlashPlayerTask.home
|
57
|
+
if(@@home)
|
58
|
+
return @@home
|
59
|
+
end
|
60
|
+
|
61
|
+
FlashPlayerTask.home_paths.each do |path|
|
62
|
+
if(File.exists?(path))
|
63
|
+
return @@home = path
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
if(@@home.nil?)
|
68
|
+
raise FlashPlayerError.new('FlashPlayer unable to find home folder for your platform')
|
69
|
+
end
|
70
|
+
return @@home
|
71
|
+
end
|
72
|
+
|
73
|
+
# Enumerate the potential locations of the Flash Player Home
|
74
|
+
# For each supported Platform, the first existing location
|
75
|
+
# will be used.
|
76
|
+
def FlashPlayerTask.home_paths
|
77
|
+
return [File.join(User.library, 'Preferences', 'Macromedia', 'Flash Player'),
|
78
|
+
File.join(User.library, 'Application Support', 'Macromedia'),
|
79
|
+
File.join(User.home, 'Application Data', 'Macromedia', 'Flash Player'),
|
80
|
+
File.join(User.home, '.macromedia', 'Flash_Player')]
|
81
|
+
end
|
82
|
+
|
83
|
+
def initialize(task_name, app)
|
84
|
+
super(task_name, app)
|
85
|
+
@version = DEFAULT_VERSION
|
86
|
+
@inside_test_result = false
|
87
|
+
@test_result = ''
|
88
|
+
end
|
89
|
+
|
90
|
+
def execute
|
91
|
+
log_file = nil
|
92
|
+
|
93
|
+
# Don't let trust or log file failures break other features...
|
94
|
+
# begin
|
95
|
+
log_file = FlashPlayerConfig.new().log
|
96
|
+
# FlashPlayerTrust.new(File.dirname(@swf))
|
97
|
+
|
98
|
+
if(File.exists?(log_file))
|
99
|
+
File.open(log_file, 'w') do |f|
|
100
|
+
f.write('')
|
101
|
+
end
|
102
|
+
else
|
103
|
+
FileUtils.mkdir_p(File.dirname(log_file))
|
104
|
+
FileUtils.touch(log_file)
|
105
|
+
end
|
106
|
+
|
107
|
+
# rescue
|
108
|
+
# puts '[WARNING] FlashPlayer encountered an error working with the mm.cfg log and/or editing the Trust file'
|
109
|
+
# end
|
110
|
+
|
111
|
+
@running_process = nil
|
112
|
+
thread = run(EXECUTABLE_NAME, version, swf)
|
113
|
+
read_log(thread, log_file)
|
114
|
+
thread.join
|
115
|
+
end
|
116
|
+
|
117
|
+
def close
|
118
|
+
Process.kill("SIGALRM", @player_pid)
|
119
|
+
end
|
120
|
+
|
121
|
+
def run(tool, version, swf)
|
122
|
+
puts "execute flash player now!"
|
123
|
+
|
124
|
+
usr = User.new()
|
125
|
+
target = Sprout.get_executable(tool, nil, version)
|
126
|
+
|
127
|
+
puts "target #{target}"
|
128
|
+
target = User.clean_path(target)
|
129
|
+
|
130
|
+
@player_pid = nil
|
131
|
+
@swf_pid = nil
|
132
|
+
@parent_pid = nil
|
133
|
+
|
134
|
+
if(usr.is_a?(OSXUser))
|
135
|
+
return Thread.new {
|
136
|
+
@player_pid = Process.fork do
|
137
|
+
exec(target)
|
138
|
+
end
|
139
|
+
@swf_pid = Process.fork do
|
140
|
+
exec("open #{swf}")
|
141
|
+
end
|
142
|
+
Process.waitpid(@player_pid)
|
143
|
+
}
|
144
|
+
else
|
145
|
+
return Thread.new {
|
146
|
+
@player_pid = exec("#{target} ./#{swf}")
|
147
|
+
# IO.popen("#{target} ./#{swf}") do |p|
|
148
|
+
# end
|
149
|
+
}
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
def define
|
155
|
+
task @name => [@swf]
|
156
|
+
|
157
|
+
if(@test_result_file)
|
158
|
+
CLEAN.add(@test_result_file)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def read_log(thread, log_file)
|
163
|
+
lines_put = 0
|
164
|
+
|
165
|
+
if(!File.exists?(log_file))
|
166
|
+
raise FlashPlayerError.new('[ERROR] Unable to find the trace output log file in the expected location: ' + log_file)
|
167
|
+
end
|
168
|
+
|
169
|
+
while(thread.alive?)
|
170
|
+
sleep(0.2)
|
171
|
+
lines_read = 0
|
172
|
+
|
173
|
+
File.open(log_file, 'r') do |file|
|
174
|
+
file.readlines.each do |line|
|
175
|
+
lines_read = lines_read + 1
|
176
|
+
if(lines_read > lines_put)
|
177
|
+
puts "[trace] #{line}"
|
178
|
+
parse_test_result(line, thread)
|
179
|
+
$stdout.flush
|
180
|
+
lines_put = lines_put + 1
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def parse_test_result(line, thread)
|
188
|
+
if(test_result_file.nil?)
|
189
|
+
return
|
190
|
+
end
|
191
|
+
|
192
|
+
if(@inside_test_result)
|
193
|
+
if(line.index(@@test_result_post_delimiter))
|
194
|
+
@inside_test_result = false
|
195
|
+
write_test_result(@test_result)
|
196
|
+
close
|
197
|
+
else
|
198
|
+
@test_result << line
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
if(line.index(@@test_result_pre_delimiter))
|
203
|
+
@inside_test_result = true
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
def write_test_result(result)
|
208
|
+
FileUtils.makedirs(File.dirname(test_result_file))
|
209
|
+
File.open(test_result_file, File::CREAT|File::TRUNC|File::RDWR) do |f|
|
210
|
+
f.puts(result)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
##########################################
|
216
|
+
# FlashPlayerConfig Class
|
217
|
+
|
218
|
+
class FlashPlayerConfig
|
219
|
+
|
220
|
+
@@file_name = 'mm.cfg'
|
221
|
+
|
222
|
+
def initialize
|
223
|
+
osx_fp9 = File.join(User.library, 'Application Support', 'Macromedia')
|
224
|
+
if(FlashPlayerTask.home == osx_fp9)
|
225
|
+
@config = File.join(osx_fp9, @@file_name)
|
226
|
+
else
|
227
|
+
@config = File.join(User.home, @@file_name)
|
228
|
+
end
|
229
|
+
|
230
|
+
if(!File.exists?(@config))
|
231
|
+
write_config(@config, content)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
def log
|
236
|
+
path = File.join(FlashPlayerTask.home, 'Logs', 'flashlog.txt')
|
237
|
+
if(User.new().is_a?(CygwinUser))
|
238
|
+
parts = path.split("/")
|
239
|
+
parts.shift()
|
240
|
+
part = parts.shift() # shift cygdrive
|
241
|
+
if(part != 'cygdrive')
|
242
|
+
Log.puts "[WARNING] There may have been a problem writing mm.cfg, please check the path in #{@config} and make sure it's a windows path..."
|
243
|
+
return path
|
244
|
+
end
|
245
|
+
drive = parts.shift()
|
246
|
+
parts.unshift(drive.upcase + ":")
|
247
|
+
path = parts.join("/")
|
248
|
+
end
|
249
|
+
return path
|
250
|
+
end
|
251
|
+
|
252
|
+
def content
|
253
|
+
return <<EOF
|
254
|
+
ErrorReportingEnable=1
|
255
|
+
MaxWarnings=0
|
256
|
+
TraceOutputEnable=1
|
257
|
+
TraceOutputFileName=#{log}
|
258
|
+
EOF
|
259
|
+
end
|
260
|
+
|
261
|
+
private
|
262
|
+
def write_config(location, content)
|
263
|
+
puts <<EOF
|
264
|
+
|
265
|
+
Correctly configured mm.cfg file not found at: #{location}
|
266
|
+
|
267
|
+
This file is required in order to capture trace output.
|
268
|
+
|
269
|
+
Would you like this file created automatically? [Yn]
|
270
|
+
|
271
|
+
EOF
|
272
|
+
answer = $stdin.gets.chomp.downcase
|
273
|
+
if(answer == 'y' || answer == '')
|
274
|
+
File.open(location, 'w') do |f|
|
275
|
+
f.write(content)
|
276
|
+
end
|
277
|
+
Log.puts ">> Created file: " + File.expand_path(location)
|
278
|
+
else
|
279
|
+
raise FlashPlayerError.new("[ERROR] Unable to create mm.cfg file at: #{location}")
|
280
|
+
end
|
281
|
+
end
|
282
|
+
end
|
283
|
+
|
284
|
+
##########################################
|
285
|
+
# FlashPlayerTrust Class
|
286
|
+
|
287
|
+
class FlashPlayerTrust
|
288
|
+
|
289
|
+
def initialize(path)
|
290
|
+
trust_file = FlashPlayerTask.trust
|
291
|
+
if(!File.exists?(trust_file))
|
292
|
+
FileUtils.touch(trust_file)
|
293
|
+
end
|
294
|
+
|
295
|
+
parts = path.split(File::SEPARATOR)
|
296
|
+
if(parts.size == 1)
|
297
|
+
path = File::SEPARATOR + path
|
298
|
+
end
|
299
|
+
|
300
|
+
if(!has_path?(trust_file, path))
|
301
|
+
File.open(trust_file, 'a') do |f|
|
302
|
+
f.puts path
|
303
|
+
end
|
304
|
+
Log.puts ">> Added #{path} to Flash Player Trust file at: #{trust_file}"
|
305
|
+
end
|
306
|
+
end
|
307
|
+
|
308
|
+
def has_path?(file, path)
|
309
|
+
File.open(file, 'r') do |f|
|
310
|
+
return (f.read.index(path))
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
end
|
316
|
+
|
317
|
+
def flash_player(args, &block)
|
318
|
+
Sprout::FlashPlayerTask.define_task(args, &block)
|
319
|
+
end
|
Binary file
|
data/sample/rakefile.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Run the flash player task from version control:
|
4
|
+
require File.dirname(__FILE__) + '/../lib/sprout/flashplayertask'
|
5
|
+
|
6
|
+
# Run the installed version:
|
7
|
+
#require 'sprout/flashplayertask'
|
8
|
+
|
9
|
+
# To run the sample:
|
10
|
+
# 1) Open a terminal
|
11
|
+
# 2) cd into the directory that contains this file
|
12
|
+
# 3) run 'rake'
|
13
|
+
# 4) the flash player should block the shell input and launch in your os
|
14
|
+
# 5) Close the flash player and you should return to the shell
|
15
|
+
|
16
|
+
# Make the default (no-name)
|
17
|
+
# rake task compile using mxmlc
|
18
|
+
task :default => :run
|
19
|
+
|
20
|
+
desc "Launch a swf with the Flash Player"
|
21
|
+
flash_player :run do |t|
|
22
|
+
t.swf = 'bin/SomeProject.swf'
|
23
|
+
t.version = '>= 9.60.0' # Default value is: '>= 9.115.0'
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: flashplayer-task
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.1.0
|
7
|
+
date: 2007-12-28 00:00:00 -08:00
|
8
|
+
summary: Flash Player Task provides rake tasks to launch and close SWF files in the Adobe Flash Player
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: projectsprouts@googlegroups.com
|
12
|
+
homepage: http://www.projectsprouts.org
|
13
|
+
rubyforge_project:
|
14
|
+
description:
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Luke Bayes
|
31
|
+
files:
|
32
|
+
- lib/sprout
|
33
|
+
- lib/sprout/flash_player_task
|
34
|
+
- lib/sprout/flash_player_task/version.rb
|
35
|
+
- lib/sprout/flash_player_task.rb
|
36
|
+
- sample/bin
|
37
|
+
- sample/bin/SomeProject.swf
|
38
|
+
- sample/rakefile.rb
|
39
|
+
test_files: []
|
40
|
+
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
extra_rdoc_files: []
|
44
|
+
|
45
|
+
executables: []
|
46
|
+
|
47
|
+
extensions: []
|
48
|
+
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
dependencies:
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
name: sprout
|
54
|
+
version_requirement:
|
55
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 0.7.1
|
60
|
+
version:
|