Skip to content

Commit 2796f2e

Browse files
committed
Some cleanups
Integration tests pass locally so I don't know what the ci is doing differently Also fix a deprecation warning
1 parent 72ff751 commit 2796f2e

File tree

7 files changed

+35
-30
lines changed

7 files changed

+35
-30
lines changed

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,7 @@ def generate_pmd_reports
132132
progress_logger.stop
133133
sum_time += execution_time
134134

135-
report_details = PmdReportDetail.new(
136-
{
137-
execution_time: execution_time,
138-
timestamp: end_time
139-
}
140-
)
135+
report_details = PmdReportDetail.new(execution_time: execution_time, timestamp: end_time)
141136
report_details.save(project.get_report_info_path(@pmd_branch_name))
142137
logger.info "#{project.name}'s PMD report was generated successfully"
143138
end

lib/pmdtester/pmd_report_detail.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def self.load(report_info_path)
2828
PmdReportDetail.new(**hash)
2929
else
3030
puts "#{report_info_path} doesn't exist"
31-
PmdReportDetail.new({})
31+
PmdReportDetail.new
3232
end
3333
end
3434

lib/pmdtester/pmd_tester_utils.rb

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,7 @@ def parse_pmd_report(report_file, branch, report_details, filter_set = nil)
3838
def compute_project_diffs(projects, base_branch, patch_branch, filter_set = nil)
3939
projects.each do |project|
4040
logger.info "Preparing report for #{project.name}"
41-
project.report_diff = build_report_diff(project.get_pmd_report_path(base_branch),
42-
project.get_pmd_report_path(patch_branch),
43-
project.get_report_info_path(base_branch),
44-
project.get_report_info_path(patch_branch),
45-
filter_set)
41+
project.compute_report_diff(base_branch, patch_branch, filter_set)
4642
end
4743
end
4844

lib/pmdtester/project.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module PmdTester
44
# This class represents all the information about the project
55
class Project
6+
include PmdTester
7+
68
REPOSITORIES_PATH = 'target/repositories'
79

810
attr_reader :name
@@ -101,5 +103,13 @@ def get_project_target_dir(branch_name)
101103
def local_source_path
102104
"#{REPOSITORIES_PATH}/#{@name}"
103105
end
106+
107+
def compute_report_diff(base_branch, patch_branch, filter_set)
108+
self.report_diff = build_report_diff(get_pmd_report_path(base_branch),
109+
get_pmd_report_path(patch_branch),
110+
get_report_info_path(base_branch),
111+
get_report_info_path(patch_branch),
112+
filter_set)
113+
end
104114
end
105115
end

lib/pmdtester/report_diff.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ def changed_total
1616
new + removed + changed
1717
end
1818

19+
def merge!(other)
20+
self.changed += other.changed
21+
self.new += other.new
22+
self.removed += other.removed
23+
self.base_total += other.base_total
24+
self.patch_total += other.patch_total
25+
end
26+
1927
def to_h
2028
{
2129
'changed' => changed,

lib/pmdtester/runner.rb

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,21 @@ def get_projects(file_path)
118118
end
119119

120120
def summarize_diffs
121-
result = {
122-
errors: { new: 0, removed: 0, changed: 0 },
123-
violations: { new: 0, removed: 0, changed: 0 },
124-
configerrors: { new: 0, removed: 0, changed: 0 }
125-
}
121+
error_total = RunningDiffCounters.new(0)
122+
violations_total = RunningDiffCounters.new(0)
126123

127124
@projects.each do |project|
128125
diff = project.report_diff
129-
result[:errors][:new] += diff.error_counts.new
130-
result[:errors][:removed] += diff.error_counts.removed
131-
result[:errors][:changed] += diff.error_counts.changed
132-
result[:violations][:new] += diff.violation_counts.new
133-
result[:violations][:removed] += diff.violation_counts.removed
134-
result[:violations][:changed] += diff.violation_counts.changed
135-
# result[:configerrors][:new] +=
136-
# result[:configerrors][:removed] += project.removed_configerrors_size
126+
127+
error_total.merge!(diff.error_counts)
128+
violations_total.merge!(diff.violation_counts)
137129
end
138130

139-
result
131+
{
132+
errors: error_total.to_h,
133+
violations: violations_total.to_h,
134+
configerrors: RunningDiffCounters.new(0).to_h # note: this is now ignored
135+
}
140136
end
141137

142138
private

test/test_runner.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_single_mode
2222
PmdReportBuilder.any_instance.stubs(:build)
2323
.returns(PmdBranchDetail.new('test_branch')).once
2424
FileUtils.expects(:cp).with(project_list_path, target_project_list_path).once
25-
Runner.any_instance.stubs(:build_report_diff).twice
25+
Project.any_instance.stubs(:build_report_diff).twice
2626
SummaryReportBuilder.any_instance.stubs(:write_all_projects).once
2727

2828
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
@@ -40,7 +40,7 @@ def test_single_mode_multithreading
4040
.once
4141
report_builder_mock.stubs(:build).returns(PmdBranchDetail.new('test_branch')).once
4242
FileUtils.expects(:cp).with(anything, anything).once
43-
Runner.any_instance.stubs(:build_report_diff).twice
43+
Project.any_instance.stubs(:build_report_diff).twice
4444
SummaryReportBuilder.any_instance.stubs(:write_all_projects).once
4545

4646
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
@@ -50,7 +50,7 @@ def test_single_mode_multithreading
5050

5151
def test_local_mode
5252
PmdReportBuilder.any_instance.stubs(:build).returns(PmdBranchDetail.new('some_branch')).twice
53-
Runner.any_instance.stubs(:build_report_diff).twice
53+
Project.any_instance.stubs(:build_report_diff).twice
5454
SummaryReportBuilder.any_instance.stubs(:write_all_projects).once
5555

5656
argv = %w[-r target/repositories/pmd -b master -bc config/design.xml -p pmd_releases/6.1.0
@@ -67,7 +67,7 @@ def test_local_mode_multithreading
6767
.returns(report_builder_mock)
6868
.twice
6969
report_builder_mock.stubs(:build).returns(PmdBranchDetail.new('some_branch')).twice
70-
Runner.any_instance.stubs(:build_report_diff).twice
70+
Project.any_instance.stubs(:build_report_diff).twice
7171
SummaryReportBuilder.any_instance.stubs(:write_all_projects).once
7272

7373
argv = %w[-r target/repositories/pmd -b master -bc config/design.xml -p pmd_releases/6.1.0

0 commit comments

Comments
 (0)