Module: PmdTester::PmdTesterUtils

Includes:
PmdTester
Included in:
Project, Runner
Defined in:
lib/pmdtester/pmd_tester_utils.rb

Overview

Some functions that that don’t belong in a specific class,

Constant Summary

Constants included from PmdTester

BASE, PATCH, PR_NUM_ENV_VAR, VERSION

Instance Method Summary collapse

Methods included from PmdTester

#logger, logger

Instance Method Details

#build_html_reports(projects, base_branch_details, patch_branch_details, filter_set = nil) ⇒ Object

Build the diff reports and write them all



50
51
52
53
54
55
56
57
# File 'lib/pmdtester/pmd_tester_utils.rb', line 50

def build_html_reports(projects, base_branch_details, patch_branch_details, filter_set = nil)
  compute_project_diffs(projects, base_branch_details.branch_name, patch_branch_details.branch_name,
                        filter_set)

  SummaryReportBuilder.new.write_all_projects(projects,
                                              base_branch_details,
                                              patch_branch_details)
end

#build_report_diff(base_report_file, patch_report_file, base_info, patch_info, filter_set = nil) ⇒ Object

Parse the base and the patch report, compute their diff Returns a ReportDiff



10
11
12
13
14
15
16
17
18
19
# File 'lib/pmdtester/pmd_tester_utils.rb', line 10

def build_report_diff(base_report_file, patch_report_file, base_info, patch_info, filter_set = nil)
  base_details = PmdReportDetail.load(base_info)
  patch_details = PmdReportDetail.load(patch_info)

  base_report = parse_pmd_report(base_report_file, BASE, base_details, filter_set)
  patch_report = parse_pmd_report(patch_report_file, PATCH, patch_details)

  logger.info 'Calculating diffs'
  ReportDiff.new(base_report: base_report, patch_report: patch_report)
end

#compute_project_diffs(projects, base_branch, patch_branch, filter_set = nil) ⇒ Object

Fill the report_diff field of every project



41
42
43
44
45
46
47
# File 'lib/pmdtester/pmd_tester_utils.rb', line 41

def compute_project_diffs(projects, base_branch, patch_branch, filter_set = nil)
  projects.each do |project|
    logger.info "Preparing report for #{project.name}"
    logger.info "  with filter #{filter_set}" unless filter_set.nil?
    project.compute_report_diff(base_branch, patch_branch, filter_set)
  end
end

#parse_pmd_report(report_file, branch, report_details, filter_set = nil) ⇒ Object

Parse the report_file to produce a Report. For the schema of xml reports, refer to pmd.sourceforge.net/report_2_0_0.xsd



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pmdtester/pmd_tester_utils.rb', line 23

def parse_pmd_report(report_file, branch, report_details, filter_set = nil)
  require 'nokogiri'

  logger.info "Parsing #{report_file}"
  doc = PmdReportDocument.new(branch, report_details.working_dir, filter_set)
  parser = Nokogiri::XML::SAX::Parser.new(doc)
  parser.parse_file(report_file) if File.exist?(report_file)
  Report.new(
    report_document: doc,
    file: report_file,

    timestamp: report_details.timestamp,
    exec_time: report_details.execution_time,
    exit_code: report_details.exit_code
  )
end