Module: FindbugsTranslateCheckstyleFormat::Translate
- Included in:
- CLI
- Defined in:
- lib/findbugs_translate_checkstyle_format/translate.rb
Class Method Summary collapse
- .create_message(bug_instance) ⇒ Object
- .fqcn_to_path(fqcn, xml) ⇒ Object
- .set_dummy(xml, checkstyle) ⇒ Object
Instance Method Summary collapse
Class Method Details
.create_message(bug_instance) ⇒ Object
57 58 59 60 |
# File 'lib/findbugs_translate_checkstyle_format/translate.rb', line 57 def self.(bug_instance) link = "http://findbugs.sourceforge.net/bugDescriptions.html##{bug_instance['@type']}" "[#{bug_instance['@category']}][#{bug_instance['@type']}] #{bug_instance['LongMessage']}\n#{link}" end |
.fqcn_to_path(fqcn, xml) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/findbugs_translate_checkstyle_format/translate.rb', line 39 def self.fqcn_to_path(fqcn, xml) path = fqcn.tr('.', '/').gsub(/\$[0-9]+/, '') + '.java' src_dirs = xml['BugCollection']['Project']['SrcDir'] src_dirs = [src_dirs] unless src_dirs.is_a?(Array) src_dirs.find { |src| !src.index(path).nil? } end |
.set_dummy(xml, checkstyle) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/findbugs_translate_checkstyle_format/translate.rb', line 46 def self.set_dummy(xml, checkstyle) dummy_src_dir = xml['BugCollection']['Project']['SrcDir'] dummy_src_dir = dummy_src_dir.first if dummy_src_dir.is_a?(Array) checkstyle.add_element('file', 'name' => dummy_src_dir ) checkstyle end |
Instance Method Details
#parse(xml) ⇒ Object
6 7 8 9 10 |
# File 'lib/findbugs_translate_checkstyle_format/translate.rb', line 6 def parse(xml) Nori .new(parser: :rexml) .parse(xml) end |
#trans(xml) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/findbugs_translate_checkstyle_format/translate.rb', line 12 def trans(xml) doc = REXML::Document.new doc << REXML::XMLDecl.new('1.0', 'UTF-8') checkstyle = doc.add_element('checkstyle') bug_instances = xml['BugCollection']['BugInstance'] if bug_instances.blank? FindbugsTranslateCheckstyleFormat::Translate.set_dummy(xml, checkstyle) return doc end bug_instances = [bug_instances] if bug_instances.is_a?(Hash) bug_instances.each do |bug_instance| source_line = bug_instance['SourceLine'] file = checkstyle.add_element('file', 'name' => FindbugsTranslateCheckstyleFormat::Translate.fqcn_to_path(source_line['@classname'], xml) ) file.add_element('error', 'line' => source_line['@start'], 'severity' => 'error', 'message' => FindbugsTranslateCheckstyleFormat::Translate.(bug_instance) ) end doc end |