rake-funnel 0.3.2.pre → 0.4.0.pre

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -2
  3. data/Gemfile +4 -0
  4. data/README.md +2 -2
  5. data/lib/rake/funnel/ambiguous_file_error.rb +31 -29
  6. data/lib/rake/funnel/execution_error.rb +28 -26
  7. data/lib/rake/funnel/extensions/case/camel_case.rb +24 -19
  8. data/lib/rake/funnel/extensions/case/pascal_case.rb +24 -19
  9. data/lib/rake/funnel/extensions/case.rb +3 -3
  10. data/lib/rake/funnel/extensions/common_path.rb +60 -52
  11. data/lib/rake/funnel/extensions/disable_colors.rb +33 -27
  12. data/lib/rake/funnel/extensions/rexml.rb +27 -23
  13. data/lib/rake/funnel/extensions/shell.rb +92 -56
  14. data/lib/rake/funnel/extensions/windows_path.rb +15 -11
  15. data/lib/rake/funnel/framework.rb +11 -16
  16. data/lib/rake/funnel/integration/progress_report.rb +72 -70
  17. data/lib/rake/funnel/integration/sync_output.rb +12 -8
  18. data/lib/rake/funnel/integration/teamcity/nunit_plugin.rb +61 -55
  19. data/lib/rake/funnel/integration/teamcity/progress_report.rb +39 -33
  20. data/lib/rake/funnel/integration/teamcity/service_messages.rb +46 -40
  21. data/lib/rake/funnel/integration/teamcity/teamcity.rb +19 -15
  22. data/lib/rake/funnel/integration/teamcity.rb +3 -5
  23. data/lib/rake/funnel/support/argument_mapper/key_value_pair.rb +16 -10
  24. data/lib/rake/funnel/support/argument_mapper/styles/default.rb +39 -31
  25. data/lib/rake/funnel/support/argument_mapper/styles/msbuild.rb +41 -33
  26. data/lib/rake/funnel/support/argument_mapper/styles/msdeploy.rb +55 -47
  27. data/lib/rake/funnel/support/argument_mapper/styles/nunit.rb +41 -33
  28. data/lib/rake/funnel/support/argument_mapper/styles.rb +3 -5
  29. data/lib/rake/funnel/support/argument_mapper/switch.rb +16 -10
  30. data/lib/rake/funnel/support/argument_mapper/value.rb +16 -10
  31. data/lib/rake/funnel/support/assembly_version/from_version_files.rb +39 -35
  32. data/lib/rake/funnel/support/assembly_version/languages/cs +5 -5
  33. data/lib/rake/funnel/support/assembly_version/languages/fs +12 -12
  34. data/lib/rake/funnel/support/assembly_version/languages/vb +5 -5
  35. data/lib/rake/funnel/support/assembly_version_writer.rb +56 -52
  36. data/lib/rake/funnel/support/binary_version_reader.rb +37 -32
  37. data/lib/rake/funnel/support/copier.rb +31 -27
  38. data/lib/rake/funnel/support/environments/loader.rb +46 -40
  39. data/lib/rake/funnel/support/environments.rb +3 -3
  40. data/lib/rake/funnel/support/internal/finder.rb +55 -51
  41. data/lib/rake/funnel/support/internal/instantiate_symbol.rb +38 -34
  42. data/lib/rake/funnel/support/mapper.rb +57 -53
  43. data/lib/rake/funnel/support/mono.rb +21 -17
  44. data/lib/rake/funnel/support/msbuild/build_tool.rb +30 -24
  45. data/lib/rake/funnel/support/msbuild.rb +3 -3
  46. data/lib/rake/funnel/support/msdeploy/registry_patch.rb +90 -84
  47. data/lib/rake/funnel/support/msdeploy.rb +3 -3
  48. data/lib/rake/funnel/support/patch.rb +41 -37
  49. data/lib/rake/funnel/support/specs_remover.rb +66 -62
  50. data/lib/rake/funnel/support/template_engine.rb +30 -26
  51. data/lib/rake/funnel/support/timing/report.rb +95 -89
  52. data/lib/rake/funnel/support/timing/statistics.rb +32 -26
  53. data/lib/rake/funnel/support/timing.rb +3 -3
  54. data/lib/rake/funnel/support/version_info.rb +103 -72
  55. data/lib/rake/funnel/support/which.rb +19 -15
  56. data/lib/rake/funnel/support/zipper.rb +53 -49
  57. data/lib/rake/funnel/tasks/assembly_version.rb +44 -40
  58. data/lib/rake/funnel/tasks/bin_path.rb +45 -41
  59. data/lib/rake/funnel/tasks/copy.rb +43 -39
  60. data/lib/rake/funnel/tasks/environments.rb +89 -89
  61. data/lib/rake/funnel/tasks/msbuild.rb +55 -51
  62. data/lib/rake/funnel/tasks/msdeploy.rb +54 -50
  63. data/lib/rake/funnel/tasks/nunit.rb +52 -48
  64. data/lib/rake/funnel/tasks/paket.rb +51 -47
  65. data/lib/rake/funnel/tasks/quick_template.rb +53 -49
  66. data/lib/rake/funnel/tasks/side_by_side_specs.rb +41 -37
  67. data/lib/rake/funnel/tasks/timing.rb +108 -104
  68. data/lib/rake/funnel/tasks/zip.rb +46 -42
  69. data/lib/rake/funnel/version.rb +1 -1
  70. data/lib/rake/funnel.rb +7 -7
  71. data/rake-funnel.gemspec +12 -3
  72. data/spec/rake/funnel/execution_error_spec.rb +67 -67
  73. data/spec/rake/funnel/extensions/case/camel_case_spec.rb +17 -17
  74. data/spec/rake/funnel/extensions/case/pascal_case_spec.rb +17 -17
  75. data/spec/rake/funnel/extensions/common_path_spec.rb +56 -56
  76. data/spec/rake/funnel/extensions/disable_colors_spec.rb +33 -33
  77. data/spec/rake/funnel/extensions/rexml_spec.rb +20 -20
  78. data/spec/rake/funnel/extensions/shell_spec.rb +237 -237
  79. data/spec/rake/funnel/extensions/windows_path_spec.rb +5 -5
  80. data/spec/rake/funnel/integration/progress_report_spec.rb +149 -149
  81. data/spec/rake/funnel/integration/sync_output_spec.rb +16 -16
  82. data/spec/rake/funnel/integration/teamcity/nunit_plugin_spec.rb +110 -110
  83. data/spec/rake/funnel/integration/teamcity/progress_report_spec.rb +174 -174
  84. data/spec/rake/funnel/integration/teamcity/service_messages_spec.rb +136 -136
  85. data/spec/rake/funnel/integration/teamcity/teamcity_spec.rb +34 -34
  86. data/spec/rake/funnel/support/argument_mapper/styles/msdeploy_spec.rb +222 -222
  87. data/spec/rake/funnel/support/argument_mapper/styles/nunit_spec.rb +25 -25
  88. data/spec/rake/funnel/support/argument_mapper/styles/styles_spec.rb +214 -214
  89. data/spec/rake/funnel/support/assembly_version/from_version_files_spec.rb +66 -61
  90. data/spec/rake/funnel/support/assembly_version_writer_spec.rb +140 -140
  91. data/spec/rake/funnel/support/binary_version_reader_spec.rb +29 -29
  92. data/spec/rake/funnel/support/copier_spec.rb +58 -58
  93. data/spec/rake/funnel/support/environments/loader_spec.rb +143 -143
  94. data/spec/rake/funnel/support/internal/finder_spec.rb +229 -229
  95. data/spec/rake/funnel/support/internal/instantiate_symbol_spec.rb +182 -183
  96. data/spec/rake/funnel/support/mapper_spec.rb +87 -87
  97. data/spec/rake/funnel/support/mono_spec.rb +57 -57
  98. data/spec/rake/funnel/support/msbuild/build_tool_spec.rb +21 -21
  99. data/spec/rake/funnel/support/msdeploy/registry_patch_spec.rb +139 -139
  100. data/spec/rake/funnel/support/patch_spec.rb +108 -108
  101. data/spec/rake/funnel/support/specs_remover/Sample.csproj +28 -28
  102. data/spec/rake/funnel/support/specs_remover_spec.rb +116 -116
  103. data/spec/rake/funnel/support/template_engine_spec.rb +65 -65
  104. data/spec/rake/funnel/support/timing/report_spec.rb +129 -129
  105. data/spec/rake/funnel/support/version_info_spec.rb +333 -228
  106. data/spec/rake/funnel/support/which_spec.rb +65 -65
  107. data/spec/rake/funnel/support/zipper_spec.rb +77 -77
  108. data/spec/rake/funnel/tasks/assembly_version_spec.rb +45 -45
  109. data/spec/rake/funnel/tasks/bin_path_spec.rb +52 -52
  110. data/spec/rake/funnel/tasks/copy_spec.rb +44 -44
  111. data/spec/rake/funnel/tasks/environments_spec.rb +249 -247
  112. data/spec/rake/funnel/tasks/msbuild_spec.rb +91 -91
  113. data/spec/rake/funnel/tasks/msdeploy_spec.rb +220 -220
  114. data/spec/rake/funnel/tasks/nunit_spec.rb +74 -74
  115. data/spec/rake/funnel/tasks/paket_spec.rb +140 -142
  116. data/spec/rake/funnel/tasks/quick_template_spec.rb +62 -62
  117. data/spec/rake/funnel/tasks/side_by_side_specs_spec.rb +58 -58
  118. data/spec/rake/funnel/tasks/timing_spec.rb +133 -133
  119. data/spec/rake/funnel/tasks/zip_spec.rb +50 -50
  120. data/spec/spec_helper.rb +43 -33
  121. metadata +2 -3
  122. data/lib/rake/funnel/support/side_by_side_specs.rb +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1da41cf4992ddeaf2f023b7d1775bbb536245d91
