Extract interface from implementation in case of Environment and ModuleRegistry
This commit is contained in:
@@ -3,18 +3,7 @@ package io.smnp.environment
|
||||
import io.smnp.ext.ModuleRegistry
|
||||
import io.smnp.type.module.Module
|
||||
|
||||
class Environment {
|
||||
private val rootModule = Module("<root>")
|
||||
private val loadedModules = mutableListOf<String>()
|
||||
|
||||
fun loadModule(path: String) {
|
||||
ModuleRegistry.requestModulesForPath(path).forEach {
|
||||
rootModule.addSubmodule(it)
|
||||
loadedModules.add(path)
|
||||
}
|
||||
}
|
||||
|
||||
fun printModules(printContent: Boolean) {
|
||||
rootModule.pretty(printContent)
|
||||
}
|
||||
interface Environment {
|
||||
fun loadModule(path: String)
|
||||
fun printModules(printContent: Boolean)
|
||||
}
|
||||
@@ -3,19 +3,6 @@ package io.smnp.ext
|
||||
import io.smnp.type.module.Module
|
||||
import org.pf4j.DefaultPluginManager
|
||||
|
||||
object 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())))
|
||||
}
|
||||
}
|
||||
|
||||
fun requestModulesForPath(path: String): List<Module> {
|
||||
return modules.filter { it.first == path }.map { it.second }
|
||||
}
|
||||
interface ModuleRegistry {
|
||||
fun requestModulesForPath(path: String): List<Module>
|
||||
}
|
||||
Reference in New Issue
Block a user