class JavaClass::Classpath::CompositeClasspath

List of class path elements constructed from a full CLASSPATH variable.

Author

Peter Kofler

Public Class Methods

new(root='.') click to toggle source

Create an empty classpath composite root. The optional file is for identifying subclasses.

Calls superclass method
# File lib/javaclass/classpath/composite_classpath.rb, line 20
def initialize(root='.')
  super(root)
  @elements = []
end

Public Instance Methods

__old__add_element__(elem)

Wrap the elem classpath with a new TrackingClasspath and add it to the list of elements.

Alias for: add_element
accessed(classname=nil) click to toggle source

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
add_element(elem) click to toggle source

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
Also aliased as: __old__add_element__
add_file_name(name) click to toggle source

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
all_accessed() click to toggle source

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
count() click to toggle source

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
elements() click to toggle source

Return all the classpath elements (the children) of this path and all child paths.

# File lib/javaclass/classpath/composite_classpath.rb, line 26
def elements
  # [self] + */
  @elements.map { |cp| cp.elements }.flatten
end
includes?(classname) click to toggle source

Return if classname is included in this classpath. If yes, return the count (usually 1).

# 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) click to toggle source

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_accessed(classname) click to toggle source

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
names(&filter) click to toggle source

Return the list of class names found in this classpath. An additional block is used as filter on class names.

# File lib/javaclass/classpath/composite_classpath.rb, line 56
def names(&filter)
  @elements.collect { |e| e.names(&filter) }.flatten.uniq
end
reset_access() click to toggle source

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
to_s() click to toggle source
Calls superclass method
# 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

Private Instance Methods

find_element_for(key) click to toggle source

Return the matching classpath element for the given key

# File lib/javaclass/classpath/composite_classpath.rb, line 94
def find_element_for(key)
  @elements.find { |e| e.includes?(key) }
end