...
 
Commits (5)
package klib.functions
import klib.library.LClass
import klib.library.LFunction
import klib.library.LibLoad
import klib.library.Library
import java.io.FileNotFoundException
/**
* Dynamically load a Class from a Jar File
*
* @param builder LibLoader Builder
* @return Returns a LClass object
* @throws FileNotFoundException
* @throws ClassNotFoundException
*
* @see LClass
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class)
fun loadClass(builder: LibLoad.() -> Unit): LClass {
return Library.loadClassFromJar(LibLoad().apply(builder))
}
/**
* Dynamically load a Method/Function from a Jar File
*
* @param builder LibLoader Builder
* @return Returns a LFunction object
* @throws FileNotFoundException
* @throws ClassNotFoundException
* @throws NoSuchMethodException
*
* @see LClass
* @see LFunction
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class, NoSuchMethodException::class)
fun loadFunction(builder: LibLoad.() -> Unit): LFunction {
return Library.loadFunctionFromJar(LibLoad().apply(builder))
}
\ No newline at end of file
package klib.library
class LibLoad(var file: String = "", var className: String = "", var functionName: String = "")
\ No newline at end of file
package klib.library
import klib.extensions.asFile
import java.io.File
import java.io.FileNotFoundException
import java.net.URL
......@@ -27,6 +28,7 @@ object Library {
* @see LClass
*
* @since 1.3.0 (Experimental)
* @since 3.1.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class)
......@@ -52,6 +54,7 @@ object Library {
* @see LFunction
*
* @since 1.3.0 (Experimental)
* @since 3.1.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class, NoSuchMethodException::class)
......@@ -64,4 +67,83 @@ object Library {
val classObject = classConstructor.newInstance()
return LFunction(classObject, method)
}
/**
* Dynamically load a Class from a Jar File
*
* @param file The Jar file to load from
* @param className The Class to load
* @return Returns a LClass object
* @throws FileNotFoundException
* @throws ClassNotFoundException
*
* @see LClass
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class)
fun loadClassFromJar(file: String, className: String): LClass {
return loadClassFromJar(file.asFile(), className)
}
/**
* Dynamically load a Method/Function from a Jar File
*
* @param file The Jar file to load from
* @param className The Class to load from
* @param functionName The Method to load
* @return Returns a LFunction object
* @throws FileNotFoundException
* @throws ClassNotFoundException
* @throws NoSuchMethodException
*
* @see LClass
* @see LFunction
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class, NoSuchMethodException::class)
fun loadFunctionFromJar(file: String, className: String, functionName: String): LFunction {
return loadFunctionFromJar(file.asFile(), className, functionName)
}
/**
* Dynamically load a Class from a Jar File
*
* @param loader LibLoader object
* @return Returns a LClass object
* @throws FileNotFoundException
* @throws ClassNotFoundException
*
* @see LClass
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class)
fun loadClassFromJar(loader: LibLoad): LClass {
return loadClassFromJar(loader.file, loader.className)
}
/**
* Dynamically load a Method/Function from a Jar File
*
* @param loader LibLoader object
* @return Returns a LFunction object
* @throws FileNotFoundException
* @throws ClassNotFoundException
* @throws NoSuchMethodException
*
* @see LClass
* @see LFunction
*
* @since 4.0.0
* @author Thomas Obernosterer
*/
@Throws(FileNotFoundException::class, ClassNotFoundException::class, NoSuchMethodException::class)
fun loadFunctionFromJar(loader: LibLoad): LFunction {
return loadFunctionFromJar(loader.file, loader.className, loader.functionName)
}
}
\ No newline at end of file
......@@ -15,7 +15,7 @@ class KSocket {
val data = buffer
var canRead: Boolean
get() = canReadFile
set(value) = TODO()
set(value) = TODO("Cannot set value '$value' on read-only field 'canRead'")
fun open(file: String, timeout: Long = 25, buffer: CharBuffer = CharBuffer.allocate(1024)) {
this.fileName = file
......
package devtests
import klib.functions.loadClass
import klib.library.LClass
import klib.library.Library
import java.io.File
/**
* Source of hello.kt
package hello
class Hello {
fun hi() {
println("Hello from Hello class")
}
}
* Compile using:
* kotlinc -d hello.jar hello.kt
*/
fun main() {
val hello = loadClass {
file = "/tmp/hello.jar"
className = "hello.Hello"
}
hello("hi")
}
\ No newline at end of file