sprout 1.0.35.pre → 1.1.2.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 (234) hide show
  1. data/Gemfile +1 -1
  2. data/Gemfile.lock +0 -2
  3. data/README.textile +1 -1
  4. data/VERSION +1 -1
  5. data/lib/sprout/concern.rb +5 -7
  6. data/lib/sprout/daemon.rb +183 -143
  7. data/lib/sprout/executable/base.rb +564 -0
  8. data/lib/sprout/executable.rb +1 -550
  9. data/lib/sprout/generator/base.rb +2 -3
  10. data/lib/sprout/generator.rb +2 -1
  11. data/lib/sprout/generators/ruby/templates/ruby_base.rb +1 -2
  12. data/lib/sprout/library.rb +3 -3
  13. data/lib/sprout/output_buffer.rb +35 -0
  14. data/lib/sprout/process_runner.rb +68 -17
  15. data/lib/sprout/progress_bar.rb +5 -5
  16. data/lib/sprout/remote_file_target.rb +1 -1
  17. data/lib/sprout/system/base_system.rb +3 -3
  18. data/lib/sprout/system/unix_system.rb +1 -1
  19. data/lib/sprout/{test/sprout_test_case.rb → test_helper.rb} +214 -14
  20. data/lib/sprout/version.rb +1 -1
  21. data/lib/sprout.rb +133 -2
  22. data/rakefile.rb +2 -0
  23. data/test/fixtures/examples/echo_inputs.rb +1 -2
  24. data/test/fixtures/executable/fdb.rb +7 -9
  25. data/test/fixtures/executable/flex3sdk_gem/fdb +49 -18
  26. data/test/fixtures/executable/mxmlc.rb +1 -2
  27. data/test/fixtures/executable/subclass/executable_subclass.rb +0 -1
  28. data/test/fixtures/executable/subclass/executable_superclass.rb +1 -2
  29. data/test/fixtures/specification/flex4sdk.rb +35 -24
  30. data/test/unit/archive_unpacker_test.rb +1 -1
  31. data/test/unit/boolean_param_test.rb +1 -1
  32. data/test/unit/daemon_test.rb +35 -3
  33. data/test/unit/executable_option_parser_test.rb +2 -3
  34. data/test/unit/executable_param_test.rb +1 -1
  35. data/test/unit/executable_test.rb +8 -15
  36. data/test/unit/fake_other_executable.rb +1 -2
  37. data/test/unit/file_param_test.rb +1 -1
  38. data/test/unit/file_target_test.rb +1 -1
  39. data/test/unit/files_param_test.rb +1 -1
  40. data/test/unit/generator_generator_test.rb +1 -1
  41. data/test/unit/generator_test.rb +1 -1
  42. data/test/unit/library_generator_test.rb +1 -1
  43. data/test/unit/library_test.rb +1 -1
  44. data/test/unit/osx_system_test.rb +1 -1
  45. data/test/unit/path_param_test.rb +1 -1
  46. data/test/unit/paths_param_test.rb +1 -1
  47. data/test/unit/platform_test.rb +1 -1
  48. data/test/unit/process_runner_test.rb +1 -1
  49. data/test/unit/rdoc_parser_test.rb +1 -1
  50. data/test/unit/remote_file_loader_test.rb +1 -1
  51. data/test/unit/remote_file_target_test.rb +1 -1
  52. data/test/unit/ruby_feature_test.rb +1 -1
  53. data/test/unit/ruby_generator_test.rb +1 -1
  54. data/test/unit/specification_test.rb +8 -1
  55. data/test/unit/sprout_test.rb +2 -2
  56. data/test/unit/string_param_test.rb +1 -1
  57. data/test/unit/string_test.rb +1 -1
  58. data/test/unit/strings_param_test.rb +1 -1
  59. data/test/unit/test_helper.rb +33 -1
  60. data/test/unit/tool_generator_test.rb +1 -1
  61. data/test/unit/unix_system_test.rb +1 -1
  62. data/test/unit/user_test.rb +1 -1
  63. data/test/unit/vista_system_test.rb +1 -1
  64. data/test/unit/win_nix_system_test.rb +1 -1
  65. data/test/unit/win_system_test.rb +1 -1
  66. data/test-stderr.log +1 -0
  67. data/test-stdout.log +237 -0
  68. metadata +15 -190
  69. data/doc/Dir.html +0 -288
  70. data/doc/Rake/Task.html +0 -184
  71. data/doc/Sprout/ArchiveUnpacker.html +0 -1246
  72. data/doc/Sprout/Base/ClassMethods.html +0 -434
  73. data/doc/Sprout/Base.html +0 -126
  74. data/doc/Sprout/Concern.html +0 -353
  75. data/doc/Sprout/Daemon/ClassMethods.html +0 -244
  76. data/doc/Sprout/Daemon/InstanceMethods.html +0 -601
  77. data/doc/Sprout/Daemon.html +0 -166
  78. data/doc/Sprout/Errors/ArchiveUnpackerError.html +0 -125
  79. data/doc/Sprout/Errors/DestinationExistsError.html +0 -133
  80. data/doc/Sprout/Errors/DuplicateMemberError.html +0 -132
  81. data/doc/Sprout/Errors/ExecutableError.html +0 -125
  82. data/doc/Sprout/Errors/ExecutableRegistrationError.html +0 -132
  83. data/doc/Sprout/Errors/ExecutionError.html +0 -121
  84. data/doc/Sprout/Errors/GeneratorError.html +0 -125
  85. data/doc/Sprout/Errors/InvalidArgumentError.html +0 -132
  86. data/doc/Sprout/Errors/LoadError.html +0 -121
  87. data/doc/Sprout/Errors/MissingArgumentError.html +0 -132
  88. data/doc/Sprout/Errors/MissingExecutableError.html +0 -132
  89. data/doc/Sprout/Errors/MissingGeneratorError.html +0 -132
  90. data/doc/Sprout/Errors/MissingTemplateError.html +0 -132
  91. data/doc/Sprout/Errors/ProcessRunnerError.html +0 -121
  92. data/doc/Sprout/Errors/RemoteFileLoaderError.html +0 -110
  93. data/doc/Sprout/Errors/SproutError.html +0 -114
  94. data/doc/Sprout/Errors/UnknownArchiveType.html +0 -122
  95. data/doc/Sprout/Errors/UsageError.html +0 -121
  96. data/doc/Sprout/Errors/ValidationError.html +0 -121
  97. data/doc/Sprout/Errors/VersionRequirementNotMetError.html +0 -121
  98. data/doc/Sprout/Errors.html +0 -101
  99. data/doc/Sprout/Executable/Boolean.html +0 -483
  100. data/doc/Sprout/Executable/ClassMethods.html +0 -417
  101. data/doc/Sprout/Executable/CollectionParam.html +0 -483
  102. data/doc/Sprout/Executable/FileParam.html +0 -484
  103. data/doc/Sprout/Executable/Files.html +0 -292
  104. data/doc/Sprout/Executable/InstanceMethods.html +0 -2006
  105. data/doc/Sprout/Executable/Number.html +0 -141
  106. data/doc/Sprout/Executable/Param.html +0 -2818
  107. data/doc/Sprout/Executable/ParameterFactory.html +0 -232
  108. data/doc/Sprout/Executable/Path.html +0 -223
  109. data/doc/Sprout/Executable/Paths.html +0 -253
  110. data/doc/Sprout/Executable/StringParam.html +0 -213
  111. data/doc/Sprout/Executable/Strings.html +0 -167
  112. data/doc/Sprout/Executable/Url.html +0 -160
  113. data/doc/Sprout/Executable/Urls.html +0 -170
  114. data/doc/Sprout/Executable.html +0 -173
  115. data/doc/Sprout/FileTarget.html +0 -1109
  116. data/doc/Sprout/Generator/Base.html +0 -1626
  117. data/doc/Sprout/Generator/Command.html +0 -690
  118. data/doc/Sprout/Generator/DirectoryManifest.html +0 -476
  119. data/doc/Sprout/Generator/FileManifest.html +0 -572
  120. data/doc/Sprout/Generator/Manifest.html +0 -377
  121. data/doc/Sprout/Generator/TemplateManifest.html +0 -196
  122. data/doc/Sprout/Generator.html +0 -689
  123. data/doc/Sprout/GeneratorGenerator.html +0 -1018
  124. data/doc/Sprout/Library.html +0 -1141
  125. data/doc/Sprout/LibraryGenerator.html +0 -309
  126. data/doc/Sprout/Log.html +0 -496
  127. data/doc/Sprout/MXMLC.html +0 -6373
  128. data/doc/Sprout/Platform.html +0 -714
  129. data/doc/Sprout/ProcessRunner.html +0 -1352
  130. data/doc/Sprout/ProgressBar.html +0 -376
  131. data/doc/Sprout/ProgressBarImpl.html +0 -2119
  132. data/doc/Sprout/ProgressBarManager.html +0 -434
  133. data/doc/Sprout/ProgressBarOutputStream.html +0 -416
  134. data/doc/Sprout/RDocParser.html +0 -211
  135. data/doc/Sprout/RemoteFileLoader.html +0 -172
  136. data/doc/Sprout/RemoteFileTarget.html +0 -679
  137. data/doc/Sprout/ReversedProgressBar.html +0 -194
  138. data/doc/Sprout/RubyFeature/ClassMethods.html +0 -1065
  139. data/doc/Sprout/RubyFeature.html +0 -155
  140. data/doc/Sprout/RubyGenerator.html +0 -764
  141. data/doc/Sprout/Specification.html +0 -767
  142. data/doc/Sprout/System/BaseSystem.html +0 -1455
  143. data/doc/Sprout/System/JavaSystem.html +0 -122
  144. data/doc/Sprout/System/OSXSystem.html +0 -335
  145. data/doc/Sprout/System/ThreadMock.html +0 -193
  146. data/doc/Sprout/System/UnixSystem.html +0 -584
  147. data/doc/Sprout/System/VistaSystem.html +0 -251
  148. data/doc/Sprout/System/WinNixSystem.html +0 -325
  149. data/doc/Sprout/System/WinSystem.html +0 -571
  150. data/doc/Sprout/System.html +0 -191
  151. data/doc/Sprout/ToolGenerator.html +0 -931
  152. data/doc/Sprout/VERSION.html +0 -128
  153. data/doc/Sprout.html +0 -144
  154. data/doc/SproutTestCase.html +0 -1412
  155. data/doc/String.html +0 -286
  156. data/doc/_index.html +0 -1035
  157. data/doc/class_list.html +0 -36
  158. data/doc/css/common.css +0 -1
  159. data/doc/css/full_list.css +0 -53
  160. data/doc/css/style.css +0 -310
  161. data/doc/file.README.html +0 -96
  162. data/doc/file.archive_unpacker.html +0 -288
  163. data/doc/file.base.html +0 -208
  164. data/doc/file.base_system.html +0 -278
  165. data/doc/file.boolean.html +0 -135
  166. data/doc/file.collection_param.html +0 -139
  167. data/doc/file.command.html +0 -126
  168. data/doc/file.concern.html +0 -136
  169. data/doc/file.daemon.html +0 -309
  170. data/doc/file.dir.html +0 -76
  171. data/doc/file.directory_manifest.html +0 -122
  172. data/doc/file.errors.html +0 -147
  173. data/doc/file.executable.html +0 -638
  174. data/doc/file.file_manifest.html +0 -109
  175. data/doc/file.file_param.html +0 -120
  176. data/doc/file.file_target.html +0 -140
  177. data/doc/file.files.html +0 -85
  178. data/doc/file.generator.html +0 -296
  179. data/doc/file.generator_class.html +0 -72
  180. data/doc/file.generator_generator.html +0 -137
  181. data/doc/file.generator_test.html +0 -92
  182. data/doc/file.generator_test_helper.html +0 -67
  183. data/doc/file.java_system.html +0 -62
  184. data/doc/file.library.html +0 -291
  185. data/doc/file.library_generator.html +0 -74
  186. data/doc/file.log.html +0 -100
  187. data/doc/file.manifest.html +0 -67
  188. data/doc/file.mxmlc.html +0 -740
  189. data/doc/file.number.html +0 -67
  190. data/doc/file.osx_system.html +0 -79
  191. data/doc/file.param.html +0 -491
  192. data/doc/file.parameter_factory.html +0 -119
  193. data/doc/file.path.html +0 -81
  194. data/doc/file.paths.html +0 -80
  195. data/doc/file.platform.html +0 -124
  196. data/doc/file.process_runner.html +0 -224
  197. data/doc/file.progress_bar.html +0 -390
  198. data/doc/file.rdoc_parser.html +0 -145
  199. data/doc/file.remote_file_loader.html +0 -117
  200. data/doc/file.remote_file_target.html +0 -176
  201. data/doc/file.ruby_base.html +0 -64
  202. data/doc/file.ruby_feature.html +0 -244
  203. data/doc/file.ruby_generator.html +0 -118
  204. data/doc/file.ruby_input.html +0 -62
  205. data/doc/file.ruby_test_case.html +0 -78
  206. data/doc/file.ruby_test_helper.html +0 -61
  207. data/doc/file.specification.html +0 -248
  208. data/doc/file.sprout.html +0 -64
  209. data/doc/file.sprout_test_case.html +0 -280
  210. data/doc/file.string.html +0 -72
  211. data/doc/file.string_param.html +0 -76
  212. data/doc/file.strings.html +0 -71
  213. data/doc/file.system.html +0 -86
  214. data/doc/file.template_manifest.html +0 -67
  215. data/doc/file.tool.html +0 -92
  216. data/doc/file.tool_generator.html +0 -90
  217. data/doc/file.unix_system.html +0 -128
  218. data/doc/file.url.html +0 -71
  219. data/doc/file.urls.html +0 -70
  220. data/doc/file.version.html +0 -71
  221. data/doc/file.vista_system.html +0 -69
  222. data/doc/file.win_nix_system.html +0 -88
  223. data/doc/file.win_system.html +0 -129
  224. data/doc/file_list.html +0 -230
  225. data/doc/frames.html +0 -13
  226. data/doc/index.html +0 -96
  227. data/doc/js/app.js +0 -202
  228. data/doc/js/full_list.js +0 -149
  229. data/doc/js/jquery.js +0 -154
  230. data/doc/method_list.html +0 -3355
  231. data/doc/top-level-namespace.html +0 -192
  232. data/lib/sprout/base.rb +0 -121
  233. data/lib/sprout/log.rb +0 -46
  234. data/test/unit/sprout_test_helper.rb +0 -33
