asproject 0.1.44 → 0.1.60

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.
@@ -12,6 +12,7 @@ if ARGV.size > 0 && ARGV[0][0]==95 && ARGV[0][-1]==95
12
12
  end
13
13
 
14
14
  require_gem 'asproject', version
15
+ require 'asproject.rb'
15
16
  require 'asclass.rb'
16
17
 
17
18
  AsProject::AsClass.new
@@ -1,7 +1,5 @@
1
1
  $:.push(File.dirname(__FILE__))
2
2
 
3
- require 'asproject'
4
-
5
3
  module AsProject
6
4
  class AsClass < AsProjectBase
7
5
  @@TEMPLATE_TYPE = 'asclass'
@@ -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
@@ -2,7 +2,7 @@ module AsProject
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 44
5
+ TINY = 61
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -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 = "/Volumes/Adobe Flash Standalone Players"
42
- @osx_extracted_file = "/en/SAFlashPlayer"
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, "r").readlines.each do |line|
92
- incr = incr + 1
93
- if(incr > index)
94
- puts "[trace] #{line}"
95
- index = index + 1
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
@@ -17,7 +17,7 @@ module AsProject
17
17
  File.open(trust_file, 'a') do |f|
18
18
  f.puts path
19
19
  end
20
- puts ">> Added #{path} to Flash Player Trust file at: #{trust_file}"
20
+ Logger.puts ">> Added #{path} to Flash Player Trust file at: #{trust_file}"
21
21
  end
22
22
  end
23
23
 
@@ -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
- :main,
11
- :header,
9
+ :cp,
10
+ :exclude,
12
11
  :frame,
13
- :verbose,
12
+ :group,
13
+ :header,
14
+ :infer,
15
+ :keep,
16
+ :main,
17
+ :msvc,
14
18
  :mx,
15
- :input,
16
- :input_swf,
17
- :class_path,
18
- :output
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
- @class_path = []
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(!input_swf && !header && pack_path.size == 0)
47
- # raise MTASCError.new('MTASC task must be provided with an input_swf, a header argument, or at least one pack_path')
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 && !input_swf && output)
50
- # raise MTASCError.new('It looks like you used the output parameter where you should have used the swf parameter')
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 => [output]
54
- CLEAN.add(output)
65
+ task name => [out]
66
+ CLEAN.add(out)
55
67
 
56
- if(input_swf)
57
- file input_swf
58
- task name => [input_swf]
68
+ if(swf)
69
+ file swf
70
+ task name => [swf]
59
71
  end
60
72
 
61
73
  @cleaned_class_paths = []
62
- class_path.each do |path|
74
+ cp.each do |path|
63
75
  add_path(path, @cleaned_class_paths)
64
76
  end
65
77
 
66
- file output do |f|
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 output => as_files
102
+ file out => as_files
87
103
  xml_files = FileList[path + '/**/**/*.xml']
88
104
  file xml_files
