class Blufin::ScannerCommon
Public Class Methods
get_non_ignored_files(path, extensions, error_handler, gitignore_path = nil)
click to toggle source
Gets all non-ignored files in a specific directory (recursively).
path = the path from root, IE: /Users/Albert/Repos/repos-blufin/[site-name]/app-infrastructure
gitignore = the path (prefix) to ignore as defined in .gitignore, IE: app-infrastructure @return Array (of files)
# File lib/core/code_scanners/common/scanner_common.rb, line 9 def self.get_non_ignored_files(path, extensions, error_handler, gitignore_path = nil) raise RuntimeError, "Expected String, instead got: #{path.class}" unless path.is_a?(String) raise RuntimeError, "Expected Array, instead got: #{extensions.class}" unless extensions.is_a?(Array) raise RuntimeError, "Expected YmlErrorHandler, instead got:#{error_handler.class}" unless error_handler.is_a?(Blufin::YmlErrorHandler) raise RuntimeError, "Expected String or Nil, instead got: #{gitignore_path.class}" unless gitignore_path.nil? || gitignore_path.is_a?(String) found_files = [] ignore_paths = [] scan_path = path gitignore_path.gsub(/\A\//, '').gsub(/\/\z/, '') unless gitignore_path.nil? unless gitignore_path.nil? || gitignore_path == '' gitignore_file = "#{path}/.gitignore" scan_path = "#{path}/#{gitignore_path}" if Blufin::Files::file_exists(gitignore_file) # Adds all ignore paths for .gitignore. Blufin::Files::read_file(gitignore_file).each do |line| line = line.gsub(/\A\//, '').gsub("\n", '') next unless line =~ /\A#{gitignore_path}\// ignore_paths << "#{path}/#{line}" end else # Add error if git ignore is missing. error_handler.add_error(Blufin::YmlErrorHandler::FILE_NOT_FOUND_GITIGNORE, gitignore_file, nil, nil, gitignore_file) return found_files end end # Gets all files (which are not ignored). Blufin::Files::get_files_in_dir("#{scan_path}").each do |file| next if is_in_ignore_path(file, ignore_paths) matches_extension = false extensions.each { |extension| matches_extension = true if file =~ /\.#{extension}\z/ } next unless matches_extension found_files << file end found_files end
swap_classpath_for_testpath(site, file)
click to toggle source
Takes a path and swaps it from classpath to test-path. @return String
# File lib/core/code_scanners/common/scanner_common.rb, line 47 def self.swap_classpath_for_testpath(site, file) raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String) site = Blufin::SiteResolver::validate_site(site) site_name = Blufin::SiteResolver::get_site_name(site) site_domain = Blufin::SiteResolver::get_site_domain(site) site_domain_gsub = site_domain.strip == '' ? '' : "#{site_domain.gsub('.', '/')}\\/" begin matches = file.match(/\/#{site_name}-(#{Blufin::SiteServices::REGEX_JAVA})\/src\/main\/java\/#{site_domain_gsub}#{site_name.gsub('-', '/')}\//) matches = matches[0].gsub(/\A\//, '').gsub(/\/\z/, '') matches = matches.split('/') service = matches[0] swap_path = "/#{service}/src/main/java/" swap_for = "/#{service}/src/test/java/" raise RuntimeError, "Unable to find swap_path: #{swap_path}" unless file =~ /#{swap_path}/ return file.gsub(swap_path, swap_for) rescue => e puts e.message raise RuntimeError, "Failed to swap_classpath_for_testpath() with file: #{file}" end end
Private Class Methods
is_in_ignore_path(file, ignore_paths)
click to toggle source
Checks if file is in ignore_paths Array. Only used internally by this class. @return Boolean
# File lib/core/code_scanners/common/scanner_common.rb, line 72 def self.is_in_ignore_path(file, ignore_paths) ignore_paths.each { |line| line = line.gsub(/\*\*\/\*\z/, '') line = line.gsub(/\*\*\//, '') line = line.gsub(/\*\z/, '') return true if file.strip =~ /\A#{line.strip}/ } false end