mvn2 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c72be85209bb1530015bcd6b2eb25e2d426e25c0
4
- data.tar.gz: 7c07e923c4bdb1ad8bf1e45bd5335045e47189e7
3
+ metadata.gz: bbe17e1824645491f53d325e16cbc27fd78fb92e
4
+ data.tar.gz: b80978a9c66ff6b807a0d0cfbc352a9b49cc1057
5
5
  SHA512:
6
- metadata.gz: 4ef22f5679a9697663580798ca40473aa527a44380c57d497646fbd767c229d3640aecf124c75fa6c6836dc3c8fd8a931e83eb55101eb281af0efe9a2fee7747
7
- data.tar.gz: f360db16d6a98677ca1822642c358339859d5373d34aac49d6c3b0b4d0dc94a70bd0ecfb783c56ab5c7fdaadb070bff3ba4344d7faee4a665ac0f5d2b7aa7c26
6
+ metadata.gz: ac64c92c0b0fdde3ef7f241594065286d9f7e0949e94cf3f442407541d91cad908ee83e484612defaa91abf1220f33f8e763f6a8e301c0e1774390510b9511cc
7
+ data.tar.gz: d2aefc76312bb99b7346327d6f189914ab3dba2a6271574d1dc0aa935e50d6c4aef330904877d549fc9b6201795682f61d97c96c3d6fd506c6419537859e4369
data/bin/mvn2 CHANGED
@@ -36,8 +36,8 @@ class MyOptions
36
36
  help_option ['--help'], desc: 'print out this help'
37
37
  end
38
38
 
39
- Mvn2::Plugins.get(:option, MyOptions)
40
- Mvn2::Plugins.get(:option_with_param, MyOptions)
39
+ Mvn2::Plugins.get :option, MyOptions
40
+ Mvn2::Plugins.get :option_with_param, MyOptions
41
41
 
42
42
  MyOptions.parse!
43
43
 
@@ -2,6 +2,7 @@ require 'mvn2/plugin'
2
2
  class AvgPlugin
3
3
  extend Mvn2::Plugin
4
4
  extend Mvn2::PluginType
5
+ extend Mvn2::TypeHelper
5
6
 
6
7
  register_variable :average
7
8
  register_variable :averages2
@@ -17,9 +18,7 @@ class AvgPlugin
17
18
  register_type(:block_average) { |list| basic_type(list) }
18
19
 
19
20
  register_type(:block_update) { |list|
20
- result = Mvn2::Plugins.get_var :result
21
- average = Mvn2::Plugins.get_var :average
22
- diff = Mvn2::Plugins.get_var :diff
21
+ result, average, diff = Mvn2::Plugins.get_vars :result, :average, :diff
23
22
  basic_type(list, result, average, diff)
24
23
  }
25
24
 
@@ -90,10 +89,9 @@ class AvgPlugin
90
89
  end
91
90
 
92
91
  def self.read_advanced_avg
93
- options = Mvn2::Plugins.get_var :options
94
- average = Mvn2::Plugins.get_var :average
95
- averages = [average]
96
- file_name = full_avg_file
92
+ options, average = Mvn2::Plugins.get_vars :options, :average
93
+ averages = [average]
94
+ file_name = full_avg_file
97
95
  if !Mvn2::Plugins.get(:block_full_average) && options[:advanced_average] && File.exist?(file_name)
98
96
  lines = IO.readlines(file_name)
99
97
  data = lines.filtermap { |line| float_filter(line) }
@@ -134,24 +132,18 @@ class AvgPlugin
134
132
  pkg = options[:package] ? 2 : 0
135
133
  average = averages[(options[:skip_tests] ? 0 : 1) + pkg]
136
134
  end
137
- Mvn2::Plugins.set_var :average, average
138
- Mvn2::Plugins.set_var :averages2, averages
139
- Mvn2::Plugins.set_var :counts, counts
135
+ Mvn2::Plugins.set_vars average: average, averages2: averages, counts: counts
140
136
  end
141
137
 
142
138
  def self.calc_new_avg(ind)
143
- averages2 = Mvn2::Plugins.get_var :averages2
144
- counts = Mvn2::Plugins.get_var :counts
145
- diff = Mvn2::Plugins.get_var :diff
146
- sum = averages2[ind] * counts[ind] + diff
147
- counts[ind] += 1
148
- averages2[ind] = sum / counts[ind]
139
+ averages2, counts, diff = Mvn2::Plugins.get_vars :averages2, :counts, :diff
140
+ sum = averages2[ind] * counts[ind] + diff
141
+ counts[ind] += 1
142
+ averages2[ind] = sum / counts[ind]
149
143
  end
150
144
 
