openstudio_measure_tester 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -33,11 +33,17 @@ module OpenStudioMeasureTester
33
33
  # Pass in the results_dir where all the results are stored
34
34
  # @param results_dir [String]: Directory where the results are scattered. Typically the root dir or where rake was executed
35
35
  # @param test_results_dir [String]: Where the final results are to be stored
36
- def initialize(results_dir, test_results_dir)
36
+ # @param orig_results_dir [String]: Optional directory where results are sometimes thrown into that need to be moved (coverage and minitest)
37
+ def initialize(results_dir, test_results_dir, orig_results_dir = nil)
37
38
  @results_dir = results_dir
38
39
  @test_results_dir = test_results_dir
40
+ @orig_results_dir = orig_results_dir
39
41
  @results = {}
40
42
 
43
+ puts "results_dir is #{@results_dir}"
44
+ puts "test_results_dir is #{@test_results_dir}"
45
+ puts "orig_results_dir is #{@orig_results_dir}"
46
+
41
47
  # get the repository info
42
48
  repo_name = 'unknown'
43
49
  current_branch = 'unknown'
@@ -68,12 +74,32 @@ module OpenStudioMeasureTester
68
74
  end
69
75
 
70
76
  def aggregate_results
71
- # TODO: check if we need this check of directories
72
- if @test_results_dir != @results_dir
77
+ # openstudio style is stored in the correct location (the test_results directory)
78
+ # OpenStudio Style will have already run, so just grab the results out of the directory and jam into
79
+ # the @results hash
80
+ filename = "#{@test_results_dir}/openstudio_style/openstudio_style.json"
81
+ if File.exist? filename
82
+ puts "Found OpenStudio Style results, parsing"
83
+ @results['openstudio_style'] = JSON.parse(File.read(filename))
84
+ end
85
+
86
+ filename = "#{@test_results_dir}/rubocop/rubocop.json"
87
+ if File.exist? filename
88
+ @results['rubocop'] = JSON.parse(File.read(filename))
89
+ elsif Dir.exist? "#{@test_results_dir}/rubocop"
90
+ # Parse the rubocop results if they were not cached
91
+ rc = OpenStudioMeasureTester::RubocopResult.new("#{@test_results_dir}/rubocop")
92
+ @results['rubocop'] = rc.summary
93
+ end
94
+
95
+ # don't copy if the directories are the same
96
+ if @test_results_dir != @orig_results_dir
73
97
  # coverage
74
- if Dir.exist? "#{@results_dir}/coverage"
98
+ if Dir.exist? "#{@orig_results_dir}/coverage"
99
+ puts "Found Coverage results, parsing"
75
100
  FileUtils.rm_rf "#{@test_results_dir}/coverage" if Dir.exist? "#{@test_results_dir}/coverage"
76
- FileUtils.mv "#{@results_dir}/coverage", "#{@test_results_dir}/."
101
+ FileUtils.cp_r "#{@orig_results_dir}/coverage/.", "#{@test_results_dir}/coverage"
102
+ FileUtils.rm_rf "#{@orig_results_dir}/coverage" if Dir.exist? "#{@orig_results_dir}/coverage"
77
103
 
78
104
  cov = OpenStudioMeasureTester::Coverage.new("#{@test_results_dir}/coverage")
79
105
  cov.parse_results
@@ -81,50 +107,29 @@ module OpenStudioMeasureTester
81
107
  end
82
108
 
83
109
  # minitest
84
- if Dir.exist?("#{@results_dir}/test/html_reports") || Dir.exist?("#{@results_dir}/test/reports")
110
+ if Dir.exist?("#{@orig_results_dir}/test/html_reports") || Dir.exist?("#{@orig_results_dir}/test/reports")
111
+ puts "Found Minitest Results, parsing"
85
112
  FileUtils.rm_rf "#{@test_results_dir}/minitest" if Dir.exist? "#{@test_results_dir}/minitest"
86
113
  FileUtils.mkdir_p "#{@test_results_dir}/minitest"
87
114
 
