class JavaClass::Classpath::AnyClasspath

Classpath containing everything under a folder. This is for an unstructured collection of JARs and class files.

Author

Peter Kofler

Public Class Methods

new(folder) click to toggle source

Create a classpath with all classes found under this folder wherever they are.

Calls superclass method
# File lib/javaclass/classpath/any_classpath.rb, line 12
def initialize(folder)
  super(File.join(folder, '*'))
  find_jars(folder)
  
  # TODO Implement "find_classes_under(folder)" to find all class folders under this path.
  # Search for classes, open the first one, check its package, backtrack to its base folder,
  # add it to this classpath "add_file_name(sub_folders)", skip it in further analysis and continue.
end

Public Instance Methods

find_jars(path) click to toggle source

Search the given path recursively for zips or jars. Add all found jars to this classpath.

# File lib/javaclass/classpath/any_classpath.rb, line 22
def find_jars(path)
  if FileTest.file?(path) && path =~ /\.jar$|\.zip$/
    add_file_name File.expand_path(path)
    return
  end
  
  current = Dir.getwd
  begin
    Dir.chdir File.expand_path(path)

    Dir['*'].sort.collect do |name|
      if FileTest.directory?(name)
        find_jars(name)
      elsif name =~ /\.jar$|\.zip$/
        add_file_name File.expand_path(name)
      end
    end

  ensure
    Dir.chdir current
  end
end