vendorificator 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/.travis.yml +5 -2
  2. data/Gemfile +0 -1
  3. data/README.md +9 -0
  4. data/Rakefile +7 -1
  5. data/features/chef_cookbook.feature +4 -6
  6. data/features/deprecated.feature +4 -4
  7. data/features/git.feature +41 -2
  8. data/features/needed.feature +8 -7
  9. data/features/smoke.feature +7 -5
  10. data/features/status.feature +15 -15
  11. data/features/step_definitions/aruba_ext.rb +11 -0
  12. data/features/step_definitions/basic.rb +16 -43
  13. data/features/step_definitions/git.rb +11 -11
  14. data/features/step_definitions/vendorificator.rb +4 -6
  15. data/features/support/aruba_ext.rb +23 -0
  16. data/features/support/env.rb +13 -20
  17. data/features/support/minigit.rb +37 -0
  18. data/features/tarball.feature +7 -7
  19. data/features/tarball_edit.feature +1 -1
  20. data/features/vendor.feature +2 -2
  21. data/lib/vendorificator/cli.rb +36 -61
  22. data/lib/vendorificator/config.rb +5 -42
  23. data/lib/vendorificator/environment.rb +111 -0
  24. data/lib/vendorificator/hooks/chef_cookbook.rb +59 -23
  25. data/lib/vendorificator/vendor/archive.rb +2 -2
  26. data/lib/vendorificator/vendor/chef_cookbook.rb +2 -2
  27. data/lib/vendorificator/vendor/download.rb +44 -0
  28. data/lib/vendorificator/vendor/git.rb +9 -11
  29. data/lib/vendorificator/vendor.rb +105 -48
  30. data/lib/vendorificator/version.rb +1 -1
  31. data/lib/vendorificator.rb +2 -0
  32. data/spec/spec_helper.rb +1 -0
  33. data/spec/vendorificator/vendor_spec.rb +15 -7
  34. data/vendorificator.gemspec +4 -4
  35. metadata +24 -21
  36. data/features/support/world_git.rb +0 -40
  37. data/features/support/world_runs.rb +0 -93
  38. data/lib/vendorificator/repo.rb +0 -69
@@ -17,9 +17,7 @@ module Vendorificator
17
17
  _cls = self # for self is obscured in define_method block's body
18
18
  ( class << Vendorificator::Config ; self ; end ).
19
19
  send(:define_method, @method_name ) do |name, *args, &block|
20
- mod = _cls.new(name.to_s, *args, &block)
21
- self[:modules] << mod
22
- mod
20
+ _cls.new(self.environment, name.to_s, *args, &block)
23
21
  end
24
22
  end
25
23
 
@@ -30,26 +28,71 @@ module Vendorificator
30
28
  end
31
29
  end
32
30
  end
33
- end
34
31
 
35
- attr_reader :name, :args, :block
36
- arg_reader :version, :path
32
+ def [](*key)
33
+ return key.map { |k| self[k] }.flatten if key.length > 1
37
34
 
38
- def path
39
- args[:path] || _join(category, name)
35
+ key = key.first
36
+
37
+ if key.is_a?(Fixnum)
38
+ self.instances[key]
39
+ else
40
+ instances.select { |i| i === key }
41
+ end
42
+ end
43
+
44
+ def each(*modules)
45
+ modpaths = modules.map { |m| File.expand_path(m) }
46
+
47
+ # We don't use instances.each here, because Vendor#run! is
48
+ # explicitly allowed to append to instantiate new
49
+ # dependencies, and #each fails to catch up on some Ruby
50
+ # implementations.
51
+ i = 0
52
+ while true
53
+ break if i >= instances.length
54
+ mod = instances[i]
55
+ yield mod if modules.empty? ||
56
+ modules.include?(mod.name) ||
57
+ modpaths.include?(mod.work_dir)
58
+ i += 1
59
+ end
60
+ end
61
+
62
+ def instances
63
+ Vendorificator::Vendor.instance_eval { @instances ||= [] }
64
+ end
65
+
66
+ def compute_dependencies!
67
+ self.instances.each(&:compute_dependencies!)
68
+ end
40
69
  end
41
70
 
42
- def initialize(name, args={}, &block)
71
+ attr_reader :environment, :name, :args, :block
72
+ arg_reader :version
73
+
74
+ def initialize(environment, name, args={}, &block)
75
+ @environment = environment
43
76
  @category = args.delete(:category) if args.key?(:category)
