require 'pluginscan/reports/sloccount_report' require 'pluginscan/reports/cloc_report' require 'pluginscan/reports/vulnerability_report' require 'pluginscan/reports/issues_report' require 'pluginscan/reports/issues_report/issues_printer_factory' require 'pluginscan/error' module Pluginscan class Scanner DEFAULT_OPTIONS = { output: $stdout, sloccount: true, cloc: true, advisories: true, issues_format: :report, hide_ignores: false, }.freeze def initialize(options = {}) @options = DEFAULT_OPTIONS.merge options end def scan(plugin_directory) fail Errno::ENOENT unless Dir.exist? plugin_directory output_sloccount_report(plugin_directory) if @options[:sloccount] output_cloc_report(plugin_directory) if @options[:cloc] output_vulnerability_report(plugin_directory) if @options[:advisories] output_issues_report(plugin_directory) output_error_list_to_file(plugin_directory) if @options[:error_list_file] true end private def output_sloccount_report(plugin_directory) sloccount_printer = SLOCCountPrinter.new(@options[:output]) Reports::SLOCCountReport.print(plugin_directory, sloccount_printer, error_printer) end private def output_cloc_report(plugin_directory) cloc_printer = CLOCPrinter.new(@options[:output]) Reports::CLOCReport.print(plugin_directory, cloc_printer, error_printer) end private def output_vulnerability_report(plugin_directory) vulnerabilities_printer = VulnerabilitiesPrinter.new(@options[:output]) Reports::VulnerabilityReport.print(plugin_directory, vulnerabilities_printer, error_printer) end private def output_issues_report(plugin_directory) printer = IssuesPrinterFactory.create_printer(@options[:issues_format], @options[:hide_ignores], @options[:output]) Reports::IssuesReport.new(plugin_directory, printer).print end private def error_printer @error_printer ||= ErrorPrinter.new(@options[:output]) end private def output_error_list_to_file(plugin_directory) error_list_file = @options[:error_list_file] fail(IOError, IOError.message(error_list_file.class)) unless error_list_file.respond_to?(:puts) printer = IssuesPrinterFactory.create_printer(:error_list, @options[:hide_ignores], error_list_file) Reports::IssuesReport.new(plugin_directory, printer).print end end end