Sha256: 0f40737cd3eb34e9a3502a27acedef369a9a1bf38a42fa2a8e67093d02e83cab

Contents?: true

Size: 993 Bytes

Versions: 3

Compression:

Stored size: 993 Bytes

Contents

require 'nori'

module FindbugsTranslateCheckstyleFormat
  module Translate
    def parse(xml)
      Nori
        .new(parser: :rexml)
        .parse(xml)
    end

    def trans(xml)
      require 'rexml/document'
      doc = REXML::Document.new
      doc << REXML::XMLDecl.new('1.0', 'UTF-8')

      checkstyle = doc.add_element("checkstyle")
      xml['BugCollection']['BugInstance'].each do |bugInstance|
        file = checkstyle.add_element("file", {
          'name' => fqcn_to_path(bugInstance['SourceLine']['@classname'], xml)
          })
        file.add_element("error", {
          'line' => bugInstance['SourceLine']['@start'],
          'severity' => '',
          'message' => "[#{bugInstance['@category']}] #{bugInstance['LongMessage']}"
          })
      end

      doc
    end

    def fqcn_to_path(fqcn, xml)
      path = fqcn.gsub('.', '/') + '.java'
      xml['BugCollection']['Project']['SrcDir'].find do |src|
        src.index(path) != nil
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
findbugs_translate_checkstyle_format-0.1.2 lib/findbugs_translate_checkstyle_format/translate.rb
findbugs_translate_checkstyle_format-0.1.1 lib/findbugs_translate_checkstyle_format/translate.rb
findbugs_translate_checkstyle_format-0.1.0 lib/findbugs_translate_checkstyle_format/translate.rb