class PmdTester::PmdReportDocument
This class is used for registering types of events you are interested in handling. Also see: www.rubydoc.info/github/sparklemotion/nokogiri/Nokogiri/XML/SAX/Document
Attributes
configerrors[R]
errors[R]
violations[R]
Public Class Methods
new(branch_name, working_dir, filter_set = nil)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 12 def initialize(branch_name, working_dir, filter_set = nil) @violations = CollectionByFile.new @errors = CollectionByFile.new @configerrors = Hash.new { |hash, key| hash[key] = [] } @current_violations = [] @current_violation = nil @current_error = nil @current_configerror = nil @filter_set = filter_set @working_dir = working_dir @branch_name = branch_name @cur_text = String.new(capacity: 200) end
Public Instance Methods
cdata_block(string)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 47 def cdata_block(string) @cur_text << remove_work_dir!(string) end
characters(string)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 43 def characters(string) @cur_text << remove_work_dir!(string) end
end_element(name)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 51 def end_element(name) case name when 'file' @violations.add_all(@current_filename, @current_violations) @current_filename = nil when 'violation' if match_filter_set?(@current_violation) @current_violation.message = finish_text! @current_violations.push(@current_violation) end @current_violation = nil when 'error' @current_error.stack_trace = finish_text! @errors.add_all(@current_filename, [@current_error]) @current_filename = nil @current_error = nil when 'configerror' @configerrors[@current_configerror.rulename].push(@current_configerror) @current_configerror = nil end @cur_text.clear end
start_element(name, attrs = [])
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 28 def start_element(name, attrs = []) attrs = attrs.to_h case name when 'file' handle_start_file attrs when 'violation' handle_start_violation attrs when 'error' handle_start_error attrs when 'configerror' handle_start_configerror attrs end end
Private Instance Methods
finish_text!()
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 83 def finish_text! res = @cur_text.strip!.dup.freeze @cur_text.clear res end
handle_start_configerror(attrs)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 126 def handle_start_configerror(attrs) @current_configerror = PmdConfigError.new(attrs, @branch_name) end
handle_start_error(attrs)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 116 def handle_start_error(attrs) @current_filename = remove_work_dir!(attrs['filename']) @current_error = PmdError.new( branch: @branch_name, filename: @current_filename, short_message: remove_work_dir!(attrs['msg']) ) end
handle_start_file(attrs)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 100 def handle_start_file(attrs) @current_filename = remove_work_dir!(attrs['name']) @current_violations = [] end
handle_start_violation(attrs)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 105 def handle_start_violation(attrs) @current_violation = PmdViolation.new( branch: @branch_name, fname: @current_filename, info_url: attrs['externalInfoUrl'], bline: attrs['beginline'].to_i, rule_name: attrs['rule'], ruleset_name: attrs['ruleset'].freeze ) end
match_filter_set?(violation)
click to toggle source
# File lib/pmdtester/parsers/pmd_report_document.rb, line 89 def match_filter_set?(violation) return true if @filter_set.nil? ruleset_attr = violation.ruleset_name.delete(' ').downcase! << '.xml' return true if @filter_set.include?(ruleset_attr) rule_ref = "#{ruleset_attr}/#{violation.rule_name}" @filter_set.include?(rule_ref) end
remove_work_dir!(str)
click to toggle source
Modifies the string in place and returns it (this is what sub! does, except it returns nil if no replacement occurred)
# File lib/pmdtester/parsers/pmd_report_document.rb, line 78 def remove_work_dir!(str) str.sub!(/#{@working_dir}/, '') str end