Module: JavaClass::Classpath::Factory
- Included in:
- JavaClass, Dsl::Mixin
- Defined in:
- lib/javaclass/classpath/factory.rb
Overview
Factory methods to create different kind of classpaths.
- Author
-
Peter Kofler
Constant Summary collapse
- Classpath_types =
[EclipseClasspath, MavenClasspath, ConventionClasspath]
Instance Method Summary collapse
-
#classpath(path, cp = CompositeClasspath.new) ⇒ Object
Parse the given path variable path and return a chain of class path elements.
-
#environment_classpath(cp = CompositeClasspath.new) ⇒ Object
Parse and set the system classpath.
-
#full_classpath(javahome, path = nil, cp = CompositeClasspath.new) ⇒ Object
Parse the given path variable path and return a chain of class path elements together with javahome if any.
-
#workspace(basepath, cp = CompositeClasspath.new) ⇒ Object
Create a classpath from a workspace basepath which contains Eclipse or Maven projects.
Instance Method Details
#classpath(path, cp = CompositeClasspath.new) ⇒ Object
Parse the given path variable path and return a chain of class path elements. The path variable is separated by : or ; depending on the platform. Adds the classpath to the optional cp element else creates a CompositeClasspath.
17 18 19 20 |
# File 'lib/javaclass/classpath/factory.rb', line 17 def classpath(path, cp=CompositeClasspath.new) path.split(File::PATH_SEPARATOR).each { |cpe| cp.add_file_name(cpe) } cp end |
#environment_classpath(cp = CompositeClasspath.new) ⇒ Object
Parse and set the system classpath. Needs JAVA_HOME
to be set. Uses additional environment CLASSPATH
if set. Adds the classpath to the optional cp element else creates a CompositeClasspath.
24 25 26 |
# File 'lib/javaclass/classpath/factory.rb', line 24 def environment_classpath(cp=CompositeClasspath.new) full_classpath(ENV['JAVA_HOME'], ENV['CLASSPATH'], cp) end |
#full_classpath(javahome, path = nil, cp = CompositeClasspath.new) ⇒ Object
Parse the given path variable path and return a chain of class path elements together with javahome if any.
29 30 31 32 33 |
# File 'lib/javaclass/classpath/factory.rb', line 29 def full_classpath(javahome, path=nil, cp=CompositeClasspath.new) cp.add_element(JavaHomeClasspath.new(javahome)) if javahome cp = classpath(path, cp) if path cp end |
#workspace(basepath, cp = CompositeClasspath.new) ⇒ Object
Create a classpath from a workspace basepath which contains Eclipse or Maven projects.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/javaclass/classpath/factory.rb', line 38 def workspace(basepath, cp=CompositeClasspath.new) # check for a valid project in this folder Classpath_types.each do |classpath_type| if classpath_type.valid_location?(basepath) cp.add_element(classpath_type.new(basepath)) return cp end end # check the children as regular workspace Dir.entries(basepath).each do |entry| next if entry == '.' || entry == '..' file = File.join(basepath, entry) Classpath_types.each do |classpath_type| if classpath_type.valid_location?(file) cp.add_element(classpath_type.new(file)) break end end end if FileTest.directory? basepath cp end |