88
- if Dir.exist?("#{@results_dir}/test/html_reports")
89
- FileUtils.mv "#{@results_dir}/test/html_reports", "#{@test_results_dir}/minitest/html_reports"
115
+ # Copy the files over in case the folder is locked.
116
+ if Dir.exist?("#{@orig_results_dir}/test/html_reports")
117
+ puts "Moving Minitest HTML results to results directory"
118
+ FileUtils.cp_r "#{@orig_results_dir}/test/html_reports/.", "#{@test_results_dir}/minitest/html_reports"
90
119
  end
91
120
 
92
- if Dir.exist?("#{@results_dir}/test/reports")
93
- FileUtils.mv "#{@results_dir}/test/reports", "#{@test_results_dir}/minitest/reports"
121
+ if Dir.exist?("#{@orig_results_dir}/test/reports")
122
+ puts "Moving Minitest XML results to results directory"
123
+ FileUtils.cp_r "#{@orig_results_dir}/test/reports/.", "#{@test_results_dir}/minitest/reports"
94
124
  end
95
125
 
96
126
  # Delete the test folder if it is empty
97
- FileUtils.rm_rf "#{@results_dir}/test" if Dir.entries("#{@results_dir}/test").size == 2
127
+ FileUtils.rm_rf "#{@orig_results_dir}/test" if Dir.exist?("#{@orig_results_dir}/test") && Dir.entries("#{@orig_results_dir}/test").size == 2
98
128
 
99
129
  # Load in the data into the minitest object
100
130
  mr = OpenStudioMeasureTester::MinitestResult.new("#{@test_results_dir}/minitest")
101
131
  @results['minitest'] = mr.summary
102
132
  end
103
-
104
- # rubocop
105
- if Dir.exist? "#{@results_dir}/rubocop"
106
- FileUtils.rm_rf "#{@test_results_dir}/rubocop" if Dir.exist? "#{@test_results_dir}/rubocop"
107
- FileUtils.mv "#{@results_dir}/rubocop", "#{@test_results_dir}/rubocop"
108
-
109
- # need to create parser here!
110
- # trying!!! &^&%##%@((@*&()))!!
111
- rc = OpenStudioMeasureTester::RubocopResult.new("#{@test_results_dir}/rubocop")
112
- @results['rubocop'] = rc.summary
113
-
114
- end
115
-
116
- # openstudio style
117
- if Dir.exist? "#{@results_dir}/openstudio_style"
118
- FileUtils.rm_rf "#{@test_results_dir}/openstudio_style" if Dir.exist? "#{@test_results_dir}/openstudio_style"
119
- FileUtils.mv "#{@results_dir}/openstudio_style", "#{@test_results_dir}/openstudio_style"
120
-
121
- # OpenStudio Style will have already run, so just grab the results out of the directory and jam into
122
- # the @results hash
123
- filename = "#{@test_results_dir}/openstudio_style/openstudio_style.json"
124
- if File.exist? filename
125
- @results['openstudio_style'] = JSON.parse(File.read(filename))
126
- end
127
- end
128
133
  end
129
134
  end
130
135
 
@@ -149,37 +154,45 @@ module OpenStudioMeasureTester
149
154
  # pp @results
150
155
  final_exit_code = 0
151
156
  if @results['rubocop']
152
- if @results['rubocop']['total_errors'] > 0
153
- puts 'RuboCop errors found.'
157
+ # more than 10 errors per file on average
158
+ status = @results['rubocop']['total_errors'] / @results['rubocop']['total_files']
159
+ if status > 10
160
+ puts "More than 10 RuboCop errors per file found. Found #{status}"
154
161
  final_exit_code = 1
155
162
  end
156
163
  end
157
164
 
158
165
  if @results['openstudio_style']
159
- if @results['openstudio_style']['total_errors'] > 0
160
- puts 'OpenStudio Style errors found.'
166
+ total_files = @results['openstudio_style']['by_measure'].count
167
+ status = @results['openstudio_style']['total_errors'] / total_files
168
+ if status > 10
169
+ puts "More than 10 OpenStudio Style errors found per file. Found #{status}"
161
170
  final_exit_code = 1
162
171
  end
