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.ext.ModuleRegistry
|
||||||
import io.smnp.type.module.Module
|
import io.smnp.type.module.Module
|
||||||
|
|
||||||
class Environment {
|
interface Environment {
|
||||||
private val rootModule = Module("<root>")
|
fun loadModule(path: String)
|
||||||
private val loadedModules = mutableListOf<String>()
|
fun printModules(printContent: Boolean)
|
||||||
|
|
||||||
fun loadModule(path: String) {
|
|
||||||
ModuleRegistry.requestModulesForPath(path).forEach {
|
|
||||||
rootModule.addSubmodule(it)
|
|
||||||
loadedModules.add(path)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun printModules(printContent: Boolean) {
|
|
||||||
rootModule.pretty(printContent)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -3,19 +3,6 @@ package io.smnp.ext
|
|||||||
import io.smnp.type.module.Module
|
import io.smnp.type.module.Module
|
||||||
import org.pf4j.DefaultPluginManager
|
import org.pf4j.DefaultPluginManager
|
||||||
|
|
||||||
object ModuleRegistry {
|
interface ModuleRegistry {
|
||||||
private val modules = mutableListOf<Pair<String, Module>>()
|
fun requestModulesForPath(path: String): List<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 }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -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