class PmdTester::PmdBranchDetail

This class represents all details about branch of pmd

Attributes

branch_last_message[RW]
branch_last_sha[RW]
branch_name[RW]
execution_time[RW]

The branch's execution time on all standard projects

jdk_version[RW]
language[RW]
pull_request[RW]
timestamp[RW]

Start of the regression report

Public Class Methods

branch_filename(branch_name) click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 21
def self.branch_filename(branch_name)
  branch_name&.tr('/', '_')
end
load(branch_name, logger) click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 41
def self.load(branch_name, logger)
  details = PmdBranchDetail.new(branch_name)
  if File.exist?(details.path_to_save_file)
    hash = JSON.parse(File.read(details.path_to_save_file))
    details.branch_last_sha = hash['branch_last_sha']
    details.branch_last_message = hash['branch_last_message']
    details.branch_name = hash['branch_name']
    details.timestamp = hash['timestamp']
    details.execution_time = hash['execution_time']
    details.jdk_version = hash['jdk_version']
    details.language = hash['language']
    details.pull_request = hash['pull_request']
  else
    details.timestamp = Time.now
    details.jdk_version = ''
    details.language = ''
    logger&.warn "#{details.path_to_save_file} doesn't exist!"
  end
  details
end
new(branch_name) click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 25
def initialize(branch_name)
  @branch_last_sha = ''
  @branch_last_message = ''
  @branch_name = branch_name
  branch_filename = PmdBranchDetail.branch_filename(branch_name)
  @base_branch_dir = "target/reports/#{branch_filename}" unless @branch_name.nil?
  @timestamp = Time.now
  @execution_time = 0
  # the result of command 'java -version' is going to stderr
  @jdk_version = Cmd.stderr_of('java -version')
  @language = ENV['LANG'] # the locale

  prnum = ENV[PR_NUM_ENV_VAR]
  @pull_request = prnum == 'false' ? nil : prnum
end

Public Instance Methods

format_execution_time() click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 92
def format_execution_time
  PmdReportDetail.convert_seconds(@execution_time)
end
path_to_save_file() click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 80
def path_to_save_file
  "#{@base_branch_dir}/branch_info.json"
end
save() click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 62
def save
  hash = { branch_last_sha: @branch_last_sha,
           branch_last_message: @branch_last_message,
           branch_name: @branch_name,
           timestamp: @timestamp,
           execution_time: @execution_time,
           jdk_version: @jdk_version,
           language: @language,
           pull_request: @pull_request }

  FileUtils.mkdir_p(@base_branch_dir) unless File.directory?(@base_branch_dir)

  file = File.new(path_to_save_file, 'w')
  file.puts JSON.generate(hash)
  file.close
  self
end
target_branch_config_path() click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 84
def target_branch_config_path
  "#{@base_branch_dir}/config.xml"
end
target_branch_project_list_path() click to toggle source
# File lib/pmdtester/pmd_branch_detail.rb, line 88
def target_branch_project_list_path
  "#{@base_branch_dir}/project-list.xml"
end