Skip to content

Commit d00bf68

Browse files
committed
Move utils into a separate module
1 parent b4e051e commit d00bf68

File tree

5 files changed

+50
-45
lines changed

5 files changed

+50
-45
lines changed

lib/pmdtester/pmd_tester_utils.rb

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,58 @@
11
# frozen_string_literal: true
22

3-
# Some functions that that don't belong in a specific class
43
module PmdTester
5-
# Parse the base and the patch report, compute their diff
6-
# Returns a +ReportDiff+
7-
def build_report_diff(base_report_file, patch_report_file, base_info, patch_info, filter_set = nil)
8-
base_details = PmdReportDetail.load(base_info)
9-
patch_details = PmdReportDetail.load(patch_info)
4+
# Some functions that that don't belong in a specific class,
5+
module PmdTesterUtils
6+
include PmdTester
107

11-
base_report = parse_pmd_report(base_report_file, BASE, base_details, filter_set)
12-
patch_report = parse_pmd_report(patch_report_file, PATCH, patch_details)
8+
# Parse the base and the patch report, compute their diff
9+
# Returns a +ReportDiff+
10+
def build_report_diff(base_report_file, patch_report_file, base_info, patch_info, filter_set = nil)
11+
base_details = PmdReportDetail.load(base_info)
12+
patch_details = PmdReportDetail.load(patch_info)
1313

14-
logger.info 'Calculating diffs'
15-
ReportDiff.new(base_report: base_report, patch_report: patch_report)
16-
end
14+
base_report = parse_pmd_report(base_report_file, BASE, base_details, filter_set)
15+
patch_report = parse_pmd_report(patch_report_file, PATCH, patch_details)
1716

18-
# Parse the +report_file+ to produce a +Report+.
19-
# For the schema of xml reports, refer to http://pmd.sourceforge.net/report_2_0_0.xsd
20-
def parse_pmd_report(report_file, branch, report_details, filter_set = nil)
21-
require 'nokogiri'
22-
23-
logger.info "Parsing #{report_file}"
24-
doc = PmdReportDocument.new(branch, report_details.working_dir, filter_set)
25-
parser = Nokogiri::XML::SAX::Parser.new(doc)
26-
parser.parse_file(report_file) if File.exist?(report_file)
27-
Report.new(
28-
violations_by_file: doc.violations,
29-
errors_by_file: doc.errors,
30-
infos_by_rule: doc.infos_by_rules,
31-
32-
timestamp: report_details.timestamp,
33-
exec_time: report_details.execution_time
34-
)
35-
end
17+
logger.info 'Calculating diffs'
18+
ReportDiff.new(base_report: base_report, patch_report: patch_report)
19+
end
3620

37-
# Fill the report_diff field of every project
38-
def compute_project_diffs(projects, base_branch, patch_branch, filter_set = nil)
39-
projects.each do |project|
40-
logger.info "Preparing report for #{project.name}"
41-
project.compute_report_diff(base_branch, patch_branch, filter_set)
21+
# Parse the +report_file+ to produce a +Report+.
22+
# For the schema of xml reports, refer to http://pmd.sourceforge.net/report_2_0_0.xsd
23+
def parse_pmd_report(report_file, branch, report_details, filter_set = nil)
24+
require 'nokogiri'
25+
26+
logger.info "Parsing #{report_file}"
27+
doc = PmdReportDocument.new(branch, report_details.working_dir, filter_set)
28+
parser = Nokogiri::XML::SAX::Parser.new(doc)
29+
parser.parse_file(report_file) if File.exist?(report_file)
30+
Report.new(
31+
violations_by_file: doc.violations,
32+
errors_by_file: doc.errors,
33+
infos_by_rule: doc.infos_by_rules,
34+
35+
timestamp: report_details.timestamp,
36+
exec_time: report_details.execution_time
37+
)
4238
end
43-
end
4439

45-
# Build the diff reports and write them all
46-
def build_html_reports(projects, base_branch_details, patch_branch_details)
47-
compute_project_diffs(projects, base_branch_details.branch_name, patch_branch_details.branch_name)
40+
# Fill the report_diff field of every project
41+
def compute_project_diffs(projects, base_branch, patch_branch, filter_set = nil)
42+
projects.each do |project|
43+
logger.info "Preparing report for #{project.name}"
44+
project.compute_report_diff(base_branch, patch_branch, filter_set)
45+
end
46+
end
47+
48+
# Build the diff reports and write them all
49+
def build_html_reports(projects, base_branch_details, patch_branch_details)
50+
compute_project_diffs(projects, base_branch_details.branch_name, patch_branch_details.branch_name)
4851

49-
SummaryReportBuilder.new.write_all_projects(projects,
50-
base_branch_details,
51-
patch_branch_details)
52+
SummaryReportBuilder.new.write_all_projects(projects,
53+
base_branch_details,
54+
patch_branch_details)
55+
end
5256
end
5357
end
58+

lib/pmdtester/project.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
module PmdTester
44
# This class represents all the information about the project
55
class Project
6-
include PmdTester
6+
include PmdTesterUtils
77

88
REPOSITORIES_PATH = 'target/repositories'
99

lib/pmdtester/runner.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ module PmdTester
44
# The Runner is a class responsible of organizing all PmdTester modules
55
# and running the PmdTester
66
class Runner
7-
include PmdTester
7+
include PmdTesterUtils
88

99
def initialize(argv)
1010
@options = Options.new(argv)

test/test_diff_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Unit test class for PmdTester::DiffBuilder
66
class TestDiffBuilder < Test::Unit::TestCase
7-
include PmdTester
7+
include PmdTester::PmdTesterUtils
88
include ProjectHasher
99
BASE_REPORT_INFO_PATH = 'test/resources/diff_builder/base_report_info.json'
1010
PATCH_REPORT_INFO_PATH = 'test/resources/diff_builder/patch_report_info.json'

test/test_project_diff_report.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
# Unit test class for PmdTester::DiffReportBuilder
66
class TestProjectDiffReport < Test::Unit::TestCase
7-
include PmdTester
7+
include PmdTester::PmdTesterUtils
88
include TestUtils
99
BASE_PMD_REPORT_PATH =
1010
'test/resources/html_report_builder/test_html_report_builder_base.xml'

0 commit comments

Comments
 (0)