Sha256: a21201fdd4b196d60ecd21c44916602f53cd477b85818b13fc2b63281b01eebc

Contents?: true

Size: 1.65 KB

Versions: 1

Compression:

Stored size: 1.65 KB

Contents

require 'plist'
require 'rexml/document'

module IosAnalytics
  module Translate
    def trans(derived_data, app_name)
      doc = REXML::Document.new
      doc << REXML::XMLDecl.new('1.0', 'UTF-8')

      checkstyle = doc.add_element('checkstyle')

      path = Pathname.new(derived_data)
        .join(
          'Build',
          'Intermediates',
          "#{app_name}.build",
          '**',
          'StaticAnalyzer',
          '**',
          '*.plist'
        )
      Dir.glob(path).each do |plist_file|
        trans_file(checkstyle, plist_file)
      end

      unless checkstyle.has_elements?
        IosAnalytics::Translate.add_dummy(checkstyle)
      end

      doc
    end

    def trans_file(checkstyle_dom, plist_file)
      result = Plist::parse_xml(plist_file)
      return checkstyle_dom if result['files'].empty?

      file_path = result['files'][0]
      result['diagnostics'].each do |diagnostics|
        create_element(checkstyle_dom, file_path, diagnostics)
      end

      checkstyle_dom
    end

    def create_element(checkstyle_dom, file_path, diagnostics)
      file = checkstyle_dom.add_element('file',
                                        'name' => file_path
                                       )
      file.add_element('error',
                       'line' => diagnostics['location']['line'],
                       'severity' => 'error',
                       'message' => "#{diagnostics['category']}\n#{diagnostics['description']}"
                      )
    end

    def self.add_dummy(checkstyle)
      checkstyle.add_element('file',
                             'name' => ''
                            )

      checkstyle
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ios_analytics-0.0.6 lib/ios_analytics/translate.rb