151
145
  def self.update_avg
152
- options = Mvn2::Plugins.get_var :options
153
- averages2 = Mvn2::Plugins.get_var :averages2
154
- counts = Mvn2::Plugins.get_var :counts
146
+ options, averages2, counts = Mvn2::Plugins.get_vars :options, :averages2, :counts
155
147
  if !Mvn2::Plugins.get(:block_average) && !Mvn2::Plugins.get(:block_update)
156
148
  options[:skip_tests] ? calc_new_avg(0) : calc_new_avg(1)
157
149
  IO.write('avg.txt', "#{averages2[0]};#{counts[0]}\n#{averages2[1]};#{counts[1]}\n#{averages2[2]};#{counts[2]}\n#{averages2[3]};#{counts[3]}")
@@ -26,8 +26,7 @@ class FilterPlugin
26
26
  str = ''
27
27
  str << INFO_LINE << "\n" unless info_line_last
28
28
  str << line << "\n"
29
- Mvn2::Plugins.set_var :found, true
30
- Mvn2::Plugins.set_var :info_line_last, false
29
+ Mvn2::Plugins.set_vars found: true, info_line_last: false
31
30
  str
32
31
  else
33
32
  nil
@@ -37,8 +36,7 @@ class FilterPlugin
37
36
  register(:line_filter, priority: 20) { |_, line|
38
37
  if line.start_with_any?('[ERROR] COMPILATION ERROR :', 'Results :')
39
38
  str = line << "\n"
40
- Mvn2::Plugins.set_var :found, true
41
- Mvn2::Plugins.set_var :info_line_last, false
39
+ Mvn2::Plugins.set_vars found: true, info_line_last: false
42
40
  str
43
41
  else
44
42
  nil
@@ -49,8 +47,7 @@ class FilterPlugin
49
47
  found = Mvn2::Plugins.get_var :found
50
48
  if found
51
49
  str = line << "\n"
52
- Mvn2::Plugins.set_var :found, true
53
- Mvn2::Plugins.set_var :info_line_last, line.start_with?(INFO_LINE)
50
+ Mvn2::Plugins.set_vars found: true, info_line_last: line.start_with?(INFO_LINE)
54
51
  str
55
52
  else
56
53
  nil
@@ -61,8 +58,7 @@ class FilterPlugin
61
58
  found = Mvn2::Plugins.get_var :found
62
59
  if options[:hide_between] && found && line.start_with?('Tests run:')
63
60
  str = line << "\n\n"
64
- Mvn2::Plugins.set_var :found, false
65
- Mvn2::Plugins.set_var :info_line_last, false
61
+ Mvn2::Plugins.set_vars found: false, info_line_last: false
66
62
  str
67
63
  else
68
64
  nil
data/lib/mvn2/plugin.rb CHANGED
@@ -43,17 +43,33 @@ module Mvn2
43
43
  @vars[name] || nil
44
44
  end
45
45
 
46
+ def get_vars(*names)
47
+ names.map { |name| get_var(name) }
48
+ end
49
+
46
50
  def set_var(name, value)
47
51
  @vars[name] = value
48
52
  end
49
53
 
54
+ def set_vars(vars = {})
55
+ vars.each { |v| set_var(*v) }
56
+ end
57
+
50
58
  def self.get_var(name)
51
59
  instance.get_var(name)
52
60
  end
53
61
 
62
+ def self.get_vars(*names)
63
+ instance.get_vars(*names)
64
+ end
65
+
54
66
  def self.set_var(name, value)
55
67
  instance.set_var(name, value)
56
68
  end
69
+
70
+ def self.set_vars(vars = {})
71
+ instance.set_vars(vars)
72
+ end
57
73
  end
58
74
  module Plugin
59
75
  def register(type, options = {}, &block)
@@ -68,20 +84,51 @@ module Mvn2
68
84
  def register_variable(name, value = nil)
69
85
  Mvn2::Plugins.instance.register_variable(name, value)
70
86
  end
71
-
87
+ end
88
+ module TypeHelper
72
89
  def basic_type(list, *args)
73
90
  options = Mvn2::Plugins.get_var :options
74
91
  list.any? { |item|
75
92
  if item[:block].nil?
76
- item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
93
+ flag_boolean(item, options)
77
94
  else
78
95
  item[:block].call(options, *args)
79
96
  end
80
97
  }
81
98
  end
99
+
100
+ def flag_boolean(item, options)
101
+ item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
102
+ end
103
+
104
+ def complex_filter(list, options, symbol)
105
+ list.filtermap { |item|
106
+ if item[:block].nil?
107
+ if item[:options].has_key?(symbol) && flag_boolean(item, options)
108
+ item[:options][symbol]
109
+ else
110
+ item[:options].has_key?(:option) && !options[item[:options][:option]].nil? ? options[item[:options][:option]] : false
111
+ end
112
+ else
113
+ rval = item[:block].call(options)
114
+ (rval.nil? || !rval) ? false : rval
115
+ end
116
+ }
117
+ end
118
+
119
+ def simple_type(list, *args)
120
+ options = Mvn2::Plugins.get_var :options
121
+ list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, *args) }
122
+ end
123
+
124
+ def simple_type_with_result(list)
125
+ result = Mvn2::Plugins.get_var :result
126
+ simple_type(list, result)
127
+ end
82
128
  end
