asproject 0.1.92 → 0.1.118

Sign up to get free protection for your applications and to get access to all the features.
Files changed (111) hide show
  1. data/lib/asclass_arguments.rb +1 -1
  2. data/lib/asproject.rb +3 -1
  3. data/lib/asproject/version.rb +1 -1
  4. data/lib/asproject_arguments.rb +5 -5
  5. data/lib/path_finder.rb +17 -7
  6. data/lib/tasks/asunit.rb +8 -0
  7. data/lib/tasks/flash_log.rb +2 -1
  8. data/lib/tasks/flash_player.rb +10 -6
  9. data/lib/tasks/mxmlc.rb +13 -2
  10. data/lib/tasks/remote_file_loader.rb +144 -0
  11. data/lib/tasks/remote_file_task.rb +2 -128
  12. data/lib/tasks/remote_library_task.rb +75 -0
  13. data/templates/asclass/as2/Class.as +1 -1
  14. data/templates/asproject/as2/{art → assets}/.crap_file +0 -0
  15. data/templates/asproject/as2/project/rakefile.rb +3 -2
  16. data/templates/asproject/as3/{art → assets}/.crap_file +0 -0
  17. data/templates/asproject/as3/project/rakefile.rb +3 -3
  18. data/templates/asproject/fdt/project/.as2_classpath +1 -1
  19. metadata +9 -129
  20. data/templates/asproject/asunit2/project/lib/asunit/AsUnitUi.swf +0 -0
  21. data/templates/asproject/asunit2/project/lib/asunit/Sys.as +0 -70
  22. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanel.as +0 -182
  23. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTest.as +0 -84
  24. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextArea.as +0 -111
  25. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTextAreaTest.as +0 -26
  26. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/LocalOutputPanelTitleBar.as +0 -81
  27. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ResizeHandle.as +0 -35
  28. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollArrow.as +0 -34
  29. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollHandle.as +0 -43
  30. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/ScrollListener.as +0 -10
  31. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/TextScroller.as +0 -169
  32. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Rectangle.as +0 -29
  33. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/controls/shapes/Triangle.as +0 -27
  34. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/AsUnit.as +0 -19
  35. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assert.as +0 -408
  36. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Assertion.as +0 -27
  37. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Reflection.as +0 -68
  38. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/Test.as +0 -3
  39. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCase.as +0 -191
  40. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestCaseXml.as +0 -31
  41. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestFailure.as +0 -15
  42. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestResult.as +0 -15
  43. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestRunner.as +0 -41
  44. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSetup.as +0 -19
  45. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/framework/TestSuite.as +0 -22
  46. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/Main.as +0 -325
  47. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/RemoteVersion.as +0 -24
  48. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/ui/SuccessMeter.as +0 -32
  49. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Comparable.as +0 -7
  50. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventListener.as +0 -29
  51. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/EventSource.as +0 -89
  52. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnClient.as +0 -42
  53. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnGateway.as +0 -47
  54. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalConnServer.as +0 -61
  55. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/LocalMessageBroker.as +0 -58
  56. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/Observable.as +0 -11
  57. data/templates/asproject/asunit2/project/lib/asunit/com/asunit/util/TextFile.as +0 -30
  58. data/templates/asproject/asunit25/project/lib/asunit/AsUnitTestRunner.as +0 -13
  59. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionFailedError.as +0 -7
  60. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/AssertionPassedError.as +0 -7
  61. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/ClassNotFoundError.as +0 -7
  62. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/IllegalOperationError.as +0 -7
  63. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +0 -7
  64. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/InvocationTargetError.as +0 -7
  65. data/templates/asproject/asunit25/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +0 -7
  66. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Assert.as +0 -376
  67. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertMock.as +0 -15
  68. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/AssertTest.as +0 -59
  69. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/ITestListener.as +0 -13
  70. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/Test.as +0 -11
  71. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCase.as +0 -278
  72. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseMock.as +0 -23
  73. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseTest.as +0 -29
  74. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestCaseXml.as +0 -38
  75. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestFailure.as +0 -47
  76. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestResult.as +0 -168
  77. data/templates/asproject/asunit25/project/lib/asunit/asunit/framework/TestSuite.as +0 -102
  78. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/BaseTestRunner.as +0 -101
  79. data/templates/asproject/asunit25/project/lib/asunit/asunit/runner/IResultPrinter.as +0 -8
  80. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/ResultPrinter.as +0 -254
  81. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/SuccessBar.as +0 -41
  82. data/templates/asproject/asunit25/project/lib/asunit/asunit/textui/TestRunner.as +0 -17
  83. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIterator.as +0 -24
  84. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/ArrayIteratorTest.as +0 -52
  85. data/templates/asproject/asunit25/project/lib/asunit/asunit/util/Iterator.as +0 -5
  86. data/templates/asproject/asunit3/project/lib/asunit/AsUnitTestRunner.as +0 -10
  87. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AbstractMemberCalledError.as +0 -10
  88. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/AssertionFailedError.as +0 -10
  89. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/ClassNotFoundError.as +0 -10
  90. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/InstanceNotFoundError.as +0 -10
  91. data/templates/asproject/asunit3/project/lib/asunit/asunit/errors/UnimplementedFeatureError.as +0 -10
  92. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Assert.as +0 -271
  93. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCase.as +0 -52
  94. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/AsynchronousTestCaseExample.as +0 -71
  95. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/Test.as +0 -15
  96. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCase.as +0 -354
  97. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestCaseExample.as +0 -73
  98. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestFailure.as +0 -47
  99. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestListener.as +0 -22
  100. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestResult.as +0 -158
  101. data/templates/asproject/asunit3/project/lib/asunit/asunit/framework/TestSuite.as +0 -115
  102. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/BaseTestRunner.as +0 -15
  103. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/TestSuiteLoader.as +0 -9
  104. data/templates/asproject/asunit3/project/lib/asunit/asunit/runner/Version.as +0 -11
  105. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexRunner.as +0 -19
  106. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/FlexTestRunner.as +0 -55
  107. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/ResultPrinter.as +0 -245
  108. data/templates/asproject/asunit3/project/lib/asunit/asunit/textui/TestRunner.as +0 -121
  109. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/ArrayIterator.as +0 -26
  110. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Iterator.as +0 -9
  111. data/templates/asproject/asunit3/project/lib/asunit/asunit/util/Properties.as +0 -30
