Class: JavaClass::Classpath::EclipseClasspath

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

Overview

An Eclipse workspace aware classpath.

Author

Peter Kofler

Constant Summary collapse

DOT_CLASSPATH =
'.classpath'

Class Method Summary collapse

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) ⇒ EclipseClasspath

Create a classpath for an Eclipse base project in folder where the .classpath is.



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/javaclass/classpath/eclipse_classpath.rb', line 30

def initialize(folder)
  unless EclipseClasspath::valid_location?(folder)
    raise IOError, "folder #{folder} not an Eclipse project"
  end
  dot_classpath = File.join(folder, DOT_CLASSPATH)
  super(dot_classpath)
  classpath = IO.readlines(dot_classpath)
  
  classpath.find_all { |line| line =~ /kind\s*=\s*"output"/ }.each do |line|
    if line =~ /path\s*=\s*"([^"]+)"/
      add_file_name(File.join(folder, $1))
    end
  end

  classpath.find_all { |line| line =~ /output\s*=\s*"/ }.each do |line|
    if line =~ /output\s*=\s*"([^"]+)"/
      add_file_name(File.join(folder, $1))
    end
  end
  
  @@skip_lib ||= false
  unless @@skip_lib
  
    classpath.find_all { |line| line =~ /kind\s*=\s*"lib"/ }.each do |line|
      if line =~ /path\s*=\s*"([^"]+)"/
        add_file_name(File.join(folder, $1))
      end
    end 
    
    @@variables ||= Hash.new
    classpath.find_all { |line| line =~ /kind\s*=\s*"var"/ }.each do |line|
      if line =~ /path\s*=\s*"([^\/]+)\/([^"]+)"/
        path = @@variables[$1]
        add_file_name(File.join(path, $2)) if path
      end
    end
    
  end

end

Class Method Details

.add_variable(name, value) ⇒ Object

Add an Eclipse variable name with _value to look up libraries.



18
19
20
21
22
# File 'lib/javaclass/classpath/eclipse_classpath.rb', line 18

def self.add_variable(name, value)
  @@variables ||= Hash.new
  @@variables.delete(name)
  @@variables[name] = value if value
end

.skip_lib(flag = :skip) ⇒ Object

Skip the lib containers if .classpath.



25
26
27
# File 'lib/javaclass/classpath/eclipse_classpath.rb', line 25

def self.skip_lib(flag=:skip)
  @@skip_lib = flag
end

.valid_location?(file) ⇒ Boolean

Check if the file is a valid location for an Eclipse classpath.

Returns:

  • (Boolean)


13
14
15
# File 'lib/javaclass/classpath/eclipse_classpath.rb', line 13

def self.valid_location?(file)
  FileTest.exist?(file) && FileTest.directory?(file) && FileTest.exist?(File.join(file, DOT_CLASSPATH))
end