44
77
 
45
78
  @name = name
46
79
  @args = args
47
80
  @block = block
81
+
82
+ self.class.instances << self
83
+ end
84
+
85
+ def ===(other)
86
+ other === self.name or File.expand_path(other.to_s) == self.work_dir
87
+ end
88
+
89
+ def path
90
+ args[:path] || _join(category, name)
48
91
  end
49
92
 
50
93
  def shell
51
94
  @shell ||=
52
- Vendorificator::Config[:shell] || Thor::Shell::Basic.new
95
+ environment.config[:shell] || Thor::Shell::Basic.new
53
96
  end
54
97
 
55
98
  def category
@@ -61,7 +104,7 @@ module Vendorificator
61
104
  end
62
105
 
63
106
  def branch_name
64
- _join(Vendorificator::Config[:branch_prefix], category, name)
107
+ _join(environment.config[:branch_prefix], category, name)
65
108
  end
66
109
 
67
110
  def to_s
@@ -73,26 +116,29 @@ module Vendorificator
73
116
  end
74
117
 
75
118
  def work_subdir
76
- File.join(Vendorificator::Config[:basedir], path)
119
+ _join(environment.config[:basedir], path)
77
120
  end
78
121
 
79
122
  def work_dir
80
- File.join(Vendorificator::Config[:root_dir], work_subdir)
123
+ _join(environment.config[:root_dir], work_subdir)
81
124
  end
82
125
 
83
126
  def head
84
- repo.get_head(branch_name)
127
+ environment.git.capturing.rev_parse({:verify => true}, "refs/heads/#{branch_name}").strip
128
+ rescue MiniGit::GitError
129
+ nil
85
130
  end
86
131
 
87
- def tag
88
- repo.tags.find { |t| t.name == tag_name }
132
+ def tagged_sha1
133
+ @tagged_sha1 ||= environment.git.capturing.rev_parse({:verify => true}, "refs/tags/#{tag_name}^{commit}").strip
134
+ rescue MiniGit::GitError
135
+ nil
89
136
  end
90
137
 
91
138
  def merged
92
139
  unless @_has_merged
93
- if head
94
- merged = repo.git.
95
- merge_base({}, head.commit.sha, repo.head.commit.sha).strip
140
+ if ( head = self.head )
141
+ merged = environment.git.capturing.merge_base(head, 'HEAD').strip
96
142
  @merged = merged unless merged.empty?
97
143
  end
98
144
  @_has_merged = true
@@ -103,7 +149,7 @@ module Vendorificator
103
149
  def merged_tag
104
150
  unless @_has_merged_tag
105
151
  if merged