163
- if @results['openstudio_style']['total_warnings'] > 10
164
- puts 'More than 10 OpenStudio Style warnings found, reporting as error'
172
+
173
+ status = @results['openstudio_style']['total_warnings'] / total_files
174
+ if status > 25
175
+ puts "More than 25 OpenStudio Style warnings found per file, reporting as error. Found #{status}"
165
176
  final_exit_code = 1
166
177
  end
167
178
  end
168
179
 
169
180
  if @results['minitest']
170
181
  if @results['minitest']['total_errors'] > 0 || @results['minitest']['total_failures'] > 0
171
- puts 'Unit Test (MiniTest) errors/failures found.'
182
+ puts 'Unit Test (Minitest) errors/failures found.'
172
183
  final_exit_code = 1
173
184
  end
174
185
  end
175
186
 
176
- if @results['coverage']
177
- if @results['coverage']['total_percent_coverage'] < 70
178
- puts 'Code coverage is less than 70%, raising error.'
179
- final_exit_code = 1
180
- end
181
- end
187
+ # if @results['coverage']
188
+ # status = @results['coverage']['total_percent_coverage']
189
+ # if status < 70
190
+ # puts "Code coverage is less than 70%, raising error. Coverage was #{status}"
191
+ # final_exit_code = 1
192
+ # end
193
+ # end
182
194
 
195
+ # Since the data are relative to the directory from which it has been run, then just show from current dir (.)
183
196
  puts 'Open ./test_results/dashboard/index.html to view measure testing dashboard.'
184
197
 
185
198
  return final_exit_code
@@ -45,213 +45,67 @@ module OpenStudioMeasureTester
45
45
 
46
46
  private
47
47
 
