sprout 0.7.219-i686-darwin10

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.

@@ -0,0 +1,71 @@
1
+
2
+ module Sprout
3
+ class RemoteFileLoaderError < StandardError #:nodoc:
4
+ end
5
+
6
+ class RemoteFileLoader #:nodoc:
7
+
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
12
+ 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')
28
+ end
29
+ end
30
+ 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
+
40
+ raise RemoteFileLoaderError.new("The RemoteFileTask failed for #{name}. We can only handle HTTP requests at this time, it seems you were trying: '#{uri.scheme}'") if uri.scheme != 'http'
41
+ begin
42
+ open(uri.to_s, :content_length_proc => lambda {|t|
43
+ if t && t > 0
44
+ progress = ProgressBar.new(name, t)
45
+ progress.file_transfer_mode
46
+ progress.set(0)
47
+ else
48
+ progress = ProgressBar.new(name, 0)
49
+ progress.file_transfer_mode
50
+ progress.set(0)
51
+ end
52
+ },
53
+ :progress_proc => lambda {|s|
54
+ progress.set s if progress
55
+ }) do |f|
56
+ response = f.read
57
+ progress.finish
58
+ end
59
+ rescue SocketError => sock_err
60
+ raise RemoteFileLoaderError.new("[ERROR] #{sock_err.to_s}")
61
+ rescue OpenURI::HTTPError => http_err
62
+ raise RemoteFileLoaderError.new("[ERROR] Failed to load file from: '#{uri.to_s}'\n[REMOTE ERROR] #{http_err.io.read.strip}")
63
+ rescue Errno::ECONNREFUSED => econ_err
64
+ raise Errno::ECONNREFUSED.new("[ERROR] Connection refused at: '#{uri.to_s}'")
65
+ end
66
+
67
+ return response
68
+ end
69
+
70
+ end
71
+ end
@@ -0,0 +1,151 @@
1
+
2
+ module Sprout
3
+ class RemoteFileTargetError < StandardError #:nodoc:
4
+ end
5
+
6
+ class RemoteFileTarget # :nodoc:
7
+
8
+ attr_writer :archive_path
9
+
10
+ # The string environment variable name to check before downloading anything.
11
+ attr_accessor :environment
12
+
13
+ # The user path where this gem will download and install files
14
+ # This value is set by the Sprout::Builder that creates this RemoteFileTarget
15
+ attr_accessor :install_path
16
+
17
+ # Optional md5 hash, usually set in the sprout.spec for each RemoteFileTarget
18
+ # If this value is set, the downloaded archive will be hashed, the hashes will
19
+ # be compared and if they differ, the installation process will break.
20
+ attr_accessor :md5
21
+
22
+ # Used for dmg archives. Absolute path to the mounted dmg (essentially its name)
23
+ attr_accessor :mount_path
24
+
25
+ # Which platform will this RemoteFileTarget support.
26
+ # Supported options are:
27
+ # * universal
28
+ # * macosx
29
+ # * win32
30
+ # * linux
31
+ attr_accessor :platform
32
+
33
+ # URL where Sprouts can go to download the RemoteFileTarget archive
34
+ attr_accessor :url
35
+
36
+ # If the archive type cannot be assumed from the returned file name,
37
+ # it must be provided as one of the following:
38
+ # :exe
39
+ # :zip
40
+ # :targz
41
+ # :gzip
42
+ # :swc
43
+ # :rb
44
+ # :dmg
45
+ # @see ArchiveUnpacker
46
+ attr_accessor :archive_type
47
+
48
+ # Filename for the downloaded file. Introduced to fix railsy URL issues.
49
+ attr_accessor :filename
50
+
51
+ # Relative path within the archive to the executable or binary of interest
52
+ def archive_path
53
+ @archive_path ||= ''
54
+ end
55
+
56
+ # Resolve this RemoteFileTarget now. This method is called by the Sprout::Builder
57
+ # and will download, install and unpack the described archive, unless it is
58
+ # already installed
59
+ def resolve(update=false)
60
+ # Wanted to raise, but it seems we support RemoteFileTargets that are actually self-installed binaries...
61
+ # like SWFMill on Linux. @see the BuilderTest.test_build_no_install for more info.
62
+ # raise RemoteFileTargetError.new('Cannot retrieve a RemoteFileTarget without a url') if url.nil?
63
+ return if url.nil?
64
+
65
+ if(filename)
66
+ self.downloaded_path = File.join(File.dirname(downloaded_path), filename)
67
+ end
68
+
69
+ if(url && (update || !File.exists?(downloaded_path)))
70
+ content = download(url, update)
71
+ FileUtils.makedirs(File.dirname(downloaded_path))
72
+ FileUtils.touch(downloaded_path)
73
+ File.open(downloaded_path, 'rb+') do |file|
74
+ file.write(content)
75
+ end
76
+ end
77
+
78
+ if(!File.exists?(installed_path) || !File.exists?(File.join(installed_path, archive_path) ))
79
+ archive_root = File.join(install_path, 'archive')
80
+ install(downloaded_path, archive_root, update, archive_type)
81
+ end
82
+ end
83
+
84
+ # Return the basename of the executable that this RemoteFileTarget refers to
85
+ def executable
86
+ return File.basename(archive_path)
87
+ end
88
+
89
+ # The root path to the unpacked archive files. This is the base path that will be added to any
90
+ # +archive_path+ relative paths
91
+ def installed_path
92
+ @installed_path ||= inferred_installed_path
93
+ return @installed_path
94
+ end
95
+
96
+ def downloaded_path=(path)
97
+ @downloaded_path = path
98
+ end
99
+
100
+ # Parent directory where archives are downloaded
101
+ # can be something like: ~/Library/Sprouts/cache/0.7/sprout-somesprout-tool.x.x.x/
102
+ def downloaded_path
103
+ @downloaded_path ||= File.join(install_path, file_name(url))
104
+ return @downloaded_path
105
+ end
106
+
107
+ # Base file name represented by the provided +url+
108
+ # Will strip off any ? arguments and trailing slashes. May not play nice with Rails URLS,
109
+ # We expect archive file name suffixes like, zip, gzip, tar.gz, dmg, etc.
110
+ def file_name(url=nil)
111
+ return @filename if(@filename)
112
+
113
+ url ||= self.url
114
+ url = url.split('?').shift
115
+
116
+ parts = url.split('/')
117
+ if(parts.last == '/')
118
+ parts.pop
119
+ end
120
+
121
+ file = parts.pop
122
+
123
+ if(!archive_type.nil? && file.match(/\.#{archive_type.to_s}$/).nil?)
124
+ file << ".#{archive_type.to_s}"
125
+ end
126
+
127
+ return file
128
+ end
129
+
130
+ private
131
+
132
+ def inferred_installed_path
133
+ if(!environment.nil? && !ENV[environment].nil? && File.exists?(ENV[environment]))
134
+ return ENV[environment]
135
+ end
136
+
137
+ return File.join(install_path, 'archive')
138
+ end
139
+
140
+ def download(url, update=false)
141
+ loader = RemoteFileLoader.new
142
+ loader.get_remote_file(url, update, md5)
143
+ end
144
+
145
+ def install(from, to, force, archive_type=nil)
146
+ unpacker = ArchiveUnpacker.new
147
+ unpacker.unpack_archive(from, to, force, archive_type)
148
+ end
149
+
150
+ end
151
+ end
@@ -0,0 +1,88 @@
1
+ =begin
2
+ Copyright (c) 2007 Pattern Park
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ =end
23
+ require 'erb'
24
+
25
+ module Sprout
26
+
27
+ class SimpleResolver #:nodoc:
28
+
29
+ def initialize(template, output, files, base_dir=nil)
30
+ @template = template
31
+ @output = output
32
+ @files = files
33
+ @base_dir = base_dir
34
+ @ignored_files = []
35
+ execute
36
+ finish
37
+ end
38
+
39
+ def execute
40
+ template_file = File.open(@template, 'r')
41
+ content = template_file.read
42
+ result = ERB.new(content, nil, '>').result(binding)
43
+
44
+ output_file = File.open(@output, 'w')
45
+ output_file.write(result)
46
+
47
+ template_file.close
48
+ output_file.close
49
+ end
50
+
51
+ def files
52
+ return @files
53
+ end
54
+
55
+ def finish
56
+ if(@ignored_files.size > 0)
57
+ Logger.puts '>> SimpleResolver ignored the following files because their names were invalid:'
58
+ @ignored_files.each do |file|
59
+ puts file
60
+ end
61
+ end
62
+ end
63
+
64
+ def xml_edit_warning
65
+ return <<EOF
66
+ <!--
67
+ DO NOT EDIT THIS FILE!
68
+ This file was auto-generated from
69
+ an ERB template which can be
70
+ found at:
71
+ #{@template}
72
+ -->
73
+ EOF
74
+ end
75
+
76
+ def edit_warning
77
+ return <<EOF
78
+ /*************************************
79
+ * DO NOT EDIT THIS FILE!
80
+ * This file was auto-generated from
81
+ * an ERB template which can be
82
+ * found at:
83
+ * #{@template}
84
+ *************************************/
85
+ EOF
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,118 @@
1
+ require 'erb'
2
+
3
+ # Rake task that makes it stupid-easy to render ERB templates
4
+ # to disk. Just add parameters to the yielded object, and
5
+ # they will be available to your Template.
6
+ #
7
+ # erb_resolver 'config/SomeFile.xml' do |t|
8
+ # t.param1 = 'value'
9
+ # t.other_param = 'other value'
10
+ # t.another_param = ['a', 'b', 'c']
11
+ # end
12
+ #
13
+ # Your erb template must be found at:
14
+ #
15
+ # [task_name].erb
16
+ #
17
+ # For the above example, this file would be:
18
+ #
19
+ # config/SomeFile.xml.erb
20
+ #
21
+ module Sprout
22
+
23
+ class ERBResolver < Rake::FileTask
24
+
25
+ # Path to the input ERB template. This
26
+ # value will default to the value of
27
+ # "#{ERBResolver.output}.erb"
28
+ attr_accessor :template
29
+
30
+ def initialize(name, app) # :nodoc:
31
+ super
32
+ @context = ERBContext.new
33
+ end
34
+
35
+ def define(args)
36
+ end
37
+
38
+ def prepare
39
+ prepare_prerequisites
40
+ end
41
+
42
+ # Modified from Rake::Task.execute
43
+ def execute(args=nil)
44
+ args ||= EMPTY_TASK_ARGS
45
+ if application.options.dryrun
46
+ puts "** Execute (dry run) #{name}"
47
+ return
48
+ end
49
+ if application.options.trace
50
+ puts "** Execute #{name}"
51
+ end
52
+ application.enhance_with_matching_rule(name) if @actions.empty?
53
+ @actions.each do |action|
54
+ execute_erb_task(action, args)
55
+ end
56
+ end
57
+
58
+ def execute_erb_task(action, args=nil)
59
+ case action.arity
60
+ when 1
61
+ action.call(@context)
62
+ else
63
+ action.call(@context, args)
64
+ end
65
+
66
+ @context.execute(template, output, args)
67
+ end
68
+
69
+ def self.define_task(*args, &block)
70
+ t = super
71
+ if(t.is_a?(ERBResolver))
72
+ t.define(args)
73
+ t.prepare
74
+ end
75
+ return t
76
+ end
77
+
78
+ def template
79
+ @template ||= "#{output}.erb"
80
+ end
81
+
82
+ def output
83
+ self.name
84
+ end
85
+
86
+ protected
87
+
88
+ def prepare_prerequisites
89
+ prerequisites << file(template)
90
+ CLEAN.add(output)
91
+ end
92
+
93
+ end
94
+
95
+ # An empty, dynamic object that will be yielded
96
+ # to the provided block and later supplied to the
97
+ # ERB template.
98
+ #
99
+ # Returning this empty object gives us the ability
100
+ # to use parameter names in our templates even if
101
+ # they are already used by Rake tasks (i.e. name).
102
+ class ERBContext
103
+ include DynamicAccessors
104
+
105
+ def execute(template, output, args=nil)
106
+ content = nil
107
+ File.open(template, 'r') { |f| content = f.read }
108
+ result = ERB.new(content, nil, '>').result(binding)
109
+ File.open(output, 'w') { |f| f.write(result) }
110
+ Log.puts ">> Created ERB output at: #{output} from: #{template}"
111
+ end
112
+ end
113
+
114
+ end
115
+
116
+ def erb_resolver(*args, &block)
117
+ Sprout::ERBResolver.define_task(args, &block)
118
+ end
@@ -0,0 +1,200 @@
1
+ =begin
2
+ Copyright (c) 2007 Pattern Park
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+
23
+ TODO: Update mxmlc task
24
+ * Update mxmlc to include all advanced options
25
+ * Clean up default values
26
+ * Investigate jruby support, especially:
27
+ http://livedocs.adobe.com/flex/201/html/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Book_Parts&file=compilers_123_09.html
28
+ =end
29
+
30
+ module Sprout
31
+ class GemWrapError < StandardError #:nodoc:
32
+ end
33
+
34
+ # Creates a ruby gem from a slightly simpler rake task than what gems provides.
35
+ # Adds support for adding a sprout.spec file to your new gem which is usually useful
36
+ # for tool or library sprout gems.
37
+ class GemWrapTask < Rake::Task
38
+ # The full name of the gem to create like:
39
+ # t.gem_name = 'sprout-as3-bundle'
40
+ attr_writer :gem_name
41
+ # The type of sprout to create, defaults to 'library'
42
+ # Other possible values are, 'bundle' and 'tool'
43
+ attr_writer :sprout_type
44
+ # Full string rubygem version for this sprout, usually in three parts like:
45
+ # t.version = '0.0.1'
46
+ attr_writer :version
47
+ # Folder that the newly-created gem should be placed in
48
+ attr_writer :package
49
+ # Summary or short description for the gem
50
+ attr_writer :summary
51
+ # The author that created the gem
52
+ attr_writer :author
53
+ # Email address for interested users to send questions to
54
+ attr_writer :email
55
+ # Homepage where users can learn more about this gem
56
+ attr_writer :homepage
57
+ # A string remote file specification usually something like:
58
+ #
59
+ # t.sprout_spec =<<EOF
60
+ # - !ruby/object:Sprout::RemoteFileTarget
61
+ # platform: universal
62
+ # url: http://as3flickrlib.googlecode.com/files/flickr-.87.zip
63
+ # archive_path: flickr-.87/src
64
+ # EOF
65
+ attr_writer :sprout_spec
66
+
67
+ def self.define_task(args, &block)
68
+ t = super
69
+ yield t if block_given?
70
+ t.define
71
+ end
72
+
73
+ def define # :nodoc:
74
+ define_gem_name
75
+ define_extensions(extensions)
76
+ end
77
+
78
+ def initialize(task_name, app) # :nodoc:
79
+ super
80
+ @sprout_type = "library"
81
+ @package = "pkg"
82
+ @summary = "#{task_name}"
83
+ @email = "projectsprouts@googlegroups.com"
84
+ @homepage = "http://www.projectsprouts.org"
85
+ end
86
+
87
+ def execute(*args) # :nodoc:
88
+ super
89
+ raise GemWrapError.new("A version must be provided to produce a Gem!") unless @version
90
+ @summary = "#{name} #{@sprout_type} generated by Sprout::GemWrapTask" unless @summary
91
+
92
+ FileUtils.mkdir_p(gem_package)
93
+ render_sprout_spec(gem_package, @sprout_spec) if @sprout_spec
94
+ # render_extensions(gem_package, extensions) if extensions.size
95
+
96
+ Dir.chdir(gem_package) do
97
+
98
+ spec = Gem::Specification.new do |s|
99
+ files = []
100
+ s.platform = Gem::Platform::RUBY
101
+ s.version = @version
102
+ s.author = @author if @author
103
+ s.summary = @summary
104
+ s.name = @gem_name
105
+ s.email = @email
106
+ s.homepage = @homepage
107
+ s.rubyforge_project = 'sprout'
108
+ gem_dependencies.each do |dep|
109
+ s.requirements << dep
110
+ end
111
+
112
+ sprout_requirement = s.requirements.collect do |req|
113
+ (req[0] == 'sprout')
114
+ end
115
+
116
+ if(!sprout_requirement)
117
+ s.add_dependency('sprout', '>= 0.7.209')
118
+ end
119
+
120
+ if(File.exists?('sprout.spec'))
121
+ files << 'sprout.spec'
122
+ end
123
+ if(extensions.size > 0)
124
+ files << 'ext'
125
+ end
126
+ zipped_extensions.each do |ext|
127
+ files << File.join('ext', File.basename(ext))
128
+ end
129
+ s.files = files
130
+ end
131
+ Gem::Builder.new(spec).build
132
+ end
133
+
134
+ FileUtils.mv("#{gem_package}/#{@gem_name}-#{@version}.gem", @package)
135
+ FileUtils.rm_rf(gem_package)
136
+ end
137
+
138
+ # Add a gem dependency either with only the gem name
139
+ # or with a full name and version hash like:
140
+ #
141
+ # t.add_dependency('sprout-flashplayer-tool')
142
+ # or
143
+ # t.add_dependency('sprout-flashplayer-tool' => '9.115.0')
144
+ #
145
+ def add_dependency(args)
146
+ gem_dependencies << args
147
+ end
148
+
149
+ def gem_dependencies
150
+ return @gem_dependencies ||= []
151
+ end
152
+
153
+ # Add files to include in the gem/ext folder
154
+ def extensions
155
+ return @extensions ||= []
156
+ end
157
+
158
+ private
159
+
160
+ def gem_package
161
+ @gem_package ||= File.join(@package, @gem_name)
162
+ end
163
+
164
+ def zipped_extensions
165
+ return @zipped_extensions ||= []
166
+ end
167
+
168
+ def define_gem_name
169
+ @gem_name = "sprout-#{name}-#{@sprout_type}" if !@gem_name
170
+ end
171
+
172
+ def define_extensions(exts)
173
+ exts.each do |ext|
174
+ if(File.directory?(ext))
175
+ full = File.expand_path(ext)
176
+ t = nil
177
+
178
+ zip full do |z|
179
+ z.input = full
180
+ z.output = File.join(gem_name, 'ext', File.basename(full) + '.zip')
181
+ end
182
+ puts "pwd: #{Dir.pwd} out #{t.output}"
183
+ zipped_extensions << File.expand_path(t.output)
184
+ prerequisites << t.output
185
+ end
186
+ end
187
+ end
188
+
189
+ def render_sprout_spec(target, spec)
190
+ File.open(File.join(target, 'sprout.spec'), 'w') do |f|
191
+ f.write(spec)
192
+ end
193
+ end
194
+
195
+ end
196
+ end
197
+
198
+ def gem_wrap(args, &block)
199
+ Sprout::GemWrapTask.define_task(args, &block)
200
+ end