4
- data.tar.gz: 427f5aefb6590394971f58dd1d0fb158ddc34a89
3
+ metadata.gz: a8f5640c14dff5bf858d39fc9ae5bac6be7871ee
4
+ data.tar.gz: 03a44a3c45f0a6f9ccaf71a2ac87e4c73accab58
5
5
  SHA512:
6
- metadata.gz: 54408b65fb95277d9c595710480504bb60bfe0974da277b5e8bbf85393c4e827d4ad37b482692804434fba1f8d1a95e0ce3042fea9f43a33311f966cd0b68043
7
- data.tar.gz: a50098c401447487a386793457e1f2dedc5b03500ee1a8e1dd07366dd0f71910c96a558d4d5be5f3edb192a57c409837f5a296116c49015245c3afe66a512f22
6
+ metadata.gz: 8759d1624ab1c1f6cb18693966e263cde514d516ce02d2250fe2da279b32561b13ad3e68785349ca5041d8beaba3622d2dac9aa1b34d43d6e8b665a20461c6c1
7
+ data.tar.gz: 99aaf5c647d45208a2056514b824e2795f7c90e053be7c7d665cb44eccc0384f4fca5520e6a024bec8ca9a37ea13a35ebce2a886d70fd849e65c6e4f8b39cb08
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --require spec_helper
2
- --tag ~@draft
1
+ --require spec_helper
2
+ --tag ~@draft
data/Gemfile CHANGED
@@ -7,6 +7,7 @@ gemspec
7
7
  group :development do