@@ -86,7 +86,7 @@ EOF
86
86
  # self[:copy_to_home] = true
87
87
  # end
88
88
  #
89
- # opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml,asunit'") do
89
+ # opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml'") do
90
90
  # self[:default_templates] = true
91
91
  # end
92
92
  #
@@ -29,7 +29,9 @@ require 'test_suite_generator'
29
29
 
30
30
  require 'tasks/simple_resolver'
31
31
  require 'tasks/env_task'
32
+ require 'tasks/remote_file_loader'
32
33
  require 'tasks/remote_file_task'
34
+ require 'tasks/remote_library_task'
33
35
  require 'tasks/flash_log'
34
36
  require 'tasks/mxmlc'
35
37
  require 'tasks/fcsh'
@@ -46,7 +48,7 @@ module AsProject
46
48
  class AsProject < AsProjectBase
47
49
  @@ASPROJECT_FILE_NAME = 'AsProject'
48
50
  @@TEMPLATE_TYPE = 'asproject'
49
- @@DEFAULT_TEMPLATES = ['as2', 'config', 'asunit25', 'fdt']
51
+ @@DEFAULT_TEMPLATES = ['as2', 'config', 'fdt']
50
52
 
51
53
  def initialize(args=nil)
52
54
  execute(args)
@@ -2,7 +2,7 @@ module AsProject
2
2
  module VERSION
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 93
5
+ TINY = 119
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -68,7 +68,7 @@ rake
68
68
 
69
69
  mkdir projects
70
70
  cd projects
71
- asproject -t 'as2,asunit25,config,fdt' MyProjectName
71
+ asproject -t 'as2,config,fdt' MyProjectName
72
72
  cd MyProjectName/project
73
73
  asclass -s utils.MathUtil
74
74
  rake test
@@ -100,7 +100,7 @@ EOF
100
100
  self[:copy_to_home] = true
101
101
  end
102
102
 
103
- # opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml,asunit'") do
103
+ # opts.on('-d', '--default-templates', "Set default templates for this project eg: 'mxml,fb2mxml'") do
104
104
  # self[:default_templates] = true
105
105
  # end
106
106
  #
@@ -167,11 +167,11 @@ EOF
167
167
 
168
168
  def get_templates_by_type(type)
169
169
  if(type == 'as2')
170
- return ['as2', 'asunit25', 'fdt']
170
+ return ['as2', 'fdt']
171
171
  elsif(type == 'as3')