48
- # Prepare the current directory and the root directory to remove old test results before running
49
- # the new tests
50
- def pre_process_minitest(base_dir)
51
- current_dir = Dir.pwd
52
- test_results_dir = "#{base_dir}/test_results"
53
-
54
- puts "Current directory is #{current_dir}"
55
- puts "Pre-processing tests run in #{base_dir}"
56
- puts "Test results will be stored in: #{test_results_dir}"
57
-
58
- FileUtils.rm_rf "#{test_results_dir}/coverage" if Dir.exist? "#{test_results_dir}/coverage"
59
- FileUtils.rm_rf "#{test_results_dir}/test/html_reports" if Dir.exist? "#{test_results_dir}/test/html_reports"
60
- FileUtils.rm_rf "#{test_results_dir}/test/reports" if Dir.exist? "#{test_results_dir}/test/reports"
61
- # remove the test directory if it is empty (size == 2 for . and ..)
62
- if Dir.exist?("#{test_results_dir}/test") && Dir.entries("#{test_results_dir}/test").size == 2
63
- FileUtils.rm_rf "#{test_results_dir}/test"
64
- end
65
- FileUtils.rm_rf "#{test_results_dir}/minitest" if Dir.exist? "#{test_results_dir}/minitest"
66
- FileUtils.rm_rf "#{base_dir}/coverage" if Dir.exist? "#{base_dir}/coverage"
67
- FileUtils.rm_rf "#{base_dir}/test" if Dir.exist? "#{base_dir}/test"
68
- FileUtils.rm_rf "#{base_dir}/minitest" if Dir.exist? "#{base_dir}/minitest"
69
- FileUtils.rm_rf "#{current_dir}/coverage" if Dir.exist? "#{current_dir}/coverage"
70
- FileUtils.rm_rf "#{current_dir}/test" if Dir.exist? "#{current_dir}/test"
71
- FileUtils.rm_rf "#{current_dir}/minitest" if Dir.exist? "#{current_dir}/minitest"
72
-
73
- # Create the test_results directory to store all the results
74
- FileUtils.mkdir_p "#{base_dir}/test_results"
75
- end
76
-
77
- # Rubocop stores the results (for now) in the test_results directory
78
- def pre_process_rubocop(base_dir)
79
- current_dir = Dir.pwd
80
- test_results_dir = "#{base_dir}/test_results"
81
-
82
- puts "Current directory is #{current_dir}"
83
- puts "Pre-processing tests run in #{base_dir}"
84
- puts "Test results will be stored in: #{test_results_dir}"
85
-
86
- FileUtils.rm_rf "#{test_results_dir}/rubocop" if Dir.exist? "#{test_results_dir}/rubocop"
87
- FileUtils.rm_rf "#{base_dir}/rubocop" if Dir.exist? "#{base_dir}/rubocop"
88
- FileUtils.rm_rf "#{current_dir}/rubocop" if Dir.exist? "#{current_dir}/rubocop"
89
-
90
- # Create the test_results directory to store all the results
91
- FileUtils.mkdir_p "#{base_dir}/test_results"
92
- end
93
-
94
- # OpenStudio style check preparation
95
- def pre_process_style(base_dir)
96
- current_dir = Dir.pwd
97
- test_results_dir = "#{base_dir}/test_results"
98
-
99
- puts "Current directory is #{current_dir}"
100
- puts "Pre-processing tests run in #{base_dir}"
101
- puts "Test results will be stored in: #{test_results_dir}"
102
-
103
- FileUtils.rm_rf "#{test_results_dir}/openstudio_style" if Dir.exist? "#{test_results_dir}/openstudio_style"
104
- FileUtils.rm_rf "#{base_dir}/openstudio_style" if Dir.exist? "#{base_dir}/openstudio_style"
105
- FileUtils.rm_rf "#{current_dir}/openstudio_style" if Dir.exist? "#{current_dir}/openstudio_style"
106
-
107
- # Create the test_results directory to store all the results
108
- FileUtils.mkdir_p "#{base_dir}/test_results"
109
- end
110
-
111
- def run_style(base_dir)
112
- style = OpenStudioMeasureTester::OpenStudioStyle.new("#{base_dir}/**/measure.rb")
113
- style.save_results
114
- end
115
-
116
- # Post process the various results and save them into the base_dir
117
- def post_process_results(base_dir)
118
- current_dir = Dir.pwd
119
- test_results_dir = "#{base_dir}/test_results"
120
-
121
- puts "Current directory: #{current_dir}"
122
- puts "Post-processing tests run in: #{base_dir}"
123
- puts "Test results will be stored in: #{test_results_dir}"
124
-
125
- FileUtils.mkdir_p test_results_dir
126
-
127
- results = OpenStudioMeasureTester::OpenStudioTestingResult.new(current_dir, test_results_dir)
128
- results.save_results # one single file for dashboard
129
-
130
- # call the create dashboard command now that we have results
131
- dashboard(base_dir)
132
-
133
- # return the results exit code
134
- return results.exit_code
135
- end
136
-
137
- # Run ERB to create the dashboard
138
- def dashboard(base_dir)
139
- template = OpenStudioMeasureTester::Dashboard.new(base_dir)
140
- template.render
141
- end
142
-
143
48
  def setup_subtasks(name)
144
49
  namespace name do
