Class: JavaClass::Classpath::CompositeClasspath
- Inherits:
-
FileClasspath
- Object
- FileClasspath
- JavaClass::Classpath::CompositeClasspath
- Defined in:
- lib/javaclass/classpath/composite_classpath.rb,
lib/javaclass/classpath/tracking_classpath.rb
Overview
List of class path elements constructed from a full CLASSPATH variable.
- Author
-
Peter Kofler
Direct Known Subclasses
Instance Method Summary collapse
-
#__old__add_element__ ⇒ Object
Wrap the elem classpath with a new TrackingClasspath and add it to the list of elements.
-
#accessed(classname = nil) ⇒ Object
Was the classname accessed then return the count? If classname is
nil
then check if any class was accessed. -
#add_element(elem) ⇒ Object
Add the elem classpath element to the list.
-
#add_file_name(name) ⇒ Object
Add the name class path which may be a file or a folder to this classpath.
-
#all_accessed ⇒ Object
Return the classnames of all accessed classes in child elements.
-
#count ⇒ Object
Return the number of classes in this classpath.
-
#elements ⇒ Object
Return all the classpath elements (the children) of this path and all child paths.
-
#includes?(classname) ⇒ Boolean
Return if classname is included in this classpath.
-
#initialize(root = '.') ⇒ CompositeClasspath
constructor
Create an empty classpath composite root.
-
#load_binary(classname) ⇒ Object
Load the binary data of the file name or class name classname from this classpath.
-
#mark_accessed(classname) ⇒ Object
Mark the classname as accessed.
-
#names(&filter) ⇒ Object
Return the list of class names found in this classpath.
-
#reset_access ⇒ Object
Reset all prior marked access in child elements.
- #to_s ⇒ Object
Methods inherited from FileClasspath
#==, #additional_classpath, #jar?, #to_key
Constructor Details
#initialize(root = '.') ⇒ CompositeClasspath
Create an empty classpath composite root. The optional file is for identifying subclasses.
20 21 22 23 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 20 def initialize(root='.') super(root) @elements = [] end |
Instance Method Details
#__old__add_element__ ⇒ Object
Wrap the elem classpath with a new TrackingClasspath and add it to the list of elements.
93 |
# File 'lib/javaclass/classpath/tracking_classpath.rb', line 93 alias __old__add_element__ add_element |
#accessed(classname = nil) ⇒ Object
Was the classname accessed then return the count? If classname is nil
then check if any class was accessed. (See TrackingClasspath)
123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/javaclass/classpath/tracking_classpath.rb', line 123 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 |
#add_element(elem) ⇒ Object
Add the elem classpath element to the list.
43 44 45 46 47 48 49 50 51 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 43 def add_element(elem) unless @elements.find { |cpe| cpe == elem } if [FolderClasspath, JarClasspath].include?(elem.class) __old__add_element__(TrackingClasspath.new(elem)) else __old__add_element__(elem) end end end |
#add_file_name(name) ⇒ Object
Add the name class path which may be a file or a folder to this classpath.
32 33 34 35 36 37 38 39 40 |
# 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 |
#all_accessed ⇒ Object
Return the classnames of all accessed classes in child elements. (See TrackingClasspath)
137 138 139 |
# File 'lib/javaclass/classpath/tracking_classpath.rb', line 137 def all_accessed @elements.map { |cp| cp.all_accessed }.flatten.sort end |
#count ⇒ Object
Return the number of classes in this classpath.
78 79 80 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 78 def count @elements.inject(0) { |s,e| s + e.count } end |
#elements ⇒ Object
Return all the classpath elements (the children) of this path and all child paths.
26 27 28 29 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 26 def elements # [self] + */ @elements.map { |cp| cp.elements }.flatten end |
#includes?(classname) ⇒ Boolean
Return if classname is included in this classpath. If yes, return the count (usually 1).
61 62 63 64 65 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 61 def includes?(classname) key = to_key(classname) found = find_element_for(key) if found then 1 else nil end end |
#load_binary(classname) ⇒ Object
Load the binary data of the file name or class name classname from this classpath.
68 69 70 71 72 73 74 75 |
# 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_accessed(classname) ⇒ Object
Mark the classname as accessed. Return the number of accesses so far. (See TrackingClasspath)
111 112 113 114 115 116 117 118 119 |
# File 'lib/javaclass/classpath/tracking_classpath.rb', line 111 def mark_accessed(classname) key = to_key(classname) found = find_element_for(key) if found found.mark_accessed(key) else nil end end |
#names(&filter) ⇒ Object
Return the list of class names found in this classpath. An additional block is used as filter on class names.
56 57 58 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 56 def names(&filter) @elements.collect { |e| e.names(&filter) }.flatten.uniq end |
#reset_access ⇒ Object
Reset all prior marked access in child elements. (See TrackingClasspath)
106 107 108 |
# File 'lib/javaclass/classpath/tracking_classpath.rb', line 106 def reset_access @elements.each { |e| e.reset_access } end |
#to_s ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 82 def to_s str = super.to_s if str=='.' @elements.collect { |e| e.to_s }.join(',') else str end end |