Class | JavaClass::ClassList::JarSearcher |
In: |
lib/javaclass/classlist/jar_searcher.rb
|
Parent: | Object |
Search in zip or JAR files for Java class files, check for package access or inner classes and call back a list of all these.
Author: | Peter Kofler |
skip_inner_classes | [RW] | |
skip_package_classes | [RW] |
Compile the class list for the given classpath . This searches the path for zips and JARs and adds them to the given list of found classes. version is a number >= 0, e.g. 2 for JDK 1.2. list must provide a add_class(entry, is_public, version) method.
# File lib/javaclass/classlist/jar_searcher.rb, line 72 def add_list_from_classpath(version, classpath, list) filter_classes(classpath.names).each do |entry| is_public = public?(classpath, entry) next if @skip_package_classes && !is_public list.add_class(entry, is_public, version) if list yield(entry, is_public, version) if block_given? end end
Compile the class list for the given version of Java. This searches the path for zips and JARs and adds them to the given list of found classes. version is a number >= 0, e.g. 2 for JDK 1.2. list must provide a add_class(entry, is_public, version) method.
# File lib/javaclass/classlist/jar_searcher.rb, line 63 def compile_list(version, path, list) cpe = Classpath::AnyClasspath.new(path) add_list_from_classpath(version, cpe, list) list end
Return the list of classnames of this list of classes . Skips inner classes if skip_inner_classes is true. Skips classes that are in the filtered packages.
# File lib/javaclass/classlist/jar_searcher.rb, line 41 def filter_classes(classes) classes.find_all do |name| !(@skip_inner_classes && name =~ /\$/) && (@package_filters.find { |filter| name =~ filter } == nil) end end
The given filters will be dropped during searching. filters contain the beginning of package paths, i.e. com/sun/.
# File lib/javaclass/classlist/jar_searcher.rb, line 34 def filters=(filters) @package_filters = filters.collect{ |f| /^#{f}/ } end
Return true if the classfile in the given classpath is public. This is expensive because the JAR file is opened and the classfile is extracted and read.
# File lib/javaclass/classlist/jar_searcher.rb, line 49 def public?(classpath, classfile) begin header = ClassFile::JavaClassHeader.new(classpath.load_binary(classfile)) rescue JavaClass::ClassFile::ClassFormatError => ex ex.add_classname(classfile, classpath.to_s) raise ex end header.magic.check("invalid java class #{classfile}") header.access_flags.accessible? end