145
- task :prepare_minitest do
146
- pre_process_minitest(Rake.application.original_dir)
147
- end
148
-
149
- task :prepare_rubocop do
150
- # copy over the .rubocop.yml file
151
- shared_rubocop_file = File.expand_path('../../.rubocop.yml', File.dirname(__FILE__))
152
- dest_file = "#{Dir.pwd}/.rubocop.yml"
153
- if shared_rubocop_file != dest_file
154
- FileUtils.copy(shared_rubocop_file, dest_file)
155
- end
156
- pre_process_rubocop(Rake.application.original_dir)
157
- end
158
-
159
- task :prepare_style do
160
- pre_process_style(Rake.application.original_dir)
161
- end
162
-
163
- task style_core: [] do
164
- run_style(Rake.application.original_dir)
165
- end
166
-
167
- task :post_process_core do
168
- post_process_results(Rake.application.original_dir)
169
- end
170
-
171
- Rake::TestTask.new(:test_core_command) do |task|
172
- task.options = '--ci-reporter'
173
- task.description = 'Run measures tests recursively from current directory'
174
- task.pattern = [
175
- "#{Rake.application.original_dir}/**/*_test.rb",
176
- "#{Rake.application.original_dir}/**/*_Test.rb"
177
- ]
178
- task.verbose = true
179
- end
180
-
181
- task :test_core do
182
- begin
183
- Rake.application['openstudio:test_core_command'].invoke
184
- rescue StandardError
185
- puts 'Test failures in openstudio:test. Will continue to post-processing.'
186
- ensure
187
- Rake.application['openstudio:test_core_command'].reenable
188
- end
189
- end
190
-
191
- # The .rubocop.yml file downloads the RuboCop rules from the OpenStudio-resources repo.
192
- # This may cause an issue if the Gem directory does not have write access.
193
- RuboCop::RakeTask.new(:rubocop_core) do |task|
194
- task.options = ['--no-color', '--out=rubocop/rubocop-results.xml', '--format=simple']
195
- task.formatters = ['RuboCop::Formatter::CheckstyleFormatter']
196
- task.requires = ['rubocop/formatter/checkstyle_formatter']
197
- # Run the rake at the original root directory
198
- task.patterns = ["#{Rake.application.original_dir}/**/*.rb"]
199
- # don't abort rake on failure
200
- task.fail_on_error = false
201
- end
202
-
203
- desc 'Run OpenStudio Measure Unit Tests'
204
- task test: ['openstudio:prepare_minitest', 'openstudio:test_core'] do
205
- exit_status = post_process_results(Rake.application.original_dir)
206
- exit exit_status
50
+ ####################################### Minitest and Coverage #######################################
51
+ desc 'new test task'
52
+ task :test do
53
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
54
+ # Need to pass in the current directory because the results of minitest and coverage end up going into
55
+ # the root directorys
56
+ exit runner.run_test(false, Dir.pwd, false)
207
57
  end
208
58
 
59
+ ####################################### RuboCop #######################################
209
60
  # Need to create a namespace so that we can have openstudio:rubocop and openstudio:rubocop:auto_correct.
210
61
  namespace :rubocop do
211
- task check: ['openstudio:prepare_rubocop', 'openstudio:rubocop_core'] do
212
- exit_status = post_process_results(Rake.application.original_dir)
213
- exit exit_status
62
+ task :check do
63
+ # original_dir is the location where Rakefile exists, Dir.pwd is where the rake task was called.
64
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
65
+
66
+ exit runner.run_rubocop(false)
214
67
  end
215
68
 
216
69
  desc 'Run RuboCop Auto Correct on Measures'
217
- task auto_correct: ['openstudio:prepare_rubocop', 'openstudio:rubocop_core:auto_correct']
70
+ task :auto_correct do
71
+ # original_dir is the location where Rakefile exists, Dir.pwd is where the rake task was called.
72
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir, Dir.pwd)
73
+
74
+ exit runner.run_rubocop(false, true)
75
+ end
218
76
  end
219
77
 
220
78
  desc 'Run RuboCop on Measures'
221
79
  task rubocop: 'openstudio:rubocop:check'
222
80
 
81
+ ####################################### Style #######################################
223
82
  desc 'Run OpenStudio Style Checks'
224
- task style: ['openstudio:prepare_style', 'openstudio:style_core'] do
225
- exit_status = post_process_results(Rake.application.original_dir)
226
- exit exit_status
83
+ task :style do
84
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
85
+ exit runner.run_style(false)
227
86
  end
228
87
 
88
+ ####################################### Post Processing and Dashboarding #######################################
229
89
  desc 'Post process results into one directory'
230
90
  task :post_process do
231
- exit_status = post_process_results(Rake.application.original_dir)
232
- exit exit_status
91
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
92
+ exit runner.post_process_results(Dir.pwd)
233
93
  end
234
94
 
235
95
  desc 'Generate dashboard'
236
96
  task :dashboard do
237
- dashboard(Rake.application.original_dir)
97
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
98
+ runner.dashboard
238
99
  end
239
100
 
240
101
  desc 'Run MiniTest, Coverage, RuboCop, and Style on measures, then dashboard results'
