Extract interface from implementation in case of Environment and ModuleRegistry
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
package io.smnp.environment
|
||||
|
||||
import io.smnp.ext.DefaultModuleRegistry
|
||||
import io.smnp.type.module.Module
|
||||
|
||||
class DefaultEnvironment : Environment {
|
||||
private val rootModule = Module("<root>")
|
||||
private val loadedModules = mutableListOf<String>()
|
||||
|
||||
override fun loadModule(path: String) {
|
||||
DefaultModuleRegistry.requestModulesForPath(path).forEach {
|
||||
rootModule.addSubmodule(it)
|
||||
loadedModules.add(path)
|
||||
}
|
||||
}
|
||||
|
||||
override fun printModules(printContent: Boolean) {
|
||||
rootModule.pretty(printContent)
|
||||
}
|
||||
}
|
||||
21
app/src/main/kotlin/io/smnp/ext/DefaultModuleRegistry.kt
Normal file
21
app/src/main/kotlin/io/smnp/ext/DefaultModuleRegistry.kt
Normal file
@@ -0,0 +1,21 @@
|
||||
package io.smnp.ext
|
||||
|
||||
import io.smnp.type.module.Module
|
||||
import org.pf4j.DefaultPluginManager
|
||||
|
||||
object DefaultModuleRegistry : ModuleRegistry {
|
||||
private val modules = mutableListOf<Pair<String, Module>>()
|
||||
init {
|
||||
val pluginManager = DefaultPluginManager()
|
||||
pluginManager.loadPlugins()
|
||||
pluginManager.startPlugins()
|
||||
|
||||
pluginManager.getExtensions(ModuleDefinition::class.java).forEach {
|
||||
modules.add(Pair(it.modulePath(), Module.create(it.modulePath(), it.functions(), it.methods())))
|
||||
}
|
||||
}
|
||||
|
||||
override fun requestModulesForPath(path: String): List<Module> {
|
||||
return modules.filter { it.first == path }.map { it.second }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user