106
- tag = repo.git.describe( {
152
+ tag = environment.git.capturing.describe( {
107
153
  :exact_match => true,
108
154
  :match => _join(tag_name_base, '*') },
109
155
  merged).strip
@@ -119,7 +165,7 @@ module Vendorificator
119
165
  end
120
166
 
121
167
  def version
122
- @args[:version] || (!conf[:use_upstream_version] && merged_version) || upstream_version
168
+ @args[:version] || (!environment.config[:use_upstream_version] && merged_version) || upstream_version
123
169
  end
124
170
 
125
171
  def upstream_version
@@ -129,9 +175,8 @@ module Vendorificator
129
175
  def updatable?
130
176
  return nil if self.status == :up_to_date
131
177
  return false if !head
132
- return false if head && merged == head.commit.sha
133
- head_tag = repo.tags.find { |t| t.name == repo.recent_tag_name(head.name) }
134
- return head_tag || true
178
+ return false if head && merged == head
179
+ environment.git.describe({:abbrev => 0, :always => true}, branch_name)
135
180
  end
136
181
 
137
182
  def status
@@ -140,16 +185,16 @@ module Vendorificator
140
185
 
141
186
  # If there's a branch but no tag, it's a known module that's not
142
187
  # been updated for the new definition yet.
143
- return :outdated unless tag
188
+ return :outdated unless tagged_sha1
144
189
 
145
190
  # Well, this is awkward: branch is in config and exists, but is
146
191
  # not merged into current branch at all.
147
192
  return :unmerged unless merged
148
193
 
149
194
  # Merge base is tagged with our tag. We're good.
150
- return :up_to_date if tag.commit.sha == merged
195
+ return :up_to_date if tagged_sha1 == merged
151
196
 
152
- return :unpulled if repo.fast_forwardable?(tag.commit.sha, merged)
197
+ return :unpulled if environment.fast_forwardable?(tagged_sha1, merged)
153
198
 
154
199
  return :unknown
155
200
  end
@@ -159,26 +204,26 @@ module Vendorificator
159
204
  end
160
205
 
161
206
  def in_branch(options={}, &block)
162
- orig_head = repo.head
207
+ orig_branch = environment.current_branch
163
208
 
164
209
  # We want to be in repository's root now, as we may need to
165
210
  # remove stuff and don't want to have removed directory as cwd.
166
- Dir::chdir repo.working_dir do
211
+ Dir::chdir environment.git.git_work_tree do
167
212
  # If our branch exists, check it out; otherwise, create a new
168
213
  # orphaned branch.
169
214
  if self.head
170
- repo.git.checkout( {}, branch_name )
171
- repo.git.rm( { :r => true, :f => true }, '.') if options[:clean]
215
+ environment.git.checkout branch_name
216
+ environment.git.rm( { :r => true, :f => true, :q => true, :ignore_unmatch => true }, '.') if options[:clean]
172
217
  else
173
- repo.git.checkout( { :orphan => true }, branch_name )
174
- repo.git.rm( { :r => true, :f => true }, '.')
218
+ environment.git.checkout( { :orphan => true }, branch_name )
219
+ environment.git.rm( { :r => true, :f => true, :q => true, :ignore_unmatch => true }, '.')
175
220
  end
176
221
  end
177
222
 
178
223
  yield
179
224
  ensure
180
- # We should make sure we're back on original branch
181
- repo.git.checkout( {}, orig_head.name ) if defined?(orig_head) rescue nil
225
+ # We should try to ensure we're back on original branch
226
+ environment.git.checkout orig_branch if defined?(orig_branch) rescue nil
182
227
  end
183
228
 
184
229
  def run!
@@ -189,7 +234,8 @@ module Vendorificator
189
234
 
190
235
  when :unpulled, :unmerged
191
236
  shell.say_status 'merging', self.to_s, :yellow
192
- repo.git.merge({}, tag.name)
237
+ environment.git.merge({:no_edit => true, :no_ff => true}, tagged_sha1)
238
+ compute_dependencies!
193
239
 
194
240
  when :outdated, :new
195
241
  shell.say_status 'fetching', self.to_s, :yellow
@@ -206,16 +252,21 @@ module Vendorificator
206
252
  ensure
207
253
  shell.padding -= 1
208
254
  end
255
+
256
+ subdir = args[:subdirectory]
257
+ make_subdir_root subdir if subdir && !subdir.empty?
209
258
  end
210
259
 
260
+
211
261
  # Commit and tag the conjured module
212
- repo.add(work_dir)
213
- repo.commit_index(conjure_commit_message)
214
- repo.git.tag( { :a => true, :m => tag_message }, tag_name )
262
+ environment.git.add work_dir
263
+ environment.git.commit :m => conjure_commit_message
264
+ environment.git.tag( { :a => true, :m => tag_message }, tag_name )
215
265
  shell.say_status :tag, tag_name
216
266
  end
217
267
  # Merge back to the original branch
218
- repo.git.merge( {}, branch_name )
268
+ environment.git.merge( {}, branch_name )
269
+ compute_dependencies!
219
270
  ensure
220
271
  shell.padding -= 1
221
272
  end
@@ -245,20 +296,26 @@ module Vendorificator
245
296
  block.call(self) if block
246
297
  end
247
298
 
248
- def dependencies ; [] ; end
299
+ def compute_dependencies! ; end
249
300
 
250
301
  private
251
302
 
252
- def conf
253
- Vendorificator::Config
303
+ def _join(*parts)
304
+ parts.compact.map(&:to_s).join('/')
254
305
  end
255
306
 
256
- def repo
257
- Vendorificator::Config.repo
258
- end
307
+ def make_subdir_root(subdir_path)
308
+ curdir = Pathname.pwd
309
+ tmpdir = Pathname.pwd.dirname.join("#{Pathname.pwd.basename}.tmp")
310
+ subdir = Pathname.pwd.join(subdir_path)
259
311
 
260
- def _join(*parts)
261
- parts.compact.map(&:to_s).join('/')
312
+ Dir.chdir('..')
313
+
314
+ subdir.rename(tmpdir.to_s)
315
+ curdir.rmtree
316
+ tmpdir.rename(curdir.to_s)
317
+ ensure
318
+ Dir.chdir(curdir.to_s) if curdir.exist?
262
319
  end
263
320
 
264
321
  install!
@@ -1,3 +1,3 @@
1
1
  module Vendorificator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,8 +3,10 @@
3
3
  require "vendorificator/version"
4
4
 
5
5
  require 'vendorificator/config'
6
+ require 'vendorificator/environment'
6
7
 
7
8
  require 'vendorificator/vendor'
9
+ require 'vendorificator/vendor/download'
8
10
  require 'vendorificator/vendor/archive'
9
11
  require 'vendorificator/vendor/git'
10
12
  require 'vendorificator/vendor/chef_cookbook'
data/spec/spec_helper.rb CHANGED
@@ -5,6 +5,7 @@ Bundler.setup
5
5
  require 'minitest/spec'
6
6
  require 'minitest/autorun'
7
7
  require 'vcr'
8
+ require 'mocha/setup'
8
9
  require 'wrong'
9
10
  require 'wrong/adapters/minitest'
10
11
 
@@ -40,22 +40,30 @@ module Vendorificator
40
40
 
41
41
  describe '#category' do
42
42
  it 'defaults to class attribute' do
43
- assert { Vendor.new('test').category == nil }
44
- assert { Vendor::Categorized.new('test').category == :test }
43
+ assert { Vendor.new(nil, 'test').category == nil }
44
+ assert { Vendor::Categorized.new(nil, 'test').category == :test }
45
45
  end
46
46
 
47
47
  it 'can be overriden by option' do
48
- assert { Vendor.new('test', :category => :foo).category == :foo }
49
- assert { Vendor::Categorized.new('test', :category => :foo).category == :foo }
48
+ assert { Vendor.new(nil, 'test', :category => :foo).category == :foo }
49
+ assert { Vendor::Categorized.new(nil, 'test', :category => :foo).category == :foo }
50
50
  end
51
51
 
52
52
  it 'can be reset to nil by option' do
53
- assert { Vendor::Categorized.new('test', :category => nil).category == nil }
53
+ assert { Vendor::Categorized.new(nil, 'test', :category => nil).category == nil }
54
54
  end
55
55
 
56
56
  it 'is inserted into paths and other names' do
57
- uncategorized = Vendor.new('test')
58
- categorized = Vendor.new('test', :category => :cat)
57
+ env = stub(
58
+ :git => stub(
59
+ :capturing => stub(
60
+ :rev_parse => 'cafe',
61
+ :merge_base => 'cafe',
62
+ :describe => '')),
63
+ :config => Vendorificator::Config)
64
+
65
+ uncategorized = Vendor.new(env, 'test')
66
+ categorized = Vendor.new(env, 'test', :category => :cat)
59
67
 
60
68
  deny { uncategorized.branch_name.include? 'cat' }
61
69
  assert { categorized.branch_name.include? 'cat' }
@@ -16,14 +16,14 @@ Gem::Specification.new do |gem|
16
16
  gem.version = Vendorificator::VERSION
17
17
 
18
18
  gem.add_dependency 'escape'
19
- gem.add_dependency 'grit'
20
19
  gem.add_dependency 'thor', '>= 0.17.0'
21
20
  gem.add_dependency 'mixlib-config'
21
+ gem.add_dependency 'minigit', '>= 0.0.3'
22
22
 
23
+ gem.add_development_dependency 'aruba'
23
24
  gem.add_development_dependency 'cucumber'
24
- gem.add_development_dependency 'git'
25
- gem.add_development_dependency 'mixlib-shellout'
26
- gem.add_development_dependency 'chef', '>= 10.16.0'
25
+ gem.add_development_dependency 'mocha'
26
+ gem.add_development_dependency 'chef', '>= 10.16.0' unless defined?(RUBY_ENGINE) && RUBY_ENGINE == 'jruby'
27
27
  gem.add_development_dependency 'vcr'
28
28
  gem.add_development_dependency 'webmock'
29
29
  gem.add_development_dependency 'wrong', '>= 0.7.0'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vendorificator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: escape
@@ -28,13 +28,13 @@ dependencies:
28
28
  - !ruby/object:Gem::Version
29
29
  version: '0'
30
30
  - !ruby/object:Gem::Dependency
31
- name: grit
31
+ name: thor
32
32
  requirement: !ruby/object:Gem::Requirement
33
33
  none: false
34
34
  requirements:
35
35
  - - ! '>='
36
36
  - !ruby/object:Gem::Version
37
- version: '0'
37
+ version: 0.17.0
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,15 +42,15 @@ dependencies:
42
42
  requirements:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
- version: '0'
45
+ version: 0.17.0
46
46
  - !ruby/object:Gem::Dependency
47
- name: thor
47
+ name: mixlib-config
48
48
  requirement: !ruby/object:Gem::Requirement
49
49
  none: false
50
50
  requirements:
51
51
  - - ! '>='
52
52
  - !ruby/object:Gem::Version
53
- version: 0.17.0
53
+ version: '0'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
@@ -58,15 +58,15 @@ dependencies:
58
58
  requirements:
59
59
  - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.17.0
61
+ version: '0'
62
62
  - !ruby/object:Gem::Dependency
63
- name: mixlib-config
63
+ name: minigit
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: 0.0.3
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,9 +74,9 @@ dependencies:
74
74
  requirements:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
- version: '0'
77
+ version: 0.0.3
78
78
  - !ruby/object:Gem::Dependency
79
- name: cucumber
79
+ name: aruba
80
80
  requirement: !ruby/object:Gem::Requirement
81
81
  none: false
82
82
  requirements:
@@ -92,7 +92,7 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
94
  - !ruby/object:Gem::Dependency
95
- name: git
95
+ name: cucumber
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
@@ -108,7 +108,7 @@ dependencies:
108
108
  - !ruby/object:Gem::Version
109
109
  version: '0'
110
110
  - !ruby/object:Gem::Dependency
111
- name: mixlib-shellout
111
+ name: mocha
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  none: false
114
114
  requirements:
@@ -248,24 +248,26 @@ files:
248
248
  - features/needed.feature
249
249
  - features/smoke.feature
250
250
  - features/status.feature
251
+ - features/step_definitions/aruba_ext.rb
251
252
  - features/step_definitions/basic.rb
252
253
  - features/step_definitions/git.rb
253
254
  - features/step_definitions/vendorificator.rb
255
+ - features/support/aruba_ext.rb
254
256
  - features/support/env.rb
257
+ - features/support/minigit.rb
255
258
  - features/support/transform_pattern.rb
256
- - features/support/world_git.rb
257
- - features/support/world_runs.rb
258
259
  - features/tarball.feature
259
260
  - features/tarball_edit.feature
260
261
  - features/vendor.feature
261
262
  - lib/vendorificator.rb
262
263
  - lib/vendorificator/cli.rb
263
264
  - lib/vendorificator/config.rb
265
+ - lib/vendorificator/environment.rb
264
266
  - lib/vendorificator/hooks/chef_cookbook.rb
265
- - lib/vendorificator/repo.rb
266
267
  - lib/vendorificator/vendor.rb
267
268
  - lib/vendorificator/vendor/archive.rb
268
269
  - lib/vendorificator/vendor/chef_cookbook.rb
270
+ - lib/vendorificator/vendor/download.rb
269
271
  - lib/vendorificator/vendor/git.rb
270
272
  - lib/vendorificator/version.rb
271
273
  - spec/smoke_spec.rb
@@ -286,7 +288,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
286
288
  version: '0'
287
289
  segments:
288
290
  - 0
289
- hash: 1910323854215610577
291
+ hash: 2433899310770864262
290
292
  required_rubygems_version: !ruby/object:Gem::Requirement
291
293
  none: false
292
294
  requirements:
@@ -295,7 +297,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
295
297
  version: '0'
296
298
  segments:
297
299
  - 0
298
- hash: 1910323854215610577
300
+ hash: 2433899310770864262
299
301
  requirements: []
300
302
  rubyforge_project:
301
303
  rubygems_version: 1.8.25
@@ -329,13 +331,14 @@ test_files:
329
331
  - features/needed.feature
330
332
  - features/smoke.feature
331
333
  - features/status.feature
334
+ - features/step_definitions/aruba_ext.rb
332
335
  - features/step_definitions/basic.rb
333
336
  - features/step_definitions/git.rb
334
337
  - features/step_definitions/vendorificator.rb
338
+ - features/support/aruba_ext.rb
335
339
  - features/support/env.rb
340
+ - features/support/minigit.rb
336
341
  - features/support/transform_pattern.rb
337
- - features/support/world_git.rb
338
- - features/support/world_runs.rb
339
342
  - features/tarball.feature
340
343
  - features/tarball_edit.feature
341
344
  - features/vendor.feature
@@ -1,40 +0,0 @@
1
- require 'fileutils'
2
- require 'git'
3
-
4
- module Vendorificator
5
- module TestSupport
6
- module Git
7
- def git(*args)
8
- @git ||= {}
9
- @git[args] ||= ::Git.init(*args)
10
- end
11
-
12
- def commit_file(path, contents, message=nil)
13
- message ||= "Added #{path}"
14
- FileUtils.mkdir_p(File.dirname(path))
15
- File.open(path, 'w') { |f| f.puts(contents) }
16
- git.add(path)
17
- git.commit(message)
18
- end
19
-
20
- def repo_clean?
21
- # FIXME: How to do that with ruby-git?
22
- `git status --porcelain` == ""
23
- end
24
-
25
- def branch
26
- git.current_branch
27
- end
28
-
29
- def branches
30
- git.branches.map(&:to_s)
31
- end
32
-
33
- def tags
34
- git.tags.map(&:name)
35
- end
36
- end
37
- end
38
- end
39
-
40
- World(Vendorificator::TestSupport::Git)
@@ -1,93 +0,0 @@
1
- require 'mixlib/shellout'
2
-
3
- class String
4
- def strip_console_escapes
5
- self.gsub(/\e\[[^m]{1,5}m/,'')
6
- end
7
-
8
- def indent(amount, char=' ')
9
- prefix = char * amount
10
- lines.map { |ln| ln =~ /^\s*$/ ? ln : prefix+ln }.join
11
- end
12
- end
13
-
14
- module Vendorificator
15
- module TestSupport
16
- module RunsCommands
17
- def command
18
- raise RuntimeError, "No command has run yet!" unless @command
19
- @command
20
- end
21
-
22
- def run(*command_args)
23
- opts = {}
24
- opts = command_args.pop if command_args.last.is_a?(Hash)
25
-
26
- # We need to clear out Git environment variables left here by
27
- # the Git gem.
28
- opts[:environment] ||= {}
29
- opts[:environment].merge!(
30
- 'GIT_DIR' => nil,
31
- 'GIT_INDEX_FILE' => nil,
32
- 'GIT_WORK_TREE' => nil)
33
-
34
- command_args.push opts
35
- @command = Mixlib::ShellOut.new(*command_args)
36
-
37
- command.run_command
38
- print_command_result if ENV['VERBOSE']
39
- end
40
-
41
- def command_succeeded(print_failed=true)
42
- begin
43
- command.error!
44
- rescue Mixlib::ShellOut::ShellCommandFailed
45
- print_command_result if print_failed
46
- false
47
- else
48
- true
49
- end
50
- end
51
-
52
- def command_stdout
53
- command.stdout.strip_console_escapes
54
- end
55
-
56
- def command_stderr
57
- command.stderr.strip_console_escapes
58
- end
59
-
60
- # Depending on stream, returns:
61
- # when 'stdout': command_stdout
62
- # when 'stderr': command_stderr
63
- # otherwise: command.stdout + "\n" + command_stderr
64
- def command_output(stream=nil)
65
- case stream
66
- when 'stdout'
67
- command_stdout
68
- when 'stderr'
69
- command_stderr
70
- else
71
- "#{command_stdout}\n#{command_stderr}"
72
- end
73
- end
74
-
75
- def print_command_result
76
- puts <<EOF
77
-
78
- -------- BEGIN #{command.command.inspect} --------
79
- Exit status: #{command.exitstatus}
80
- Execution time: #{command.execution_time}
81
- Stdout:
82
- #{command_stdout.indent(4)}
83
- Stderr:
84
- #{command_stderr.indent(4)}
85
- -------- END #{command.command.inspect} --------
86
-
87
- EOF
88
- end
89
- end
90
- end
91
- end
92
-
93
- World(Vendorificator::TestSupport::RunsCommands)