241
- task all: ['openstudio:prepare_minitest',
242
- 'openstudio:test_core',
243
- 'openstudio:prepare_rubocop',
244
- 'openstudio:rubocop_core',
245
- 'openstudio:prepare_style',
246
- 'openstudio:style_core'] do
247
- exit_status = post_process_results(Rake.application.original_dir)
248
- exit exit_status
102
+ task :all do
103
+ runner = OpenStudioMeasureTester::Runner.new(Rake.application.original_dir)
104
+ exit runner.run_all(Dir.pwd)
249
105
  end
250
106
 
251
107
  # Hide the core tasks from being displayed when calling rake -T
252
- Rake::Task['openstudio:rubocop_core'].clear_comments
253
- Rake::Task['openstudio:test_core_command'].clear_comments
254
- Rake::Task['openstudio:rubocop_core:auto_correct'].clear_comments
108
+ # Rake::Task['openstudio:test_core_command'].clear_comments
255
109
  end
256
110
  end
257
111
  end
@@ -65,34 +65,32 @@ module OpenStudioMeasureTester
65
65
  end
66
66
 
67
67
  def parse_results
68
- # needs rescue
69
68
  Dir["#{@path_to_results}/rubocop-results.xml"].each do |file|
70
69
  puts "Parsing Rubocop report #{file}"
71
- hash = Hash.from_xml(File.read(file))
72
70
 
73
- if hash.nil?
74
- puts 'Error reporting Rubocop'
75
- return
76
- end
77
-
78
- # get measure names
79
71
  measure_names = []
80
- # cn= ''
81
- hash['checkstyle']['file'].each do |key, data|
82
- parts = key['name'].split('/')
83
- if parts.last == 'measure.rb'
84
- name = parts[-2]
85
- measure_names << name
72
+
73
+ @total_files = 0
74
+ doc = REXML::Document.new(File.open(file)).root
75
+
76
+ puts "Finished reading #{file}"
77
+
78
+ # Go through the XML and find all the measure names first
79
+ doc.elements.each('file') do |rc_file|
80
+ @total_files += 1
81
+ measure_name = rc_file.attributes['name']
82
+ if measure_name
83
+ parts = measure_name.split('/')
84
+ if parts.last == 'measure.rb'
85
+ measure_names << parts[-2]
86
+ end
86
87
  end
87
88
  end
88
89
 
89
90
  @total_measures = measure_names.length
90
- @total_files = hash['checkstyle']['file'].length
91
91
 
92
+ # now go find the specific data about the measure
92
93
  measure_names.each do |measure_name|
93
- cn = ''
94
- results = hash['checkstyle']['file'].select { |data| data['name'].include? measure_name }
95
-
96
94
  mhash = {}
97
95
  mhash['measure_issues'] = 0
98
96
  mhash['measure_info'] = 0
@@ -100,83 +98,75 @@ module OpenStudioMeasureTester
100
98
  mhash['measure_errors'] = 0
101
99
  mhash['files'] = []
102
100
 
103
- results.each do |key, data|
101
+ cn = ''
102
+ doc.elements.each('file') do |rc_file|
103
+ next unless rc_file.attributes['name'].include? measure_name
104
+
105
+ # Save off the file information
104
106
  fhash = {}
105
- fhash['file_name'] = key['name'].split('/')[-1]
107
+ fhash['file_name'] = rc_file.attributes['name'].split('/')[-1]
106
108
  fhash['violations'] = []
107
109
 
108
- # get the class name
110
+ # get the class name out of the measure file! wow, okay... sure why not.
109
111
  if fhash['file_name'] == 'measure.rb'
110
- File.readlines(key['name']).each do |line|
111
- if (line.include? 'class') && line.split(' ')[0] == 'class'
112
- cn = line.split(' ')[1].gsub /_?[tT]est\z/, ''
113
- break
114
- end
115
- end
116
- end
117
-
118
- if key['error']
119
- @file_issues = 0
120
- @file_info = 0
121
- @file_warnings = 0
122
- @file_errors = 0
123
-
124
- violations = []
125
-
126
- if key['error'].class == Array
127
- @file_issues = key['error'].length
128
- key['error'].each do |s|
129
- if s['severity'] === 'info'
130
- @file_info += 1
131
- elsif s['severity'] === 'warning'
132
- @file_warnings += 1
133
- elsif s['severity'] === 'error' # TODO: look up complete list of codes
134
- @file_errors += 1
112
+ if File.exist? rc_file.attributes['name']
113
+ File.readlines(rc_file.attributes['name']).each do |line|
114
+ if (line.include? 'class') && line.split(' ')[0] == 'class'
115
+ cn = line.split(' ')[1].gsub /_?[tT]est\z/, ''
116
+ break
135
117
  end
