sprout 0.7.246 → 1.0.0.pre

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of sprout might be problematic. Click here for more details.

Files changed (211) hide show
  1. data/CHANGELOG.md +10 -0
  2. data/Gemfile +28 -0
  3. data/MIT-LICENSE +3 -2
  4. data/POSTINSTALL.rdoc +28 -0
  5. data/README.textile +152 -0
  6. data/bin/sprout +1 -131
  7. data/bin/sprout-generator +10 -0
  8. data/bin/sprout-library +11 -0
  9. data/bin/sprout-tool +10 -0
  10. data/lib/sprout.rb +4 -500
  11. data/lib/sprout/archive_unpacker.rb +122 -206
  12. data/lib/sprout/base.rb +90 -0
  13. data/lib/sprout/concern.rb +30 -0
  14. data/lib/sprout/dir.rb +23 -0
  15. data/lib/sprout/errors.rb +94 -0
  16. data/lib/sprout/executable.rb +496 -0
  17. data/lib/sprout/executable/boolean.rb +35 -0
  18. data/lib/sprout/executable/collection_param.rb +53 -0
  19. data/lib/sprout/executable/file_param.rb +53 -0
  20. data/lib/sprout/executable/files.rb +26 -0
  21. data/lib/sprout/executable/number.rb +10 -0
  22. data/lib/sprout/executable/param.rb +222 -0
  23. data/lib/sprout/executable/parameter_factory.rb +28 -0
  24. data/lib/sprout/executable/path.rb +21 -0
  25. data/lib/sprout/executable/paths.rb +21 -0
  26. data/lib/sprout/executable/string_param.rb +15 -0
  27. data/lib/sprout/executable/strings.rb +11 -0
  28. data/lib/sprout/executable/url.rb +10 -0
  29. data/lib/sprout/executable/urls.rb +10 -0
  30. data/lib/sprout/file_target.rb +76 -0
  31. data/lib/sprout/generator/base.rb +233 -0
  32. data/lib/sprout/generator/command.rb +67 -0
  33. data/lib/sprout/generator/directory_manifest.rb +49 -0
  34. data/lib/sprout/generator/file_manifest.rb +55 -0
  35. data/lib/sprout/generator/manifest.rb +13 -0
  36. data/lib/sprout/generator/template_manifest.rb +13 -0
  37. data/lib/sprout/generators/generator/generator_generator.rb +48 -0
  38. data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
  39. data/lib/sprout/generators/generator/templates/generator_executable +9 -0
  40. data/lib/sprout/generators/generator/templates/generator_template +1 -0
  41. data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
  42. data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
  43. data/lib/sprout/generators/library/library_generator.rb +20 -0
  44. data/lib/sprout/generators/library/templates/library.gemspec +19 -0
  45. data/lib/sprout/generators/library/templates/library.rb +15 -0
  46. data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
  47. data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
  48. data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
  49. data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
  50. data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
  51. data/lib/sprout/generators/tool/templates/Gemfile +4 -0
  52. data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
  53. data/lib/sprout/generators/tool/templates/tool.rb +38 -0
  54. data/lib/sprout/generators/tool/tool_generator.rb +36 -0
  55. data/lib/sprout/library.rb +111 -0
  56. data/lib/sprout/log.rb +1 -0
  57. data/lib/sprout/platform.rb +71 -0
  58. data/lib/sprout/process_runner.rb +80 -40
  59. data/lib/sprout/progress_bar.rb +341 -0
  60. data/lib/sprout/rdoc_parser.rb +91 -0
  61. data/lib/sprout/remote_file_loader.rb +72 -50
  62. data/lib/sprout/remote_file_target.rb +44 -152
  63. data/lib/sprout/ruby_feature.rb +167 -0
  64. data/lib/sprout/specification.rb +197 -0
  65. data/lib/sprout/string.rb +19 -0
  66. data/lib/sprout/system.rb +35 -0
  67. data/lib/sprout/system/base_system.rb +225 -0
  68. data/lib/sprout/system/java_system.rb +9 -0
  69. data/lib/sprout/system/osx_system.rb +26 -0
  70. data/lib/sprout/system/unix_system.rb +72 -0
  71. data/lib/sprout/system/vista_system.rb +16 -0
  72. data/lib/sprout/system/win_nix_system.rb +41 -0
  73. data/lib/sprout/system/win_system.rb +76 -0
  74. data/lib/sprout/test/sprout_test_case.rb +211 -0
  75. data/lib/sprout/version.rb +9 -4
  76. data/rakefile.rb +85 -144
  77. data/script/console +10 -0
  78. data/script/destroy +14 -0
  79. data/script/generate +14 -0
  80. data/sprout.gemspec +26 -0
  81. data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
  82. data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
  83. data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
  84. data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
  85. data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
  86. data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
  87. data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
  88. data/test/fixtures/examples/app_generator.rb +127 -0
  89. data/test/fixtures/examples/echo_inputs.rb +151 -0
  90. data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
  91. data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
  92. data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
  93. data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
  94. data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
  95. data/test/fixtures/executable/mxmlc.rb +805 -0
  96. data/test/fixtures/executable/params/input.as +0 -0
  97. data/test/fixtures/executable/params/input2.as +0 -0
  98. data/test/fixtures/executable/params/input3.as +0 -0
  99. data/test/fixtures/executable/params/mxmlc +5 -0
  100. data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
  101. data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
  102. data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
  103. data/test/fixtures/executable/paths/folder1/file1 +0 -0
  104. data/test/fixtures/executable/paths/folder1/file2 +0 -0
  105. data/test/fixtures/executable/paths/folder1/file3 +0 -0
  106. data/test/fixtures/executable/paths/folder2/file4 +0 -0
  107. data/test/fixtures/executable/paths/folder2/file5 +0 -0
  108. data/test/fixtures/executable/paths/folder3/file6 +0 -0
  109. data/test/fixtures/executable/src/Main.as +0 -0
  110. data/test/fixtures/executable/windows_line_endings +47 -0
  111. data/test/fixtures/generators/song_generator.rb +11 -0
  112. data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
  113. data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
  114. data/test/fixtures/generators/temp_generator.rb +24 -0
  115. data/test/fixtures/generators/templates/Main.as +9 -0
  116. data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
  117. data/test/fixtures/generators/templates/SomeFile +1 -0
  118. data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
  119. data/test/fixtures/generators/templates/Song.txt +3 -0
  120. data/test/fixtures/generators/templates/destroy +0 -0
  121. data/test/fixtures/generators/templates/generate +0 -0
  122. data/test/fixtures/library/archive/Archive.swc +0 -0
  123. data/test/fixtures/library/sources/lib/a/A.as +0 -0
  124. data/test/fixtures/library/sources/lib/b/B.as +0 -0
  125. data/test/fixtures/library/sources/src/Source.as +0 -0
  126. data/test/fixtures/process_runner/chmod_script.sh +3 -0
  127. data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
  128. data/test/fixtures/process_runner/failure +5 -0
  129. data/test/fixtures/process_runner/success +4 -0
  130. data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
  131. data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
  132. data/test/fixtures/remote_file_target/bin/echochamber +3 -0
  133. data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
  134. data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
  135. data/test/fixtures/specification/asunit4.rb +25 -0
  136. data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
  137. data/test/fixtures/specification/flashplayer.rb +30 -0
  138. data/test/fixtures/specification/flex4sdk.rb +72 -0
  139. data/test/fixtures/specification/flexunit4.sproutspec +17 -0
  140. data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
  141. data/test/fixtures/specification/src/AsUnit.as +0 -0
  142. data/test/fixtures/user/mxmlc_crlf +3 -0
  143. data/test/unit/archive_unpacker_test.rb +108 -0
  144. data/test/unit/boolean_param_test.rb +38 -0
  145. data/test/unit/executable_option_parser_test.rb +142 -0
  146. data/test/unit/executable_param_test.rb +76 -0
  147. data/test/unit/executable_test.rb +237 -0
  148. data/test/unit/fake_executable_task.rb +22 -0
  149. data/test/unit/fake_other_executable.rb +20 -0
  150. data/test/unit/fake_process_runner.rb +29 -0
  151. data/test/unit/file_param_test.rb +61 -0
  152. data/test/unit/file_target_test.rb +42 -0
  153. data/test/unit/files_param_test.rb +72 -0
  154. data/test/unit/generator_generator_test.rb +85 -0
  155. data/test/unit/generator_test.rb +333 -0
  156. data/test/unit/library_generator_test.rb +41 -0
  157. data/test/unit/library_test.rb +88 -0
  158. data/test/unit/osx_system_test.rb +20 -0
  159. data/test/unit/path_param_test.rb +43 -0
  160. data/test/unit/paths_param_test.rb +53 -0
  161. data/test/unit/platform_test.rb +76 -0
  162. data/test/unit/process_runner_test.rb +104 -0
  163. data/test/unit/rdoc_parser_test.rb +15 -0
  164. data/test/unit/remote_file_loader_test.rb +34 -0
  165. data/test/unit/remote_file_target_test.rb +105 -0
  166. data/test/unit/ruby_feature_test.rb +108 -0
  167. data/test/unit/ruby_generator_test.rb +70 -0
  168. data/test/unit/specification_test.rb +73 -0
  169. data/test/unit/sprout_test.rb +170 -0
  170. data/test/unit/sprout_test_helper.rb +18 -0
  171. data/test/unit/string_param_test.rb +19 -0
  172. data/test/unit/string_test.rb +20 -0
  173. data/test/unit/strings_param_test.rb +27 -0
  174. data/test/unit/test_helper.rb +1 -0
  175. data/test/unit/tool_generator_test.rb +43 -0
  176. data/test/unit/unix_system_test.rb +52 -0
  177. data/test/unit/user_test.rb +147 -0
  178. data/test/unit/vista_system_test.rb +40 -0
  179. data/test/unit/win_nix_system_test.rb +26 -0
  180. data/test/unit/win_system_test.rb +61 -0
  181. metadata +318 -113
  182. data/doc/Bundle +0 -14
  183. data/doc/Generator +0 -35
  184. data/doc/Library +0 -63
  185. data/doc/Task +0 -21
  186. data/doc/Tool +0 -20
  187. data/lib/platform.rb +0 -113
  188. data/lib/progress_bar.rb +0 -354
  189. data/lib/sprout/builder.rb +0 -51
  190. data/lib/sprout/bundle_resolver.rb +0 -349
  191. data/lib/sprout/commands/generate.rb +0 -9
  192. data/lib/sprout/dynamic_accessors.rb +0 -40
  193. data/lib/sprout/general_tasks.rb +0 -6
  194. data/lib/sprout/generator.rb +0 -7
  195. data/lib/sprout/generator/base_mixins.rb +0 -186
  196. data/lib/sprout/generator/named_base.rb +0 -227
  197. data/lib/sprout/project_model.rb +0 -278
  198. data/lib/sprout/simple_resolver.rb +0 -88
  199. data/lib/sprout/tasks/erb_resolver.rb +0 -118
  200. data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
  201. data/lib/sprout/tasks/git_task.rb +0 -134
  202. data/lib/sprout/tasks/library_task.rb +0 -118
  203. data/lib/sprout/tasks/sftp_task.rb +0 -248
  204. data/lib/sprout/tasks/ssh_task.rb +0 -153
  205. data/lib/sprout/tasks/tool_task.rb +0 -836
  206. data/lib/sprout/tasks/zip_task.rb +0 -158
  207. data/lib/sprout/tool_task_model.rb +0 -19
  208. data/lib/sprout/user.rb +0 -415
  209. data/lib/sprout/version_file.rb +0 -89
  210. data/lib/sprout/zip_util.rb +0 -61
  211. data/samples/gem_wrap/rakefile.rb +0 -17
