class JavaClass::Classpath::MavenClasspath

A Maven folder structure aware classpath. Maven submodules are supported.

Author

Peter Kofler

Constants

POM_XML

Public Class Methods

new(folder) click to toggle source

Create a classpath for a Maven base project folder

# File lib/javaclass/classpath/maven_classpath.rb, line 18
def initialize(folder)
  unless MavenClasspath::valid_location?(folder)
    raise IOError, "folder #{folder} not a Maven project"
  end
  pom = File.join(folder, POM_XML)
  super(pom)
  add_if_exist(File.join(folder, 'target/classes'))
  add_if_exist(File.join(folder, 'target/test-classes'))

  # look for submodules
  Dir.entries(folder).each do |dir|
    next if dir =~ /^(?:\.|\.\.|src|target|pom.xml|\.settings)$/
    folder = File.join(folder, dir)
    add_element(MavenClasspath.new(folder)) if MavenClasspath::valid_location?(folder)
  end
end
valid_location?(file) click to toggle source

Check if the file is a valid location for a Maven classpath.

# File lib/javaclass/classpath/maven_classpath.rb, line 13
def self.valid_location?(file)
  FileTest.exist?(file) && FileTest.directory?(file) && FileTest.exist?(File.join(file, POM_XML))
end

Private Instance Methods

add_if_exist(folder) click to toggle source
# File lib/javaclass/classpath/maven_classpath.rb, line 37
def add_if_exist(folder)
  add_file_name(folder) if FileTest.exist?(folder) && FileTest.directory?(folder)
end