Class: Gjp::KitChecker
- Inherits:
-
Object
- Object
- Gjp::KitChecker
- Includes:
- Logging
- Defined in:
- lib/gjp/kit_checker.rb
Overview
checks kits for errors
Instance Method Summary collapse
-
#compiled_classes(paths) ⇒ Object
returns a list of class names for which we have binary files in kit/.
-
#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.
-
#source_class_names(paths) ⇒ Object
returns a list of class names for which we have source files in kit/.
-
#unsourced_archives ⇒ Object
returns a hash that associates archive names and the unsourced classes within them.
Methods included from Logging
Constructor Details
#initialize(project) ⇒ KitChecker
Returns a new instance of KitChecker.
11 12 13 |
# File 'lib/gjp/kit_checker.rb', line 11 def initialize(project) @project = project end |
Instance Method Details
#compiled_classes(paths) ⇒ Object
returns a list of class names for which we have binary files in kit/
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/gjp/kit_checker.rb', line 66 def 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 |
#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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/gjp/kit_checker.rb', line 17 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::File.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 |
#source_class_names(paths) ⇒ Object
returns a list of class names for which we have source files in kit/
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/gjp/kit_checker.rb', line 43 def 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 |
#unsourced_archives ⇒ Object
returns a hash that associates archive names and the unsourced classes within them
84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gjp/kit_checker.rb', line 84 def unsourced_archives paths = kit_file_paths source_class_names = source_class_names(paths) archive_paths_to_class_names = 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 |