Class: PmdTester::PmdError

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

Overview

This class represents a ‘error’ element of Pmd xml report and which Pmd branch the ‘error’ is from

Constant Summary

Constants included from PmdTester

BASE, PATCH, PR_NUM_ENV_VAR, VERSION

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from PmdTester

#logger, logger

Constructor Details

#initialize(branch:, filename:, short_message:) ⇒ PmdError

Returns a new instance of PmdError.



24
25
26
27
28
29
30
# File 'lib/pmdtester/pmd_error.rb', line 24

def initialize(branch:, filename:, short_message:)
  @branch = branch
  @stack_trace = ''
  @changed = false
  @short_message = short_message
  @filename = filename
end

Instance Attribute Details

#branchObject (readonly)

The pmd branch type, ‘base’ or ‘patch’



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

def branch
  @branch
end

#filenameObject (readonly)

Returns the value of attribute filename.



22
23
24
# File 'lib/pmdtester/pmd_error.rb', line 22

def filename
  @filename
end

#old_errorObject

Returns the value of attribute old_error.



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

def old_error
  @old_error
end

#short_messageObject (readonly)

Returns the value of attribute short_message.



22
23
24
# File 'lib/pmdtester/pmd_error.rb', line 22

def short_message
  @short_message
end

#stack_traceObject

The schema of ‘error’ node:

 <xs:complexType name="error">
   <xs:simpleContent>
     <xs:extension base="xs:string">
       <xs:attribute name="filename" type="xs:string" use="required"/>
       <xs:attribute name="msg" type="xs:string" use="required"/>
     </xs:extension>
   </xs:simpleContent>
</xs:complexType>


20
21
22
# File 'lib/pmdtester/pmd_error.rb', line 20

def stack_trace
  @stack_trace
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/pmdtester/pmd_error.rb', line 36

def changed?
  @changed
end

#eql?(other) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
43
44
# File 'lib/pmdtester/pmd_error.rb', line 40

def eql?(other)
  filename.eql?(other.filename) &&
    short_message.eql?(other.short_message) &&
    stack_trace.eql?(other.stack_trace)
end

#hashObject



46
47
48
# File 'lib/pmdtester/pmd_error.rb', line 46

def hash
  [filename, stack_trace].hash
end

#short_filenameObject



32
33
34
# File 'lib/pmdtester/pmd_error.rb', line 32

def short_filename
  filename.gsub(%r{([^/]*+/)+}, '')
end

#sort_keyObject



50
51
52
# File 'lib/pmdtester/pmd_error.rb', line 50

def sort_key
  filename
end

#try_merge?(other) ⇒ Boolean

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/pmdtester/pmd_error.rb', line 54

def try_merge?(other)
  if branch != BASE &&
     branch != other.branch &&
     filename == other.filename &&
     !changed? # not already changed
    @changed = true
    @old_error = other
    true
  else
    false
  end
end