Add support for modules dependencies
This commit is contained in:
@@ -1,21 +1,22 @@
|
||||
package io.smnp.ext
|
||||
|
||||
import io.smnp.type.module.Module
|
||||
import org.pf4j.DefaultPluginManager
|
||||
|
||||
object DefaultModuleRegistry : ModuleRegistry {
|
||||
private val modules = mutableListOf<Pair<String, Module>>()
|
||||
private val modules = mutableMapOf<String, ModuleDefinition>()
|
||||
init {
|
||||
val pluginManager = DefaultPluginManager()
|
||||
pluginManager.loadPlugins()
|
||||
pluginManager.startPlugins()
|
||||
|
||||
pluginManager.getExtensions(ModuleDefinition::class.java).forEach {
|
||||
modules.add(it.path to it.module())
|
||||
modules[it.path] = it
|
||||
}
|
||||
}
|
||||
|
||||
override fun requestModulesForPath(path: String): List<Module> {
|
||||
return modules.filter { it.first == path }.map { it.second }
|
||||
override fun requestModulesForPath(path: String): ModuleDefinition {
|
||||
return modules[path] ?: throw RuntimeException("Module $path not found")
|
||||
}
|
||||
|
||||
override fun registeredModules() = modules.keys.toList()
|
||||
}
|
||||
Reference in New Issue
Block a user