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.
- data/CHANGELOG.md +10 -0
- data/Gemfile +28 -0
- data/MIT-LICENSE +3 -2
- data/POSTINSTALL.rdoc +28 -0
- data/README.textile +152 -0
- data/bin/sprout +1 -131
- data/bin/sprout-generator +10 -0
- data/bin/sprout-library +11 -0
- data/bin/sprout-tool +10 -0
- data/lib/sprout.rb +4 -500
- data/lib/sprout/archive_unpacker.rb +122 -206
- data/lib/sprout/base.rb +90 -0
- data/lib/sprout/concern.rb +30 -0
- data/lib/sprout/dir.rb +23 -0
- data/lib/sprout/errors.rb +94 -0
- data/lib/sprout/executable.rb +496 -0
- data/lib/sprout/executable/boolean.rb +35 -0
- data/lib/sprout/executable/collection_param.rb +53 -0
- data/lib/sprout/executable/file_param.rb +53 -0
- data/lib/sprout/executable/files.rb +26 -0
- data/lib/sprout/executable/number.rb +10 -0
- data/lib/sprout/executable/param.rb +222 -0
- data/lib/sprout/executable/parameter_factory.rb +28 -0
- data/lib/sprout/executable/path.rb +21 -0
- data/lib/sprout/executable/paths.rb +21 -0
- data/lib/sprout/executable/string_param.rb +15 -0
- data/lib/sprout/executable/strings.rb +11 -0
- data/lib/sprout/executable/url.rb +10 -0
- data/lib/sprout/executable/urls.rb +10 -0
- data/lib/sprout/file_target.rb +76 -0
- data/lib/sprout/generator/base.rb +233 -0
- data/lib/sprout/generator/command.rb +67 -0
- data/lib/sprout/generator/directory_manifest.rb +49 -0
- data/lib/sprout/generator/file_manifest.rb +55 -0
- data/lib/sprout/generator/manifest.rb +13 -0
- data/lib/sprout/generator/template_manifest.rb +13 -0
- data/lib/sprout/generators/generator/generator_generator.rb +48 -0
- data/lib/sprout/generators/generator/templates/generator_class.rb +17 -0
- data/lib/sprout/generators/generator/templates/generator_executable +9 -0
- data/lib/sprout/generators/generator/templates/generator_template +1 -0
- data/lib/sprout/generators/generator/templates/generator_test.rb +37 -0
- data/lib/sprout/generators/generator/templates/generator_test_helper.rb +16 -0
- data/lib/sprout/generators/library/library_generator.rb +20 -0
- data/lib/sprout/generators/library/templates/library.gemspec +19 -0
- data/lib/sprout/generators/library/templates/library.rb +15 -0
- data/lib/sprout/generators/ruby/ruby_generator.rb +59 -0
- data/lib/sprout/generators/ruby/templates/ruby_base.rb +10 -0
- data/lib/sprout/generators/ruby/templates/ruby_executable +6 -0
- data/lib/sprout/generators/ruby/templates/ruby_gemfile +4 -0
- data/lib/sprout/generators/ruby/templates/ruby_input.rb +7 -0
- data/lib/sprout/generators/tool/templates/Gemfile +4 -0
- data/lib/sprout/generators/tool/templates/tool.gemspec +22 -0
- data/lib/sprout/generators/tool/templates/tool.rb +38 -0
- data/lib/sprout/generators/tool/tool_generator.rb +36 -0
- data/lib/sprout/library.rb +111 -0
- data/lib/sprout/log.rb +1 -0
- data/lib/sprout/platform.rb +71 -0
- data/lib/sprout/process_runner.rb +80 -40
- data/lib/sprout/progress_bar.rb +341 -0
- data/lib/sprout/rdoc_parser.rb +91 -0
- data/lib/sprout/remote_file_loader.rb +72 -50
- data/lib/sprout/remote_file_target.rb +44 -152
- data/lib/sprout/ruby_feature.rb +167 -0
- data/lib/sprout/specification.rb +197 -0
- data/lib/sprout/string.rb +19 -0
- data/lib/sprout/system.rb +35 -0
- data/lib/sprout/system/base_system.rb +225 -0
- data/lib/sprout/system/java_system.rb +9 -0
- data/lib/sprout/system/osx_system.rb +26 -0
- data/lib/sprout/system/unix_system.rb +72 -0
- data/lib/sprout/system/vista_system.rb +16 -0
- data/lib/sprout/system/win_nix_system.rb +41 -0
- data/lib/sprout/system/win_system.rb +76 -0
- data/lib/sprout/test/sprout_test_case.rb +211 -0
- data/lib/sprout/version.rb +9 -4
- data/rakefile.rb +85 -144
- data/script/console +10 -0
- data/script/destroy +14 -0
- data/script/generate +14 -0
- data/sprout.gemspec +26 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.exe +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.rb +0 -0
- data/test/fixtures/archive_unpacker/copyable/some_file.swc +0 -0
- data/test/fixtures/archive_unpacker/tgz/some folder.tgz +0 -0
- data/test/fixtures/archive_unpacker/tgz/some_file.tgz +0 -0
- data/test/fixtures/archive_unpacker/zip/some folder.zip +0 -0
- data/test/fixtures/archive_unpacker/zip/some_file.zip +0 -0
- data/test/fixtures/examples/app_generator.rb +127 -0
- data/test/fixtures/examples/echo_inputs.rb +151 -0
- data/test/fixtures/executable/echochamber_gem/bin/echochamber +3 -0
- data/test/fixtures/executable/echochamber_gem/echo_chamber.rb +10 -0
- data/test/fixtures/executable/flex3sdk_gem/flex3sdk.rb +11 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc +3 -0
- data/test/fixtures/executable/flex3sdk_gem/mxmlc.bat +3 -0
- data/test/fixtures/executable/mxmlc.rb +805 -0
- data/test/fixtures/executable/params/input.as +0 -0
- data/test/fixtures/executable/params/input2.as +0 -0
- data/test/fixtures/executable/params/input3.as +0 -0
- data/test/fixtures/executable/params/mxmlc +5 -0
- data/test/fixtures/executable/path with spaces/input.as b/data/test/fixtures/executable/path with → spaces/input.as +0 -0
- data/test/fixtures/executable/path with spaces/input2.as b/data/test/fixtures/executable/path with → spaces/input2.as +0 -0
- data/test/fixtures/executable/path with spaces/input3.as b/data/test/fixtures/executable/path with → spaces/input3.as +0 -0
- data/test/fixtures/executable/paths/folder1/file1 +0 -0
- data/test/fixtures/executable/paths/folder1/file2 +0 -0
- data/test/fixtures/executable/paths/folder1/file3 +0 -0
- data/test/fixtures/executable/paths/folder2/file4 +0 -0
- data/test/fixtures/executable/paths/folder2/file5 +0 -0
- data/test/fixtures/executable/paths/folder3/file6 +0 -0
- data/test/fixtures/executable/src/Main.as +0 -0
- data/test/fixtures/executable/windows_line_endings +47 -0
- data/test/fixtures/generators/song_generator.rb +11 -0
- data/test/fixtures/generators/song_subclass/least_favorite.rb +10 -0
- data/test/fixtures/generators/song_subclass/templates/Song.txt +3 -0
- data/test/fixtures/generators/temp_generator.rb +24 -0
- data/test/fixtures/generators/templates/Main.as +9 -0
- data/test/fixtures/generators/templates/OtherFileTemplate +1 -0
- data/test/fixtures/generators/templates/SomeFile +1 -0
- data/test/fixtures/generators/templates/SomeSubclassFile +2 -0
- data/test/fixtures/generators/templates/Song.txt +3 -0
- data/test/fixtures/generators/templates/destroy +0 -0
- data/test/fixtures/generators/templates/generate +0 -0
- data/test/fixtures/library/archive/Archive.swc +0 -0
- data/test/fixtures/library/sources/lib/a/A.as +0 -0
- data/test/fixtures/library/sources/lib/b/B.as +0 -0
- data/test/fixtures/library/sources/src/Source.as +0 -0
- data/test/fixtures/process_runner/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/dir with spaces/chmod_script.sh +3 -0
- data/test/fixtures/process_runner/failure +5 -0
- data/test/fixtures/process_runner/success +4 -0
- data/test/fixtures/remote_file_loader/md5/echochamber-test.zip +0 -0
- data/test/fixtures/remote_file_loader/md5/file_with_known_md5 +0 -0
- data/test/fixtures/remote_file_target/bin/echochamber +3 -0
- data/test/fixtures/remote_file_target/bin/echochamber.bat +3 -0
- data/test/fixtures/remote_file_target/echochamber-test.zip +0 -0
- data/test/fixtures/specification/asunit4.rb +25 -0
- data/test/fixtures/specification/ext/AsUnit-4.1.pre.swc +0 -0
- data/test/fixtures/specification/flashplayer.rb +30 -0
- data/test/fixtures/specification/flex4sdk.rb +72 -0
- data/test/fixtures/specification/flexunit4.sproutspec +17 -0
- data/test/fixtures/specification/lib/as3reflection/Reflection.as +0 -0
- data/test/fixtures/specification/src/AsUnit.as +0 -0
- data/test/fixtures/user/mxmlc_crlf +3 -0
- data/test/unit/archive_unpacker_test.rb +108 -0
- data/test/unit/boolean_param_test.rb +38 -0
- data/test/unit/executable_option_parser_test.rb +142 -0
- data/test/unit/executable_param_test.rb +76 -0
- data/test/unit/executable_test.rb +237 -0
- data/test/unit/fake_executable_task.rb +22 -0
- data/test/unit/fake_other_executable.rb +20 -0
- data/test/unit/fake_process_runner.rb +29 -0
- data/test/unit/file_param_test.rb +61 -0
- data/test/unit/file_target_test.rb +42 -0
- data/test/unit/files_param_test.rb +72 -0
- data/test/unit/generator_generator_test.rb +85 -0
- data/test/unit/generator_test.rb +333 -0
- data/test/unit/library_generator_test.rb +41 -0
- data/test/unit/library_test.rb +88 -0
- data/test/unit/osx_system_test.rb +20 -0
- data/test/unit/path_param_test.rb +43 -0
- data/test/unit/paths_param_test.rb +53 -0
- data/test/unit/platform_test.rb +76 -0
- data/test/unit/process_runner_test.rb +104 -0
- data/test/unit/rdoc_parser_test.rb +15 -0
- data/test/unit/remote_file_loader_test.rb +34 -0
- data/test/unit/remote_file_target_test.rb +105 -0
- data/test/unit/ruby_feature_test.rb +108 -0
- data/test/unit/ruby_generator_test.rb +70 -0
- data/test/unit/specification_test.rb +73 -0
- data/test/unit/sprout_test.rb +170 -0
- data/test/unit/sprout_test_helper.rb +18 -0
- data/test/unit/string_param_test.rb +19 -0
- data/test/unit/string_test.rb +20 -0
- data/test/unit/strings_param_test.rb +27 -0
- data/test/unit/test_helper.rb +1 -0
- data/test/unit/tool_generator_test.rb +43 -0
- data/test/unit/unix_system_test.rb +52 -0
- data/test/unit/user_test.rb +147 -0
- data/test/unit/vista_system_test.rb +40 -0
- data/test/unit/win_nix_system_test.rb +26 -0
- data/test/unit/win_system_test.rb +61 -0
- metadata +318 -113
- data/doc/Bundle +0 -14
- data/doc/Generator +0 -35
- data/doc/Library +0 -63
- data/doc/Task +0 -21
- data/doc/Tool +0 -20
- data/lib/platform.rb +0 -113
- data/lib/progress_bar.rb +0 -354
- data/lib/sprout/builder.rb +0 -51
- data/lib/sprout/bundle_resolver.rb +0 -349
- data/lib/sprout/commands/generate.rb +0 -9
- data/lib/sprout/dynamic_accessors.rb +0 -40
- data/lib/sprout/general_tasks.rb +0 -6
- data/lib/sprout/generator.rb +0 -7
- data/lib/sprout/generator/base_mixins.rb +0 -186
- data/lib/sprout/generator/named_base.rb +0 -227
- data/lib/sprout/project_model.rb +0 -278
- data/lib/sprout/simple_resolver.rb +0 -88
- data/lib/sprout/tasks/erb_resolver.rb +0 -118
- data/lib/sprout/tasks/gem_wrap_task.rb +0 -214
- data/lib/sprout/tasks/git_task.rb +0 -134
- data/lib/sprout/tasks/library_task.rb +0 -118
- data/lib/sprout/tasks/sftp_task.rb +0 -248
- data/lib/sprout/tasks/ssh_task.rb +0 -153
- data/lib/sprout/tasks/tool_task.rb +0 -836
- data/lib/sprout/tasks/zip_task.rb +0 -158
- data/lib/sprout/tool_task_model.rb +0 -19
- data/lib/sprout/user.rb +0 -415
- data/lib/sprout/version_file.rb +0 -89
- data/lib/sprout/zip_util.rb +0 -61
- 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
|
-
|
5
|
+
##
|
6
|
+
# This class is used to load remote files from the network.
|
7
|
+
class RemoteFileLoader
|
8
|
+
|
9
|
+
class << self
|
7
10
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
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
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
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
|
-
|
51
|
-
|
52
|
-
|
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
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
-
|
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
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
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
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
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
|
-
|
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
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
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
|
139
|
-
|
33
|
+
|
34
|
+
def downloaded_file
|
35
|
+
@downloaded_file ||= File.join(Sprout.cache, pkg_name, "#{md5}.#{archive_type}")
|
140
36
|
end
|
141
|
-
|
142
|
-
def
|
143
|
-
|
37
|
+
|
38
|
+
def unpacked_file
|
39
|
+
@unpacked_file ||= File.join(Sprout.cache, pkg_name, pkg_version)
|
144
40
|
end
|
145
41
|
|
146
|
-
def
|
147
|
-
if(
|
148
|
-
if(!File.
|
149
|
-
|
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
|
-
|
47
|
+
unpack_archive
|
152
48
|
end
|
153
49
|
end
|
154
50
|
|
155
|
-
def
|
156
|
-
|
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
|
162
|
-
|
163
|
-
|
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
|
167
|
-
|
168
|
-
|
169
|
-
|
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
|
+
|