172
- return ['as3', 'asunit3', 'fb2as']
172
+ return ['as3', 'fb2as']
173
173
  elsif(type == 'mxml')
174
- return ['mxml', 'asunit3', 'fb2as']
174
+ return ['mxml', 'fb2as']
175
175
  end
176
176
  end
177
177
 
@@ -50,6 +50,14 @@ module AsProject
50
50
  parent = File.dirname(File.dirname(__FILE__))
51
51
  return File.expand_path(parent)
52
52
  end
53
+
54
+ def lib_downloads
55
+ return File.join(downloads, 'lib')
56
+ end
57
+
58
+ def downloads
59
+ return user.downloads
60
+ end
53
61
 
54
62
  def user
55
63
  return @user
@@ -367,13 +375,11 @@ EOF
367
375
  @@LIBRARY = 'Library'
368
376
  def initialize
369
377
  super
370
- @flash_player_7_url = "/pub/flashplayer/updaters/7/sa_flashplayer_7_all_debug.dmg"
371
- @flash_player_8_url = "/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip"
372
- @flash_player_9_url = "/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg"
373
-
374
- @zip_target = File.join('Players', 'Debug', 'SAFlashPlayer.dmg')
375
-
376
- @flash_player_8_target = File.join('Players', 'Debug', 'SAFlashPlayer.exe')
378
+ # @flash_player_7_url = "/pub/flashplayer/updaters/7/sa_flashplayer_7_all_debug.dmg"
379
+ # @flash_player_8_url = "/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip"
380
+ # @flash_player_9_url = "/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg"
381
+ # @zip_target = File.join('Players', 'Debug', 'SAFlashPlayer.dmg')
382
+ # @flash_player_8_target = File.join('Players', 'Debug', 'SAFlashPlayer.exe')
377
383
 
378
384
  @osx_asproject = 'AsProject'
379
385
  end
@@ -393,6 +399,10 @@ EOF
393
399
  return File.join(library, 'Preferences', 'Macromedia', 'Flash Player')
394
400
  end
395
401
 
402
+ def flash_player_config
403
+ return File.join('/Library/Application Support/Macromedia/', 'mm.cfg')
404
+ end
405
+
396
406
  def library
397
407
  lib = File.join(home, @@LIBRARY)
398
408
  if(File.exists?(lib))
@@ -0,0 +1,8 @@
1
+
2
+ AsProject::RemoteLibraryTask.new(:asunit25) do |t|
3
+ t.url = 'http://asproject.googlecode.com/files/asunit25.zip'
4
+ end
5
+
6
+ AsProject::RemoteLibraryTask.new(:asunit3) do |t|
7
+ t.url = 'http://asproject.googlecode.com/files/asunit3.zip'
8
+ end
@@ -32,7 +32,8 @@ This file is required in order to capture trace output.
32
32
  Would you like this file created automatically? [Yn]
33
33
 
34
34
  EOF
35
- if($stdin.gets.chomp.downcase.index('y'))
35
+ answer = $stdin.gets.chomp.downcase
36
+ if(answer.index('y') || answer == '')
36
37
  File.open(location, 'w') do |f|
37
38
  f.write(content)
38
39
  end
@@ -30,19 +30,17 @@ module AsProject
30
30
  elsif(version == 8)
31
31
  @win_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/flash_player_update3_flash8_win.zip"
32
32
  @win_extracted_file = "/Players/Debug/SAFlashPlayer.exe"
33
- @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg"
34
- @osx_mounted_path = "Adobe Flash Player Standalone"
33
+ @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_debug.app.zip"
35
34
  @osx_extracted_file = "Flash\ Player.app"
36
35
  # @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/8/sa_flashplayer_8_all_debug.dmg"
37
- # @osx_mounted_path = "Adobe Flash Standalone Players"
38
36
  # @osx_extracted_file = "en/SAFlashPlayer"
37
+ # @osx_mounted_path = "Adobe Flash Standalone Players"
39
38
  @unix_url = nil
40
39
  @unix_extracted_file = nil
41
40
  elsif(version == 9)
42
41
  @win_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_debug.exe"
43
42
  @win_extracted_file = "sa_flashplayer_9_debug.exe"
44
- @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg"
45
- @osx_mounted_path = "Adobe Flash Player Standalone"
43
+ @osx_url = "http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_debug.app.zip"
46
44
  @osx_extracted_file = "Flash\ Player.app"
47
45
  @unix_url = nil
48
46
  @unix_extracted_file = nil
