sprout 0.7.220-x86-darwin-10

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,186 @@
1
+
2
+ class Gem::SourceIndex
3
+
4
+ # This feature seems to be getting deprecated from the latest
5
+ # gems releases (1.3.x).
6
+ # We actually need it and don't want the nagging - so,
7
+ # copied sources from RubyGems SVN trunk, and mixing in...
8
+ # :-(
9
+ # There should be a more stable integration point with RubyGems
10
+ # Any ideas or contributions are welcome!
11
+ def sprout_search(gem_pattern, platform_only = false)
12
+ version_requirement = nil
13
+ only_platform = false
14
+
15
+ # unless Gem::Dependency === gem_pattern
16
+ # warn "#{Gem.location_of_caller.join ':'}:Warning: Gem::SourceIndex#search support for #{gem_pattern.class} patterns is deprecated"
17
+ # end
18
+
19
+ case gem_pattern
20
+ when Regexp then
21
+ version_requirement = platform_only || Gem::Requirement.default
22
+ when Gem::Dependency then
23
+ only_platform = platform_only
24
+ version_requirement = gem_pattern.version_requirements
25
+ gem_pattern = if Regexp === gem_pattern.name then
26
+ gem_pattern.name
27
+ elsif gem_pattern.name.empty? then
28
+ //
29
+ else
30
+ /^#{Regexp.escape gem_pattern.name}$/
31
+ end
32
+ else
33
+ version_requirement = platform_only || Gem::Requirement.default
34
+ gem_pattern = /#{gem_pattern}/i
35
+ end
36
+
37
+ unless Gem::Requirement === version_requirement then
38
+ version_requirement = Gem::Requirement.create version_requirement
39
+ end
40
+
41
+ specs = @gems.values.select do |spec|
42
+ spec.name =~ gem_pattern and
43
+ version_requirement.satisfied_by? spec.version
44
+ end
45
+
46
+ if only_platform then
47
+ specs = specs.select do |spec|
48
+ Gem::Platform.match spec.platform
49
+ end
50
+ end
51
+
52
+ begin
53
+ specs.sort_by { |s| s.sort_obj }
54
+ rescue NoMethodError => e
55
+ puts "It looks like your RubyGems installation is not compatible with this version of Sprouts.\n\nTo update, run:\ngem update --system\n\n"
56
+ raise e
57
+ end
58
+ end
59
+ end
60
+
61
+ module RubiGen # :nodoc:[all]
62
+
63
+ class Base # :nodoc:[all]
64
+
65
+ def initialize(runtime_args, runtime_options = {})
66
+ @args = runtime_args
67
+ parse!(@args, runtime_options)
68
+
69
+ # Derive source and destination paths.
70
+ @source_root = options[:source] || File.join(spec.path, 'templates')
71
+
72
+ if options[:destination]
73
+ @destination_root = options[:destination]
74
+ elsif defined? Sprout::Sprout.project_path
75
+ @destination_root = Sprout::Sprout.project_path
76
+ else
77
+ @destination_root = Dir.pwd
78
+ end
79
+
80
+ # Silence the logger if requested.
81
+ logger.quiet = options[:quiet]
82
+
83
+ # Raise usage error if help is requested.
84
+ usage if options[:help]
85
+ end
86
+
87
+ end
88
+
89
+ # GemGeneratorSource hits the mines to quarry for generators. The latest versions
90
+ # of gems named sprout-#{sprout_name}-bundle are selected.
91
+ class GemGeneratorSource < AbstractGemSource # :nodoc:[all]
92
+
93
+ def initialize(name=nil)
94
+ super()
95
+ @sprout_name = name
96
+ end
97
+
98
+ # Yield latest versions of generator gems.
99
+ def each
100
+ Gem::cache.sprout_search(/sprout-*#{@sprout_name}-bundle$/).inject({}) do |latest, gem|
101
+ hem = latest[gem.name]
102
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
103
+ latest
104
+ end.values.each do |gem|
105
+ yield Spec.new(gem.name.sub(/sprout-*#{@sprout_name}-bundle$/, ''), gem.full_gem_path, label)
106
+ end
107
+ end
108
+
109
+ def each_sprout
110
+ Gem::cache.sprout_search(/^sprout-.*/).inject({}) do |latest, gem|
111
+ hem = latest[gem.name]
112
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
113
+ latest
114
+ end.values.each do |gem|
115
+ yield Spec.new(gem.name, gem.full_gem_path, label)
116
+ end
117
+ end
118
+ end
119
+
120
+ # GemPathSource looks for generators within any RubyGem's
121
+ # /sprout/generators/<generator_name>/<generator_name>_generator.rb file.
122
+ # It will only include generators from sprouts whose name includes
123
+ # #{sprout_name}-bundle
124
+ class GemPathSource < AbstractGemSource # :nodoc:[all]
125
+
126
+ def initialize(name=nil)
127
+ super()
128
+ @sprout_name = name
129
+ end
130
+
131
+ # Yield each generator within generator subdirectories.
132
+ def each
133
+ generator_full_paths.each do |generator|
134
+ yield Spec.new(File.basename(generator).sub(/_generator.rb$/, ''), File.dirname(generator), label)
135
+ end
136
+ end
137
+
138
+ private
139
+ def generator_full_paths
140
+ @generator_full_paths ||=
141
+ Gem::cache.inject({}) do |latest, name_gem|
142
+ name, gem = name_gem
143
+ hem = latest[gem.name]
144
+ latest[gem.name] = gem if hem.nil? or gem.version > hem.version
145
+ latest
146
+ end.values.inject([]) do |mem, gem|
147
+ Dir[gem.full_gem_path + '/lib/sprout/**/generators/**/*_generator.rb'].each do |generator|
148
+ if(@sprout_name && gem.name.match(/sprout-#{@sprout_name}-bundle/))
149
+ mem << generator
150
+ end
151
+ end
152
+ mem
153
+ end
154
+ end
155
+ end
156
+
157
+ module Lookup # :nodoc:[all]
158
+ module ClassMethods # :nodoc:[all]
159
+
160
+ def use_sprout_sources!(sprout_name, project_path=nil)
161
+ reset_sources
162
+
163
+ # Project-specific generator paths
164
+ if project_path
165
+ sources << PathSource.new(:project, "#{project_path}/generators")
166
+ sources << PathSource.new(:script, "#{project_path}/script/generators")
167
+ sources << PathSource.new(:vendor, "#{project_path}/vendor/generators")
168
+ end
169
+
170
+ # System-wide generator paths
171
+ system_path = "#{Sprout::Sprout.sprout_cache}/generators/#{sprout_name}"
172
+ if(File.exists?(system_path))
173
+ sources << PathSource.new(:system, system_path)
174
+ end
175
+
176
+ # Gem generators will collect all
177
+ # rubygems that end with -bundle or -generators
178
+ if(Object.const_defined?(:Gem))
179
+ sources << GemGeneratorSource.new(sprout_name)
180
+ sources << GemPathSource.new(sprout_name)
181
+ end
182
+ end
183
+ end
184
+ end
185
+
186
+ end
@@ -0,0 +1,227 @@
1
+
2
+ module Sprout
3
+ module Generator #:nodoc:
4
+
5
+ class NamedBaseError < StandardError #:nodoc:
6
+ end
7
+
8
+ # The NamedBase is a good default base class for ActionScript class Generators.
9
+ # This class will accept the first command line argument and create
10
+ # many helpful properties for concrete generators to use.
11
+ #
12
+ # Can accept class names in following formats:
13
+ # * src/package/package/ClassName.as
14
+ # * test/package/package/ClassName.as
15
+ # * package/package/ClassName
16
+ # * package.package.ClassName
17
+ #
18
+ # Regardless of which format the name was sent in, the helper
19
+ # methods should provide valid results
20
+ #
21
+ class NamedBase < RubiGen::Base
22
+
23
+ # Fully qualified class named including package name like 'flash.display.Sprite'
24
+ attr_reader :full_class_name
25
+ # Path to the class file relative to your src_dir like 'flash/display/Sprite.as'
26
+ attr_reader :class_file
27
+ # The directory that contains the file, relative to your src_dir like 'flash/diplay'
28
+ attr_reader :class_dir
29
+ # The unqualified name of the class like 'Sprite'
30
+ attr_reader :class_name
31
+ # The package name of the class like 'flash.display'
32
+ attr_reader :package_name
33
+
34
+ def initialize(runtime_args, runtime_options = {})
35
+ super
36
+
37
+ rakefile = Sprout.project_rakefile
38
+ if(rakefile && File.exists?(rakefile))
39
+ load rakefile
40
+ end
41
+ @model = ProjectModel.instance
42
+
43
+ # Had to stop throwing on no args because the suite generator does
44
+ # not require the user to send in a class name....
45
+ #usage("Final argument must be a name parameter") if runtime_args.empty?
46
+ @args = runtime_args.dup
47
+ assign_names! @args.shift
48
+ end
49
+
50
+ # Quick access to the source directory identified by your project model
51
+ def src_dir
52
+ return model.src_dir
53
+ end
54
+
55
+ # Quick access to the test directory identified by your project model
56
+ def test_dir
57
+ return model.test_dir
58
+ end
59
+
60
+ # Quick access to the library directory identified by your project model
61
+ def lib_dir
62
+ return model.lib_dir
63
+ end
64
+
65
+ # The path to your project. This will either be the directory from which
66
+ # the sprout gem was executed, or the nearest ancestor directory that
67
+ # contains a properly named rakefile.
68
+ def project_path
69
+ return model.project_path
70
+ end
71
+
72
+ # The project_name that was either sent to the sprout gem or
73
+ # defined in your rakefile project model
74
+ def project_name
75
+ @project_name ||= (Sprout.project_name || model.project_name)
76
+ end
77
+
78
+ # The technology language that is stored in your project model usually (as2 or as3)
79
+ def language
80
+ return model.language
81
+ end
82
+
83
+ # Name of possible test case for this class_name
84
+ def test_case_name
85
+ @test_case_name ||= class_name + 'Test'
86
+ end
87
+
88
+ # Full name of the possible test case for this class_name
89
+ def full_test_case_name
90
+ full_class_name + 'Test'
91
+ end
92
+
93
+ # Full path to the parent directory that contains the class
94
+ # like 'src/flash/display' for flash.display.Sprite class.
95
+ def full_class_dir
96
+ @full_class_dir ||= File.join(src_dir, class_dir)
97
+ # pull trailing slash for classes in the root package
98
+ @full_class_dir.gsub!(/\/$/, '')
99
+ @full_class_dir
100
+ end
101
+
102
+ # Full path to the class file from your project_path like 'src/flash/display/Sprite.as'
103
+ def full_class_path
104
+ @full_class_path ||= File.join(src_dir, class_file)
105
+ end
106
+
107
+ # Filesystem path to the folder that contains the TestCase file
108
+ def full_test_dir
109
+ @full_test_dir ||= full_class_dir.gsub(src_dir, test_dir)
110
+ end
111
+
112
+ # Filesystem path to the TestCase file
113
+ def full_test_case_path
114
+ @full_test_case_path ||= File.join(full_test_dir, test_case_name + '.as')
115
+ end
116
+
117
+ # Path to the in-project generate script
118
+ # pulled out for DOS branching
119
+ def generate_script_path
120
+ usr = User.new
121
+ if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser))
122
+ return File.join(class_name, 'script', "generate.rb")
123
+ else
124
+ return File.join(class_name, 'script', "generate")
125
+ end
126
+ end
127
+
128
+ def instance_name
129
+ name = class_name.dup;
130
+ char = name[0, 1]
131
+ name[0, 1] = char.downcase
132
+ if(name.size > 10)
133
+ name = 'instance'
134
+ end
135
+ return name
136
+ end
137
+
138
+ # Will return whether the user originally requested a class name
139
+ # that looks like a test case (e.g., name.match(/Test$/) )
140
+ def user_requested_test
141
+ @user_requested_test ||= false
142
+ end
143
+
144
+ # Glob that is used to search for test cases and build
145
+ # up the test suites
146
+ def test_glob
147
+ return @test_glob ||= '**/**/?*Test.as'
148
+ end
149
+
150
+ def test_glob=(glob)
151
+ @test_glob = glob
152
+ end
153
+
154
+ # Collection of all test case files either assigned or found
155
+ # using the test_glob as provided.
156
+ def test_cases
157
+ @test_cases ||= Dir.glob(test_dir + test_glob)
158
+ end
159
+
160
+ def test_cases=(collection)
161
+ @test_cases = collection
162
+ end
163
+
164
+ # Get the list of test_cases (which are files) as a
165
+ # list of fully qualified class names
166
+ def test_case_classes
167
+ @test_case_classes = self.test_cases.dup
168
+ @test_case_classes.collect! do |file|
169
+ actionscript_file_to_class_name(file)
170
+ end
171
+ @test_case_classes
172
+ end
173
+
174
+ # Transform a file name in the source or test path
175
+ # to a fully-qualified class name
176
+ def actionscript_file_to_class_name(file)
177
+ name = file.dup
178
+ name.gsub!(/^#{Dir.pwd}\//, '')
179
+ name.gsub!(/^#{test_dir}\//, '')
180
+ name.gsub!(/^#{src_dir}\//, '')
181
+ name.gsub!(/.as$/, '')
182
+ name.gsub!(/#{File::SEPARATOR}/, '.')
183
+ return name
184
+ end
185
+
186
+ protected
187
+
188
+ def banner
189
+ "Usage: #{$0} [options] packagename.ClassName"
190
+ end
191
+
192
+ def model
193
+ @model ||= ProjectModel.instance
194
+ end
195
+
196
+ def assign_names!(name)
197
+ # trim file name suffix in case it was submitted
198
+ name.gsub!(/\//, '.')
199
+ name.gsub!(/\.as$/, '')
200
+ name.gsub!(/\.mxml$/, '')
201
+ if(model)
202
+ # Pull leading src_dir from class name if submitted
203
+ name.gsub!(/^#{src_dir}\./, '')
204
+ name.gsub!(/^#{test_dir}\./, '')
205
+ end
206
+
207
+ if(name.match(/Test$/))
208
+ @user_requested_test = true
209
+ name = name.gsub(/Test$/, '')
210
+ end
211
+ if(name.match(/^I/) || name.match(/able$/))
212
+ @user_requested_interface = true
213
+ end
214
+
215
+ @full_class_name = name
216
+ parts = name.split('.')
217
+ @class_name = parts.pop
218
+ @package_name = parts.join('.')
219
+ @class_file = @full_class_name.split('.').join(File::SEPARATOR) + '.as'
220
+ @class_dir = File.dirname(@class_file)
221
+ if(@class_dir == '.')
222
+ @class_dir = ''
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end
@@ -0,0 +1,7 @@
1
+ # gem 'activesupport', '>= 2.0.2'
2
+ gem 'rubigen'
3
+ require 'rubigen'
4
+ require 'sprout/generator/base_mixins'
5
+ require 'sprout/generator/named_base'
6
+
7
+ # This is the entry point for sprout generator features
data/lib/sprout/log.rb ADDED
@@ -0,0 +1,46 @@
1
+
2
+ module Sprout #:nodoc:
3
+
4
+ class Log #:nodoc:
5
+ @@debug = false
6
+ @@output = ''
7
+ @@printout = ''
8
+
9
+ def Log.debug=(debug)
10
+ @@debug = debug
11
+ end
12
+
13
+ def Log.debug
14
+ return @@debug
15
+ end
16
+
17
+ def Log.puts(msg)
18
+ @@output << msg + "\n"
19
+ Log.flush
20
+ end
21
+
22
+ def Log.print(msg)
23
+ @@printout << msg
24
+ Log.flush_print
25
+ end
26
+
27
+ def Log.printf(msg)
28
+ @@printout << msg
29
+ Log.flush_print
30
+ end
31
+
32
+ def Log.flush_print
33
+ if(!Log.debug)
34
+ $stdout.print @@printout
35
+ @@printout = ''
36
+ end
37
+ end
38
+
39
+ def Log.flush
40
+ if(!Log.debug)
41
+ $stdout.puts @@output
42
+ @@output = ''
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,111 @@
1
+
2
+ module Sprout #:nodoc:
3
+ class ProcessRunnerError < StandardError # :nodoc:
4
+ end
5
+
6
+ class ProcessRunner #:nodoc:
7
+ attr_reader :pid,
8
+ :r,
9
+ :w,
10
+ :e
11
+
12
+ def initialize(*command)
13
+ @command = command
14
+ begin
15
+ @alive = true
16
+ usr = User.new()
17
+ if(usr.is_a?(WinUser) && !usr.is_a?(CygwinUser))
18
+ gem 'win32-open3', '0.2.5'
19
+ require 'win32/open3'
20
+ Open3.popen3(*@command) do |w, r, e, pid|
21
+ @w = w
22
+ @r = r
23
+ @e = e
24
+ @pid = pid
25
+ end
26
+ else
27
+ require 'open4'
28
+ @pid, @w, @r, @e = open4.popen4(*@command)
29
+ end
30
+ rescue Errno::EACCES => e
31
+ update_executable_mode(*@command)
32
+ @pid, @w, @r, @e = open4.popen4(*@command)
33
+ rescue Errno::ENOENT => e
34
+ @alive = false
35
+ part = command[0].split(' ').shift
36
+ raise ProcessRunnerError.new("The expected executable was not found for command [#{part}], please check your system path and/or sprout definition")
37
+ end
38
+ end
39
+
40
+ def update_executable_mode(*command)
41
+ parts = command.join(' ').split(' ')
42
+ str = parts.shift
43
+ while(parts.size > 0)
44
+ if(File.exists?(str))
45
+ FileUtils.chmod(744, str)
46
+ return
47
+ else
48
+ str << " #{parts.shift}"
49
+ end
50
+ end
51
+ end
52
+
53
+ def alive?
54
+ @alive = update_status
55
+ end
56
+
57
+ def kill
58
+ Process.kill(9, pid)
59
+ end
60
+
61
+ def close
62
+ update_status
63
+ end
64
+
65
+ def update_status
66
+ pid_int = Integer("#{ @pid }")
67
+ begin
68
+ Process::kill 0, pid_int
69
+ true
70
+ rescue Errno::ESRCH
71
+ false
72
+ end
73
+ end
74
+
75
+ def readpartial(count)
76
+ @r.readpartial(count)
77
+ end
78
+
79
+ def readlines
80
+ @r.readlines
81
+ end
82
+
83
+ def flush
84
+ @w.flush
85
+ end
86
+
87
+ def getc
88
+ @r.getc
89
+ end
90
+
91
+ def print(msg)
92
+ @w.print msg
93
+ end
94
+
95
+ def puts(msg)
96
+ @w.puts(msg)
97
+ end
98
+
99
+ def close_write
100
+ @w.close_write
101
+ end
102
+
103
+ def read
104
+ return @r.read
105
+ end
106
+
107
+ def read_err
108
+ return @e.read
109
+ end
110
+ end
111
+ end