83
129
  class DefaultTypes
84
130
  extend Mvn2::PluginType
131
+ extend Mvn2::TypeHelper
85
132
 
86
133
  register_variable :options
87
134
  register_variable :result
@@ -100,16 +147,19 @@ module Mvn2
100
147
  }
101
148
  end
102
149
 
103
- register_type(:option) { |list, options| register_option(list, options) { |id, names, option| options.option id, names, option[:options] } }
150
+ def self.def_options
151
+ register_type(:option) { |list, options| register_option(list, options) { |id, names, option| options.option id, names, option[:options] } }
152
+ register_type(:option_with_param) { |list, options| register_option(list, options) { |id, names, option| options.option_with_param id, names, option[:options] } }
153
+ end
104
154
 
105
- register_type(:option_with_param) { |list, options| register_option(list, options) { |id, names, option| options.option_with_param id, names, option[:options] } }
155
+ def_options
106
156
 
107
157
  register_type(:command_flag) { |list|
108
158
  options = Mvn2::Plugins.get_var :options
109
159
  flags = []
110
160
  list.each { |flag|
111
161
  if flag[:block].nil?
112
- flags << " #{flag[:options][:flag]}" if flag[:options].has_key?(:option) && options[flag[:options][:option]] == (flag[:options].has_key?(:value) ? flag[:options][:value] : true)
162
+ flags << " #{flag[:options][:flag]}" if flag_boolean(flag, options)
113
163
  else
114
164
  flag[:block].call(options, flags)
115
165
  end
@@ -117,64 +167,32 @@ module Mvn2
117
167
  flags.join
118
168
  }
119
169
 
120
- register_type(:before_run) { |list|
121
- options = Mvn2::Plugins.get_var :options
122
- list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options) }
123
- }
124
-
125
- register_type(:after_run) { |list|
126
- options = Mvn2::Plugins.get_var :options
127
- result = Mvn2::Plugins.get_var :result
128
- list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, result) }
129
- }
130
-
131
- register_type(:before_start) { |list|
132
- options = Mvn2::Plugins.get_var :options
133
- list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options) }
134
- }
135
-
136
- register_type(:after_end) { |list|
137
- options = Mvn2::Plugins.get_var :options
138
- result = Mvn2::Plugins.get_var :result
139
- list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, result) }
140
- }
170
+ def self.def_actions
171
+ register_type(:before_run) { |list| simple_type(list) }
172
+ register_type(:after_run) { |list| simple_type_with_result(list) }
173
+ register_type(:before_start) { |list| simple_type(list) }
174
+ register_type(:after_end) { |list| simple_type_with_result(list) }
175
+ register_type(:notification) { |list|
176
+ options, result, cmd_clean, message_text = Mvn2::Plugins.get_vars :options, :result, :cmd_clean, :message_text
177
+ list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, result, cmd_clean, message_text) }
178
+ }
179
+ end
141
180
 
142
- register_type(:notification) { |list|
143
- options = Mvn2::Plugins.get_var :options
144
- result = Mvn2::Plugins.get_var :result
145
- cmd_clean = Mvn2::Plugins.get_var :cmd_clean
146
- message_text = Mvn2::Plugins.get_var :message_text
147
- list.sort_by { |v| v[:options][:order] }.each { |item| item[:block].call(options, result, cmd_clean, message_text) }
148
- }
181
+ def_actions
149
182
 
150
- register_type(:log_file_name) { |list|
183
+ def self.get_name(list)
151
184
  options = Mvn2::Plugins.get_var :options
152
- name = nil
153
- list.sort_by { |v| -v[:options][:priority] }.each { |item|
154
- if item[:block].nil?
155
- if item[:options].has_key?(:name) && item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
156
- name = item[:options][:name]
157
- break
158
- elsif item[:options].has_key?(:option) && !options[item[:options][:option]].nil?
159
- name = options[item[:options][:option]]
160
- break
161
- end
162
- else
163
- rval = item[:block].call(options)
164
- unless rval.nil?
165
- name = rval
166
- break
167
- end
168
- end
169
- }
170
- name
171
- }
185
+ rval = complex_filter(list.sort_by { |v| -v[:options][:priority] }, options, :name)
186
+ (rval.nil? || rval.empty?) ? false : rval.first
187
+ end
172
188
 