89
- file output => xml_files
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 << "-mx" if mx
98
- result << "-v" if verbose
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 << "-cp " + @cleaned_class_paths.join(" -cp ") if class_path.size > 0
101
- result << "-swf" << clean_path(input_swf) if input_swf
102
- result << "-out" << clean_path(output) if output
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 define_user_task
45
- if(@user_task.nil?)
46
- if(remote_task_name.nil?)
47
- raise UsageError.new('RemoteFileTask created without a remote_task_name value...')
48
- end
49
- @user = PathFinder.new().user
50
- @user_task = @user.remote_file_task(remote_task_name, self)
51
- task name => remote_task_name
52
- end
53
- @user_task
54
- end
55
-
56
- def execute(params)
57
- user_task.execute(params)
58
- end
59
-
60
- def clean_path(path)
61
- define_user_task
62
- return user_task.clean_path(path)
63
- end
64
- end
65
-
66
- ###################################
67
- # Concrete instances returned from
68
- # User objects
69
- class AbstractRemoteFileTask
70
- include Archive::Tar
71
-
72
- attr_accessor :name,
73
- :url,
74
- :mounted_path,
75
- :extracted_file
76
-
77
- def initialize(name, user)
78
- @name = name
79
- @user = user
80
- yield self if block_given?
81
- define
82
- end
83
-
84
- def define
85
- @uri = URI.parse(url)
86
- downloaded_file = downloaded_file_path
87
- file downloaded_file do |f|
88
- get_remote_file(@uri, downloaded_file)
89
- end
90
-
91
- if(extracted_file_path != downloaded_file)
92
- if(!Rake::Task.task_defined?(extracted_file_path))
93
- file extracted_file_path => downloaded_file do |f|
94
- unpack_downloaded_file(downloaded_file, extracted_file_path)
95
- File.chmod(0755, extracted_file_path)
96
- end
97
- end
98
-
99
- # else
100
- # File.chmod(0755, downloaded_file)
101
- # task @name => url
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
- if(!File.exists?(expected_file))
120
- if(is_zip?(file_name))
121
- unpack_zip(file_name, dir)
122
- elsif(is_targz?(file_name))
123
- unpack_targz(file_name, dir)
124
- elsif(is_dmg?(file_name))
125
- unpack_dmg(file_name, dir)
126
- elsif(!is_exe?(file_name))
127
- raise UsageError.new("RemoteFileTask does not know how to unpack files of type: #{file_name}")
128
- end
129
- end
130
- end
131
-
132
- def unpack_zip(zip_file, dir)
133
- Zip::ZipFile::open(zip_file) do |zf|
134
- zf.each do |e|
135
- fpath = File.join(dir, e.name)
136
- FileUtils.mkdir_p(File.dirname(fpath))
137
- zf.extract(e, fpath)
138
- end
139
- end
140
- end
141
-
142
- def unpack_targz(tgz_file, dir)
143
- tar = Zlib::GzipReader.new(File.open(tgz_file, 'rb'))
144
- Minitar.unpack(tar, dir)
145
- end
146
-
147
- # This probably NOT the correct way to do this,
148
- # But I don't know much about macs, osx or dmgs
149
- # and it seems to work...
150
- # IF you know a better way - PLEASE let me know
151
- def unpack_dmg(dmg_file, dir)
152
- # 1) Mount the dmg in place
153
- # 2) Recursively Copy it's contents to asproject_home
154
- # 3) Unmount the dmg
155
- if(mounted_path.nil?)
156
- raise StandardError.new('DMG file downloaded, but the RemoteFileTask needs a mounted_path in order to mount it')
157
- end
158
-
159
- puts "Creating mounted path task: #{File.exists?(mounted_path)}"
160
- if(!File.exists?(mounted_path))
161
- system(%{hdiutil mount #{dmg_file}})
162
- end
163
- resolver = TemplateResolver.new
164
- resolver.copy_files(mounted_path, dir, false)
165
- File.chmod(0755, extracted_file)
166
- system(%{hdiutil unmount #{mounted_path}})
167
- end
168
-
169
- def is_exe?(file)
170
- return (file.split('.').pop == 'exe')
171
- end
172
-
173
- def is_zip?(file)
174
- return (file.split('.').pop == 'zip')
175
- end
176
-
177
- def is_targz?(file)
178
- parts = file.split('.')
179
- return (parts.pop == 'gz' && parts.pop == 'tar')
180
- end
181
-
182
- def is_gzip?(file)
183
- return (file.split('.').pop == 'gz')
184
- end
185
-
186
- def is_dmg?(file)
187
- return (file.split('.').pop == 'dmg')
188
- end
189
-
190
- def make_downloaded_dir(file)
191
- dir = File.dirname(file)
192
- File.makedirs(dir)
193
- end
194
-
195
- def remote_file_dir
196
- return File.join(@user.downloads, @name.to_s)
197
- end
198
-
199
- def remote_location
200
- return File.join(remote_file_dir, extracted_file)
201
- end
202
-
203
- def fetch(location, limit = 10)
204
- uri = URI.parse(location)
205
-
206
- # Download the file now to the downloads dir
207
- # If the file is an archive (zip, gz, tar, tar.gz, dmg), extract to
208
- # AsProject/remote_files/@name/@location
209
- # Check the location again...
210
- raise UsageError.new("The RemoteFileTask can only handle HTTP requests at this time, it seems you were trying: #{uri.scheme}") if uri.scheme != 'http'
211
- raise UsageError.new('HTTP redirect too deep') if limit == 0
212
-
213
- response = nil
214
- t = Thread.new {
215
- response = Net::HTTP.get_response(uri.host, uri.path)
216
- }
217
- # TODO: Add actual bytesLoaded vs bytesTotal
218
- # To the output...
219
- while t.alive?
220
- print(".")
221
- $stdout.flush
222
- sleep(0.2)
223
- end
224
-
225
- if(response.is_a? Net::HTTPSuccess)
226
- return response
227
- elsif(response.is_a? Net::HTTPRedirection)
228
- return fetch(response['location'], limit - 1)
229
- else
230
- puts response.to_s
231
- return response.error!
232
- end
233
- end
234
-
235
- def get_remote_file(uri, target)
236
- if(!File.exists?(target))
237
- puts "Fetching #{uri.to_s} now!"
238
- response = fetch(uri.to_s)
239
-
240
- File.makedirs(File.dirname(target))
241
- # Store the downloaded file on disk
242
- File.open(target, 'wb') do |f|
243
- f.write(response.body)
244
- end
245
-
246
- puts ""
247
- puts "Downloaded #{(response.body.size / 1024).to_s} KB"
248
- puts "to: #{target}"
249
- puts ""
250
- end
251
- end
252
-
253
- def clean_path(path)
254
- if(path.index(' '))
255
- return %{'#{path}'}
256
- end
257
- return path
258
- end
259
-
260
- def execute(params)
261
- # Execute the system call with params
262
- # Sometimes DOS wants a 'run' prefix
263
- # Sometimes OSX wants a 'open' prefix
264
- # Sometimes Cygwin wants a './' prefix
265
- # This method should be overridden in
266
- # subclasses
267
- sh %{#{clean_path(extracted_file_path)} #{params}}
268
- end
269
- end
270
-
271
- class WinRemoteFileTask < AbstractRemoteFileTask
272
-
273
- def clean_path(path)
274
- path = path.split('/').join(File::SEPARATOR)
275
- if(path.index(' '))
276
- return %{"#{path}"}
277
- end
278
- return path
279
- end
280
-
281
- def execute(params)
282
- sh(%{"#{extracted_file_path}" #{params}})
283
- end
284
- end
285
-
286
- class CygwinRemoteFileTask < AbstractRemoteFileTask
287
-
288
- def execute(params)
289
- sh %{#{clean_path(extracted_file_path)} #{params}}
290
- end
291
- end
292
-
293
- class OSXRemoteFileTask < AbstractRemoteFileTask
294
- end
295
-
296
- class UnixRemoteFileTask < AbstractRemoteFileTask
297
- end
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