|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | | -# Some functions that that don't belong in a specific class |
4 | 3 | 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 |
10 | 7 |
|
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) |
13 | 13 |
|
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) |
17 | 16 |
|
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 |
36 | 20 |
|
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 | + ) |
42 | 38 | end |
43 | | - end |
44 | 39 |
|
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) |
48 | 51 |
|
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 |
52 | 56 | end |
53 | 57 | end |
| 58 | + |
0 commit comments