Class: JavaClass::Classpath::AnyClasspath

Inherits:
CompositeClasspath show all
Defined in:
lib/javaclass/classpath/any_classpath.rb

Overview

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

Author

Peter Kofler

Instance Method Summary collapse

Methods inherited from CompositeClasspath

#__old__add_element__, #accessed, #add_element, #add_file_name, #all_accessed, #count, #elements, #includes?, #load_binary, #mark_accessed, #names, #reset_access, #to_s

Methods inherited from FileClasspath

#==, #additional_classpath, #elements, #jar?, #to_key, #to_s

Constructor Details

#initialize(folder) ⇒ AnyClasspath

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



12
13
14
15
16
17
18
19
# 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

Instance Method Details

#find_jars(path) ⇒ Object

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



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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['*'].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