Skip to content

Commit

Permalink
allow to change plugins dir
Browse files Browse the repository at this point in the history
  • Loading branch information
topi314 committed Jul 3, 2023
1 parent 1e2db07 commit fc51c58
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,22 @@ import java.util.regex.Pattern


@SpringBootApplication
class PluginManager(config: PluginsConfig) {
class PluginManager(val config: PluginsConfig) {

final val pluginManifests: MutableList<PluginManifest> = mutableListOf()
var classLoader: ClassLoader = PluginManager::class.java.classLoader

init {
manageDownloads(config)
manageDownloads()
pluginManifests.apply {
addAll(readClasspathManifests())
addAll(loadJars())
}
}

private fun manageDownloads(config: PluginsConfig) {
private fun manageDownloads() {
if (config.plugins.isEmpty()) return
val directory = File("./plugins")
val directory = File(config.pluginsDir)
directory.mkdir()

data class PluginJar(val name: String, val version: String, val file: File)
Expand Down Expand Up @@ -89,11 +89,11 @@ class PluginManager(config: PluginsConfig) {
}

private fun loadJars(): List<PluginManifest> {
val directory = File("./plugins")
val directory = File(config.pluginsDir)
if (!directory.isDirectory) return emptyList()
val jarsToLoad = mutableListOf<File>()

Files.list(File("./plugins").toPath()).forEach { path ->
Files.list(File(config.pluginsDir).toPath()).forEach { path ->
val file = path.toFile()
if (!file.isFile) return@forEach
if (file.extension != "jar") return@forEach
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.springframework.stereotype.Component
@Component
class PluginsConfig {
var plugins: List<PluginDeclaration> = emptyList()
var pluginsDir: String = "./plugins"
}

data class PluginDeclaration(
Expand Down

0 comments on commit fc51c58

Please sign in to comment.