@@ -0,0 +1,91 @@
1
+ require 'rdoc/rdoc'
2
+
3
+ module Sprout
4
+
5
+ class RDocParser
6
+
7
+ def parse content
8
+ end
9
+
10
+ def parse_from_caller_string caller_string
11
+ class_name, file_name, line_number = parse_caller_string caller_string
12
+ rdoc_description_for class_name, file_name, line_number
13
+ end
14
+
15
+ private
16
+
17
+ ##
18
+ # NOTE: Don't forget that this string *sometimes* contains a colon on Windows...
19
+ def parse_caller_string caller_string
20
+ sections = caller_string.split(' ')
21
+ parts = sections.first.split(':')
22
+ file_name = parts.shift
23
+ line_number = parts.shift
24
+ class_name = class_name_from_caller_string caller_string
25
+ #puts ">> class_name: #{class_name} file_name: #{file_name} line_number: #{line_number}"
26
+ [class_name, file_name, line_number]
27
+ end
28
+
29
+ def class_name_from_caller_string caller_string
30
+ parts = caller_string.split(' ')
31
+ long = parts.pop
32
+ matched = long.match /<class:([\w:]+)>/
33
+ matched[1] unless matched.nil?
34
+ end
35
+
36
+ def rdoc_description_for class_name, file_name, line_number
37
+ rendered = rendered_rdoc file_name
38
+ end
39
+
40
+ def rendered_rdoc file
41
+ @rendered_rdoc ||= render_rdoc file
42
+ end
43
+
44
+ def render_rdoc file
45
+ rdoc = RDoc::RDoc.new
46
+ puts "==================================="
47
+ puts ">> generating rdoc for: #{file}"
48
+
49
+ rdoc.document [ file, "--format=xml", "--output=temp" ]
50
+ {}
51
+ end
52
+
53
+ def render_rdoc_from_files
54
+ # This works to some extent...
55
+ #rdoc test/fixtures/examples/echo_inputs.rb --fmt=xml --op=tmp --all -q
56
+ # But the following does not do the same thing:
57
+ #response = rdoc.document [ file, '--fmt=xml', '--op=tmp', '--all', '-q' ]
58
+
59
+ options = RDoc::Options.new
60
+ options.files = FileList[ file ]
61
+ options.formatter = 'markup'
62
+ options.op_dir = './tmp'
63
+ options.verbosity = 0
64
+
65
+ rdoc.options = options
66
+
67
+ #rdoc.stats = RDoc::Stats.new 1, options.verbosity
68
+ #response = rdoc.document []
69
+
70
+ response = rdoc.parse_files [ file ]
71
+ render_rdoc_toplevel response
72
+ end
73
+
74
+ def render_rdoc_toplevel toplevel
75
+ puts ">> toplevel: #{toplevel}"
76
+ toplevel.each do |file|
77
+ puts ">> file: #{file.name}"
78
+ puts ">> pretty: #{file.pretty_print}"
79
+ end
80
+
81
+ toplevel
82
+ end
83
+
84
+ def render_rdoc_bak file
85
+ rdoc = RDoc::RDoc.new
86
+ rdoc.options = RDoc::Options.new
87
+ rdoc.parse_files [file]
88
+ end
89
+ end
90
+ end
91
+
@@ -1,70 +1,92 @@
1
+ require 'digest/md5'
1
2
 
