Sha256: 4b3de27e48e895a44cad97b69ac3a5f969fc740b343bc29394a66fd98b1f3f8c

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

require 'nori'

module PmdTranslateCheckstyleFormat
  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")
      if xml['pmd'].blank? || xml['pmd']['file'].blank?
        # set_dummy(xml, checkstyle)
        return doc
      end

      files = xml['pmd']['file']
      files = [files] if files.is_a?(Hash)
      files.each do |file|
        violations = file['violation']
        violations = [violations] unless violations.is_a?(Array)
        violations.each do |violation|
          puts violation.attributes
          file_element = checkstyle.add_element("file", {
            'name' => file['@name']
            })
          file_element.add_element("error", {
            'line' => violation.attributes['beginline'],
            'severity' => '',
            'message' => "[#{violation.attributes['rule']}] #{violation.strip}\\n#{violation.attributes['externalInfoUrl']}"
            })
        end
      end

      doc
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pmd_translate_checkstyle_format-0.1.0 lib/pmd_translate_checkstyle_format/translate.rb