cuken 0.1.13 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/.rvmrc +61 -0
  2. data/Gemfile +17 -15
  3. data/Gemfile.lock +55 -63
  4. data/VERSION +1 -1
  5. data/cuken.gems +46 -0
  6. data/cuken.gemspec +85 -31
  7. data/features/about.md +4 -0
  8. data/features/avagrant_steps/vagrant_steps.feature +13 -0
  9. data/features/chef_examples/cookbooks_cookbook.feature +1 -1
  10. data/features/chef_examples/cookbooks_metadata.feature +5 -5
  11. data/features/chef_examples/cookbooks_repo.feature +1 -1
  12. data/features/chef_examples/knife_admin_client.feature +12 -12
  13. data/features/chef_examples/knife_client_create.feature +1 -1
  14. data/features/chef_examples/zenoss_example/01_chef_server_setup.feature +1 -1
  15. data/features/chef_examples/zenoss_example/02_monitor_vm_setup.feature +1 -1
  16. data/features/chef_steps/cookbook_steps.feature +6 -16
  17. data/features/command_examples/commands.feature +3 -3
  18. data/features/command_examples/exit_statuses.feature +49 -0
  19. data/features/command_examples/file_system_commands.feature +128 -0
  20. data/features/command_examples/flushing.feature +24 -0
  21. data/features/command_examples/interactive.feature +57 -0
  22. data/features/command_examples/no_clobber.feature +41 -0
  23. data/features/command_examples/output.feature +205 -0
  24. data/features/command_steps/command_steps.feature +49 -42
  25. data/features/file_examples/files.feature +5 -5
  26. data/features/git_examples/git_clone.feature +33 -0
  27. data/features/ssh_examples/ssh.feature +11 -2
  28. data/features/step_definitions/cuken_steps.rb +3 -2
  29. data/features/support/env.rb +2 -1
  30. data/lib/cuken/all.rb +1 -0
  31. data/lib/cuken/api/aruba/api.rb +342 -0
  32. data/lib/cuken/api/aruba/hooks.rb +63 -0
  33. data/lib/cuken/api/aruba/process.rb +74 -0
  34. data/lib/cuken/api/aruba.rb +5 -0
  35. data/lib/cuken/api/chef/common.rb +8 -1
  36. data/lib/cuken/api/chef/cookbook.rb +31 -5
  37. data/lib/cuken/api/chef/knife.rb +3 -3
  38. data/lib/cuken/api/chef/role.rb +3 -3
  39. data/lib/cuken/api/chef.rb +98 -9
  40. data/lib/cuken/api/cmd.rb +8 -8
  41. data/lib/cuken/api/common.rb +11 -23
  42. data/lib/cuken/api/file.rb +38 -38
  43. data/lib/cuken/api/git/clone.rb +25 -0
  44. data/lib/cuken/api/git/common.rb +37 -0
  45. data/lib/cuken/api/git/remote.rb +16 -0
  46. data/lib/cuken/api/git/repository.rb +62 -0
  47. data/lib/cuken/api/git.rb +69 -0
  48. data/lib/cuken/api/rvm/common.rb +10 -0
  49. data/lib/cuken/api/rvm/gemsets.rb +33 -0
  50. data/lib/cuken/api/rvm/wip.rb +554 -0
  51. data/lib/cuken/api/rvm.rb +25 -479
  52. data/lib/cuken/api/ssh.rb +85 -4
  53. data/lib/cuken/api/vagrant/common.rb +7 -4
  54. data/lib/cuken/api/vagrant/v_m.rb +2 -2
  55. data/lib/cuken/api/vagrant.rb +3 -3
  56. data/lib/cuken/common.rb +3 -1
  57. data/lib/cuken/cucumber/chef/common.rb +3 -3
  58. data/lib/cuken/cucumber/chef/cookbook/action.rb +81 -0
  59. data/lib/cuken/cucumber/chef/cookbook/local.rb +71 -0
  60. data/lib/cuken/cucumber/chef/cookbook/remote.rb +37 -0
  61. data/lib/cuken/cucumber/chef/cookbook.rb +3 -140
  62. data/lib/cuken/cucumber/chef/cookbook_steps.rb +1 -1
  63. data/lib/cuken/cucumber/chef/deploy_steps.rb +1 -1
  64. data/lib/cuken/cucumber/chef/done_directory_steps.rb +2 -2
  65. data/lib/cuken/cucumber/chef/done_file_steps.rb +5 -5
  66. data/lib/cuken/cucumber/chef/knife.rb +1 -1
  67. data/lib/cuken/cucumber/chef.rb +1 -1
  68. data/lib/cuken/cucumber/cmd/execution.rb +34 -0
  69. data/lib/cuken/cucumber/cmd/exit_status.rb +30 -0
  70. data/lib/cuken/cucumber/cmd.rb +2 -36
  71. data/lib/cuken/cucumber/common.rb +42 -6
  72. data/lib/cuken/cucumber/file.rb +42 -37
  73. data/lib/cuken/cucumber/git/clone.rb +51 -0
  74. data/lib/cuken/cucumber/git/common.rb +36 -0
  75. data/lib/cuken/cucumber/git/local.rb +19 -0
  76. data/lib/cuken/cucumber/git/remote.rb +22 -0
  77. data/lib/cuken/cucumber/git.rb +26 -0
  78. data/lib/cuken/cucumber/output/all.rb +41 -0
  79. data/lib/cuken/cucumber/output/cmd.rb +46 -0
  80. data/lib/cuken/cucumber/output/stderr.rb +33 -0
  81. data/lib/cuken/cucumber/output/stdout.rb +34 -0
  82. data/lib/cuken/cucumber/rvm/common.rb +0 -0
  83. data/lib/cuken/cucumber/rvm/gemsets.rb +32 -0
  84. data/lib/cuken/cucumber/rvm/hooks.rb +0 -0
  85. data/lib/cuken/cucumber/rvm.rb +3 -1
  86. data/lib/cuken/cucumber/ssh/common.rb +51 -0
  87. data/lib/cuken/cucumber/ssh.rb +3 -35
  88. data/lib/cuken/cucumber/vagrant.rb +1 -1
  89. data/lib/cuken/git.rb +21 -0
  90. data/spec/api/rvm/gemsets/api_spec.rb +41 -0
  91. data/spec/api/rvm/gemsets/helper_spec.rb +19 -0
  92. data/spec/api/rvm_spec.rb +63 -15
  93. data/spec/api/vagrant/v_m/Vagrantfile +82 -0
  94. data/spec/api/vagrant/v_m/api_spec.rb +37 -0
  95. data/spec/spec_helper.rb +39 -0
  96. metadata +123 -45
  97. data/spec/cuken_spec.rb +0 -7