@@ -86,7 +84,13 @@ module AsProject
86
84
  end
87
85
 
88
86
  def run_osx
89
- player = extracted_file_path + '/Contents/MacOS/standalone'
87
+ if(extracted_file_path.index('.app'))
88
+ player = extracted_file_path + "/Contents/MacOS/Flash\ Player"
89
+ else
90
+ player = extracted_file_path
91
+ end
92
+ File.chmod(0755, player)
93
+
90
94
  swf = clean_path(@swf)
91
95
 
92
96
  t = Thread.new {
@@ -33,6 +33,7 @@ module AsProject
33
33
  @theme = []
34
34
  @runtime_shared_libraries = []
35
35
  @incremental = false
36
+ @optimize = false
36
37
  path_finder = PathFinder.new
37
38
  @target = path_finder.mxmlc
38
39
  @name = name
@@ -66,10 +67,20 @@ module AsProject
66
67
  task @name => [@output]
67
68
  end
68
69
 
69
- def execute(cmd, args)
70
+ def execute(cmd, args, retries=0)
70
71
  begin
71
- sh(%{#{cmd} #{args}})
72
+ sh("#{cmd} #{args}")
72
73
  rescue
74
+ default_mxmlc_osx_path = "/Applications/Adobe\ Flex\ Builder\ 2/Flex\ SDK\ 2/bin"
75
+ default_flex_home_path = File.join(ENV['FLEX_HOME'], 'bin', cmd)
76
+ if(retries == 0 && File.exists?(default_mxmlc_osx_path))
77
+ ENV['PATH'] = ENV['PATH'] + ':' + default_mxmlc_osx_path
78
+ execute(cmd, args, 1)
79
+ return
80
+ elsif(retries == 0 && File.exists?(default_flex_home_path))
81
+ execute("'#{default_flex_home_path}'", args, 1)
82
+ return
83
+ end
73
84
  puts 'There was an error executing mxmlc, please make sure mxmlc is in your class path and can be executed from the same environment this rake task was run from'
74
85
  end
75
86
  end
@@ -0,0 +1,144 @@
1
+
2
+ module AsProject
3
+ class RemoteFileLoader < Rake::TaskLib
4
+
5
+ def fetch(location, limit = 10)
6
+ uri = URI.parse(location)
7
+
8
+ # Download the file now to the downloads dir
9
+ # If the file is an archive (zip, gz, tar, tar.gz, dmg), extract to
10
+ # AsProject/remote_files/@name/@location
11
+ # Check the location again...
12
+ raise UsageError.new("The RemoteFileTask can only handle HTTP requests at this time, it seems you were trying: #{uri.scheme}") if uri.scheme != 'http'
13
+ raise UsageError.new('HTTP redirect too deep') if limit == 0
14
+
15
+ response = nil
16
+ t = Thread.new {
17
+ response = Net::HTTP.get_response(uri.host, uri.path)
18
+ }
19
+
20
+ print(">> Downloading")
21
+ # TODO: Add actual bytesLoaded vs bytesTotal
22
+ # To the output...
23
+ while t.alive?
24
+ print(".")
25
+ $stdout.flush
26
+ sleep(0.2)
27
+ end
28
+ puts ""
29
+
30
+ if(response.is_a? Net::HTTPSuccess)
31
+ return response
32
+ elsif(response.is_a? Net::HTTPRedirection)
33
+ return fetch(response['location'], limit - 1)
34
+ else
35
+ if(response.nil?)
36
+ raise UsageError.new("Network connection failed!")
37
+ else
38
+ puts response.to_s
39
+ return response.error!
40
+ end
41
+ end
42
+ end
43
+
44
+ def unpack_downloaded_file(file_name, expected_file)
45
+ dir = File.dirname(file_name)
46
+ if(!File.exists?(expected_file))
47
+ if(is_zip?(file_name))
48
+ unpack_zip(file_name, dir)
49
+ elsif(is_targz?(file_name))
50
+ unpack_targz(file_name, dir)
51
+ elsif(is_dmg?(file_name))
52
+ unpack_dmg(file_name, dir)
53
+ elsif(is_swc?(file_name))
54
+ # just copy the swc...
55
+ elsif(!is_exe?(file_name))
56
+ raise UsageError.new("RemoteFileTask does not know how to unpack files of type: #{file_name}")
57
+ end
58
+ end
59
+ end
60
+
61
+ def unpack_zip(zip_file, dir)
62
+ Zip::ZipFile::open(zip_file) do |zf|
63
+ zf.each do |e|
64
+ fpath = File.join(dir, e.name)
65
+ FileUtils.mkdir_p(File.dirname(fpath))
66
+ zf.extract(e, fpath)
67
+ end
68
+ end
69
+ end
70
+
71
+ def unpack_targz(tgz_file, dir)
72
+ tar = Zlib::GzipReader.new(File.open(tgz_file, 'rb'))
73
+ Minitar.unpack(tar, dir)
74
+ end
75
+
76
+ # This is actually not unpacking the FlashPlayer
77
+ # Binary file as expected...
78
+ # OSX is treated the player binary as if it is
79
+ # a regular text file, but if it is copied manually,
80
+ # the command works fine!?
81
+ def unpack_dmg(dmg_file, dir)
82
+ # 1) Mount the dmg in place
83
+ # 2) Recursively Copy it's contents to asproject_home
84
+ # 3) Unmount the dmg
85
+ if(mounted_path.nil?)
86
+ raise StandardError.new('DMG file downloaded, but the RemoteFileTask needs a mounted_path in order to mount it')
87
+ end
88
+
89
+ if(!File.exists?(full_mounted_path))
90
+ system("hdiutil mount #{dmg_file}")
91
+ end
92
+
93
+ begin
94
+ mounted_target = File.join(full_mounted_path, extracted_file)
95
+
96
+ # Copy the DMG contents using system copy rather than ruby utils
97
+ # Because OS X does something special with .app files that the
98
+ # Ruby FileUtils and File classes break...
99
+ puts '=================='
100
+ from = mounted_target
101
+ # from = File.join(full_mounted_path, extracted_file)
102
+ to = File.join(@user.downloads, @name.to_s, extracted_file)
103
+ puts 'from: ' + from
104
+ puts 'to: ' + to
105
+ FileUtils.makedirs(File.dirname(to))
106
+
107
+ if(File.exists?(from))
108
+ `ditto '#{from}' '#{to}'`
109
+ end
110
+ rescue
111
+ puts 'inside finally!'
112
+ if(File.exists?(full_mounted_path))
113
+ puts 'unmounting now!'
114
+ system("hdiutil unmount -force \"#{full_mounted_path}\"")
115
+ end
116
+ end
117
+ end
118
+
119
+ def is_exe?(file)
120
+ return (file.split('.').pop == 'exe')
121
+ end
122
+
123
+ def is_zip?(file)
124
+ return (file.split('.').pop == 'zip')
125
+ end
126
+
127
+ def is_targz?(file)
128
+ parts = file.split('.')
129
+ return (parts.pop == 'gz' && parts.pop == 'tar')
130
+ end
131
+
132
+ def is_gzip?(file)
133
+ return (file.split('.').pop == 'gz')
134
+ end
135
+
136
+ def is_swc?(file)
137
+ return (file.split('.').pop == 'swc')
138
+ end
139
+
140
+ def is_dmg?(file)
141
+ return (file.split('.').pop == 'dmg')
142
+ end
143
+ end
144
+ end
@@ -70,7 +70,7 @@ module AsProject
70
70
  ###################################
71
71
  # Concrete instances returned from
72
72
  # User objects
73
- class AbstractRemoteFileTask
73
+ class AbstractRemoteFileTask < RemoteFileLoader
74
74
  include Archive::Tar
75
75
 
76
76
  attr_accessor :name,
@@ -119,96 +119,6 @@ module AsProject
119
119
  return File.join(@user.downloads, @name.to_s, file)
120
120
  end
121
121
 
122
- def unpack_downloaded_file(file_name, expected_file)
123
- # Remove previously downloaded files...
124
- dir = File.dirname(file_name)
125
- Dir[dir + '/*'].each do |child|
126
- if(child != '.' && child != '..' && child != file_name)
127
- FileUtils.rm_rf(child)
128
- end
129
- end
130
-
131
- if(!File.exists?(expected_file))
132
- if(is_zip?(file_name))
133
- unpack_zip(file_name, dir)
134
- elsif(is_targz?(file_name))
135
- unpack_targz(file_name, dir)
136
- elsif(is_dmg?(file_name))
137
- unpack_dmg(file_name, dir)
138
- elsif(!is_exe?(file_name))
139
- raise UsageError.new("RemoteFileTask does not know how to unpack files of type: #{file_name}")
140
- end
141
- end
142
- end
143
-
144
- def unpack_zip(zip_file, dir)
145
- Zip::ZipFile::open(zip_file) do |zf|
146
- zf.each do |e|
147
- fpath = File.join(dir, e.name)
148
- FileUtils.mkdir_p(File.dirname(fpath))
149
- zf.extract(e, fpath)
150
- end
151
- end
152
- end
153
-
154
- def unpack_targz(tgz_file, dir)
155
- tar = Zlib::GzipReader.new(File.open(tgz_file, 'rb'))
156
- Minitar.unpack(tar, dir)
157
- end
158
-
159
- # This is actually not unpacking the FlashPlayer
160
- # Binary file as expected...
161
- # OSX is treated the player binary as if it is
162
- # a regular text file, but if it is copied manually,
163
- # the command works fine!?
164
- def unpack_dmg(dmg_file, dir)
165
- # 1) Mount the dmg in place
166
- # 2) Recursively Copy it's contents to asproject_home
167
- # 3) Unmount the dmg
168
- if(mounted_path.nil?)
169
- raise StandardError.new('DMG file downloaded, but the RemoteFileTask needs a mounted_path in order to mount it')
170
- end
171
-
172
- if(!File.exists?(full_mounted_path))
173
- system("hdiutil mount #{dmg_file}")
174
- end
175
-
176
- mounted_target = File.join(full_mounted_path, extracted_file)
177
-
178
- # Copy the DMG contents using system copy rather than ruby utils
179
- # Because OS X does something special with .app files that the
180
- # Ruby FileUtils and File classes break...
181
- from = full_mounted_path
182
- to = File.join(@user.downloads, @name.to_s)
183
- if(File.exists?(from))
184
- `ditto '#{from}' #{to}`
185
- end
186
- if(File.exists?(full_mounted_path))
187
- system("hdiutil unmount -force \"#{full_mounted_path}\"")
188
- end
189
- end
190
-
191
- def is_exe?(file)
192
- return (file.split('.').pop == 'exe')
193
- end
194
-
195
- def is_zip?(file)
196
- return (file.split('.').pop == 'zip')
197
- end
198
-
199
- def is_targz?(file)
200
- parts = file.split('.')
201
- return (parts.pop == 'gz' && parts.pop == 'tar')
202
- end
203
-
204
- def is_gzip?(file)
205
- return (file.split('.').pop == 'gz')
206
- end
207
-
208
- def is_dmg?(file)
209
- return (file.split('.').pop == 'dmg')
210
- end
211
-
212
122
  def make_downloaded_dir(file)
213
123
  dir = File.dirname(file)
214
124
  File.makedirs(dir)
@@ -222,42 +132,6 @@ module AsProject
222
132
  return File.join(remote_file_dir, extracted_file)
223
133
  end
224
134
 
225
- def fetch(location, limit = 10)
226
- uri = URI.parse(location)
227
-
228
- # Download the file now to the downloads dir
229
- # If the file is an archive (zip, gz, tar, tar.gz, dmg), extract to
230
- # AsProject/remote_files/@name/@location
231
- # Check the location again...
232
- raise UsageError.new("The RemoteFileTask can only handle HTTP requests at this time, it seems you were trying: #{uri.scheme}") if uri.scheme != 'http'
233
- raise UsageError.new('HTTP redirect too deep') if limit == 0
234
-
235
- response = nil
236
- t = Thread.new {
237
- response = Net::HTTP.get_response(uri.host, uri.path)
238
- }
239
- # TODO: Add actual bytesLoaded vs bytesTotal
240
- # To the output...
241
- while t.alive?
242
- print(".")
243
- $stdout.flush
244
- sleep(0.2)
245
- end
246
-
247
- if(response.is_a? Net::HTTPSuccess)
248
- return response
249
- elsif(response.is_a? Net::HTTPRedirection)
250
- return fetch(response['location'], limit - 1)
251
- else
252
- if(response.nil?)
253
- raise UsageError.new("Network connection failed!")
254
- else
255
- puts response.to_s
256
- return response.error!
257
- end
258
- end
259
- end
260
-
261
135
  def get_remote_file(uri, target)
262
136
  if(!File.exists?(target))
263
137
  puts "Fetching #{uri.to_s} into #{target} now!"
@@ -339,7 +213,7 @@ module AsProject
339
213
  end
340
214
 
341
215
  def full_mounted_path
342
- return '/Volumes/' + mounted_path
216
+ return File.join('/Volumes', mounted_path)
343
217
  end
344
218
  end
345
219