136
- violations << { line: s['line'], column: s['column'], severity: s['severity'], message: s['message'] }
137
118
  end
119
+ else
120
+ puts "Could not find measure to parse for extracting class name in Rubocop. PWD: #{Dir.pwd} filename: #{rc_file.attributes['name']}"
138
121
  end
122
+ end
139
123
 
140
- if key['error'].class == Hash
141
- @file_issues = 1
142
- if key['error']['severity'] === 'info'
143
- @file_info += 1
144
- elsif key['error']['severity'] === 'warning'
145
- @file_warnings += 1
146
- elsif key['error']['severity'] === 'error'
147
- @file_errors += 1
148
- end
149
- violations << { line: key['error']['line'], column: key['error']['column'], severity: key['error']['severity'], message: key['error']['message'] }
124
+ @file_issues = 0
125
+ @file_info = 0
126
+ @file_warnings = 0
127
+ @file_errors = 0
128
+
129
+ violations = []
130
+ rc_file.elements.each('error') do |rc_error|
131
+ @file_issues += 1
132
+ if rc_error.attributes['severity'] == 'info'
133
+ @file_info += 1
134
+ elsif rc_error.attributes['severity'] == 'warning'
135
+ @file_warnings += 1
136
+ elsif rc_error.attributes['severity'] == 'error'
137
+ @file_errors += 1
150
138
  end
151
-
152
- fhash['issues'] = @file_issues
153
- fhash['info'] = @file_info
154
- fhash['warning'] = @file_warnings
155
- fhash['error'] = @file_errors
156
- fhash['violations'] = violations
157
-
158
- mhash['measure_issues'] += @file_issues
159
- mhash['measure_info'] += @file_info
160
- mhash['measure_warnings'] += @file_warnings
161
- mhash['measure_errors'] += @file_errors
162
-
163
- @total_issues += @file_issues
164
- @total_info += @file_info
165
- @total_warnings += @file_warnings
166
- @total_errors += @file_errors
167
-
139
+ violations << {
140
+ line: rc_error.attributes['line'],
141
+ column: rc_error.attributes['column'],
142
+ severity: rc_error.attributes['severity'],
143
+ message: rc_error.attributes['message']
144
+ }
168
145
  end
146
+ fhash['issues'] = @file_issues
147
+ fhash['info'] = @file_info
148
+ fhash['warning'] = @file_warnings
149
+ fhash['error'] = @file_errors
150
+ fhash['violations'] = violations
151
+
152
+ mhash['measure_issues'] += @file_issues
153
+ mhash['measure_info'] += @file_info
154
+ mhash['measure_warnings'] += @file_warnings
155
+ mhash['measure_errors'] += @file_errors
156
+
157
+ @total_issues += @file_issues
158
+ @total_info += @file_info
159
+ @total_warnings += @file_warnings
160
+ @total_errors += @file_errors
169
161
 
170
162
  mhash['files'] << fhash
171
163
  end
172
-
173
- # @summary << mhash
174
164
  @by_measure[cn] = mhash
175
165
  end
176
166
  end
177
167
 
178
- puts "total files: #{total_files}"
179
- puts "total issues: #{@total_issues} (#{@total_info} info, #{@total_warnings} warnings, #{@total_errors} errors)"
168
+ puts "Total files: #{@total_files}"
169
+ puts "Total issues: #{@total_issues} (#{@total_info} info, #{@total_warnings} warnings, #{@total_errors} errors)"
180
170
 
181
171
  @error_status = true if @total_errors > 0
182
172
  end