@@ -0,0 +1,554 @@
1
+ #
2
+ # These methods have to be verified as working with RVM API - many were broken as of 1.6.5
3
+ #
4
+ module ::Cuken
5
+ module Api
6
+ module Rvm
7
+
8
+ class RvmrcProcessor
9
+
10
+ attr_writer :gemspecs_to_install
11
+
12
+ def initialize(path)
13
+ @root_path = ::File.directory?(path) ? path : File.dirname(path)
14
+ rvmrc_read(path)
15
+ end
16
+
17
+ # read the .rvmrc file contents into @rvmrc
18
+ def rvmrc_read(path)
19
+ fn = ::File.directory?(path) ? path + '/.rvmrc' : path
20
+ @rvmrc = ::File.new(fn).read
21
+ return true if @rvmrc.size > 0
22
+ end
23
+
24
+ # return the .rvmrc file contents
25
+ def rvmrc
26
+ @rvmrc
27
+ end
28
+
29
+ # return ruby name parsed from .rvmrc file contents
30
+ def rvmrc_ruby_name
31
+ extract_rubie(rvmrc)
32
+ end
33
+
34
+ # return gemset name parsed from .rvmrc file contents
35
+ def rvmrc_gemset_name
36
+ extract_gemset(rvmrc)
37
+ end
38
+
39
+ # return concatenated string of rvmrc_ruby@rvmrc_gemset
40
+ def rvmrc_ruby_gemset(rvmrc)
41
+ "#{extract_rubie(rvmrc)}@#{extract_gemset(rvmrc)}"
42
+ end
43
+
44
+ # return an array of .rvmrc file paths found beneath a root folder
45
+ def find_rvmrc_files(rvmrc_root)
46
+ Dir.glob(rvmrc_root + '/**' + '/.rvmrc')
47
+ end
48
+
49
+ # return an arry of paths containing .rvmrc files
50
+ def find_rvmrc_paths(rvmrc_root)
51
+ root = File.directory?(rvmrc_root) ? rvmrc_root : File.dirname(rvmrc_root)
52
+ dirs = []
53
+ find_rvmrc_files(root).each do |path|
54
+ dirs << File.dirname(File.expand_path(path)) if File.file?(path)
55
+ end
56
+ dirs
57
+ end
58
+
59
+ #return an array of *.gems file paths found beneath a root folder
60
+ def find_gems_files(rvmrc_root)
61
+ Dir.glob(rvmrc_root + '/**' + '/*.gems')
62
+ end
63
+
64
+ # returns rubies and gemsets from .rvmrc files glob'ed below
65
+ # a root folder.
66
+ def all_rubies_gemsets(root_path=@root_path)
67
+ @all_rubies_gemsets = Hash.new([])
68
+ arry=find_rvmrc_paths(root_path)
69
+ arry.each do |dir|
70
+ Dir.glob(dir + '/*.gems').each do |fn|
71
+ gsn = File.basename(fn,'.gems').to_s
72
+ rvmrc_read(dir + '/.rvmrc')
73
+ rube = rvmrc_ruby_name
74
+ egsn = rvmrc_gemset_name
75
+ @all_rubies_gemsets[rube] = [] unless @all_rubies_gemsets.key? rube
76
+ if gsn == egsn
77
+ @all_rubies_gemsets[rube] << {:ruby_alias => "cuken_#{rube}",:gemset_alias => "cuken_#{gsn}", :gemset_name => gsn, :gemset_path => fn}
78
+ end
79
+ end
80
+ end
81
+ @all_rubies_gemsets
82
+ end
83
+
84
+ # returns hash of all gemsets, per-Ruby, in all .rvmrc files beneath a root folder
85
+ def all_gemsets(root_path=@root_path)
86
+ default = Hash.new{|hsh,ky| hsh[ky] = {:ruby_alias => "cuken_#{ky}"}}
87
+ @all_rubies_gemsets ||= all_rubies_gemsets(root_path)
88
+ @all_gemsets = @all_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
89
+ end
90
+
91
+ # returns array of all rubies in all .rvmrc files beneath a root folder
92
+ def all_rubies(root_path=@root_path)
93
+ @all_rubies_gemsets ||= all_rubies_gemsets(root_path)
94
+ @all_rubies = @all_rubies_gemsets.keys
95
+ end
96
+
97
+ # yield a block in the environment of each in the installed rubies,
98
+ # and return current Ruby string even if the given block raises
99
+ def each_ruby
100
+ begin
101
+ all_rubies(@root_path).each do |rubie|
102
+ RVM.use(rubie)
103
+ yield rubie
104
+ end
105
+ rescue
106
+ ensure
107
+ RVM.reset_current!
108
+ end
109
+ end
110
+
111
+ # create gemsets parsed from all .rvmrc files beneath a root folder
112
+ def create_gemsets
113
+ each_ruby do |rubie|
114
+ all_gemsets(@root_path)[rubie][:gemsets].each do |hsh|
115
+ ::RVM.gemset.create([hsh[:gemset_name]])
116
+ end
117
+ end
118
+ end
119
+
120
+ # Return array of [gem_name, gem_version] to be installed into all
121
+ # gemsets found in .rvmrc files. Default is Bundler versio 1.0.10
122
+ def gemspecs_to_install
123
+ @gemspecs_to_install ||= [['bundler', '1.0.10']]
124
+ end
125
+
126
+ # Install @gemspecs_to_install contents using rubies and gemsets
127
+ # found in .rvmrc files.
128
+ def gems_install
129
+ create_gemsets
130
+ each_ruby do |rubie|
131
+ gemspecs_to_install.each { |spec| install_gem(rubie, spec) }
132
+ end
133
+ end
134
+
135
+ # return the options string for Ruby's `gem install...` CLI
136
+ def gem_install_options
137
+ @gem_install_options ||= ['no_ri', 'no_rdoc']
138
+ "--" + @gem_install_options.join(' --')
139
+ end
140
+
141
+ # install given gem into all ruby+gemsets parsed from .rvmrc files beneath a root folder
142
+ def install_gem(rubie, spec)
143
+ gem, version = spec
144
+ all_gemsets.each do |rubie, hsh|
145
+ hsh[:gemsets].each do |h|
146
+ if gem_available?(spec)
147
+ puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
148
+ else
149
+ puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
150
+ RVM.gemset.use(h[:gemset_alias])
151
+ RVM.run("rvm --create use #{h[:gemset_alias]}; gem install #{gem} -v#{version} #{gem_install_options}")
152
+ end
153
+ end
154
+ end
155
+ end
156
+
157
+ # return the parsed .rvmrc info for the current ruby
158
+ def current_ruby_info(rubie)
159
+ @all_rubies_gemsets ||= all_rubies_gemsets
160
+ @all_rubies_gemsets[rubie]
161
+ end
162
+
163
+ def rvm_path
164
+ pn = Pathname.new(File.expand_path(ENV['rvm_path'] || '~/.rvm'))
165
+ pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller)
166
+ end
167
+ # Does not install existing RVM rubies that are listed in the .rvmrc files
168
+ # raise an error if RVM's install root does not exist
169
+ def setup_rubies
170
+ rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
171
+ @all_rubies_gemsets ||= all_rubies_gemsets(@root_path)
172
+ @all_rubies_gemsets.keys.each do |rubie|
173
+ if RVM.list_strings.include?(rubie)
174
+ puts "info: Rubie #{rubie} already installed."
175
+ else
176
+ with_rvm_environment_vars do
177
+ install_rubie(rubie)
178
+ end
179
+ end
180
+ RVM.alias_create(current_ruby_info(rubie)[0][:ruby_alias], "#{rubie}") unless rubie == current_ruby_info(rubie)[0][:ruby_alias]
181
+ end
182
+ end
183
+
184
+ private
185
+ def extract_rubie(rvmrc)
186
+ rvmrc[/ruby_id=\"(.*)\"/, 1]
187
+ end
188
+ def extract_gemset(rvmrc)
189
+ rvmrc[/gemset_id=\"(.*)\"/, 1]
190
+ end
191
+ def gem_available?(spec)
192
+ gem, version = spec
193
+ RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
194
+ end
195
+ def rvm_current_name
196
+ RVM.current.expanded_name
197
+ end
198
+
199
+ def rvm_loaded?
200
+ @rvm_setup = defined?(RVM) ? true : false
201
+ return(true) if @rvm_setup
202
+ rvm_lib_path = rvm_path + "lib" rescue return
203
+ $LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
204
+ require 'rvm'
205
+ @rvm_setup = defined?(RVM) ? true : false
206
+ end
207
+
208
+ def install_rubie(rubie)
209
+ std_msg = "info: Rubie #{rubie} installed."
210
+ err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
211
+ puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
212
+ RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
213
+ end
214
+
215
+ def rvm_install_options
216
+ { }
217
+ end
218
+
219
+ def with_rvm_environment_vars
220
+ my_vars = rvm_environment_vars
221
+ current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
222
+ set_environment_vars(my_vars)
223
+ yield
224
+ ensure
225
+ set_environment_vars(current_vars)
226
+ end
227
+
228
+ def set_environment_vars(vars)
229
+ vars.each { |k,v| ENV[k] = v }
230
+ end
231
+
232
+ def rvm_environment_vars
233
+ if rvm_for_macports?
234
+ {'CC' => '/usr/bin/gcc-4.2',
235
+ 'CFLAGS' => '-O2 -arch x86_64',
236
+ 'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
237
+ 'CPPFLAGS' => '-I/opt/local/include'}
238
+ else
239
+ {}
240
+ end
241
+ end
242
+
243
+ def rvm_for_macports?
244
+ `uname`.strip == 'Darwin' && `which port`.present?
245
+ end
246
+
247
+ end # class RvmrcProcessor
248
+
249
+ module_function
250
+ class << self
251
+ attr_accessor :rvm_install_rubies, :rvm_install_gem_specs,
252
+ :rvm_gem_install_options
253
+ end
254
+
255
+ def run_simple_gemset(cmd_str, options = {} )
256
+ # RVM 1.6.5 is not generating rvm-legal code when given a command str so we write to a temp file
257
+ tmpfile = ::Tempfile.open("cuken_#{__method__.to_s}_"){ |f| f.puts(cmd_str);f }
258
+ tmpfile.close
259
+ Pathname(tmpfile).chmod(0700)
260
+ FileUtils.copy(tmpfile,tmpfile.path+'.bak')
261
+ @run_simple_gemset_result = nil
262
+ begin
263
+ case
264
+ when options.key?(:ruby) && options.key?(:gemset)
265
+ full_gemset_string = "#{options[:ruby]}@#{options[:gemset]}"
266
+ when options.key?(:ruby) && !options.key?(:gemset)
267
+ full_gemset_string = "#{options[:ruby]}@#{RVM.current.gemset.name}"
268
+ when !options.key?(:ruby) && options.key?(:gemset)
269
+ full_gemset_string = "#{RVM.current.expanded_name[/(.*)@/,1]}@#{options[:gemset]}"
270
+ when !options.key?(:ruby) && !options.key?(:gemset)
271
+ full_gemset_string = RVM.current.expanded_name
272
+ else
273
+ full_gemset_string = RVM.current.expanded_name
274
+ end
275
+ raise(::ArgumentError, "The RVM gemset #{full_gemset_string} is not present.") unless ::RVM.list_gemsets.include?(full_gemset_string)
276
+ ::RVM.environment(full_gemset_string) do |env|
277
+ if @announce_env
278
+ announce_or_puts("Ruby environment for #{::RVM.current.expanded_name}:")
279
+ announce_or_puts("#{env.info.inspect}")
280
+ end
281
+ @run_simple_gemset_result = env.ruby(tmpfile, options)
282
+ #sin = @run_simple_gemset_result.command
283
+ #sout = @run_simple_gemset_result.stdout
284
+ #serr = @run_simple_gemset_result.stderr
285
+ #estat = @run_simple_gemset_result.exit_status
286
+ end
287
+ rescue ::Exception => e
288
+ puts e.message
289
+ puts e.backtrace.join('\n')
290
+ raise
291
+ rescue ::ArgumentError => e
292
+ puts "Exception raised by run_simple_gemset(#{cmd_str}, #{options})"
293
+ puts "Script executed from #{tmpfile.to_s}:\n#{tmpfile.open.readlines}"
294
+ puts "Exception: #{e.message}"
295
+ puts e.backtrace.join('\n')
296
+ raise e
297
+ ensure
298
+ tmpfile.unlink
299
+ end
300
+ @run_simple_gemset_result.inspect
301
+ end
302
+
303
+ def rvmrc(path)
304
+ @rvmrc ||= RvmrcProcessor.new(path)
305
+ end
306
+
307
+ def rvm_current_name
308
+ RVM.current.expanded_name
309
+ end
310
+
311
+ def rvm_gem_install_options
312
+ @rvm_gem_install_options ||= ['no_ri', 'no_rdoc']
313
+ "--" + @rvm_gem_install_options.join(' --')
314
+ end
315
+
316
+ def rvm_install_rubies
317
+ @rvm_install_rubies ||= []
318
+ end
319
+
320
+ def rvm_install_gemspecs
321
+ @rvm_install_gemspecs ||= [['bundler', '1.0.10']]
322
+ end
323
+
324
+ def rvm_create_gemsets
325
+ @rvm_create_gemsets ||= []
326
+ end
327
+
328
+ def rvm_requested_gemset(gemset)
329
+ @rvm_requested_gemset = gemset
330
+ end
331
+
332
+ def rvm_requested_gemset
333
+ @rvm_requested_gemset ||='vagrant'
334
+ end
335
+ #wip
336
+ def rvm_path
337
+ pn = Pathname.new(File.expand_path(ENV['rvm_path'] || '~/.rvm'))
338
+ pn.exist? ? pn : raise(RuntimeError, "Could not find RVM's .rvm folder (#{pn})", caller)
339
+ end
340
+
341
+ def rvm_local_install?
342
+ rvm_path.dirname.realpath.directory?
343
+ end
344
+ # done
345
+ def rvm_loaded?
346
+ _rvm_load
347
+ end
348
+
349
+ def rvm_gemset_paths(root_path='/usr/src/cuken')
350
+ rpn = Pathname(root_path)
351
+ rvmrc_dirs = []
352
+ Dir.glob((rpn + '**' + '.rvmrc').to_s).each do |d|
353
+ dn = File.dirname(d)
354
+ rvmrc_dirs << dn if File.directory?(dn)
355
+ end
356
+ rvmrc_dirs
357
+ end
358
+
359
+ # done
360
+ def rvmrc_rubies_gemsets(root_path='/usr/src/cuken')
361
+ @rvmrc_rubies_gemsets = Hash.new([])
362
+ arry=rvm_gemset_paths(root_path)
363
+ arry.each do |dir|
364
+ Dir.glob(dir + '/*.gems').each do |fn|
365
+ gsn = File.basename(fn,'.gems').to_s
366
+ rvmrc = File.new(File.dirname(fn) + '/.rvmrc').read
367
+ rube = rvmrc_extract_ruby(rvmrc)
368
+ egsn = rvmrc_extract_gemset(rvmrc)
369
+ @rvmrc_rubies_gemsets[rube] = [] unless @rvmrc_rubies_gemsets.key? rube
370
+ @rvmrc_rubies_gemsets[rube] << gsn if gsn == egsn
371
+ end
372
+ end
373
+ @rvmrc_rubies_gemsets
374
+ end
375
+ # done
376
+ def rvmrc_rubies
377
+ @rvmrc_rubies ||= _rvmrc_rubies #.keys.map{ |rubie| "#{rubie}@#{rvm_requested_gemset}" }
378
+ end
379
+ #wip
380
+ def rvm_rubies_setup(root_path='/usr/src/cuken')
381
+ rvm_loaded? ? true : raise(RuntimeError, "RVM library not loaded.", caller)
382
+ @rvmrc_rubies_gemsets ? true : rvmrc_rubies_gemsets(root_path)
383
+ @rvmrc_rubies_gemsets.keys.each do |rubie|
384
+ if RVM.list_strings.include?(rubie)
385
+ puts "info: Rubie #{rubie} already installed."
386
+ else
387
+ with_rvm_environment_vars do
388
+ _rvm_install_rubie(rubie)
389
+ end
390
+ end
391
+ RVM.alias_create(rvmrc_rubies[rubie][:alias], "#{rubie}@#{rvm_requested_gemset}") unless rubie == rvmrc_rubies[rubie][:alias]
392
+ end
393
+ end
394
+ #done
395
+ def rvm_current_rubie_info
396
+ rvmrc_rubies[_rvm_current_rubie_name]
397
+ end
398
+
399
+ # Install @rvm_install_gemspecs gemspec using rubies and gemsets
400
+ # found in .rvmrc files.
401
+ # done
402
+ def rvmrc_gems_install(root_path)
403
+ @rvmrc_root_path = root_path
404
+ _rvmrc_create_gemsets
405
+ _each_rvmrc_rubie do |rubie|
406
+ rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
407
+ end
408
+ end
409
+
410
+ def rvmrc_gemsets_install(root_path)
411
+ @rvmrc_root_path = root_path
412
+ _each_rvmrc_rubie do |rubie|
413
+ rvm_install_gemspecs.each { |spec| _rvmrc_install_gem(rubie, spec) }
414
+ end
415
+ end
416
+
417
+ protected
418
+ #done
419
+ def _rvm_load
420
+ @rvm_setup = false
421
+ rvm_lib_path = rvm_path + "lib" rescue return
422
+ $LOAD_PATH.unshift(rvm_lib_path.to_s) unless $LOAD_PATH.include?(rvm_lib_path.to_s)
423
+ require 'rvm'
424
+ @rvm_setup = defined?(RVM) ? true : false
425
+ end
426
+ module_function :_rvm_load
427
+ #done
428
+ def _rvm_install_rubie(rubie)
429
+ std_msg = "info: Rubie #{rubie} installed."
430
+ err_msg = "Failed #{rubie} install! Check RVM logs here: #{RVM.path}/log/#{rubie}"
431
+ puts "info: Rubie #{rubie} installation inprogress. This couldtake awhile..."
432
+ RVM.install(rubie, rvm_install_options) ? puts(std_msg) : abort(err_msg)
433
+ end
434
+ module_function :_rvm_install_rubie
435
+
436
+ #done
437
+ def rvmrc_extract_ruby_gemset(rvmrc)
438
+ "#{rvmrc_extract_ruby(rvmrc)}@#{rvmrc_extract_gemset(rvmrc)}"
439
+ end
440
+ module_function :rvmrc_extract_ruby_gemset
441
+ #done
442
+ def rvmrc_extract_ruby(rvmrc)
443
+ rvmrc[/ruby_id=\"(.*)\"/, 1]
444
+ end
445
+ module_function :rvmrc_extract_ruby
446
+ #done
447
+ def rvmrc_extract_gemset(rvmrc)
448
+ rvmrc[/gemset_id=\"(.*)\"/, 1]
449
+ end
450
+ module_function :rvmrc_extract_gemset
451
+ #done
452
+ def _rvmrc_rubies
453
+ default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
454
+ @rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
455
+ @rvmrc_rubies = @rvmrc_rubies_gemsets.keys.inject(default){|h,(k,v)| h[k]; h }
456
+ end
457
+ module_function :_rvmrc_rubies
458
+ #done
459
+ def _rvmrc_gemsets
460
+ default = Hash.new{|hsh,ky| hsh[ky] = {:alias => "cuken-#{ky}"}}
461
+ @rvmrc_rubies_gemsets ||= rvmrc_rubies_gemsets(@rvmrc_root_path)
462
+ @rvmrc_gemsets = @rvmrc_rubies_gemsets.inject(default){|h,(k,v)| h[k]; h[k][:gemsets]=v; h }
463
+ end
464
+ module_function :_rvmrc_gemsets
465
+ # done
466
+ def _each_rvmrc_rubie
467
+ _rvmrc_rubies.each do |ary|
468
+ RVM.use(ary[0])
469
+ yield ary[0]
470
+ end
471
+ ensure
472
+ RVM.reset_current!
473
+ end
474
+ module_function :_each_rvmrc_rubie
475
+ # done
476
+ def _rvmrc_create_gemsets
477
+ _rvmrc_gemsets.each do |hsh|
478
+ RVM.use hsh[0]
479
+ hsh[1][:gemsets].each do |gmst|
480
+ # TODO: Post refactor
481
+ #RVM.gemset.create([gmst])
482
+ end
483
+ end
484
+ end
485
+ module_function :_rvmrc_create_gemsets
486
+ #done
487
+ def _rvmrc_install_gem(rubie, spec)
488
+ gem, version = spec
489
+ _rvmrc_gemsets.each do |hsh|
490
+ rubie = hsh[0]
491
+ hsh[1][:gemsets].each do |gmst|
492
+ if RVM.gemset.instance_of? ::RVM::Environment::GemsetWrapper
493
+ #RVM.gemset.create([gmst])
494
+ RVM.gemset.use(gmst)
495
+ if _rvm_gem_available?(spec)
496
+ puts "info: Gem #{gem}-#{version} already installed in #{rvm_current_name}."
497
+ else
498
+ puts "info: Installing gem #{gem}-#{version} in #{rvm_current_name}..."
499
+ RVM.run("rvm --create use #{rubie}@#{gmst}; gem install #{gem} -v#{version} #{rvm_gem_install_options}")
500
+ end
501
+ end
502
+ end
503
+ end
504
+ end
505
+ module_function :_rvmrc_install_gem
506
+
507
+ # done
508
+ def set_environment_vars(vars)
509
+ vars.each { |k,v| ENV[k] = v }
510
+ end
511
+ module_function :set_environment_vars
512
+ #done
513
+ def with_rvm_environment_vars
514
+ my_vars = rvm_environment_vars
515
+ puts my_vars
516
+ current_vars = my_vars.inject({}) { |cvars,kv| k,v = kv ; cvars[k]= ENV[k] ; cvars }
517
+ puts current_vars
518
+ set_environment_vars(my_vars)
519
+ yield
520
+ ensure
521
+ set_environment_vars(current_vars)
522
+ end
523
+ module_function :with_rvm_environment_vars
524
+ #done
525
+ def rvm_environment_vars
526
+ if rvm_for_macports?
527
+ {'CC' => '/usr/bin/gcc-4.2',
528
+ 'CFLAGS' => '-O2 -arch x86_64',
529
+ 'LDFLAGS' => '-L/opt/local/lib -arch x86_64',
530
+ 'CPPFLAGS' => '-I/opt/local/include'}
531
+ else
532
+ {}
533
+ end
534
+ end
535
+ module_function :rvm_environment_vars
536
+ #done
537
+ def rvm_for_macports?
538
+ `uname`.strip == 'Darwin' && `which port`.present?
539
+ end
540
+ module_function :rvm_for_macports?
541
+ # done
542
+ def rvm_install_options
543
+ { }
544
+ end
545
+ module_function :rvm_install_options
546
+ #done
547
+ def _rvm_gem_available?(spec)
548
+ gem, version = spec
549
+ RVM.ruby_eval("require 'rubygems' ; print Gem.available?('#{gem}','#{version}')").stdout == 'true'
550
+ end
551
+ module_function :_rvm_gem_available?
552
+ end
553
+ end
554
+ end