173
- register_type(:log_file_disable) { |list| basic_type(list) }
189
+ def self.def_logs
190
+ register_type(:log_file_name) { |list| get_name(list) }
191
+ register_type(:log_file_disable) { |list| basic_type(list) }
192
+ register_type(:log_file_enable) { |list| (Mvn2::Plugins.get(:log_file_name).nil? || Mvn2::Plugins.get(:log_file_disable)) ? false : basic_type(list) }
193
+ end
174
194
 
175
- register_type(:log_file_enable) { |list|
176
- (Mvn2::Plugins.get(:log_file_name).nil? || Mvn2::Plugins.get(:log_file_disable)) ? false : basic_type(list)
177
- }
195
+ def_logs
178
196
 
179
197
  register_type(:line_filter) { |list, line|
180
198
  options = Mvn2::Plugins.get_var :options
@@ -197,8 +215,7 @@ module Mvn2
197
215
  register_type(:runner_enable) { |list, key| basic_type(list.select { |v| v[:options][:key] == key }) }
198
216
 
199
217
  register_type(:runner) { |list|
200
- options = Mvn2::Plugins.get_var :options
201
- cmd = Mvn2::Plugins.get_var :cmd
218
+ options, cmd = Mvn2::Plugins.get_vars :options, :cmd
202
219
  Mvn2::Plugins.set_var :result, false
203
220
  list.sort_by { |v| -v[:options][:priority] }.each { |item|
204
221
  if Mvn2::Plugins.get(:runner_enable, item[:options][:key])
@@ -210,24 +227,11 @@ module Mvn2
210
227
  Mvn2::Plugins.get_var :result
211
228
  }
212
229
 
213
- def self.goal_filter(item, options)
214
- if item[:block].nil?
215
- if item[:options].has_key?(:goal) && item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
216
- item[:options][:goal]
217
- else
218
- item[:options].has_key?(:option) && !options[item[:options][:option]].nil? ? options[item[:options][:option]] : false
219
- end
220
- else
221
- rval = item[:block].call(options)
222
- (rval.nil? || !rval) ? false : rval
223
- end
224
- end
225
-
226
230
  register_type(:goal_override) { |list|
227
231
  options = Mvn2::Plugins.get_var :options
228
- full_overrides = list.select { |v| v[:options][:override_all] }.sort_by { |v| -v[:options][:priority] }.filtermap { |item| goal_filter(item, options) }
232
+ full_overrides = complex_filter(list.select { |v| v[:options][:override_all] }.sort_by { |v| -v[:options][:priority] }, options, :goal)
229
233
  if full_overrides.nil? || full_overrides.empty?
230
- goals = list.select { |v| !v[:options][:override_all] }.sort_by { |v| v[:options][:order] }.filtermap { |item| goal_filter(item, options) }
234
+ goals = complex_filter(list.select { |v| !v[:options][:override_all] }.sort_by { |v| v[:options][:order] }, options, :goal)
231
235
  goals = ['install'] if (goals - ['clean']).empty?
232
236
  goals = ['clean'] + goals unless goals.include?('clean')
233
237
  goals.join(' ')
@@ -236,28 +240,7 @@ module Mvn2
236
240
  end
237
241
  }
238
242
 
239
- register_type(:operation_name) { |list|
240
- options = Mvn2::Plugins.get_var :options
241
- name = false
242
- list.sort_by { |v| -v[:options][:priority] }.each { |item|
243
- if item[:block].nil?
244
- if item[:options].has_key?(:name) && item[:options].has_key?(:option) && options[item[:options][:option]] == (item[:options].has_key?(:value) ? item[:options][:value] : true)
245
- name = item[:options][:name]
246
- break
247
- elsif item[:options].has_key?(:option) && !options[item[:options][:option]].nil?
248
- name = options[item[:options][:option]]
249
- break
250
- end
251
- else
252
- rval = item[:block].call(options)
253
- unless rval.nil? || !rval
254
- name = rval
255
- break
256
- end
257
- end
258
- }
259
- name || 'Operation'
260
- }
243
+ register_type(:operation_name) { |list| get_name(list) || 'Operation' }
261
244
 
262
245
  DEFAULT_COLOR_OPTS = {
263
246
  time: {
data/lib/mvn2/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mvn2
2
- VERSION = '2.0.2'
2
+ VERSION = '2.1.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mvn2
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Henderson