class Blufin::ScannerJava
Constants
- NAME
- PATH
- TEST
- TEST_NOT_RELATED_TO_CLASS
- TEST_REQUIRED
- TYPE
- TYPE_CLASS
- TYPE_CLASS_ABSTRACT
- TYPE_ENUM
- TYPE_INTERFACE
Public Class Methods
scan(file, site, error_handler)
click to toggle source
Returns a Hash containing info about the Java class. @return void
# File lib/core/code_scanners/common/scanner_java.rb, line 22 def self.scan(file, site, error_handler) return @@scanned_classes[file] unless @@scanned_classes[file].nil? raise RuntimeError, "Expected String, instead got: #{file.class}" unless file.is_a?(String) raise RuntimeError, "This method only accepts .java files. You passed: #{file}" unless file =~ /\.java\z/ site = Blufin::SiteResolver::validate_site(site) site_path = Blufin::SiteResolver::get_site_location(site) fps = Blufin::YmlCommon::split_to_path_file(file, site_path) info = { NAME => fps[1], PATH => fps[0], } # Is this a test? info[TEST] = (file =~ /\/src\/test\//) ? true : false info[TEST_REQUIRED] = true unless info[TEST] @test_required = false @test_not_required = false @test_not_related_to_class = false Blufin::Files::read_file(file).each do |line| get_java_class_type(info, line, file) if info[TYPE].nil? get_java_test_required(info, line) if info[TEST_REQUIRED] get_java_test_not_related_to_class(info, line) if info[TEST] end # Errors tests_annotations_found = [] tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_REQUIRED if @test_required tests_annotations_found << Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED if @test_not_required error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_ONE_OR_ANOTHER, file, nil, nil, [Blufin::SiteServices::ANNOTATION_TEST_REQUIRED, Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED].inspect) if @test_required && @test_not_required error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, tests_annotations_found.inspect) if info[TEST] && tests_annotations_found.any? error_handler.add_error(Blufin::YmlErrorHandler::ANNOTATIONS_NOT_EXPECTED, file, nil, nil, Blufin::SiteServices::ANNOTATION_TEST_NOT_RELATED_TO_CLASS.inspect) if info[TEST] == false && @test_not_related_to_class info[TEST_REQUIRED] = true if @test_required info[TEST_REQUIRED] = false if @test_not_required raise RuntimeError, "Unrecognized ClassType: #{file}" if info[TYPE].nil? @@scanned_classes[file] = info info end
Private Class Methods
get_java_class_type(info, line, file)
click to toggle source
Gets the Java class TYPE
. @return void
# File lib/core/code_scanners/common/scanner_java.rb, line 66 def self.get_java_class_type(info, line, file) if line =~ /\Apublic class\s/ || line =~ /\Apublic final class\s/ info[TYPE] = TYPE_CLASS elsif line =~ /\Aclass\s/ || line =~ /\Afinal class\s/ info[TYPE] = TYPE_CLASS # TODO - 05-06-19 - Remove this warning once we have some kind of code-formatter. Blufin::Terminal::output("Class in file is not public: #{file}", Blufin::Terminal::MSG_WARNING) elsif line =~ /\Apublic abstract class/ info[TYPE] = TYPE_CLASS_ABSTRACT elsif line =~ /\Apublic enum/ info[TYPE] = TYPE_ENUM elsif line =~ /\Apublic interface/ info[TYPE] = TYPE_INTERFACE end end
get_java_test_required(info, line)
click to toggle source
Looks for @TestRequired, @NoTestRequired annotation. @return void
# File lib/core/code_scanners/common/scanner_java.rb, line 84 def self.get_java_test_required(info, line) return if (@test_required || @test_not_required) && !info[TYPE].nil? info[TEST_REQUIRED] = false if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED}/ info[TEST_REQUIRED] = false if line =~ /\Apublic abstract class/ @test_required = true if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_REQUIRED}/ @test_not_required = true if line =~ /\A#{Blufin::SiteServices::ANNOTATION_TEST_NOT_REQUIRED}/ end