asproject 0.1.44 → 0.1.60
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/asclass +1 -0
- data/lib/asclass.rb +0 -2
- data/lib/asproject.rb +37 -0
- data/lib/asproject/version.rb +1 -1
- data/lib/tasks/flash_player.rb +44 -17
- data/lib/tasks/flash_player_trust.rb +1 -1
- data/lib/tasks/mtasc.rb +53 -27
- data/lib/tasks/remote_file_task.rb +337 -297
- data/lib/tasks/simple_resolver.rb +2 -2
- data/lib/tasks/swfmill_input.rb +1 -1
- data/lib/template_resolver.rb +37 -7
- data/lib/test_suite_generator.rb +3 -3
- data/rakefile.rb +2 -2
- data/templates/asproject/as2/project/rakefile.rb +8 -8
- data/templates/asproject/as3/project/rakefile.rb +18 -18
- metadata +2 -14
- data/templates/asclass/mxml/.crap_file +0 -10
- data/templates/asproject/as2/art/.crap_file +0 -10
- data/templates/asproject/as2/doc/.crap_file +0 -10
- data/templates/asproject/as2/project/bin/.crap_file +0 -10
- data/templates/asproject/as2/project/lib/.crap_file +0 -10
- data/templates/asproject/as3/art/.crap_file +0 -10
- data/templates/asproject/as3/doc/.crap_file +0 -10
- data/templates/asproject/as3/project/bin/.crap_file +0 -10
- data/templates/asproject/as3/project/lib/.crap_file +0 -10
- data/templates/asproject/as3/project/test/.crap_file +0 -10
- data/templates/asproject/mxml/.crap_file +0 -10
data/bin/asclass
CHANGED
data/lib/asclass.rb
CHANGED
data/lib/asproject.rb
CHANGED
@@ -39,6 +39,7 @@ require 'tasks/swfmill_input'
|
|
39
39
|
require 'tasks/swfmill'
|
40
40
|
|
41
41
|
module AsProject
|
42
|
+
|
42
43
|
class AsProject < AsProjectBase
|
43
44
|
@@ASPROJECT_FILE_NAME = 'AsProject'
|
44
45
|
@@TEMPLATE_TYPE = 'asproject'
|
@@ -266,4 +267,40 @@ EOF
|
|
266
267
|
return @context.project_path
|
267
268
|
end
|
268
269
|
end
|
270
|
+
|
271
|
+
class Logger
|
272
|
+
@@output = ''
|
273
|
+
@@debug = false
|
274
|
+
|
275
|
+
def Logger.debug=(debug)
|
276
|
+
@@debug = debug
|
277
|
+
end
|
278
|
+
|
279
|
+
def Logger.debug
|
280
|
+
return @@debug
|
281
|
+
end
|
282
|
+
|
283
|
+
def Logger.puts(line)
|
284
|
+
if(!Logger.debug)
|
285
|
+
$stdout.puts line
|
286
|
+
else
|
287
|
+
@@output << "#{line}\n"
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
def Logger.printf(msg)
|
292
|
+
if(!Logger.debug)
|
293
|
+
$stdout.puts msg
|
294
|
+
else
|
295
|
+
@@output << msg
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
def Logger.flush
|
300
|
+
if(!Logger.debug)
|
301
|
+
$stdout.puts @@output
|
302
|
+
end
|
303
|
+
@@output = ''
|
304
|
+
end
|
305
|
+
end
|
269
306
|
end
|
data/lib/asproject/version.rb
CHANGED
data/lib/tasks/flash_player.rb
CHANGED
@@ -1,11 +1,4 @@
|
|
1
1
|
|
2
|
-
# Pull in the project-local config file
|
3
|
-
# if it exists...
|
4
|
-
if(File.exists?('script/asclass_config.rb'))
|
5
|
-
# require 'script/asclass_config'
|
6
|
-
# include Config
|
7
|
-
end
|
8
|
-
|
9
2
|
module AsProject
|
10
3
|
class FlashPlayerError < StandardError; end
|
11
4
|
|
@@ -38,8 +31,8 @@ module AsProject
|
|
38
31
|
@win_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip"
|
39
32
|
@win_extracted_file = "/Players/Debug/SAFlashPlayer.exe"
|
40
33
|
@osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/sa_flashplayer_8_all_debug.dmg"
|
41
|
-
@osx_mounted_path = "
|
42
|
-
@osx_extracted_file = "
|
34
|
+
@osx_mounted_path = "Adobe Flash Standalone Players"
|
35
|
+
@osx_extracted_file = "en/SAFlashPlayer"
|
43
36
|
@unix_url = nil
|
44
37
|
@unix_extracted_file = nil
|
45
38
|
elsif(version == 9)
|
@@ -70,15 +63,36 @@ module AsProject
|
|
70
63
|
rescue
|
71
64
|
puts 'Warning, was unable to update the FlashPlayerTrust file'
|
72
65
|
end
|
73
|
-
|
74
|
-
index = 0
|
66
|
+
|
75
67
|
File.open(log_file, 'w') do |f|
|
76
68
|
f.write('')
|
77
69
|
end
|
78
70
|
|
71
|
+
thread = nil
|
72
|
+
if(Logger.debug)
|
73
|
+
thread = ThreadMock.new
|
74
|
+
elsif(@user_task.is_a?(OSXRemoteFileTask) && !Logger.debug)
|
75
|
+
thread = run_osx
|
76
|
+
else
|
77
|
+
thread = run_other
|
78
|
+
end
|
79
|
+
|
80
|
+
read_log(thread, log_file)
|
81
|
+
end
|
82
|
+
|
83
|
+
def run_osx
|
84
|
+
system(%{open -a #{extracted_file_path} ./#{@swf}})
|
85
|
+
return OSXPlayerThread.new
|
86
|
+
end
|
87
|
+
|
88
|
+
def run_other
|
79
89
|
player_thread = Thread.new {
|
80
90
|
execute("./#{@swf}")
|
81
91
|
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def read_log(player_thread, log_file)
|
95
|
+
index = 0
|
82
96
|
|
83
97
|
if(!File.exists?(log_file))
|
84
98
|
raise UsageError.new('Unable to find the trace output log file in the expected location: ' + log_file)
|
@@ -88,16 +102,29 @@ module AsProject
|
|
88
102
|
sleep(0.2)
|
89
103
|
incr = 0
|
90
104
|
|
91
|
-
File.open(log_file,
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
105
|
+
File.open(log_file, 'r') do |file|
|
106
|
+
file.readlines.each do |line|
|
107
|
+
incr = incr + 1
|
108
|
+
if(incr > index)
|
109
|
+
puts "[trace] #{line}"
|
110
|
+
index = index + 1
|
111
|
+
end
|
96
112
|
end
|
97
113
|
end
|
98
114
|
end
|
99
115
|
end
|
100
116
|
end
|
101
117
|
end
|
102
|
-
end
|
103
118
|
|
119
|
+
class ThreadMock
|
120
|
+
def alive?
|
121
|
+
return false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class OSXPlayerThread
|
126
|
+
def alive?
|
127
|
+
return true
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
data/lib/tasks/mtasc.rb
CHANGED
@@ -5,22 +5,33 @@ module AsProject
|
|
5
5
|
class MTASC < RemoteFileTask
|
6
6
|
|
7
7
|
attr_accessor :name,
|
8
|
-
:version,
|
9
8
|
:compiler_version,
|
10
|
-
:
|
11
|
-
:
|
9
|
+
:cp,
|
10
|
+
:exclude,
|
12
11
|
:frame,
|
13
|
-
:
|
12
|
+
:group,
|
13
|
+
:header,
|
14
|
+
:infer,
|
15
|
+
:keep,
|
16
|
+
:main,
|
17
|
+
:msvc,
|
14
18
|
:mx,
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
19
|
+
:out,
|
20
|
+
:pack,
|
21
|
+
:strict,
|
22
|
+
:swf,
|
23
|
+
:trace,
|
24
|
+
:verbose,
|
25
|
+
:version,
|
26
|
+
:wimp,
|
27
|
+
:input
|
19
28
|
|
20
29
|
def initialize(name=:compile, do_not_define=false)
|
21
30
|
@compiler_version = '1.13'
|
22
31
|
@options = []
|
23
|
-
@
|
32
|
+
@cp = []
|
33
|
+
@pack = []
|
34
|
+
|
24
35
|
@user_task = nil
|
25
36
|
@win_url = "http://www.mtasc.org/zip/mtasc-#{compiler_version}.zip"
|
26
37
|
@win_extracted_file = "/mtasc-#{compiler_version}/mtasc.exe"
|
@@ -43,27 +54,32 @@ module AsProject
|
|
43
54
|
# Create the tasks defined by this task lib.
|
44
55
|
def define
|
45
56
|
super
|
46
|
-
# if(!
|
47
|
-
# raise MTASCError.new('MTASC task must be provided with an
|
57
|
+
# if(!swf && !header && pack_path.size == 0)
|
58
|
+
# raise MTASCError.new('MTASC task must be provided with an swf, a header argument, or at least one pack_path')
|
48
59
|
# end
|
49
|
-
# if(header && !
|
50
|
-
# raise MTASCError.new('It looks like you used the
|
60
|
+
# if(header && !swf && out)
|
61
|
+
# raise MTASCError.new('It looks like you used the out parameter where you should have used the swf parameter')
|
51
62
|
# end
|
63
|
+
|
52
64
|
desc compile_task_desc
|
53
|
-
task name => [
|
54
|
-
CLEAN.add(
|
65
|
+
task name => [out]
|
66
|
+
CLEAN.add(out)
|
55
67
|
|
56
|
-
if(
|
57
|
-
file
|
58
|
-
task name => [
|
68
|
+
if(swf)
|
69
|
+
file swf
|
70
|
+
task name => [swf]
|
59
71
|
end
|
60
72
|
|
61
73
|
@cleaned_class_paths = []
|
62
|
-
|
74
|
+
cp.each do |path|
|
63
75
|
add_path(path, @cleaned_class_paths)
|
64
76
|
end
|
65
77
|
|
66
|
-
file
|
78
|
+
file out do |f|
|
79
|
+
# if(input && !File.exists?(input))
|
80
|
+
# raise MTASCError.new('MTASC.input must be an existing file')
|
81
|
+
# end
|
82
|
+
|
67
83
|
user_task.execute(option_list.join(' '))
|
68
84
|
end
|
69
85
|
|
@@ -83,10 +99,10 @@ module AsProject
|
|
83
99
|
def add_path(path, list)
|
84
100
|
as_files = FileList[path + '/**/**/*.as']
|
85
101
|
file as_files
|
86
|
-
file
|
102
|
+
file out => as_files
|
87
103
|
xml_files = FileList[path + '/**/**/*.xml']
|
88
104
|
file xml_files
|
89
|
-
file
|
105
|
+
file out => xml_files
|
90
106
|
|
91
107
|
list << clean_path(path)
|
92
108
|
end
|
@@ -94,13 +110,23 @@ module AsProject
|
|
94
110
|
def option_list
|
95
111
|
result = @options.dup
|
96
112
|
result << "-header" << header if header
|
97
|
-
result << "-
|
98
|
-
result << "-
|
113
|
+
result << "-cp " + @cleaned_class_paths.join(" -cp ") if cp.size > 0
|
114
|
+
result << "-exclude" << exclude if exclude
|
99
115
|
result << "-frame" << frame if frame
|
100
|
-
result << "-
|
101
|
-
result << "-
|
102
|
-
result << "-
|
116
|
+
result << "-group" if group
|
117
|
+
result << "-infer" if infer
|
118
|
+
result << "-keep" if keep
|
103
119
|
result << "-main" if main
|
120
|
+
result << "-msvc" if msvc
|
121
|
+
result << "-strict" if strict
|
122
|
+
result << "-mx" if mx
|
123
|
+
result << "-trace" << trace if trace
|
124
|
+
result << "-v" if verbose
|
125
|
+
result << "-version" << version if version
|
126
|
+
result << "-wimp" if wimp
|
127
|
+
result << "-pack " + pack.join(" -pack ") if pack.size > 0
|
128
|
+
result << "-swf" << clean_path(swf) if swf
|
129
|
+
result << "-out" << clean_path(out) if out
|
104
130
|
result << clean_path(input) if input
|
105
131
|
return result
|
106
132
|
end
|
@@ -1,298 +1,338 @@
|
|
1
|
-
|
2
|
-
# Tell Rake NOT to remove directory(ies) named 'core'
|
3
|
-
CLEAN.exclude("core")
|
4
|
-
|
5
|
-
module AsProject
|
6
|
-
# The RemoteFileTask was created to resolve
|
7
|
-
# external tool dependencies for relatively stable
|
8
|
-
# tools like mtasc, swfmill and mxmlc
|
9
|
-
# The intention is that common tools will have
|
10
|
-
# RemoteFileTasks deployed with AsProject and will
|
11
|
-
# include mac/win/unix targets so that users on
|
12
|
-
# each platform will seamlessly download and
|
13
|
-
# target these tools.
|
14
|
-
class RemoteFileTask < Rake::TaskLib
|
15
|
-
|
16
|
-
attr_accessor :name,
|
17
|
-
:user_task,
|
18
|
-
:remote_task_name,
|
19
|
-
:win_url,
|
20
|
-
:osx_url,
|
21
|
-
:unix_url,
|
22
|
-
:win_extracted_file,
|
23
|
-
:osx_extracted_file,
|
24
|
-
:unix_extracted_file,
|
25
|
-
:osx_mounted_path
|
26
|
-
|
27
|
-
def initialize(name=:remote_file_task, do_not_define=false)
|
28
|
-
@name = name
|
29
|
-
@user_task = nil
|
30
|
-
@remote_task_name = name.to_s
|
31
|
-
yield self if block_given?
|
32
|
-
define unless do_not_define
|
33
|
-
end
|
34
|
-
|
35
|
-
def define
|
36
|
-
define_user_task
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def user
|
41
|
-
return @user
|
42
|
-
end
|
43
|
-
|
44
|
-
def
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
user_task
|
58
|
-
end
|
59
|
-
|
60
|
-
def
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
end
|
103
|
-
|
104
|
-
task @name => [extracted_file_path]
|
105
|
-
end
|
106
|
-
|
107
|
-
def extracted_file_path
|
108
|
-
return File.join(@user.downloads, @name.to_s, extracted_file)
|
109
|
-
end
|
110
|
-
|
111
|
-
def downloaded_file_path
|
112
|
-
parts = @uri.path.split('/')
|
113
|
-
file = parts.pop
|
114
|
-
return File.join(@user.downloads, @name.to_s, file)
|
115
|
-
end
|
116
|
-
|
117
|
-
def unpack_downloaded_file(file_name, expected_file)
|
118
|
-
dir = File.dirname(file_name)
|
119
|
-
|
120
|
-
if(
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
puts
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
1
|
+
|
2
|
+
# Tell Rake NOT to remove directory(ies) named 'core'
|
3
|
+
CLEAN.exclude("core")
|
4
|
+
|
5
|
+
module AsProject
|
6
|
+
# The RemoteFileTask was created to resolve
|
7
|
+
# external tool dependencies for relatively stable
|
8
|
+
# tools like mtasc, swfmill and mxmlc
|
9
|
+
# The intention is that common tools will have
|
10
|
+
# RemoteFileTasks deployed with AsProject and will
|
11
|
+
# include mac/win/unix targets so that users on
|
12
|
+
# each platform will seamlessly download and
|
13
|
+
# target these tools.
|
14
|
+
class RemoteFileTask < Rake::TaskLib
|
15
|
+
|
16
|
+
attr_accessor :name,
|
17
|
+
:user_task,
|
18
|
+
:remote_task_name,
|
19
|
+
:win_url,
|
20
|
+
:osx_url,
|
21
|
+
:unix_url,
|
22
|
+
:win_extracted_file,
|
23
|
+
:osx_extracted_file,
|
24
|
+
:unix_extracted_file,
|
25
|
+
:osx_mounted_path
|
26
|
+
|
27
|
+
def initialize(name=:remote_file_task, do_not_define=false)
|
28
|
+
@name = name
|
29
|
+
@user_task = nil
|
30
|
+
@remote_task_name = name.to_s
|
31
|
+
yield self if block_given?
|
32
|
+
define unless do_not_define
|
33
|
+
end
|
34
|
+
|
35
|
+
def define
|
36
|
+
define_user_task
|
37
|
+
self
|
38
|
+
end
|
39
|
+
|
40
|
+
def user
|
41
|
+
return @user
|
42
|
+
end
|
43
|
+
|
44
|
+
def extracted_file_path
|
45
|
+
return @user_task.extracted_file_path
|
46
|
+
end
|
47
|
+
|
48
|
+
def define_user_task
|
49
|
+
if(@user_task.nil?)
|
50
|
+
if(remote_task_name.nil?)
|
51
|
+
raise UsageError.new('RemoteFileTask created without a remote_task_name value...')
|
52
|
+
end
|
53
|
+
@user = PathFinder.new().user
|
54
|
+
@user_task = @user.remote_file_task(remote_task_name, self)
|
55
|
+
task name => remote_task_name
|
56
|
+
end
|
57
|
+
@user_task
|
58
|
+
end
|
59
|
+
|
60
|
+
def execute(params)
|
61
|
+
user_task.execute(params)
|
62
|
+
end
|
63
|
+
|
64
|
+
def clean_path(path)
|
65
|
+
define_user_task
|
66
|
+
return user_task.clean_path(path)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
###################################
|
71
|
+
# Concrete instances returned from
|
72
|
+
# User objects
|
73
|
+
class AbstractRemoteFileTask
|
74
|
+
include Archive::Tar
|
75
|
+
|
76
|
+
attr_accessor :name,
|
77
|
+
:url,
|
78
|
+
:mounted_path,
|
79
|
+
:extracted_file
|
80
|
+
|
81
|
+
def initialize(name, user)
|
82
|
+
@name = name
|
83
|
+
@user = user
|
84
|
+
yield self if block_given?
|
85
|
+
define
|
86
|
+
end
|
87
|
+
|
88
|
+
def define
|
89
|
+
@uri = URI.parse(url)
|
90
|
+
downloaded_file = downloaded_file_path
|
91
|
+
file downloaded_file do |f|
|
92
|
+
get_remote_file(@uri, downloaded_file)
|
93
|
+
end
|
94
|
+
|
95
|
+
if(extracted_file_path != downloaded_file)
|
96
|
+
if(!Rake::Task.task_defined?(extracted_file_path))
|
97
|
+
file extracted_file_path => downloaded_file do |f|
|
98
|
+
unpack_downloaded_file(downloaded_file, extracted_file_path)
|
99
|
+
File.chmod(0755, extracted_file_path)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
task @name => [extracted_file_path]
|
105
|
+
end
|
106
|
+
|
107
|
+
def extracted_file_path
|
108
|
+
return File.join(@user.downloads, @name.to_s, extracted_file)
|
109
|
+
end
|
110
|
+
|
111
|
+
def downloaded_file_path
|
112
|
+
parts = @uri.path.split('/')
|
113
|
+
file = parts.pop
|
114
|
+
return File.join(@user.downloads, @name.to_s, file)
|
115
|
+
end
|
116
|
+
|
117
|
+
def unpack_downloaded_file(file_name, expected_file)
|
118
|
+
dir = File.dirname(file_name)
|
119
|
+
Dir[dir + '/*'].each do |child|
|
120
|
+
if(child != '.' && child != '..' && child != file_name)
|
121
|
+
FileUtils.rm_rf(child)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if(!File.exists?(expected_file))
|
126
|
+
if(is_zip?(file_name))
|
127
|
+
unpack_zip(file_name, dir)
|
128
|
+
elsif(is_targz?(file_name))
|
129
|
+
unpack_targz(file_name, dir)
|
130
|
+
elsif(is_dmg?(file_name))
|
131
|
+
unpack_dmg(file_name, dir)
|
132
|
+
elsif(!is_exe?(file_name))
|
133
|
+
raise UsageError.new("RemoteFileTask does not know how to unpack files of type: #{file_name}")
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def unpack_zip(zip_file, dir)
|
139
|
+
Zip::ZipFile::open(zip_file) do |zf|
|
140
|
+
zf.each do |e|
|
141
|
+
fpath = File.join(dir, e.name)
|
142
|
+
FileUtils.mkdir_p(File.dirname(fpath))
|
143
|
+
zf.extract(e, fpath)
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def unpack_targz(tgz_file, dir)
|
149
|
+
tar = Zlib::GzipReader.new(File.open(tgz_file, 'rb'))
|
150
|
+
Minitar.unpack(tar, dir)
|
151
|
+
end
|
152
|
+
|
153
|
+
# This is actually not unpacking the FlashPlayer
|
154
|
+
# Binary file as expected...
|
155
|
+
# OSX is treated the player binary as if it is
|
156
|
+
# a regular text file, but if it is copied manually,
|
157
|
+
# the command works fine!?
|
158
|
+
def unpack_dmg(dmg_file, dir)
|
159
|
+
# 1) Mount the dmg in place
|
160
|
+
# 2) Recursively Copy it's contents to asproject_home
|
161
|
+
# 3) Unmount the dmg
|
162
|
+
if(mounted_path.nil?)
|
163
|
+
raise StandardError.new('DMG file downloaded, but the RemoteFileTask needs a mounted_path in order to mount it')
|
164
|
+
end
|
165
|
+
|
166
|
+
if(!File.exists?(full_mounted_path))
|
167
|
+
system("hdiutil mount #{dmg_file}")
|
168
|
+
end
|
169
|
+
|
170
|
+
mounted_target = File.join(full_mounted_path, extracted_file)
|
171
|
+
|
172
|
+
# Copy the Singular target out:
|
173
|
+
FileUtils.makedirs(File.dirname(extracted_file_path))
|
174
|
+
FileUtils.copy(mounted_target, extracted_file_path)
|
175
|
+
|
176
|
+
# Copy the entire DMG out:
|
177
|
+
# resolver = TemplateResolver.new
|
178
|
+
# resolver.replace_all = true
|
179
|
+
# resolver.copy_files(full_mounted_path, dir, false)
|
180
|
+
if(File.exists?(full_mounted_path))
|
181
|
+
system("hdiutil unmount -force \"#{full_mounted_path}\"")
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
def is_exe?(file)
|
186
|
+
return (file.split('.').pop == 'exe')
|
187
|
+
end
|
188
|
+
|
189
|
+
def is_zip?(file)
|
190
|
+
return (file.split('.').pop == 'zip')
|
191
|
+
end
|
192
|
+
|
193
|
+
def is_targz?(file)
|
194
|
+
parts = file.split('.')
|
195
|
+
return (parts.pop == 'gz' && parts.pop == 'tar')
|
196
|
+
end
|
197
|
+
|
198
|
+
def is_gzip?(file)
|
199
|
+
return (file.split('.').pop == 'gz')
|
200
|
+
end
|
201
|
+
|
202
|
+
def is_dmg?(file)
|
203
|
+
return (file.split('.').pop == 'dmg')
|
204
|
+
end
|
205
|
+
|
206
|
+
def make_downloaded_dir(file)
|
207
|
+
dir = File.dirname(file)
|
208
|
+
File.makedirs(dir)
|
209
|
+
end
|
210
|
+
|
211
|
+
def remote_file_dir
|
212
|
+
return File.join(@user.downloads, @name.to_s)
|
213
|
+
end
|
214
|
+
|
215
|
+
def remote_location
|
216
|
+
return File.join(remote_file_dir, extracted_file)
|
217
|
+
end
|
218
|
+
|
219
|
+
def fetch(location, limit = 10)
|
220
|
+
uri = URI.parse(location)
|
221
|
+
|
222
|
+
# Download the file now to the downloads dir
|
223
|
+
# If the file is an archive (zip, gz, tar, tar.gz, dmg), extract to
|
224
|
+
# AsProject/remote_files/@name/@location
|
225
|
+
# Check the location again...
|
226
|
+
raise UsageError.new("The RemoteFileTask can only handle HTTP requests at this time, it seems you were trying: #{uri.scheme}") if uri.scheme != 'http'
|
227
|
+
raise UsageError.new('HTTP redirect too deep') if limit == 0
|
228
|
+
|
229
|
+
response = nil
|
230
|
+
t = Thread.new {
|
231
|
+
response = Net::HTTP.get_response(uri.host, uri.path)
|
232
|
+
}
|
233
|
+
# TODO: Add actual bytesLoaded vs bytesTotal
|
234
|
+
# To the output...
|
235
|
+
while t.alive?
|
236
|
+
print(".")
|
237
|
+
$stdout.flush
|
238
|
+
sleep(0.2)
|
239
|
+
end
|
240
|
+
|
241
|
+
if(response.is_a? Net::HTTPSuccess)
|
242
|
+
return response
|
243
|
+
elsif(response.is_a? Net::HTTPRedirection)
|
244
|
+
return fetch(response['location'], limit - 1)
|
245
|
+
else
|
246
|
+
puts response.to_s
|
247
|
+
return response.error!
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
def get_remote_file(uri, target)
|
252
|
+
if(!File.exists?(target))
|
253
|
+
puts "Fetching #{uri.to_s} into #{target} now!"
|
254
|
+
response = fetch(uri.to_s)
|
255
|
+
|
256
|
+
File.makedirs(File.dirname(target))
|
257
|
+
# Store the downloaded file on disk
|
258
|
+
File.open(target, 'wb') do |f|
|
259
|
+
f.write(response.body)
|
260
|
+
end
|
261
|
+
|
262
|
+
puts ""
|
263
|
+
puts "Downloaded #{(response.body.size / 1024).to_s} KB"
|
264
|
+
puts "to: #{target}"
|
265
|
+
puts ""
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
269
|
+
def clean_path(path)
|
270
|
+
if(path.index(' '))
|
271
|
+
return %{'#{path}'}
|
272
|
+
end
|
273
|
+
return path
|
274
|
+
end
|
275
|
+
|
276
|
+
def execute(params)
|
277
|
+
# Execute the system call with params
|
278
|
+
# Sometimes DOS wants a 'run' prefix
|
279
|
+
# Sometimes OSX wants a 'open' prefix
|
280
|
+
# Sometimes Cygwin wants a './' prefix
|
281
|
+
# This method should be overridden in
|
282
|
+
# subclasses
|
283
|
+
target = File.basename(extracted_file_path)
|
284
|
+
if(!Logger.debug)
|
285
|
+
puts("#{target} #{params}")
|
286
|
+
end
|
287
|
+
system("#{clean_path(extracted_file_path)} #{params}")
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
291
|
+
class WinRemoteFileTask < AbstractRemoteFileTask
|
292
|
+
|
293
|
+
def clean_path(path)
|
294
|
+
path = path.split('/').join(File::SEPARATOR)
|
295
|
+
if(path.index(' '))
|
296
|
+
return %{"#{path}"}
|
297
|
+
end
|
298
|
+
return path
|
299
|
+
end
|
300
|
+
|
301
|
+
def execute(params)
|
302
|
+
target = File.basename(extracted_file_path)
|
303
|
+
if(!Logger.debug)
|
304
|
+
puts("#{target} #{params}")
|
305
|
+
end
|
306
|
+
system(%{"#{extracted_file_path}" #{params}})
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
310
|
+
class CygwinRemoteFileTask < AbstractRemoteFileTask
|
311
|
+
|
312
|
+
def execute(params)
|
313
|
+
target = File.basename(extracted_file_path)
|
314
|
+
if(!Logger.debug)
|
315
|
+
puts("#{target} #{params}")
|
316
|
+
end
|
317
|
+
system(%{#{clean_path(extracted_file_path)} #{params}})
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
class OSXRemoteFileTask < AbstractRemoteFileTask
|
322
|
+
|
323
|
+
def execute(params)
|
324
|
+
target = File.basename(extracted_file_path)
|
325
|
+
if(!Logger.debug)
|
326
|
+
puts("#{target} #{params}")
|
327
|
+
end
|
328
|
+
system("#{clean_path(extracted_file_path)} #{params}")
|
329
|
+
end
|
330
|
+
|
331
|
+
def full_mounted_path
|
332
|
+
return '/Volumes/' + mounted_path
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
class UnixRemoteFileTask < AbstractRemoteFileTask
|
337
|
+
end
|
298
338
|
end
|