Class: LockJar::ClassLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/lock_jar/class_loader.rb

Overview

Create a ClassLoader populated by a lockfile

Author:

  • Michael Guymon

Instance Method Summary collapse

Constructor Details

#initialize(lockfile) ⇒ ClassLoader

Create new instance, populating ClassLoader with lockfile

Parameters:

  • lockfile (String)

    path



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/lock_jar/class_loader.rb', line 29

def initialize(lockfile)
  # XXX: ensure Naether has been loaded, this should be handled less
  #     clumsily
  LockJar::Runtime.instance.resolver(nil)
  @class_loader = com.tobedevoured.naether.PathClassLoader.new(
    JRuby.runtime.jruby_class_loader)

  jars = LockJar.list(lockfile, local_paths: true)
  jars.each do |jar|
    add_path(jar)
  end
end

Instance Method Details

#add_path(path) ⇒ Boolean

Add path to the ClassLoader

Parameters:

  • path (String)

    of Jar or directory to add to ClassLoader

Returns:

  • (Boolean)

    if added



53
54
55
# File 'lib/lock_jar/class_loader.rb', line 53

def add_path(path)
  @class_loader.addPath(path)
end

#isolate(&blk) ⇒ Object

Execute block

Parameters:

  • blk (Block)


45
46
47
# File 'lib/lock_jar/class_loader.rb', line 45

def isolate(&blk)
  instance_eval(&blk)
end

#new_instance(clazz, *args) ⇒ Object

Create new instance of a Java class using the populated ClassLoader

Parameters:

  • clazz (String)

    fully qualified Java class

  • args (Array)

    arguments for constructing the Java class

Returns:

  • (Object)


63
64
65
# File 'lib/lock_jar/class_loader.rb', line 63

def new_instance(clazz, *args)
  @class_loader.newInstance(clazz, *args)
end