Class: PmdTester::PmdBranchDetail
- Inherits:
-
Object
- Object
- PmdTester::PmdBranchDetail
- 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
-
#branch_last_message ⇒ Object
Returns the value of attribute branch_last_message.
-
#branch_last_sha ⇒ Object
Returns the value of attribute branch_last_sha.
-
#branch_name ⇒ Object
Returns the value of attribute branch_name.
-
#cpu_info ⇒ Object
Returns the value of attribute cpu_info.
-
#execution_time ⇒ Object
The branch’s execution time on all standard projects.
-
#jdk_version ⇒ Object
Returns the value of attribute jdk_version.
-
#language ⇒ Object
Returns the value of attribute language.
-
#os_info ⇒ Object
Returns the value of attribute os_info.
-
#physical_memory ⇒ Object
Returns the value of attribute physical_memory.
-
#pull_request ⇒ Object
Returns the value of attribute pull_request.
-
#timestamp ⇒ Object
Start of the regression report.
Class Method Summary collapse
Instance Method Summary collapse
- #format_execution_time ⇒ Object
-
#initialize(branch_name) ⇒ PmdBranchDetail
constructor
A new instance of PmdBranchDetail.
- #parse_from_json ⇒ Object
- #path_to_save_file ⇒ Object
- #save ⇒ Object
- #target_branch_config_path ⇒ Object
- #target_branch_project_list_path ⇒ Object
Methods included from PmdTester
Constructor Details
#initialize(branch_name) ⇒ PmdBranchDetail
Returns a new instance of PmdBranchDetail.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 28 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.fetch('LANG') # the locale system_info = PmdTester::SystemInfo.new @cpu_info = system_info.cpu_info @physical_memory = system_info.physical_memory @os_info = system_info.uname prnum = ENV.fetch(PR_NUM_ENV_VAR, 'false') @pull_request = prnum == 'false' ? nil : prnum end |
Instance Attribute Details
#branch_last_message ⇒ Object
Returns the value of attribute branch_last_message.
11 12 13 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 11 def @branch_last_message end |
#branch_last_sha ⇒ Object
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_name ⇒ Object
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 |
#cpu_info ⇒ Object
Returns the value of attribute cpu_info.
19 20 21 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 19 def cpu_info @cpu_info end |
#execution_time ⇒ Object
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_version ⇒ Object
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 |
#language ⇒ Object
Returns the value of attribute language.
18 19 20 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 18 def language @language end |
#os_info ⇒ Object
Returns the value of attribute os_info.
21 22 23 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 21 def os_info @os_info end |
#physical_memory ⇒ Object
Returns the value of attribute physical_memory.
20 21 22 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 20 def physical_memory @physical_memory end |
#pull_request ⇒ Object
Returns the value of attribute pull_request.
22 23 24 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 22 def pull_request @pull_request end |
#timestamp ⇒ Object
Start of the regression report
14 15 16 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 14 def @timestamp end |
Class Method Details
.branch_filename(branch_name) ⇒ Object
24 25 26 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 24 def self.branch_filename(branch_name) branch_name&.tr('/', '_') end |
.load(branch_name, logger) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 48 def self.load(branch_name, logger) details = PmdBranchDetail.new(branch_name) if File.exist?(details.path_to_save_file) details.parse_from_json else details. = Time.now details.jdk_version = '' details.language = '' details.cpu_info = '' details.physical_memory = '' details.os_info = '' logger&.warn "#{details.path_to_save_file} doesn't exist!" end details end |
Instance Method Details
#format_execution_time ⇒ Object
97 98 99 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 97 def format_execution_time PmdReportDetail.convert_seconds(@execution_time) end |
#parse_from_json ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 101 def parse_from_json hash = JSON.parse(File.read(path_to_save_file)) @branch_last_sha = hash['branch_last_sha'] @branch_last_message = hash['branch_last_message'] @branch_name = hash['branch_name'] @timestamp = hash['timestamp'] @execution_time = hash['execution_time'] @jdk_version = hash['jdk_version'] @language = hash['language'] @cpu_info = hash['cpu_info'] @physical_memory = hash['physical_memory'] @os_info = hash['os_info'] @pull_request = hash['pull_request'] end |
#path_to_save_file ⇒ Object
85 86 87 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 85 def path_to_save_file "#{@base_branch_dir}/branch_info.json" end |
#save ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 64 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, cpu_info: @cpu_info, physical_memory: @physical_memory, os_info: @os_info, 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 ⇒ Object
89 90 91 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 89 def target_branch_config_path "#{@base_branch_dir}/config.xml" end |
#target_branch_project_list_path ⇒ Object
93 94 95 |
# File 'lib/pmdtester/pmd_branch_detail.rb', line 93 def target_branch_project_list_path "#{@base_branch_dir}/project-list.xml" end |