@@ -12,6 +12,7 @@ require 'sprout/executable/url'
12
12
  require 'sprout/executable/urls'
13
13
  require 'sprout/executable/parameter_factory'
14
14
  require 'rake/clean'
15
+ require 'sprout/executable/base'
15
16
 
16
17
  module Sprout
17
18
 
@@ -36,556 +37,6 @@ module Sprout
36
37
  DEFAULT_PREFIX = '--'
37
38
  DEFAULT_SHORT_PREFIX = '-'
38
39
 
39
- extend Concern
40
-
41
- module ClassMethods
42
- ##
43
- # +add_param+ is the workhorse of the Task.
44
- # This method is used to add new shell parameters to the executable interface.
45
- #
46
- # +name+ is a symbol or string that represents the parameter that you would like to add
47
- # such as :debug or :source_path.
48
- #
49
- # +type+ is a class reference of the Executable::Param that you'd like to use.
50
- # At the time of this writing, add_param will accept 2 class references that
51
- # do not extend Param - String and File. The ParameterFactory will automatically
52
- # resolve these to the correct data type when they are created.
53
- #
54
- # Boolean true or false
55
- # File Path to a file
56
- # Number Any number
57
- # Path Path to a directory
58
- # String Any string value
59
- # Url Basic URL
60
- #
61
- # Files Collection of files
62
- # Paths Collection of directories
63
- # Strings Collection of arbitrary strings
64
- # Urls Collection of URLs
65
- #
66
- # Be sure to check out the Sprout::Executable::Param class to learn more about
67
- # working with executable parameters.
68
- #
69
- # Once parameters have been added using the +add_param+ method, clients
70
- # can set and get those parameters from any newly created executable instance,
71
- # or from the command line.
72
- #
73
- # In the case of an executable delegate, parameter values will be sent to the
74
- # command line executable in the order they are added using +add_param+.
75
- #
76
- # In the case of a Ruby executable, command line parameters will be interpreted
77
- # in the order they are defined using +add_param+.
78
- #
79
- def add_param(name, type, options=nil) # :yields: Sprout::Executable::Param
80
- raise Sprout::Errors::UsageError.new "[DEPRECATED] add_param no longer uses closures, you can provide the same values as a hash in the optional last argument." if block_given?
81
- raise Sprout::Errors::UsageError.new "The first parameter (name:SymbolOrString) is required" if name.nil?
82
- raise Sprout::Errors::UsageError.new "The second parameter (type:Class) is required" if type.nil?
83
- raise Sprout::Errors::UsageError.new "The type parameter must be a Class by reference" if !type.is_a?(Class)
84
-
85
- options ||= {}
86
- options[:name] = name
87
- options[:type] = type
88
- # TODO: Integrate the RDOC-parsed parameter description here:
89
- #options[:description] ||= Sprout::RDocParser.description_for_caller caller.shift
90
-
91
- create_param_accessors options
92
- static_parameter_collection << options
93
- options
94
- end
95
-
96
- def add_param_alias new_name, old_name
97
- create_param_accessors :name => new_name, :real_name => old_name
98
- end
99
-
100
- def static_parameter_collection
101
- @static_parameter_collection ||= []
102
- end
103
-
104
- def static_default_value_collection
105
- @static_default_value_collection ||= []
106
- end
107
-
108
- def set key, value
109
- set_default_value key, value
110
- end
111
-
112
- private
113
-
114
- def accessor_can_be_defined_at name
115
- if(instance_defines? name)
116
- message = "add_param called with a name that is already in use (#{name}=) on (#{self})"
117
- raise Sprout::Errors::DuplicateMemberError.new(message)
118
- end
119
- end
120
-
121
- def create_param_accessors options
122
- name = options[:name]
123
- real_name = options[:real_name] || name
124
- accessor_can_be_defined_at name
125
-
126
- # define the writer:
127
- define_method("#{name}=") do |value|
128
- if(!options[:writer].nil?)
129
- value = self.send(options[:writer], value)
130
- end
131
- param_hash[real_name].value = value
132
- instance_variable_set("@#{name}", value)
133
- end
134
-
135
- # define the reader:
136
- define_method(name) do
137
- if(options[:reader].nil?)
138
- if(param_hash[real_name].nil?)
139
- raise Sprout::Errors::UsageError.new "Unable to use requested parameter (#{real_name}) try adding it using:\n\n add_param :#{real_name}, String\n\n"
140
- end
141
- param_hash[real_name].value
142
- else
143
- self.send(options[:reader])
144
- end
145
- end
146
- end
147
-
148
- def instance_defines? name
149
- # In Ruby 1.9.1 instance_methods are symbols,
150
- # In Ruby 1.8.7 instance_methods are strings.
151
- # Boo.
152
- self.instance_methods.include?(name.to_s) ||
153
- self.instance_methods.include?(name)
154
- end
155
-
156
- def set_default_value key, value
157
- if(!defined? key)
158
- raise Sprout::Errors::UsageError.new("Cannot set default value (#{value}) for unknown parameter (#{key})")
159
- end
160
- static_default_value_collection << { :name => key, :value => value }
161
- end
162
- end
163
-
164
- module InstanceMethods
165
- ##
166
- # The default RubyGem that we will use when requesting our executable.
167
- #
168
- # Classes that include the Executable can set the default value for this property
169
- # at the class level with:
170
- #
171
- # set :pkg_name, 'sprout-sometoolname'
172
- #
173
- # But that value can be overridden on each instance like:
174
- #
175
- # executable = SomeToolTask.new
176
- # executable.pkg_name = 'sprout-othertoolname'
177
- #
178
- # This parameter is required - either from the including class or instance
179
- # configuration.
180
- #
181
- attr_accessor :pkg_name
182
-
183
- ##
184
- # The default RubyGem version that we will use when requesting our executable.
185
- #
186
- # Classes that include the Task can set the default value for this property
187
- # at the class level with:
188
- #
189
- # set :pkg_version, '>= 1.0.3'
190
- #
191
- # But that value can be overriden on each instance like:
192
- #
193
- # executable = SomeToolTask.new
194
- # too.pkg_version = '>= 2.0.0'
195
- #
196
- # This parameter is required - either from the including class or instance
197
- # configuration.
198
- #
199
- attr_accessor :pkg_version
200
-
201
-
202
- ##
203
- # The default command line prefix that should be used in front of parameter
204
- # names.
205
- #
206
- # The default value for this parameter is '--', but some command line
207
- # applications (like MXMLC) prefer '-'.
208
- #
209
- attr_accessor :default_prefix
210
-
211
- ##
212
- # The default command line prefix for short name parameters.
213
- #
214
- # This value defaults to '-', but can be changed to whatever a particular
215
- # tool prefers.
216
- #
217
- attr_accessor :default_short_prefix
218
-
219
- ##
220
- # The default Sprout executable that we will use for this executable.
221
- #
222
- # Classes that include the Task can set the default value for this property
223
- # at the class level with:
224
- #
225
- # set :executable, :mxmlc
226
- #
227
- # But that value can be overriden on each instance like:
228
- #
229
- # executable = SomeToolTask.new
230
- # too.executable :compc
231
- #
232
- # This parameter is required - either from the including class or instance
233
- # configuration.
234
- #
235
- attr_accessor :executable
236
-
237
- ##
238
- # Configure the executable instance to output failure messages to
239
- # stderr and abort with non-zero response.
240
- attr_accessor :abort_on_failure
241
-
242
- ##
243
- # If the executable is configured as a Rake::Task, it will extract the
244
- # Rake::Task[:name] property and apply it to this field.
245
- #
246
- # Concrete parameters can pull this value from their +belongs_to+
247
- # parameter.
248
- attr_accessor :rake_task_name
249
-
250
- attr_reader :param_hash
251
- attr_reader :params
252
- attr_reader :prerequisites
253
-
254
- def initialize
255
- super
256
- @abort_on_failure = true
257
- @appended_args = nil
258
- @prepended_args = nil
259
- @param_hash = {}
260
- @params = []
261
- @prerequisites = []
262
- @option_parser = OptionParser.new
263
- @default_prefix = DEFAULT_PREFIX
264
- @default_short_prefix = DEFAULT_SHORT_PREFIX
265
- initialize_defaults
266
- initialize_parameters
267
- end
268
-
269
- def parse! commandline_options
270
- begin
271
- option_parser.parse! commandline_options
272
- parse_extra_options! commandline_options
273
- validate unless help_requested? commandline_options
274
- rescue StandardError => e
275
- handle_parse_error e
276
- end
277
- end
278
-
279
- ##
280
- # Execute the feature after calling parse
281
- # with command line arguments.
282
- #
283
- # Subclasses will generally override this method
284
- # if they are a Ruby executable, but if you're
285
- # just delegating to an external CLI application,
286
- # calling execute will wind up executing the
287
- # external process.
288
- def execute
289
- execute_delegate
290
- end
291
-
292
- ##
293
- # Call the provided executable delegate.
294
- #
295
- # This method is generally called from Rake task wrappers.
296
- #
297
- def execute_delegate
298
- system_execute binary_path, to_shell
299
- end
300
-
301
- def prepare
302
- params.each do |param|
303
- param.prepare
304
- end
305
- end
306
-
307
- def to_rake *args
308
- # Define the file task first - so that
309
- # desc blocks hook up to it...
310
- outer_task = create_outer_task *args
311
- update_rake_task_name_from_args *args
312
- yield self if block_given?
313
- prepare
314
-
315
- # TODO: Tried auto-updating with library
316
- # prerequisites, but this led to strange
317
- # behavior with multiple registrations.
318
- handle_library_prerequisites outer_task.prerequisites
319
-
320
- # Add the library resolution rake task
321
- # as a prerequisite
322
- outer_task.prerequisites << task(Sprout::Library::TASK_NAME)
323
- prerequisites.each do |prereq|
324
- outer_task.prerequisites << prereq
325
- end
326
- outer_task
327
- end
328
-
329
- ##
330
- # This will create a hash of ONLY values that are created
331
- # using +add_param+, properties that are created with
332
- # attr_accessor must be handled manually, or patches are welcome!
333
- def to_hash
334
- result = {}
335
- params.each do |param|
336
- result[param.name] = self.send(param.name)
337
- end
338
- result
339
- end
340
-
341
- ##
342
- # This will ignore unknown parameters, because our very
343
- # first use case, is when generators call other generators
344
- # and generator A might have different parameters than
345
- # generator B.
346
- def from_hash hash
347
- hash.each_pair do |key, value|
348
- if(self.respond_to?(key))
349
- self.send "#{key}=", value
350
- end
351
- end
352
- end
353
-
354
- def to_help
355
- option_parser.to_s
356
- end
357
-
358
- # Create a string that represents this configured executable for shell execution
359
- def to_shell
360
- return @to_shell_proc.call(self) unless @to_shell_proc.nil?
361
-
362
- result = []
363
- result << @prepended_args unless @prepended_args.nil?
364
- params.each do |param|
365
- if(param.visible?)
366
- result << param.to_shell
367
- end
368
- end
369
- result << @appended_args unless @appended_args.nil?
370
- return result.join(' ')
371
- end
372
-
373
- ##
374
- # Called by Parameters like :path and :paths
375
- #
376
- def default_file_expression
377
- @default_file_expression ||= Sprout::Executable::DEFAULT_FILE_EXPRESSION
378
- end
379
-
380
- protected
381
-
382
- ##
383
- # Create the outer rake task.
384
- # For most executables, this will be a Rake::File task,
385
- # This is a template method that should be overridden
386
- # for executables that do not result in the creation of
387
- # a file.
388
- #
389
- # @see update_rake_task_name_from_args
390
- def create_outer_task *args
391
- file *args do
392
- execute
393
- end
394
- end
395
-
396
- ##
397
- # This method will add the current task to the Rake CLEAN
398
- # collection.
399
- #
400
- # Any Executable that does not create a Rake::File task
401
- # should also override this method and prevent it from
402
- # calling +CLEAN.add+.
403
- #
404
- # @see create_outer_task
405
- def update_rake_task_name_from_args *args
406
- self.rake_task_name = parse_rake_task_arg args.last
407
- CLEAN.add(self.rake_task_name)
408
- self.rake_task_name
409
- end
410
-
411
- def parse_rake_task_arg arg
412
- return arg if arg.is_a?(Symbol) || arg.is_a?(String)
413
- arg.each_pair do |key, value|
414
- return key
415
- end
416
- nil
417
- end
418
-
419
- def parse_extra_options! options
420
- options.each do |value|
421
- params.each do |param|
422
- if param.hidden_name?
423
- self.send "#{param.name}=", value
424
- break
425
- end
426
- end
427
- end
428
- end
429
-
430
- ##
431
- # This method will generally be overridden
432
- # by subclasses and they can do whatever customization
433
- # is necessary for a particular library type.
434
- #
435
- # It's important to note that this value can be
436
- # a String path to a file (or folder), or it can
437
- # be an Array of paths to files (or folders).
438
- def library_added path_or_paths
439
- end
440
-
441
- def system_execute binary, params
442
- Sprout.current_system.execute binary, params
443
- end
444
-
445
- private
446
-
447
- def binary_path
448
- Sprout::Executable.load(executable, pkg_name, pkg_version).path
449
- end
450
-
451
- def handle_library_prerequisites items
452
- items.each do |task_name|
453
- t = Rake.application[task_name]
454
- if(!t.sprout_entity.nil?)
455
- library_added t.sprout_entity.installed_project_path
456
- end
457
- end
458
- end
459
-
460
- def help_requested? options
461
- options.include? '--help'
462
- end
463
-
464
- def handle_parse_error error
465
- if(abort_on_failure)
466
- parts = []
467
- parts << nil
468
- parts << "[ERROR - #{error.class.name}] #{error.message}"
469
- parts << nil
470
- parts << option_parser.to_s
471
- parts << nil
472
- abort parts.join("\n")
473
- else
474
- raise error
475
- end
476
- end
477
-
478
- def initialize_parameters
479
- add_help_param
480
- assembled_parameter_collection.each do |declaration|
481
- param = initialize_parameter declaration
482
- short = param.option_parser_short_name
483
-
484
- option_parser.on short,
485
- param.option_parser_declaration,
486
- param.description do |value|
487
- if(param.is_a?(CollectionParam) && param.delimiter == '+=')
488
- eval "self.#{param.name} << '#{value}'"
489
- else
490
- self.send "#{param.name}=", value
491
- end
492
- end
493
- end
494
- end
495
-
496
- def initialize_defaults
497
- assembled_default_parameter_collection.reverse.each do |option|
498
- #puts ">> updating default on: #{self} for: #{option[:name]} with: #{option[:value]}"
499
- self.send "#{option[:name]}=", option[:value]
500
- end
501
- end
502
-
503
- def assembled_parameter_collection
504
- assembled_static_collection :static_parameter_collection
505
- end
506
-
507
- def assembled_default_parameter_collection
508
- assembled_static_collection :static_default_value_collection
509
- end
510
-
511
- def assembled_static_collection collection_name
512
- collection = []
513
- inheritance_chain.reverse.each do |clazz|
514
- if(clazz.respond_to?(collection_name))
515
- collection.concat clazz.send(collection_name)
516
- end
517
- end
518
- collection
519
- end
520
-
521
- def inheritance_chain
522
- chain = []
523
- clazz = self.class
524
- while clazz do
525
- chain << clazz
526
- clazz = clazz.superclass
527
- end
528
- chain
529
- end
530
-
531
- def add_help_param
532
- option_parser.on '--help', 'Display this help message' do
533
- puts option_parser.to_s
534
- exit
535
- end
536
- end
537
-
538
- def initialize_parameter declaration
539
- name = declaration[:name]
540
- name_s = name.to_s
541
- type = declaration[:type]
542
-
543
- # First ensure the named accessor doesn't yet exist...
544
- if(parameter_hash_includes? name)
545
- raise Sprout::Errors::ExecutableError.new("ToolTask.add_param called with existing parameter name: #{name_s}")
546
- end
547
-
548
- create_parameter declaration
549
- end
550
-
551
- def create_parameter declaration
552
- param = ParameterFactory.create declaration[:type]
553
- param.belongs_to = self
554
-
555
- begin
556
- declaration.each_pair do |key, value|
557
- param.send "#{key}=", value
558
- end
559
- rescue ArgumentError
560
- raise Sprout::Errors::UsageError.new "Unexpected parameter option encountered with: #{key} and value: #{value}"
561
- end
562
-
563
- raise Sprout::Errors::UsageError.new "Parameter name is required" if(param.name.nil?)
564
-
565
- param_hash[param.name.to_sym] = param
566
- params << param
567
-
568
- # Expose this parameter to command line arguments:
569
- #add_commandline_param param
570
-
571
- param
572
- end
573
-
574
- def parameter_hash_includes? name
575
- param_hash.has_key? name.to_sym
576
- end
577
-
578
- def validate
579
- params.each do |param|
580
- param.validate
581
- end
582
- end
583
-
584
- def option_parser
585
- @option_parser
586
- end
587
-
588
- end
589
40
  end
