diff --git a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsDevelopmentPluginLoader.kt b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginLoader.kt similarity index 93% rename from gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsDevelopmentPluginLoader.kt rename to gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginLoader.kt index 6072204..bb56d85 100644 --- a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsDevelopmentPluginLoader.kt +++ b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginLoader.kt @@ -9,7 +9,7 @@ import java.nio.file.Path /** * @see https://stackoverflow.com/questions/73654174/my-application-cant-find-the-extension-with-pf4j */ -class SpringDevtoolsDevelopmentPluginLoader( +class GameyfinPluginLoader( pluginManager: PluginManager, private val parentClassLoader: ClassLoader ) : DevelopmentPluginLoader(pluginManager) { diff --git a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsPluginManager.kt b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginManager.kt similarity index 94% rename from gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsPluginManager.kt rename to gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginManager.kt index 62494db..a882610 100644 --- a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/SpringDevtoolsPluginManager.kt +++ b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/GameyfinPluginManager.kt @@ -18,7 +18,7 @@ import java.nio.file.Path /** * @see https://stackoverflow.com/questions/73654174/my-application-cant-find-the-extension-with-pf4j */ -class SpringDevtoolsPluginManager( +class GameyfinPluginManager( path: Path, private val pluginConfigRepository: PluginConfigRepository ) : DefaultPluginManager(path) { @@ -34,7 +34,7 @@ class SpringDevtoolsPluginManager( override fun createPluginLoader(): PluginLoader { val compoundPluginLoader = CompoundPluginLoader() - val developmentPluginLoader = SpringDevtoolsDevelopmentPluginLoader(this, javaClass.classLoader) + val developmentPluginLoader = GameyfinPluginLoader(this, javaClass.classLoader) val jarPluginLoader = JarPluginLoader(this) val defaultPluginLoader = DefaultPluginLoader(this) diff --git a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginConfigService.kt b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginConfigService.kt index fbab6d2..36a8a2d 100644 --- a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginConfigService.kt +++ b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginConfigService.kt @@ -7,12 +7,12 @@ import org.springframework.stereotype.Service @Service class PluginConfigService( private val pluginConfigRepository: PluginConfigRepository, - private val pluginManager: SpringDevtoolsPluginManager + private val pluginManager: GameyfinPluginManager ) { fun getConfigMetadata(pluginId: String): List { val plugin = pluginManager.getPlugin(pluginId).plugin as GameyfinPlugin - return plugin.getConfigMetadata() + return plugin.configMetadata } fun getConfig(pluginId: String): Map { diff --git a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginManagerConfig.kt b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginManagerConfig.kt index 980d968..ed0c751 100644 --- a/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginManagerConfig.kt +++ b/gameyfin/src/main/kotlin/de/grimsi/gameyfin/core/plugins/PluginManagerConfig.kt @@ -15,7 +15,7 @@ class PluginManagerConfig( private val pluginPath = System.getProperty("pf4j.pluginsDir", "plugins") @Bean - fun pluginManager() = SpringDevtoolsPluginManager(Path.of(pluginPath), pluginConfigRepository) + fun pluginManager() = GameyfinPluginManager(Path.of(pluginPath), pluginConfigRepository) @EventListener(ApplicationReadyEvent::class) fun loadPlugins() { diff --git a/plugin-api/build.gradle.kts b/plugin-api/build.gradle.kts index 96f562a..980066a 100644 --- a/plugin-api/build.gradle.kts +++ b/plugin-api/build.gradle.kts @@ -13,6 +13,8 @@ dependencies { api("org.pf4j:pf4j:${rootProject.extra["pf4jVersion"]}") { exclude(group = "org.slf4j") } + + api("org.slf4j:slf4j-api:2.0.16") implementation(kotlin("stdlib")) diff --git a/plugin-api/src/main/kotlin/de/grimsi/gameyfin/pluginapi/core/GameyfinPlugin.kt b/plugin-api/src/main/kotlin/de/grimsi/gameyfin/pluginapi/core/GameyfinPlugin.kt index 48f6c50..f7c1438 100644 --- a/plugin-api/src/main/kotlin/de/grimsi/gameyfin/pluginapi/core/GameyfinPlugin.kt +++ b/plugin-api/src/main/kotlin/de/grimsi/gameyfin/pluginapi/core/GameyfinPlugin.kt @@ -1,7 +1,18 @@ package de.grimsi.gameyfin.pluginapi.core -interface GameyfinPlugin { - fun getConfigMetadata(): List - fun getCurrentConfig(): Map - fun loadConfig(config: Map) +import org.pf4j.Plugin +import org.pf4j.PluginWrapper + +abstract class GameyfinPlugin(wrapper: PluginWrapper) : Plugin(wrapper) { + + abstract val configMetadata: List + protected open var config: Map = emptyMap() + + open fun getCurrentConfig(): Map { + return config + } + + open fun loadConfig(config: Map) { + this.config = config + } } \ No newline at end of file diff --git a/plugins/build.gradle.kts b/plugins/build.gradle.kts index 7f92301..bca916d 100644 --- a/plugins/build.gradle.kts +++ b/plugins/build.gradle.kts @@ -7,7 +7,6 @@ subprojects { dependencies { compileOnly(project(":plugin-api")) - implementation("io.github.oshai:kotlin-logging-jvm:7.0.0") } tasks.jar { diff --git a/plugins/igdb/src/main/kotlin/de/grimsi/gameyfin/plugins/igdb/IgdbPlugin.kt b/plugins/igdb/src/main/kotlin/de/grimsi/gameyfin/plugins/igdb/IgdbPlugin.kt index d7f8d48..70fae7e 100644 --- a/plugins/igdb/src/main/kotlin/de/grimsi/gameyfin/plugins/igdb/IgdbPlugin.kt +++ b/plugins/igdb/src/main/kotlin/de/grimsi/gameyfin/plugins/igdb/IgdbPlugin.kt @@ -11,66 +11,48 @@ import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadata import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadataFetcher import de.grimsi.gameyfin.pluginapi.gamemetadata.Genre import de.grimsi.gameyfin.pluginapi.gamemetadata.Theme -import io.github.oshai.kotlinlogging.KotlinLogging import org.pf4j.Extension -import org.pf4j.Plugin import org.pf4j.PluginWrapper +import org.slf4j.LoggerFactory import java.time.Instant import kotlin.collections.filter -class IgdbPlugin(wrapper: PluginWrapper) : Plugin(wrapper), GameyfinPlugin { +class IgdbPlugin(wrapper: PluginWrapper) : GameyfinPlugin(wrapper) { - private val log = KotlinLogging.logger {} - - private val configMetadata: List = listOf( + override val configMetadata: List = listOf( PluginConfigElement("clientId", "Twitch client ID", "Your Twitch Client ID"), PluginConfigElement("clientSecret", "Twitch client secret", "Your Twitch Client Secret") ) - private var config: Map = configMetadata.associate { it.key to null } - - override fun getConfigMetadata(): List { - return configMetadata - } - - override fun getCurrentConfig(): Map { - return config - } - - override fun loadConfig(config: Map) { - this.config = config - } - - override fun start() { try { authenticate() } catch (e: PluginConfigError) { - log.error { e.message } + log.error(e.message) } } override fun stop() { - log.debug { "IgdbPlugin.stop()" } + log.debug("IgdbPlugin.stop()") } private fun authenticate() { - log.debug { "Authenticating on Twitch API..." } + log.debug("Authenticating on Twitch API...") val clientId: String = config["clientId"] ?: throw PluginConfigError("Twitch Client ID not set") val clientSecret: String = config["clientSecret"] ?: throw PluginConfigError("Twitch Client Secret not set") val token = TwitchAuthenticator.requestTwitchToken(clientId, clientSecret) - ?: throw PluginConfigError("Failed to authenticate on Twitch API") + ?: throw PluginConfigError("Failed to authenticate on Twitch API with provided credentials") IGDBWrapper.setCredentials(clientId, token.access_token) - log.debug { "Authentication successful" } + log.debug("Authentication successful") } @Extension class IgdbMetadataFetcher : GameMetadataFetcher { - private val log = KotlinLogging.logger {} + private val log = LoggerFactory.getLogger(javaClass) override fun fetchMetadata(gameId: String): GameMetadata { val findGameByName = APICalypse() @@ -124,7 +106,7 @@ class IgdbPlugin(wrapper: PluginWrapper) : Plugin(wrapper), GameyfinPlugin { "hack-and-slash-beat-em-up" -> Genre.HACK_AND_SLASH_BEAT_EM_UP "quiz-trivia" -> Genre.QUIZ_TRIVIA else -> { - log.warn { "Unknown genre: ${genre.slug}" } + log.warn("Unknown genre: {}", genre.slug) Genre.UNKNOWN } } @@ -155,7 +137,7 @@ class IgdbPlugin(wrapper: PluginWrapper) : Plugin(wrapper), GameyfinPlugin { "erotic" -> Theme.EROTIC "romance" -> Theme.ROMANCE else -> { - log.warn { "Unknown theme: ${theme.slug}" } + log.warn("Unknown theme: {}", theme.slug) Theme.UNKNOWN } }