2
3
  module Sprout
3
- class RemoteFileLoaderError < StandardError #:nodoc:
4
- end
5
4
 
6
- class RemoteFileLoader #:nodoc:
5
+ ##
6
+ # This class is used to load remote files from the network.
7
+ class RemoteFileLoader
8
+
9
+ class << self
7
10
 
8
- def get_remote_file(uri, force=false, md5=nil)
9
- response = fetch(uri.to_s)
10
- if(force || response_is_valid?(response, md5))
11
- return response
11
+ def load uri, md5=nil, filename=nil, force=false
12
+ response = fetch uri.to_s, filename
13
+ if(force || response_is_valid?(response, md5))
14
+ return response
15
+ end
16
+ nil
12
17
  end
13
- end
14
-
15
- def response_is_valid?(response, expected_md5sum=nil)
16
- if(expected_md5sum)
17
- md5 = Digest::MD5.new
18
- md5 << response
19
-
20
- if(expected_md5sum != md5.hexdigest)
21
- puts "The MD5 Sum of the downloaded file (#{md5.hexdigest}) does not match what was expected (#{expected_md5sum})."
22
- puts "Would you like to install anyway? [Yn]"
23
- response = $stdin.gets.chomp!
24
- if(response.downcase == 'y')
25
- return true
26
- else
27
- raise RemoteFileLoaderError.new('MD5 Checksum failed')
18
+
19
+ private
20
+
21
+ def response_is_valid? response, expected_md5sum
22
+ if(expected_md5sum)
23
+ md5 = Digest::MD5.new
24
+ md5 << response
25
+
26
+ if(expected_md5sum != md5.hexdigest)
27
+ return prompt_for_md5_failure md5, expected_md5sum
28
28
  end
