Class: JavaClass::Classpath::CompositeClasspath
- Inherits:
-
Object
- Object
- JavaClass::Classpath::CompositeClasspath
- Defined in:
- lib/javaclass/classpath/composite_classpath.rb
Overview
List of class path elements.
- Author
-
Peter Kofler
Instance Method Summary collapse
-
#add_element(elem) ⇒ Object
Add the elem classpath element to the list.
-
#add_file_name(name) ⇒ Object
Add the name class path file/folder name to the list.
-
#additional_classpath ⇒ Object
Return an empty array.
-
#count ⇒ Object
Return the number of classes in this jar.
-
#elements ⇒ Object
Return the classpath elements of this path.
-
#find_jars(path) ⇒ Object
Search the given path recursievely for zips or jars.
-
#includes?(classname) ⇒ Boolean
Return if classname is included in this classpath.
-
#initialize ⇒ CompositeClasspath
constructor
Return the list of classnames found in this path.
-
#jar? ⇒ Boolean
Return false.
-
#load_binary(classname) ⇒ Object
Load the binary data of the file name or class name classname from this classpath.
-
#names ⇒ Object
Return the list of class names found in this classpath.
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ CompositeClasspath
Return the list of classnames found in this path.
10 11 12 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 10 def initialize @elements = [] end |
Instance Method Details
#add_element(elem) ⇒ Object
Add the elem classpath element to the list.
48 49 50 51 52 53 54 55 56 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 48 def add_element(elem) @elements << elem unless @elements.find { |cpe| cpe == elem } elem.additional_classpath.each do |acpe| # referred classpath elements may be missing if FileTest.exist? acpe add_element(JarClasspath.new(acpe)) end end end |
#add_file_name(name) ⇒ Object
Add the name class path file/folder name to the list.
39 40 41 42 43 44 45 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 39 def add_file_name(name) if FileTest.directory? name add_element(FolderClasspath.new(name)) else add_element(JarClasspath.new(name)) end end |
#additional_classpath ⇒ Object
Return an empty array.
64 65 66 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 64 def additional_classpath [] end |
#count ⇒ Object
Return the number of classes in this jar.
88 89 90 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 88 def count @elements.inject(0) { |s,e| s + e.count } end |
#elements ⇒ Object
Return the classpath elements of this path.
15 16 17 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 15 def elements @elements.dup end |
#find_jars(path) ⇒ Object
Search the given path recursievely for zips or jars. Add all found jars to this classpath.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 20 def find_jars(path) current = Dir.getwd begin Dir.chdir File.(path) Dir['*'].collect do |name| if FileTest.directory?(name) find_jars(name) elsif name =~ /\.jar$|\.zip$/ add_file_name File.(name) end end ensure Dir.chdir current end end |
#includes?(classname) ⇒ Boolean
Return if classname is included in this classpath.
74 75 76 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 74 def includes?(classname) @elements.find { |e| e.includes?(classname) } != nil end |
#jar? ⇒ Boolean
Return false.
59 60 61 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 59 def jar? false end |
#load_binary(classname) ⇒ Object
Load the binary data of the file name or class name classname from this classpath.
79 80 81 82 83 84 85 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 79 def load_binary(classname) found = @elements.find { |e| e.includes?(classname) } if (found) return found.load_binary(classname) end raise "class #{classname} not found in classpath #{to_s}" end |
#names ⇒ Object
Return the list of class names found in this classpath.
69 70 71 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 69 def names @elements.collect { |e| e.names }.flatten.uniq end |
#to_s ⇒ Object
92 93 94 |
# File 'lib/javaclass/classpath/composite_classpath.rb', line 92 def to_s @elements.collect { |e| e.to_s }.join(',') end |