WIP: Plugin for IGDB

This commit is contained in:
grimsi
2024-10-08 22:45:38 +02:00
parent fa685dc541
commit bfcd3d83c9
9 changed files with 51 additions and 11 deletions
+13 -4
View File
@@ -68,9 +68,6 @@ dependencies {
// Plugins
implementation(project(":plugin-api"))
implementation("org.pf4j:pf4j-spring:${rootProject.extra["pf4jSpringVersion"]}") {
exclude("org.slf4j")
}
// Development
developmentOnly("org.springframework.boot:spring-boot-devtools")
@@ -88,6 +85,18 @@ dependencyManagement {
}
}
// Task to copy the bundled plugin JARs to the plugins directory
val copyPlugins by tasks.registering(Copy::class) {
// Directory where plugins will be copied
val pluginsDir = layout.buildDirectory.dir("plugins")
from(project(":plugins:igdb").tasks.named("jar"))
into(pluginsDir)
}
tasks.named("compileKotlin") {
dependsOn(copyPlugins)
}
tasks.withType<Test> {
useJUnitPlatform()
}
}
@@ -1,11 +1,14 @@
package de.grimsi.gameyfin.core
import org.pf4j.spring.SpringPluginManager
import org.pf4j.DefaultPluginManager
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import java.nio.file.Path
@Configuration
class PluginManagerConfig {
private val pluginPath = Path.of("plugins")
@Bean
fun pluginManager() = SpringPluginManager()
fun pluginManager() = DefaultPluginManager(pluginPath)
}
@@ -1,7 +1,10 @@
package de.grimsi.gameyfin.games
import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadataPlugin
import org.pf4j.spring.SpringPluginManager
import io.github.oshai.kotlinlogging.KotlinLogging
import org.pf4j.PluginManager
import org.springframework.boot.context.event.ApplicationReadyEvent
import org.springframework.context.event.EventListener
import org.springframework.data.repository.findByIdOrNull
import org.springframework.stereotype.Service
import java.nio.file.Path
@@ -9,11 +12,20 @@ import java.nio.file.Path
@Service
class GameService(
private val gameRepository: GameRepository,
private val pluginManager: SpringPluginManager
private val pluginManager: PluginManager
) {
val metadataPlugins: List<GameMetadataPlugin>
private val log = KotlinLogging.logger {}
private val metadataPlugins: List<GameMetadataPlugin>
get() = pluginManager.getExtensions(GameMetadataPlugin::class.java)
@EventListener(ApplicationReadyEvent::class)
fun loadedPlugins() {
pluginManager.loadPlugins()
pluginManager.startPlugins()
log.info { "Loaded metadata plugins: ${metadataPlugins.map { it::class.simpleName }}" }
}
fun createOrUpdate(game: Game): Game {
return gameRepository.save(game)
}