Class: RokuBuilder::Analyzer

Inherits:
Util
  • Object
show all
Extended by:
Plugin
Defined in:
lib/roku_builder/plugins/analyzer.rb

Overview

Collects information on a package for submission

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Plugin

commands, dependencies, parse_options, validate

Methods inherited from Util

#initialize

Constructor Details

This class inherits a constructor from RokuBuilder::Util

Class Method Details

.commandsObject



9
10
11
12
13
# File 'lib/roku_builder/plugins/analyzer.rb', line 9

def self.commands
  {
    analyze: {source: true, stage: true},
  }
end

.dependenciesObject



32
33
34
# File 'lib/roku_builder/plugins/analyzer.rb', line 32

def self.dependencies
  [Loader]
end

.parse_options(parser:, options:) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/roku_builder/plugins/analyzer.rb', line 15

def self.parse_options(parser:, options:)
  parser.separator "Commands:"
  parser.on("--analyze", "Run a static analysis on a given stage") do
    options[:analyze] = true
  end
  parser.separator "Options:"
  parser.on("--include-libraries", "Include libraries in analyze") do
    options[:include_libraries] = true
  end
  parser.on("--include-libraries-sca", "Include libraries in roku Static Code Aanlysis") do
    options[:include_libraries_sca] = true
  end
  parser.on("--skip-sca", "Skip Roku Static Code Analysis") do |command|
    options[:skip_sca] = command
  end
end

Instance Method Details

#analyze(options:, quiet: false) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/roku_builder/plugins/analyzer.rb', line 36

def analyze(options:, quiet: false)
  @options = options
  @warnings = []
  @sca_warning = {}
  performance_config = get_config("performance_config.json")
  linter_config = get_config(".roku_builder_linter.json", true)
  linter_config ||= {is_ssai: false}
  loader = Loader.new(config: @config)
  Dir.mktmpdir do |dir|
    loader.copy(options: options, path: dir)
    run_sca_tool(path: dir, linter_config: linter_config) unless options[:skip_sca]
    libraries = @config.project[:libraries]
    libraries ||= []
    Dir.glob(File.join(dir, "**", "*")).each do |file_path|
      #byebug if file_path.include?("adTuningChannelComponent.brs")
      file = file_path.dup; file.slice!(dir)
      unless libraries.any_is_start?(file) and not @options[:include_libraries]
        if File.file?(file_path) and file_path.end_with?(".brs", ".xml")
          line_inspector_config = []
          line_inspector_config = performance_config unless linter_config[:skip_performance]
          line_inspector_config += linter_config[:rules] if linter_config[:rules]
          line_inspector = LineInspector.new(inspector_config: line_inspector_config, indent_config: linter_config[:indentation])
          @warnings.concat(line_inspector.run(file_path))
        end
      end
    end
    format_messages(dir)
    print_warnings unless quiet
  end
  @warnings
end