sprout 0.7.219-i686-darwin10

Sign up to get free protection for your applications and to get access to all the features.
@@ -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
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
@@ -0,0 +1,278 @@
1
+
2
+ module Sprout
3
+ # The ProjectModel gives you a place to describe your project so that you
4
+ # don't need to repeat yourself throughout a rakefile.
5
+ #
6
+ # The default set of properties are also used from code generators, library tasks and sometimes tools.
7
+ #
8
+ # The ProjectModel can be configured as follows:
9
+ # project_model :model do |p|
10
+ # p.name = 'SomeProject'
11
+ # p.source_path << 'somedir/otherdir'
12
+ # p.library_path << 'somedir'
13
+ # end
14
+ #
15
+ # This class should have some reasonable default values, but can be modified from any rakefile.
16
+ # If you don't find some properties that you'd like on the ProjectModel, you can simply add
17
+ # new properties and use them however you wish.
18
+ #
19
+ # Arbitrary properties can be added as follows:
20
+ # m = project_model :model do |p|
21
+ # p.unknown_property = 'someValue'
22
+ # end
23
+ #
24
+ # puts "Unknown Property: #{m.unknown_property}"
25
+ #
26
+ # The ProjectModel is typically treated as if it is a Singleton, and many helper tasks
27
+ # will automatically go look for their model at:
28
+ #
29
+ # Sprout::ProjectModel.instance
30
+ #
31
+ # Unlike a real Singleton, this static property will actually be populated with the most
32
+ # recently instantiated ProjectModel, and any well-behaved helper task will also
33
+ # allow you to send in a model as a prerequisite.
34
+ #
35
+ # project_model :model_a
36
+ # project_model :model_b
37
+ #
38
+ # desc 'Compile and run a'
39
+ # debug :debug_a => :model_a
40
+ #
41
+ # desc 'Compile and run b'
42
+ # debug :debug_b => :model_b
43
+ #
44
+ class ProjectModel < Hash
45
+
46
+ # Relative path to the folder where compile time assets will be stored
47
+ attr_accessor :asset_dir
48
+ # The folder where binary files will be created. Usually this is where any build artifacts like SWF files get placed.
49
+ attr_accessor :bin_dir
50
+ # The Background Color of the SWF file
51
+ attr_accessor :background_color
52
+ # Contributors to the SWF file
53
+ attr_accessor :contributors
54
+ # If you don't want to use the default compiler for your language
55
+ # set it manually here.
56
+ # Possible values are:
57
+ # * sprout-flex2sdk-tool
58
+ # * sprout-flex3sdk-tool
59
+ # * sprout-flex4sdk-tool (Experimental)
60
+ # * sprout-mtasc-tool
61
+ attr_accessor :compiler_gem_name
62
+ # The version number of the compiler gem to use
63
+ attr_accessor :compiler_gem_version
64
+ # The primary creator of the SWF file
65
+ attr_accessor :creator
66
+ # Directory where documentation should be placed.
67
+ attr_accessor :doc_dir
68
+ # CSS documents that should be individually compiled
69
+ # for runtime stylesheet loading.
70
+ attr_accessor :external_css
71
+ # The default frame rate of the SWF file
72
+ attr_accessor :frame_rate
73
+ # The default height of the SWF file
74
+ # _(This value is overridden when embedded in an HTML page)_
75
+ attr_accessor :height
76
+ # The technology language that is being used, right now this value can be 'as2', 'as3' or 'mxml'.
77
+ # Code generators take advantage of this setting to determine which templates to use
78
+ # and build tasks use this setting to determin the input file suffix (.as or .mxml).
79
+ attr_accessor :language
80
+ # The relative path to your library directory. Defaults to 'lib'
81
+ #
82
+ # Any remote .SWC and source libraries that are referenced in your rakefile will be installed
83
+ # into this directory. Source libraries will be placed in a folder that matches the library name,
84
+ # while SWCs will be simply placed directly into the lib_dir.
85
+ attr_accessor :lib_dir
86
+ # Array of sprout library symbols
87
+ attr_accessor :libraries
88
+ # The Array of SWC paths to add to all compilation tasks
89
+ attr_accessor :library_path
90
+ # The locale for the SWF file
91
+ attr_accessor :locale
92
+ # A collection of Flex Module root source files. If this collection
93
+ # has items added to it, the deploy task will generate a 'link_report' from
94
+ # the main application compilation and then consume it as 'load_externs' for
95
+ # each module compilation.
96
+ attr_accessor :modules
97
+ # Organization responsible for this SWF file
98
+ attr_accessor :organization
99
+ # The production file that this Project will generate
100
+ attr_accessor :output
101
+ # Terminal command to preprocessor application that accepts STDIN and returns on STDOUT
102
+ attr_accessor :preprocessor
103
+ # Folder where preprocessed files will be created. Defaults to '.preprocessed'
104
+ attr_accessor :preprocessed_path
105
+ # The real name of the project, usually capitalized like a class name 'SomeProject'
106
+ attr_accessor :project_name
107
+ # The folder where compile time skins can be loaded from
108
+ attr_accessor :skin_dir
109
+ # The skin file that will be generated
110
+ attr_accessor :skin_output
111
+ # The Array of source paths to add to all compilation tasks
112
+ # _Do not add task-specific paths (like lib/asunit) to this value_
113
+ attr_accessor :source_path
114
+ # The relative path to your main source directory. Defaults to 'src'
115
+ attr_accessor :src_dir
116
+ # Enforce strict type checking
117
+ attr_accessor :strict
118
+ # The relative path to the directory where swc files should be kept.
119
+ # This value defaults to lib_dir
120
+ attr_accessor :swc_dir
121
+ # Relative path to the folder that contains your test cases
122
+ attr_accessor :test_dir
123
+ # The test executable
124
+ attr_accessor :test_output
125
+ # The test runner SWF height
126
+ attr_accessor :test_height
127
+ # The test runner SWF width
128
+ attr_accessor :test_width
129
+ # Tasks that can, will use the Flex Compiler SHell.
130
+ attr_accessor :use_fcsh
131
+ # Flash Player Tasks will launch using the Flex Debugger.
132
+ attr_accessor :use_fdb
133
+ # The default width of the SWF file
134
+ # _(This value is overridden when embedded in an HTML page)_
135
+ attr_accessor :width
136
+
137
+ # Static method that returns the most recently instantiated ProjectModel,
138
+ # or instantiates one if none have been created yet.
139
+ def self.instance
140
+ @@instance ||= ProjectModel.new
141
+ yield @@instance if block_given?
142
+ return @@instance
143
+ end
144
+
145
+ # Decorates the static instance method.
146
+ def self.setup
147
+ @@instance ||= ProjectModel.new
148
+ yield @@instance if block_given?
149
+ return @@instance
150
+ end
151
+
152
+ def self.destroy # :nodoc:
153
+ @@instance = nil
154
+ end
155
+
156
+ def initialize
157
+ super
158
+ @project_name = ''
159
+ @doc_dir = 'doc'
160
+ @src_dir = 'src'
161
+ @lib_dir = 'lib'
162
+ @swc_dir = 'lib'
163
+ @bin_dir = 'bin'
164
+ @test_dir = 'test'
165
+ @asset_dir = 'assets'
166
+ @skin_dir = File.join(@asset_dir, 'skins')
167
+ @frame_rate = 24
168
+ @language = 'as3'
169
+
170
+ @external_css = []
171
+ @libraries = []
172
+ @library_path = []
173
+ @modules = []
174
+ @source_path = []
175
+
176
+ @model_dir = nil
177
+ @view_dir = nil
178
+ @controller_dir = nil
179
+
180
+ @test_height = 550
181
+ @test_width = 900
182
+ @@instance = self
183
+ end
184
+
185
+ # Path to the project directory from which all other paths are created
186
+ def project_path
187
+ return Sprout.project_path
188
+ end
189
+
190
+ def model_dir=(dir)
191
+ @model_dir = dir
192
+ end
193
+
194
+ # Simple MVC helper for project-wide models if your project is called 'SomeProject'
195
+ # this will default to:
196
+ # SomeProject/src/someproject/models
197
+ def model_dir
198
+ if(@model_dir.nil?)
199
+ @model_dir = File.join(src_dir, project_name.downcase, 'models')
200
+ end
201
+ return @model_dir
202
+ end
203
+
204
+ def view_dir=(dir)
205
+ @view_dir = dir
206
+ end
207
+
208
+ # Simple MVC helper for project-wide views if your project is called 'SomeProject'
209
+ # this will default to:
210
+ # SomeProject/src/someproject/views
211
+ def view_dir
212
+ if(@view_dir.nil?)
213
+ @view_dir = File.join(src_dir, project_name.downcase, 'views')
214
+ end
215
+ return @view_dir
216
+ end
217
+
218
+ def controller_dir=(dir)
219
+ @controller_dir = dir
220
+ end
221
+
222
+ # Simple MVC helper for project-wide views if your project is called 'SomeProject'
223
+ # this will default to:
224
+ # SomeProject/src/someproject/controllers
225
+ def controller_dir
226
+ if(@controller_dir.nil?)
227
+ @controller_dir = File.join(src_dir, project_name.downcase, 'controllers')
228
+ end
229
+ return @controller_dir
230
+ end
231
+
232
+ # Alias for project_name
233
+ def name=(name)
234
+ @project_name = name
235
+ end
236
+
237
+ def name
238
+ @project_name
239
+ end
240
+
241
+ def to_s
242
+ return "[Sprout::ProjectModel project_name=#{project_name}]"
243
+ end
244
+
245
+ protected
246
+
247
+ def method_missing(method_name, *args)
248
+ method_name = method_name.to_s
249
+ if method_name =~ /=$/
250
+ super if args.size > 1
251
+ self[method_name[0...-1]] = args[0]
252
+ else
253
+ super unless has_key?(method_name) and args.empty?
254
+ self[method_name]
255
+ end
256
+ end
257
+ end
258
+ end
259
+
260
+ # Helper method to expose the project model as a Rake Task
261
+ def project_model(task_name)
262
+ model = Sprout::ProjectModel.new
263
+ yield model if block_given?
264
+
265
+ t = task task_name
266
+
267
+ def t.project_model=(model)
268
+ @model = model
269
+ end
270
+
271
+ def t.project_model
272
+ return @model
273
+ end
274
+
275
+ t.project_model = model
276
+ return model
277
+ end
278
+