Class: PmdTester::PmdBranchDetail

Inherits:
Object
  • Object
show all
Includes:
PmdTester
Defined in:
lib/pmdtester/pmd_branch_detail.rb

Overview

This class represents all details about branch of pmd

Constant Summary

Constants included from PmdTester

BASE, PATCH, PR_NUM_ENV_VAR, VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PmdTester

#logger, logger

Constructor Details

#initialize(branch_name) ⇒ PmdBranchDetail

Returns a new instance of PmdBranchDetail.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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

Instance Attribute Details

#branch_last_messageObject

Returns the value of attribute branch_last_message.



11
12
13
# File 'lib/pmdtester/pmd_branch_detail.rb', line 11

def branch_last_message
  @branch_last_message
end

#branch_last_shaObject

Returns the value of attribute branch_last_sha.



10
11
12
# File 'lib/pmdtester/pmd_branch_detail.rb', line 10

def branch_last_sha
  @branch_last_sha
end

#branch_nameObject

Returns the value of attribute branch_name.



12
13
14
# File 'lib/pmdtester/pmd_branch_detail.rb', line 12

def branch_name
  @branch_name
end

#execution_timeObject

The branch’s execution time on all standard projects



16
17
18
# File 'lib/pmdtester/pmd_branch_detail.rb', line 16

def execution_time
  @execution_time
end

#jdk_versionObject

Returns the value of attribute jdk_version.



17
18
19
# File 'lib/pmdtester/pmd_branch_detail.rb', line 17

def jdk_version
  @jdk_version
end

#languageObject

Returns the value of attribute language.



18
19
20
# File 'lib/pmdtester/pmd_branch_detail.rb', line 18

def language
  @language
end

#pull_requestObject

Returns the value of attribute pull_request.



19
20
21
# File 'lib/pmdtester/pmd_branch_detail.rb', line 19

def pull_request
  @pull_request
end

#timestampObject

Start of the regression report



14
15
16
# File 'lib/pmdtester/pmd_branch_detail.rb', line 14

def timestamp
  @timestamp
end

Class Method Details

.branch_filename(branch_name) ⇒ Object



21
22
23
# File 'lib/pmdtester/pmd_branch_detail.rb', line 21

def self.branch_filename(branch_name)
  branch_name&.tr('/', '_')
end

.load(branch_name, logger) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 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

Instance Method Details

#format_execution_timeObject



92
93
94
# File 'lib/pmdtester/pmd_branch_detail.rb', line 92

def format_execution_time
  PmdReportDetail.convert_seconds(@execution_time)
end

#path_to_save_fileObject



80
81
82
# File 'lib/pmdtester/pmd_branch_detail.rb', line 80

def path_to_save_file
  "#{@base_branch_dir}/branch_info.json"
end

#saveObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# 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_pathObject



84
85
86
# File 'lib/pmdtester/pmd_branch_detail.rb', line 84

def target_branch_config_path
  "#{@base_branch_dir}/config.xml"
end

#target_branch_project_list_pathObject



88
89
90
# File 'lib/pmdtester/pmd_branch_detail.rb', line 88

def target_branch_project_list_path
  "#{@base_branch_dir}/project-list.xml"
end