Class | JavaClass::Classpath::CompositeClasspath |
In: |
lib/javaclass/classpath/composite_classpath.rb
lib/javaclass/classpath/tracking_classpath.rb |
Parent: | FileClasspath |
List of class path elements constructed from a full CLASSPATH variable.
Author: | Peter Kofler |
Create an empty classpath composite root. The optional file is for identifying subclasses.
# File lib/javaclass/classpath/composite_classpath.rb, line 20 def initialize(root='.') super(root) @elements = [] end
Was the classname accessed then return the count? If classname is nil then check if any class was accessed. (See TrackingClasspath)
# File lib/javaclass/classpath/tracking_classpath.rb, line 125 def accessed(classname=nil) if classname key = to_key(classname) found = find_element_for(key) if found then found.accessed(key) else 0 end else @elements.inject(0) do |s,e| accessed = e.accessed if accessed then s + accessed else s end end end end
# File lib/javaclass/classpath/tracking_classpath.rb, line 96 def add_element(elem) unless @elements.find { |cpe| cpe == elem } if [FolderClasspath, JarClasspath].include?(elem.class) # TODO check for any subclass of FileClasspath instead -> fail a test with ConventionClasspath and Tracker __old__add_element__(TrackingClasspath.new(elem)) else __old__add_element__(elem) end end end
Add the elem classpath element to the list.
# File lib/javaclass/classpath/composite_classpath.rb, line 43 def add_element(elem) if elem.count > 0 && !@elements.find { |cpe| cpe == elem } @elements << elem end elem.additional_classpath.each do |acpe| # referred classpath elements may be missing if JarClasspath.valid_location?(acpe) add_element(JarClasspath.new(acpe)) end end end
Add the name class path which may be a file or a folder to this classpath.
# File lib/javaclass/classpath/composite_classpath.rb, line 32 def add_file_name(name) if FolderClasspath.valid_location?(name) add_element(FolderClasspath.new(name)) elsif JarClasspath.valid_location?(name) add_element(JarClasspath.new(name)) else warn("tried to add an invalid classpath location #{name}") end end
Return the classnames of all accessed classes in child elements. (See TrackingClasspath)
# File lib/javaclass/classpath/tracking_classpath.rb, line 139 def all_accessed @elements.map { |cp| cp.all_accessed }.flatten.sort end
Return the number of classes in this classpath.
# File lib/javaclass/classpath/composite_classpath.rb, line 78 def count @elements.inject(0) { |s,e| s + e.count } end
Load the binary data of the file name or class name classname from this classpath.
# File lib/javaclass/classpath/composite_classpath.rb, line 68 def load_binary(classname) key = to_key(classname) found = find_element_for(key) unless found raise ClassNotFoundError.new(key, to_s) end found.load_binary(key) end
Mark the classname as accessed. Return the number of accesses so far. (See TrackingClasspath)
# File lib/javaclass/classpath/tracking_classpath.rb, line 113 def mark_accessed(classname) key = to_key(classname) found = find_element_for(key) if found found.mark_accessed(key) else nil end end
Reset all prior marked access in child elements. (See TrackingClasspath)
# File lib/javaclass/classpath/tracking_classpath.rb, line 108 def reset_access @elements.each { |e| e.reset_access } end