8
8
  gem 'guard-bundler', require: false
9
9
  gem 'guard-rspec', require: false
10
+ gem 'guard-rubocop', require: false
10
11
 
11
12
  case RbConfig::CONFIG['target_os']
12
13
  when /windows|bccwin|cygwin|djgpp|mingw|mswin|wince/i
@@ -26,4 +27,7 @@ group :development, :ci do
26
27
  gem 'rspec-collection_matchers', require: false
27
28
  gem 'coveralls', require: false
28
29
  gem 'codeclimate-test-reporter', require: false
30
+ gem 'rubocop', require: false
31
+ gem 'rubocop-rspec', require: false
32
+ gem 'simplecov-teamcity-summary', require: false
29
33
  end
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # rake-funnel
2
2
 
3
- [![Gem Version](https://badge.fury.io/rb/rake-funnel.png)](http://badge.fury.io/rb/rake-funnel) [![Build Status](https://travis-ci.org/agross/rake-funnel.png?branch=master)](https://travis-ci.org/agross/rake-funnel) [![Dependency Status](https://gemnasium.com/agross/rake-funnel.png)](https://gemnasium.com/agross/rake-funnel) [![Code Climate](https://codeclimate.com/github/agross/rake-funnel.png)](https://codeclimate.com/github/agross/rake-funnel) [![Coverage Status](https://coveralls.io/repos/agross/rake-funnel/badge.png)](https://coveralls.io/r/agross/rake-funnel)
3
+ [![Gem Version](https://badge.fury.io/rb/rake-funnel.svg)](http://badge.fury.io/rb/rake-funnel) [![Build Status](https://travis-ci.org/agross/rake-funnel.png?branch=master)](https://travis-ci.org/agross/rake-funnel) [![Dependency Status](https://gemnasium.com/agross/rake-funnel.svg)](https://gemnasium.com/agross/rake-funnel) [![Code Climate](https://codeclimate.com/github/agross/rake-funnel.png)](https://codeclimate.com/github/agross/rake-funnel) [![Coverage Status](https://coveralls.io/repos/agross/rake-funnel/badge.svg)](https://coveralls.io/r/agross/rake-funnel)
4
4
 
5
5
  rake-funnel is my set of rake tasks, mostly targeted at .NET development.
6
6
 
7
- * Tested against Ruby 2.0.0, 2.1.0 and 2.2.0 and ruby-head
7
+ * Tested against Ruby 2.0.0, 2.1.0 through 2.2.1 and ruby-head
8
8
  * Ruby < 2.0 is not supported
9
9
 
10
10
  ## Installation
@@ -1,29 +1,31 @@
1
- module Rake::Funnel
2
- class AmbiguousFileError < StandardError
3
- attr_reader :task_name, :search_pattern, :candidates, :description
4
-
5
- def initialize(message, task_name, search_pattern, candidates)
6
- description = "Could not run task '#{task_name}'. #{message}"
7
- super(description)
8
-
9
- @description = description
10
- @task_name = task_name
11
- @search_pattern = search_pattern
12
- @candidates = candidates
13
- end
14
-
15
- def to_s
16
- msg = []
17
- (msg << description) if description
18
- (msg << "Search pattern used: #{@search_pattern}") if @search_pattern
19
- unless (@candidates || []).empty?
20
- msg << 'Candidates:'
21
- msg << @candidates.map { |c| " - #{c}" }
22
- end
23
-
24
- msg = [super.to_s] if msg.empty?
25
-
26
- msg.join("\n")
27
- end
28
- end
29
- end
1
+ module Rake
2
+ module Funnel
3
+ class AmbiguousFileError < StandardError
4
+ attr_reader :task_name, :search_pattern, :candidates, :description
5
+
6
+ def initialize(message, task_name, search_pattern, candidates)
7
+ description = "Could not run task '#{task_name}'. #{message}"
8
+ super(description)
9
+
10
+ @description = description
11
+ @task_name = task_name
12
+ @search_pattern = search_pattern
13
+ @candidates = candidates
14
+ end
15
+
16
+ def to_s
17
+ msg = []
18
+ (msg << description) if description
19
+ (msg << "Search pattern used: #{@search_pattern}") if @search_pattern
20
+ unless (@candidates || []).empty?
21
+ msg << 'Candidates:'
22
+ msg << @candidates.map { |c| " - #{c}" }
23
+ end
24
+
25
+ msg = [super.to_s] if msg.empty?
26
+
27
+ msg.join("\n")
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,26 +1,28 @@
1
- module Rake::Funnel
2
- class ExecutionError < StandardError
3
- attr_reader :command, :exit_code, :output, :description
4
-
5
- def initialize(command = nil, exit_code = nil, output = nil, description = nil)
6
- super(description)
7
-
8
- @description = description
9
- @command = command
10
- @exit_code = exit_code
11
- @output = output
12
- end
13
-
14
- def to_s
15
- msg = []
16
- (msg << description << nil) if description
17
- (msg << 'Error executing:' << command << nil) if command
18
- (msg << "Exit code: #{exit_code}" << nil) if exit_code
19
- (msg << 'Command output (last 10 lines):' << output.split("\n").last(10) << nil) if output
20
-
21
- msg = [super.to_s] if msg.empty?
22
-
23
- msg.join("\n")
24
- end
25
- end
26
- end
1
+ module Rake
2
+ module Funnel
3
+ class ExecutionError < StandardError
4
+ attr_reader :command, :exit_code, :output, :description
5
+
6
+ def initialize(command = nil, exit_code = nil, output = nil, description = nil)
7
+ super(description)
8
+
9
+ @description = description
10
+ @command = command
11
+ @exit_code = exit_code
12
+ @output = output
13
+ end
14
+
15
+ def to_s
16
+ msg = []
17
+ (msg << description << nil) if description
18
+ (msg << 'Error executing:' << command << nil) if command
19
+ (msg << "Exit code: #{exit_code}" << nil) if exit_code
20
+ (msg << 'Command output (last 10 lines):' << output.split("\n").last(10) << nil) if output
21
+
22
+ msg = [super.to_s] if msg.empty?
23
+
24
+ msg.join("\n")
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,19 +1,24 @@
1
- module Rake::Funnel::Extensions
2
- module CamelCase
3
- def camelize
4
- self
5
- .to_s
6
- .split('_')
7
- .inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }
8
- .join
9
- end
10
- end
11
- end
12
-
13
- class String
14
- include Rake::Funnel::Extensions::CamelCase
15
- end
16
-
17
- class Symbol
18
- include Rake::Funnel::Extensions::CamelCase
19
- end
1
+ module Rake
2
+ module Funnel
3
+ module Extensions
4
+ module Case
5
+ module CamelCase
6
+ def camelize
7
+ to_s
8
+ .split('_')
9
+ .inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }
10
+ .join
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class String
19
+ include Rake::Funnel::Extensions::Case::CamelCase
20
+ end
21
+
22
+ class Symbol
23
+ include Rake::Funnel::Extensions::Case::CamelCase
24
+ end
@@ -1,19 +1,24 @@
1
- module Rake::Funnel::Extensions
2
- module PascalCase
3
- def pascalize
4
- self
5
- .to_s
6
- .split('_')
7
- .inject([]) { |buffer, e| buffer.push(e.slice(0, 1).capitalize + e.slice(1..-1)) }
8
- .join
9
- end
10
- end
11
- end
12
-
13
- class String
14
- include Rake::Funnel::Extensions::PascalCase
15
- end
16
-
17
- class Symbol
18
- include Rake::Funnel::Extensions::PascalCase
19
- end
1
+ module Rake
2
+ module Funnel
3
+ module Extensions
4
+ module Case
5
+ module PascalCase
6
+ def pascalize
7
+ to_s
8
+ .split('_')
9
+ .inject([]) { |buffer, e| buffer.push(e.slice(0, 1).capitalize + e.slice(1..-1)) }
10
+ .join
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+
18
+ class String
19
+ include Rake::Funnel::Extensions::Case::PascalCase
20
+ end
21
+
22
+ class Symbol
23
+ include Rake::Funnel::Extensions::Case::PascalCase
24
+ end
@@ -1,3 +1,3 @@
1
- Dir["#{File.dirname(__FILE__)}/case/*.rb"].each do |path|
2
- require path
3
- end
1
+ Dir["#{File.dirname(__FILE__)}/case/*.rb"].each do |path|
2
+ require path
3
+ end
@@ -1,52 +1,60 @@
1
- require 'abbrev'
2
- require 'pathname'
3
-
4
- module Rake::Funnel::Extensions
5
- module CommonPath
6
- def common_path
7
- list = self
8
- .to_a
9
- .compact
10
- .map { |x| components(x) }
11
-
12
- min = list.min_by { |x| x.length }
13
-
14
- matches = list.map do |path|
15
- longest_prefix = []
16
-
17
- path.zip(min).each do |left, right|
18
- if left != right
19
- next
20
- end
21
- longest_prefix << right
22
- end
23
-
24
- File.join(longest_prefix)
25
- end
26
-
27
- matches.min_by { |x| x.length } || ''
28
- end
29
-
30
- private
31
- def components(path)
32
- paths = []
33
- Pathname.new(path).descend do |p|
34
- paths << p
35
- end
36
-
37
- paths.inject([]) { |components, path|
38
- relative = path.relative_path_from(components.last[:absolute]) if components.any?
39
-
40
- components << { absolute: path, relative: relative || path }
41
- }.map { |component| component[:relative].to_s }
42
- end
43
- end
44
- end
45
-
46
- class Array
47
- include Rake::Funnel::Extensions::CommonPath
48
- end
49
-
50
- class Rake::FileList
51
- include Rake::Funnel::Extensions::CommonPath
52
- end
1
+ require 'abbrev'
2
+ require 'pathname'
3
+
4
+ module Rake
5
+ module Funnel
6
+ module Extensions
7
+ module CommonPath
8
+ def common_path
9
+ list = to_a
10
+ .compact
11
+ .map { |x| components(x) }
12
+
13
+ min = list.min_by(&:length)
14
+
15
+ matches = find_matches(list, min)
16
+ matches.min_by(&:length) || ''
17
+ end
18
+
19
+ private
20
+ def components(path)
21
+ paths = []
22
+ Pathname.new(path).descend do |p|
23
+ paths << p
24
+ end
25
+
26
+ paths = paths.inject([]) { |components, p|
27
+ relative = p.relative_path_from(components.last[:absolute]) if components.any?
28
+
29
+ components << { absolute: p, relative: relative || p }
30
+ }
31
+
32
+ paths.map { |component| component[:relative].to_s }
33
+ end
34
+
35
+ def find_matches(list, min)
36
+ list.map do |path|
37
+ longest_prefix = []
38
+
39
+ path.zip(min).each do |left, right|
40
+ next if left != right
41
+ longest_prefix << right
42
+ end
43
+
44
+ File.join(longest_prefix)
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ class Array
53
+ include Rake::Funnel::Extensions::CommonPath
54
+ end
55
+
56
+ module Rake
57
+ class FileList
58
+ include Rake::Funnel::Extensions::CommonPath
59
+ end
60
+ end
@@ -1,27 +1,33 @@
1
- require 'smart_colored'
2
- require 'smart_colored/extend'
3
-
4
- module Rake::Funnel::Extensions
5
- module DisableColors
6
- def self.included(klass)
7
- original_apply_format = klass.instance_method(:apply_format)
8
-
9
- define_method(:apply_format) do |format|
10
- return self unless $stdout.tty?
11
-
12
- bind_to = self
13
- bind_to = SmartColored::String.new(self) if klass == SmartColored::String
14
-
15
- original_apply_format.bind(bind_to).call(format)
16
- end
17
- end
18
- end
19
- end
20
-
21
- class SmartColored::String
22
- include Rake::Funnel::Extensions::DisableColors
23
- end
24
-
25
- class String
26
- include Rake::Funnel::Extensions::DisableColors
27
- end
1
+ require 'smart_colored'
2
+ require 'smart_colored/extend'
3
+
4
+ module Rake
5
+ module Funnel
6
+ module Extensions
7
+ module DisableColors
8
+ def self.included(klass)
9
+ original_apply_format = klass.instance_method(:apply_format)
10
+
11
+ define_method(:apply_format) do |format|
12
+ return self unless $stdout.tty?
13
+
14
+ bind_to = self
15
+ bind_to = SmartColored::String.new(self) if klass == SmartColored::String
16
+
17
+ original_apply_format.bind(bind_to).call(format)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ module SmartColored
26
+ class String
27
+ include Rake::Funnel::Extensions::DisableColors
28
+ end
29
+ end
30
+
31
+ class String
32
+ include Rake::Funnel::Extensions::DisableColors
33
+ end
@@ -1,23 +1,27 @@
1
- require 'rexml/document'
2
-
3
- module Rake::Funnel::Extensions
4
- module REXML
5
- module Functions
6
- def lower_case(string)
7
- string.first.to_s.downcase
8
- end
9
-
10
- def matches(string, test)
11
- File.fnmatch?(test, string.first.to_s, File::FNM_CASEFOLD)
12
- end
13
- end
14
- end
15
- end
16
-
17
- module REXML
18
- module Functions
19
- class << self
20
- include Rake::Funnel::Extensions::REXML::Functions
21
- end
22
- end
23
- end
1
+ require 'rexml/document'
2
+
3
+ module Rake
4
+ module Funnel
5
+ module Extensions
6
+ module REXML
7
+ module Functions
8
+ def lower_case(string)
9
+ string.first.to_s.downcase
10
+ end
11
+
12
+ def matches(string, test)
13
+ File.fnmatch?(test, string.first.to_s, File::FNM_CASEFOLD)
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ module REXML
22
+ module Functions
23
+ class << self
24
+ include Rake::Funnel::Extensions::REXML::Functions
25
+ end
26
+ end
27
+ end
@@ -1,56 +1,92 @@
1
- require 'rake'
2
- require 'open3'
3
- require 'smart_colored/extend'
4
-
5
- module Rake::Funnel::Extensions
6
- module Shell
7
- def shell(*cmd, log_file: nil, error_lines: nil)
8
- mkdir_p(File.dirname(log_file)) if log_file
9
-
10
- stdout = -> (msg) { $stdout.puts msg.sub(/\n$/, '').green }
11
-
12
- error_logged = false
13
- stderr = -> (msg) {
14
- error_logged = true
15
- $stderr.puts msg.sub(/\n$/, '').bold.red
16
- }
17
-
18
- log = StringIO.new
19
-
20
- begin
21
- cmd = cmd.flatten.reject(&:nil?)
22
- Rake.rake_output_message(cmd.join(' '))
23
-
24
- Open3.popen2e(*cmd) do |_, stdout_and_stderr, wait_thread|
25
- stdout_and_stderr.each do |line|
26
- out = stdout
27
- out = stderr if error_lines && line =~ error_lines
28
- out.call(line)
29
-
30
- log.write(line)
31
- File.open(log_file, 'a') { |f| f.write(line) } if log_file
32
- end
33
-
34
- success = wait_thread.value.success? && error_logged == false
35
- result = [cmd.join(' '),
36
- wait_thread.value.exitstatus,
37
- log.string]
38
-
39
- if block_given?
40
- yield(success, *result)
41
- return
42
- end
43
-
44
- raise Rake::Funnel::ExecutionError.new(*result) unless success
45
- end
46
- ensure
47
- log.close
48
- end
49
- end
50
- end
51
- end
52
-
53
- module Rake::DSL
54
- include Rake::Funnel::Extensions::Shell
55
- private(*Rake::Funnel::Extensions::Shell.instance_methods(false))
56
- end
1
+ require 'rake'
2
+ require 'open3'
3
+ require 'smart_colored/extend'
4
+ require 'stringio'
5
+
6
+ module Rake
7
+ module Funnel
8
+ module Extensions
9
+ module Shell
10
+ def shell(*cmd, log_file: nil, error_lines: nil, &block)
11
+ mkdir_p(File.dirname(log_file)) if log_file
12
+
13
+ run(cmd, log_file, error_lines) do |success, readable_cmd, result, log|
14
+ if block
15
+ block.call(success, readable_cmd, result, log)
16
+ return
17
+ end
18
+ end
19
+ end
20
+
21
+ private
22
+ def run(cmd, log_file, error_lines)
23
+ cmd, readable_cmd = normalize(cmd)
24
+
25
+ Rake.rake_output_message(readable_cmd)
26
+
27
+ Open3.popen2e(*cmd) do |_, stdout_and_stderr, wait_thread|
28
+ log, error_logged = log_output(stdout_and_stderr, log_file, error_lines)
29
+ success = wait_thread.value.success? && error_logged == false
30
+
31
+ result = [readable_cmd, wait_thread.value.exitstatus, log]
32
+
33
+ yield(success, *result) if block_given?
34
+
35
+ fail Rake::Funnel::ExecutionError.new(*result) unless success
36
+ end
37
+ end
38
+
39
+ def normalize(cmd)
40
+ cmd = cmd.flatten.reject(&:nil?)
41
+ readable_cmd = cmd.join(' ')
42
+
43
+ [cmd, readable_cmd]
44
+ end
45
+
46
+ def log_output(stdout_and_stderr, log_file, error_lines)
47
+ log_string = StringIO.new
48
+
49
+ begin
50
+ statuses = log_lines(stdout_and_stderr, log_file, error_lines, log_string)
51
+
52
+ [log_string.string, statuses.any? { |s| s == :error }]
53
+ ensure
54
+ log_string.close
55
+ end
56
+ end
57
+
58
+ def log_lines(stdout_and_stderr, log_file, error_lines, log_string)
59
+ stdout_and_stderr.map do |line|
60
+ log_string.write(line)
61
+ File.open(log_file, 'a') { |f| f.write(line) } if log_file
62
+
63
+ handle_line(line, error_lines)
64
+ end
65
+ end
66
+
67
+ def handle_line(line, error_lines)
68
+ to_stderr(line, error_lines) || to_stdout(line)
69
+ end
70
+
71
+ def to_stdout(line)
72
+ $stdout.puts line.sub(/\n$/, '').green
73
+ :success
74
+ end
75
+
76
+ def to_stderr(line, error_lines)
77
+ return unless error_lines && line =~ error_lines
78
+
79
+ $stderr.puts line.sub(/\n$/, '').bold.red
80
+ :error
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ module Rake
88
+ module DSL
89
+ include Rake::Funnel::Extensions::Shell
90
+ private(*Rake::Funnel::Extensions::Shell.instance_methods(false))
91
+ end
92
+ end