590
41
  end
591
42
 
@@ -1,8 +1,7 @@
1
1
  module Sprout
2
2
  module Generator
3
3
 
4
- class Base
5
- include Sprout::Executable
4
+ class Base < Sprout::Executable::Base
6
5
 
7
6
  def self.inherited base
8
7
  # NOTE: We can NOT instantiate the class here,
@@ -10,7 +9,7 @@ module Sprout
10
9
  # instantiate here, none of the code declared in the class body will
11
10
  # be associated with this instance.
12
11
  #
13
- # Go ahead and register the class and update instances afterwards.
12
+ # Go ahead and register the class and update instances later...
14
13
  Sprout::Generator.register base, template_from_caller(caller.first)
15
14
  end
16
15
 
@@ -103,7 +103,8 @@ module Sprout
103
103
  # @see Sprout::RubyFeature
104
104
  # @see Sprout::System
105
105
  #
106
- module Generator
106
+ module Generator
107
+
107
108
  include RubyFeature
108
109
 
109
110
  class << self
@@ -2,8 +2,7 @@ require 'sprout'
2
2
 
3
3
  module <%= input.camel_case %>
4
4
 
5
- class Base
6
- include Sprout::Executable
5
+ class Base < Sprout::Executable::Base
7
6
 
8
7
  end
