Class: PmdTester::PmdReportDetail

Inherits:
Object
  • Object
show all
Defined in:
lib/pmdtester/pmd_report_detail.rb

Overview

This class represents all details about an execution of PMD

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cmdlineObject

Returns the value of attribute cmdline.



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

def cmdline
  @cmdline
end

#execution_timeObject

Returns the value of attribute execution_time.



8
9
10
# File 'lib/pmdtester/pmd_report_detail.rb', line 8

def execution_time
  @execution_time
end

#exit_codeObject

Returns the value of attribute exit_code.



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

def exit_code
  @exit_code
end

#jfr_summaryObject

Returns the value of attribute jfr_summary.



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

def jfr_summary
  @jfr_summary
end

#oomObject

Returns the value of attribute oom.



15
16
17
# File 'lib/pmdtester/pmd_report_detail.rb', line 15

def oom
  @oom
end

#stderrObject

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



13
14
15
# File 'lib/pmdtester/pmd_report_detail.rb', line 13

def stdout
  @stdout
end

#timestampObject

Returns the value of attribute timestamp.



9
10
11
# File 'lib/pmdtester/pmd_report_detail.rb', line 9

def timestamp
  @timestamp
end

#working_dirObject

Returns the value of attribute working_dir.



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

def working_dir
  @working_dir
end

Class Method Details

.convert_seconds(seconds) ⇒ Object

convert seconds into HH::MM::SS



76
77
78
# File 'lib/pmdtester/pmd_report_detail.rb', line 76

def self.convert_seconds(seconds)
  Time.at(seconds.abs).utc.strftime('%H:%M:%S')
end

.create(execution_time: 0, timestamp: '', working_dir: Dir.getwd, cmdline: '', exit_code: nil, stdout: '', stderr: '', oom: false, report_info_path:, jfr_summary: nil) ⇒ Object



60
61
62
63
64
65
66
67
68
# File 'lib/pmdtester/pmd_report_detail.rb', line 60

def self.create(execution_time: 0, timestamp: '', working_dir: Dir.getwd, cmdline: '',
                exit_code: nil, stdout: '', stderr: '', oom: false,
                report_info_path:, jfr_summary: nil)
  detail = PmdReportDetail.new(execution_time: execution_time, timestamp: timestamp,
                               working_dir: working_dir, cmdline: cmdline, oom: oom,
                               exit_code: exit_code, stdout: stdout, stderr: stderr, jfr_summary: jfr_summary)
  detail.save(report_info_path)
  detail
end

.emptyObject



70
71
72
73
# File 'lib/pmdtester/pmd_report_detail.rb', line 70

def self.empty
  new(execution_time: 0, timestamp: '', working_dir: Dir.getwd, cmdline: '',
      exit_code: nil, stdout: '', stderr: '', oom: false)
end

.load(report_info_path) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/pmdtester/pmd_report_detail.rb', line 35

def self.load(report_info_path)
  if File.exist?(report_info_path)
    hash = JSON.parse(File.read(report_info_path), symbolize_names: true)
    PmdReportDetail.new(**hash)
  else
    PmdTester.logger.warn("#{report_info_path} doesn't exist")
    PmdReportDetail.new
  end
end

Instance Method Details

#execution_time_formattedObject



45
46
47
# File 'lib/pmdtester/pmd_report_detail.rb', line 45

def execution_time_formatted
  self.class.convert_seconds(@execution_time)
end

#save(report_info_path) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/pmdtester/pmd_report_detail.rb', line 18

def save(report_info_path)
  hash = {
    execution_time: @execution_time,
    timestamp: @timestamp,
    working_dir: @working_dir,
    cmdline: @cmdline,
    exit_code: @exit_code,
    stdout: @stdout,
    stderr: @stderr,
    oom: @oom,
    jfr_summary: @jfr_summary.to_h
  }
  file = File.new(report_info_path, 'w')
  file.puts JSON.pretty_generate(hash)
  file.close
end

#to_hObject



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

def to_h
  {
    'timestamp' => @timestamp,
    'exit_code' => @exit_code,
    'cmdline' => @cmdline,
    'execution_time' => execution_time_formatted,
    'oom' => @oom,
    'jfr_summary' => @jfr_summary.to_h_for_liquid
  }
end