29
29
  end
30
+ return true
30
31
  end
31
- return true
32
- end
33
-
34
- def fetch(uri)
35
- uri = URI.parse(uri)
36
- progress = nil
37
- response = nil
38
- name = uri.path.split("/").pop
39
32
 
40
- begin
41
- open(uri.to_s, :content_length_proc => lambda {|t|
42
- if t && t > 0
43
- progress = ProgressBar.new(name, t)
44
- progress.file_transfer_mode
45
- progress.set(0)
46
- else
47
- progress = ProgressBar.new(name, 0)
33
+ def fetch uri, name=nil
34
+ begin
35
+ return open_uri uri, name
36
+ rescue SocketError => sock_err
37
+ raise Sprout::Errors::RemoteFileLoaderError.new("[ERROR] #{sock_err.to_s}")
38
+ rescue OpenURI::HTTPError => http_err
39
+ raise Sprout::Errors::RemoteFileLoaderError.new("[ERROR] Failed to load file from: '#{uri.to_s}'\n[REMOTE ERROR] #{http_err.io.read.strip}")
40
+ rescue Errno::ECONNREFUSED => econ_err
41
+ raise Errno::ECONNREFUSED.new("[ERROR] Connection refused at: '#{uri.to_s}'")
42
+ end
43
+ end
44
+
45
+ private
46
+
47
+ def open_uri uri, name=nil
48
+ uri = URI.parse(uri)
49
+ progress = nil
50
+ response = nil
51
+ name ||= uri.path.split("/").pop
52
+
53
+ # Why was this here? Shouldn't the 'open' command work for other
54
+ # protocols like https?
55
+ #
56
+ #message = "The RemoteFileTask failed for #{name}. We can only handle HTTP requests at this time, it seems you were trying: '#{uri.scheme}'"
57
+ #raise Sprout::Errors::RemoteFileLoaderError.new(message) if uri.scheme != 'http' || uri.scheme != 'https'
58
+
59
+ # This is the strangest implementation I've seen in Ruby yet.
60
+ # Double lambda arguments with a block to top it off?! Gawsh.
61
+ open(uri.to_s,
62
+ :content_length_proc => lambda {|length|
63
+ length ||= 0
64
+ progress = Sprout::ProgressBar.new(name, length)
48
65
  progress.file_transfer_mode
49
66
  progress.set(0)
50
- end
51
- },
52
- :progress_proc => lambda {|s|
53
- progress.set s if progress
67
+ },
68
+ :progress_proc => lambda {|length|
69
+ progress.set length if progress
54
70
  }) do |f|
55
71
  response = f.read
56
72
  progress.finish
57
73
  end
58
- rescue SocketError => sock_err
59
- raise RemoteFileLoaderError.new("[ERROR] #{sock_err.to_s}")
60
- rescue OpenURI::HTTPError => http_err
61
- raise RemoteFileLoaderError.new("[ERROR] Failed to load file from: '#{uri.to_s}'\n[REMOTE ERROR] #{http_err.io.read.strip}")
62
- rescue Errno::ECONNREFUSED => econ_err
63
- raise Errno::ECONNREFUSED.new("[ERROR] Connection refused at: '#{uri.to_s}'")
74
+
75
+ response
76
+ end
77
+
78
+ def prompt_for_md5_failure md5, expected_md5sum
79
+ puts "The MD5 Sum of the downloaded file (#{md5.hexdigest}) does not match what was expected (#{expected_md5sum})."
80
+ puts "Would you like to install anyway? [Yn]"
81
+ response = $stdin.gets.chomp!
82
+ if(response.downcase == 'y')
83
+ return true
84
+ else
85
+ raise Sprout::Errors::RemoteFileLoaderError.new('MD5 Checksum failed')
86
+ end
64
87
  end
65
88
 
66
- return response
67
89
  end
68
-
69
90
  end
70
91
  end
92
+
@@ -1,178 +1,70 @@
1
1
 
2
2
  module Sprout
3
- class RemoteFileTargetError < StandardError #:nodoc:
4
- end
5
-
6
- class RemoteFileTarget # :nodoc:
7
-
8
-
9
- attr_accessor :gem_name
10
- attr_accessor :gem_version
11
-
12
- attr_writer :archive_path
13
-
14
- # The string environment variable name to check before downloading anything.
15
- attr_accessor :environment
16
-
17
- # The user path where this gem will download and install files
18
- # This value is set by the Sprout::Builder that creates this RemoteFileTarget
19
- attr_accessor :install_path
20
-
21
- # Optional md5 hash, usually set in the sprout.spec for each RemoteFileTarget
22
- # If this value is set, the downloaded archive will be hashed, the hashes will
23
- # be compared and if they differ, the installation process will break.
24
- attr_accessor :md5
25
-
26
- # Used for dmg archives. Absolute path to the mounted dmg (essentially its name)
27
- attr_accessor :mount_path
28
3
 
29
- # Which platform will this RemoteFileTarget support.
30
- # Supported options are:
31
- # * universal
32
- # * macosx
33
- # * win32
34
- # * linux
35
- attr_accessor :platform
4
+ class RemoteFileTarget < FileTarget
36
5
 
37
- # URL where Sprouts can go to download the RemoteFileTarget archive
38
- attr_accessor :url
39
-
40
- # If the archive type cannot be assumed from the returned file name,
41
- # it must be provided as one of the following:
42
- # :exe
43
- # :zip
44
- # :targz
45
- # :gzip
46
- # :swc
47
- # :rb
48
- # :dmg
49
- # @see ArchiveUnpacker
50
6
  attr_accessor :archive_type
7
+ attr_accessor :url
8
+ attr_accessor :md5
51
9
 
52
- # Filename for the downloaded file. Introduced to fix railsy URL issues.
53
- attr_accessor :filename
54
-
55
- # Relative path within the archive to the executable or binary of interest
56
- def archive_path
57
- @archive_path ||= ''
10
+ def validate
11
+ super
12
+ raise Sprout::Errors::ValidationError.new "RemoteFileTarget.url is a required field" if url.nil?
13
+ raise Sprout::Errors::ValidationError.new "RemoteFileTarget.md5 is a required field" if md5.nil?
14
+ raise Sprout::Errors::ValidationError.new "RemoteFileTarget.archive_type is a required field" if archive_type.nil?
58
15
  end
59
16
 
60
- # Resolve this RemoteFileTarget now. This method is called by the Sprout::Builder
61
- # and will download, install and unpack the described archive, unless it is
62
- # already installed
63
- def resolve(update=false)
64
- # Wanted to raise, but it seems we support RemoteFileTargets that are actually self-installed binaries...
65
- # like SWFMill on Linux. @see the BuilderTest.test_build_no_install for more info.
66
- # raise RemoteFileTargetError.new('Cannot retrieve a RemoteFileTarget without a url') if url.nil?
67
- return if url.nil?
68
-
69
- if(filename)
70
- self.downloaded_path = File.join(File.dirname(downloaded_path), filename)
71
- end
72
-
73
- should_download = ( url && !File.exists?(installed_path) && !File.exists?(downloaded_path) )
17
+ def resolve
18
+ validate
19
+ load_unpack_or_ignore_archive
20
+ self
21
+ end
74
22
 
75
- if(should_download)
76
- content = download(url, update)
77
- FileUtils.makedirs(File.dirname(downloaded_path))
78
- FileUtils.touch(downloaded_path)
79
- File.open(downloaded_path, 'rb+') do |file|
80
- file.write(content)
81
- end
82
- end
23
+ protected
83
24
 
84
- if(!File.exists?(installed_path) && !File.exists?(File.join(installed_path, archive_path)) )
85
- archive_root = File.join(install_path, 'archive')
86
- install(downloaded_path, archive_root, update, archive_type)
87
- end
88
- end
89
-
90
- # Return the basename of the executable that this RemoteFileTarget refers to
91
- def executable
92
- return File.basename(archive_path)
93
- end
94
-
95
- # The root path to the unpacked archive files. This is the base path that will be added to any
96
- # +archive_path+ relative paths
97
- def installed_path
98
- @installed_path ||= inferred_installed_path
99
- return @installed_path
100
- end
101
-
102
- def downloaded_path=(path)
103
- @downloaded_path = path
104
- end
105
-
106
- # Parent directory where archives are downloaded
107
- # can be something like: ~/Library/Sprouts/cache/0.7/sprout-somesprout-tool.x.x.x/
108
- def downloaded_path
109
- @downloaded_path ||= File.join(install_path, file_name(url))
110
- return @downloaded_path
111
- end
112
-
113
- # Base file name represented by the provided +url+
114
- # Will strip off any ? arguments and trailing slashes. May not play nice with Rails URLS,
115
- # We expect archive file name suffixes like, zip, gzip, tar.gz, dmg, etc.
116
- def file_name(url=nil)
117
- return @filename if(@filename)
118
-
119
- url ||= self.url
120
- url = url.split('?').shift
121
-
122
- parts = url.split('/')
123
- if(parts.last == '/')
124
- parts.pop
125
- end
126
-
127
- file = parts.pop
128
-
129
- if(!archive_type.nil? && file.match(/\.#{archive_type.to_s}$/).nil?)
130
- file << ".#{archive_type.to_s}"
131
- end
132
-
133
- return file
25
+ def expand_executable_path path
26
+ # TODO: This is failing b/c it gets called before
27
+ # we can set pkg_name and pkg_version - so join
28
+ # raises null pointer error.
29
+ File.join unpacked_file, path
134
30
  end
135
-
31
+
136
32
  private
137
-
138
- def inferred_installed_path
139
- return environment_path || File.join(install_path, 'archive')
33
+
34
+ def downloaded_file
35
+ @downloaded_file ||= File.join(Sprout.cache, pkg_name, "#{md5}.#{archive_type}")
140
36
  end
141
-
142
- def environment_path
143
- path_for_environmental_name(inferred_env_name_with_version) || path_for_environmental_name(inferred_env_name) || path_for_environmental_name(environment)
37
+
38
+ def unpacked_file
39
+ @unpacked_file ||= File.join(Sprout.cache, pkg_name, pkg_version)
144
40
  end
145
41
 
146
- def path_for_environmental_name(name)
147
- if(name && ENV[name])
148
- if(!File.exist?(ENV[name]))
149
- raise UsageError.new("Found Environmental variable at: #{name} but no files found at: #{ENV[name]}")
42
+ def load_unpack_or_ignore_archive
43
+ if(!File.exists?(unpacked_file))
44
+ if(!File.exists?(downloaded_file))
45
+ write_archive download_archive
150
46
  end
151
- ENV[name]
47
+ unpack_archive
152
48
  end
153
49
  end
154
50
 
155
- def inferred_env_name_with_version
156
- return nil if (gem_version.nil? || gem_name.nil?)
157
- version = gem_version.to_s.gsub('.', '_')
158
- "#{inferred_env_name}_#{version}"
51
+ def download_archive
52
+ Sprout::RemoteFileLoader.load(url, md5, pkg_name)
159
53
  end
160
54
 
161
- def inferred_env_name
162
- return nil if gem_name.nil?
163
- return gem_name.gsub('-', '_').upcase
55
+ def write_archive bytes
56
+ FileUtils.mkdir_p File.dirname(downloaded_file)
57
+ File.open downloaded_file, 'w+' do |f|
58
+ f.write bytes
59
+ end
164
60
  end
165
61
 
166
- def download(url, update=false)
167
- loader = RemoteFileLoader.new
168
- loader.get_remote_file(url, update, md5)
169
- end
170
-
171
- def install(from, to, force, archive_type=nil)
172
- unpacker = ArchiveUnpacker.new
173
- #puts "Unpacking from: #{from} to: #{to} force: #{force} type: #{archive_type}"
174
- unpacker.unpack_archive(from, to, force, archive_type)
62
+ def unpack_archive
63
+ FileUtils.mkdir_p unpacked_file
64
+ unpacker = Sprout::ArchiveUnpacker.new
65
+ unpacker.unpack downloaded_file, unpacked_file, archive_type
175
66
  end
176
-
67
+
177
68
  end
178
69
  end
70
+