Class: Blufin::ScannerCommon
- Inherits:
-
Object
- Object
- Blufin::ScannerCommon
- Defined in:
- lib/core/code_scanners/common/scanner_common.rb
Class Method Summary collapse
-
.get_non_ignored_files(path, extensions, error_handler, gitignore_path = nil) ⇒ Object
Gets all non-ignored files in a specific directory (recursively).
-
.swap_classpath_for_testpath(site, file) ⇒ Object
Takes a path and swaps it from classpath to test-path.
Class Method Details
.get_non_ignored_files(path, extensions, error_handler, gitignore_path = nil) ⇒ Object
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
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# 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) ⇒ Object
Takes a path and swaps it from classpath to test-path.
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# 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. raise RuntimeError, "Failed to swap_classpath_for_testpath() with file: #{file}" end end |