9
8
  end
@@ -179,7 +179,7 @@ module Sprout
179
179
  if !File.exists?(dir)
180
180
  define_file_task dir do
181
181
  FileUtils.mkdir_p dir
182
- Sprout::Log.puts ">> Created directory at: #{dir}"
182
+ Sprout.stdout.puts ">> Created directory at: #{dir}"
183
183
  end
184
184
  end
185
185
  end
@@ -196,7 +196,7 @@ module Sprout
196
196
  def define_directory_copy_task path, install_path
197
197
  define_file_task install_path do
198
198
  FileUtils.cp_r path, install_path
199
- Sprout::Log.puts ">> Copied files from: (#{path}) to: (#{install_path})"
199
+ Sprout.stdout.puts ">> Copied files from: (#{path}) to: (#{install_path})"
200
200
  end
201
201
  install_path
202
202
  end
@@ -206,7 +206,7 @@ module Sprout
206
206
  define_file_task task_name do
207
207
  FileUtils.mkdir_p install_path
208
208
  FileUtils.cp path, "#{install_path}/"
209
- Sprout::Log.puts ">> Copied file from: (#{path}) to: (#{task_name})"
209
+ Sprout.stdout.puts ">> Copied file from: (#{path}) to: (#{task_name})"
210
210
  end
211
211
  task_name
212
212
  end
@@ -0,0 +1,35 @@
1
+
2
+ module Sprout
3
+
4
+ class OutputBuffer < Logger
5
+
6
+ def initialize *args
7
+ super
8
+ @characters = ''
9
+ end
10
+
11
+ def puts msg
12
+ flush if @characters.size > 0
13
+ info msg
14
+ end
15
+
16
+ def print msg
17
+ @characters << msg
18
+ flush
19
+ end
20
+
21
+ def printf msg
22
+ @characters << msg
23
+ flush
24
+ end
25
+
26
+ def flush
27
+ if @characters.match /\n/
28
+ info @characters
29
+ @characters = ''
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+