Class: Gjp::KitChecker
- Inherits:
-
Object
- Object
- Gjp::KitChecker
- Includes:
- Logger
- Defined in:
- lib/gjp/kit_checker.rb
Overview
checks kits for errors
Instance Method Summary collapse
-
#get_compiled_classes(paths) ⇒ Object
returns a list of class names for which we have binary files in kit/.
-
#get_source_class_names(paths) ⇒ Object
returns a list of class names for which we have source files in kit/.
-
#get_unsourced ⇒ Object
returns a hash that associates archive names and the unsourced classes within them.
-
#initialize(project) ⇒ KitChecker
constructor
A new instance of KitChecker.
-
#kit_file_paths ⇒ Object
returns an array of [path, archive] couples found in kit/ archive is not nil if path is inside a zip file.
Methods included from Logger
Constructor Details
#initialize(project) ⇒ KitChecker
Returns a new instance of KitChecker.
10 11 12 |
# File 'lib/gjp/kit_checker.rb', line 10 def initialize(project) @project = project end |
Instance Method Details
#get_compiled_classes(paths) ⇒ Object
returns a list of class names for which we have binary files in kit/
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/gjp/kit_checker.rb', line 65 def get_compiled_classes(paths) result = {} compiled_paths = paths.select do |path, archive| path =~ /\.class$/ end.each do |path, archive| class_name = path_to_class(path) if result[archive] == nil result[archive] = [class_name] else result[archive] << class_name end end result end |
#get_source_class_names(paths) ⇒ Object
returns a list of class names for which we have source files in kit/
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/gjp/kit_checker.rb', line 42 def get_source_class_names(paths) source_paths = paths.select do |path, archive| path =~ /\.java$/ end # heuristically add all possible package names, walking # back the directory tree all the way back to root. # This could add non-existent names, but allows not looking # in the file at all class_names = source_paths.map do |path, archive| class_name = path_to_class(path) parts = class_name.split(".") last_index = parts.length() -1 (0..last_index).map do |i| parts[i..last_index].join(".") end end.flatten Set.new(class_names) end |
#get_unsourced ⇒ Object
returns a hash that associates archive names and the unsourced classes within them
83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/gjp/kit_checker.rb', line 83 def get_unsourced paths = kit_file_paths source_class_names = get_source_class_names(paths) archive_paths_to_class_names = get_compiled_classes(paths) result = archive_paths_to_class_names.map do |archive, class_names| unsourced_class_names = class_names.select do |class_name| source_class_names.include?(class_name) == false end {:archive => archive, :class_names => class_names, :unsourced_class_names => unsourced_class_names} end.select do |archive| archive[:unsourced_class_names].any? end end |
#kit_file_paths ⇒ Object
returns an array of [path, archive] couples found in kit/ archive is not nil if path is inside a zip file
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gjp/kit_checker.rb', line 16 def kit_file_paths @project.from_directory("kit") do plain_file_paths = Dir[File.join("**", "*")].select do |path| File.file?(path) end.map do |path| [path, nil] end archived_file_paths = plain_file_paths.select do |path, archive| path. =~ /\.(zip)|([jwe]ar)$/ end.map do |path, archive| result = [] Zip::ZipFile.foreach(path) do |entry| if entry.file? result << [entry.to_s, path] end end result end.flatten(1) plain_file_paths + archived_file_paths end end |