lib/roku_builder/plugins/analyzer.rb in roku_builder-4.17.1 vs lib/roku_builder/plugins/analyzer.rb in roku_builder-4.18.0
- old
+ new
@@ -28,66 +28,82 @@
end
def analyze(options:, quiet: false)
@options = options
@warnings = []
- analyzer_config = get_config("inspector_config.json")
performance_config = get_config("performance_config.json")
linter_config = get_config(".roku_builder_linter.json", true)
- linter_config ||= {}
- @inspector_config = analyzer_config[:inspectors]
+ linter_config ||= {is_ssai: false}
loader = Loader.new(config: @config)
Dir.mktmpdir do |dir|
loader.copy(options: options, path: dir)
- raf_inspector = RafInspector.new(config: @config, dir: dir)
- manifest_inspector = ManifestInspector.new(config: @config, dir: dir, raf: raf_inspector)
- @warnings.concat(manifest_inspector.run(analyzer_config[:inspectors]))
- has_source_dir = false
+ run_sca_tool(path: dir, ssai: linter_config[:is_ssai])
libraries = @config.project[:libraries]
libraries ||= []
Dir.glob(File.join(dir, "**", "*")).each do |file_path|
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 = analyzer_config[:lineInspectors]
- line_inspector_config += performance_config
+ line_inspector_config = performance_config
line_inspector_config += linter_config[:rules] if linter_config[:rules]
- line_inspector = LineInspector.new(config: @config, raf: raf_inspector, inspector_config: line_inspector_config, indent_config: linter_config[:indentation])
+ line_inspector = LineInspector.new(inspector_config: line_inspector_config, indent_config: linter_config[:indentation])
@warnings.concat(line_inspector.run(file_path))
end
- if file_path.end_with?("__MACOSX")
- add_warning(warning: :packageMacosxDirectory, path: file_path)
- end
- if file_path.end_with?(".zip", ".md", ".pkg")
- add_warning(warning: :packageExtraneousFiles, path: file_path)
- end
end
- has_source_dir = true if file_path.end_with?("source")
end
- unless has_source_dir
- add_warning(warning: :packageSourceDirectory, path: "source")
- end
- @warnings.concat(raf_inspector.run(analyzer_config[:inspectors]))
format_messages(dir)
print_warnings unless quiet
end
@warnings
end
private
+ def run_sca_tool(path:, ssai:)
+ if OS.unix?
+ command = File.join(File.dirname(__FILE__), "sca-cmd", "bin", "sca-cmd")
+ else
+ command = File.join(File.dirname(__FILE__), "sca-cmd", "bin", "sca-cmd.bat")
+ end
+ results = `#{command} #{path}`.split("\n")
+ process_sca_results(results, ssai)
+ end
+
+ def process_sca_results(results, ssai)
+ results.each do |result_line|
+ if /-----+/.match(result_line) or /\*\*\*\*\*+/.match(result_line)
+ @warnings.push(@sca_warning) if add_warning?(ssai)
+ @sca_warning = {}
+ elsif data = /^(\[WARNING\]|\[INFO\]|\[ERROR\])(.*)$/.match(result_line)
+ @warnings.push(@sca_warning) if add_warning?(ssai)
+ @sca_warning = {}
+ @sca_warning[:severity] = data[1].gsub(/(\[|\])/, "").downcase
+ @sca_warning[:message] = data[2]
+ elsif data = /^\sPath: ([^ ]*) Line: (\d*)./.match(result_line)
+ @sca_warning[:path] = data[1]+":"+data[2]
+ elsif @sca_warning and @sca_warning[:message]
+ @sca_warning[:message] += " " + result_line
+ end
+ end
+ end
+
+ def add_warning?(ssai)
+ if @sca_warning and @sca_warning[:severity]
+ if ssai and /SetAdUrl\(\) method is missing/.match(@sca_warning[:message])
+ return false
+ end
+ return true
+ end
+ return false
+ end
+
def get_config(file, project_root=false)
if project_root
file = File.join(@config.root_dir, file)
else
file = File.join(File.dirname(__FILE__), file)
end
JSON.parse(File.open(file).read, {symbolize_names: true}) if File.exist? file
- end
-
- def add_warning(warning:, path:)
- @warnings.push(@inspector_config[warning].deep_dup)
- @warnings.last[:path] = path
end
def print_warnings
logger = ::Logger.new(STDOUT)
logger.level = @logger.level