class JavaClass::Classpath::FolderClasspath
Abstraction of a folder on the CLASSPATH. This is a leaf in the classpath tree.
- Author
-
Peter Kofler
Public Class Methods
new(folder)
click to toggle source
Create a classpath with this folder .
Calls superclass method
JavaClass::Classpath::FileClasspath::new
# File lib/javaclass/classpath/folder_classpath.rb, line 18 def initialize(folder) super(folder) unless FolderClasspath::valid_location?(folder) raise IOError, "folder #{folder} not found/no folder" end @folder = folder init_classes end
valid_location?(file)
click to toggle source
Check if the file is a valid location for a folder classpath.
# File lib/javaclass/classpath/folder_classpath.rb, line 13 def self.valid_location?(file) FileTest.exist?(file) && FileTest.directory?(file) end
Public Instance Methods
count()
click to toggle source
Return the number of classes in this folder.
# File lib/javaclass/classpath/folder_classpath.rb, line 51 def count @class_names.size end
includes?(classname)
click to toggle source
Return if classname is included in this folder.
# File lib/javaclass/classpath/folder_classpath.rb, line 37 def includes?(classname) @class_lookup[to_key(classname).file_name] end
load_binary(classname)
click to toggle source
Load the binary data of the file name or class name classname from this folder.
# File lib/javaclass/classpath/folder_classpath.rb, line 42 def load_binary(classname) key = to_key(classname) unless includes?(key) raise ClassNotFoundError.new(key, @folder) end File.open(File.join(@folder, key), 'rb') { |io| io.read.freeze } end
names(&filter)
click to toggle source
Return the list of class names found in this folder. An additional block is used as filter on class names.
# File lib/javaclass/classpath/folder_classpath.rb, line 28 def names(&filter) if block_given? @class_names.find_all { |n| filter.call(n) } else @class_names.dup end end
Private Instance Methods
init_classes()
click to toggle source
Set up the class names.
# File lib/javaclass/classpath/folder_classpath.rb, line 72 def init_classes @class_names = list_classes.sort.reject { |n| n =~ /package-info\.class$/ }.collect { |cl| JavaClassFileName.new(cl) } pairs = @class_names.map { |name| [name.file_name, 1] }.flatten @class_lookup = Hash[ *pairs ] # file_name (String) => anything end
list_classes()
click to toggle source
Return the list of classnames (in fact file names) found in this folder.
# File lib/javaclass/classpath/folder_classpath.rb, line 58 def list_classes current = Dir.getwd begin Dir.chdir @folder list = Dir["**/*#{JavaLanguage::CLASS}"] ensure Dir.chdir current end list end