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



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

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



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

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

#isolate(&blk) ⇒ Object

Execute block

Parameters:

  • blk (Block)


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

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)


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

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