mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-16 08:15:48 +00:00
Further work and debugging on plugin integration
This commit is contained in:
+26
-16
@@ -1,4 +1,6 @@
|
||||
group = "de.grimsi"
|
||||
val pluginDir: File by rootProject.extra
|
||||
val appMainClass = "de.grimsi.gameyfin.GameyfinApplication"
|
||||
|
||||
plugins {
|
||||
id("org.springframework.boot")
|
||||
@@ -7,21 +9,19 @@ plugins {
|
||||
kotlin("jvm")
|
||||
kotlin("plugin.spring")
|
||||
kotlin("plugin.jpa")
|
||||
java
|
||||
application
|
||||
id("com.google.devtools.ksp") version "2.0.20-1.0.24"
|
||||
}
|
||||
|
||||
application {
|
||||
mainClass.set(appMainClass)
|
||||
}
|
||||
|
||||
allOpen {
|
||||
annotations("javax.persistence.Entity", "javax.persistence.MappedSuperclass", "javax.persistence.Embedabble")
|
||||
}
|
||||
|
||||
configurations {
|
||||
compileOnly {
|
||||
extendsFrom(configurations.annotationProcessor.get())
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
setUrl("https://maven.vaadin.com/vaadin-addons")
|
||||
}
|
||||
@@ -68,6 +68,7 @@ dependencies {
|
||||
|
||||
// Plugins
|
||||
implementation(project(":plugin-api"))
|
||||
ksp("care.better.pf4j:pf4j-kotlin-symbol-processing:2.0.20-1.0.1")
|
||||
|
||||
// Development
|
||||
developmentOnly("org.springframework.boot:spring-boot-devtools")
|
||||
@@ -85,16 +86,25 @@ 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<JavaExec>("run") {
|
||||
systemProperty("pf4j.pluginsDir", pluginDir.absolutePath)
|
||||
}
|
||||
|
||||
tasks.named("compileKotlin") {
|
||||
dependsOn(copyPlugins)
|
||||
tasks.register<Jar>("uberJar") {
|
||||
dependsOn(tasks.named("compileKotlin"))
|
||||
archiveClassifier.set("uber")
|
||||
|
||||
from(sourceSets.main.get().output)
|
||||
|
||||
dependsOn(configurations.runtimeClasspath)
|
||||
from({
|
||||
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
|
||||
})
|
||||
manifest {
|
||||
attributes["Main-Class"] = appMainClass
|
||||
}
|
||||
|
||||
archiveBaseName.set(project.name)
|
||||
}
|
||||
|
||||
tasks.withType<Test> {
|
||||
|
||||
@@ -1,14 +1,25 @@
|
||||
package de.grimsi.gameyfin.core
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import org.pf4j.DefaultPluginManager
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
import org.springframework.context.event.EventListener
|
||||
import java.nio.file.Path
|
||||
|
||||
@Configuration
|
||||
class PluginManagerConfig {
|
||||
private val log = KotlinLogging.logger {}
|
||||
private val pluginPath = Path.of("plugins")
|
||||
|
||||
@Bean
|
||||
fun pluginManager() = DefaultPluginManager(pluginPath)
|
||||
|
||||
@EventListener(ApplicationReadyEvent::class)
|
||||
fun loadedPlugins() {
|
||||
pluginManager().loadPlugins()
|
||||
pluginManager().startPlugins()
|
||||
log.info { "Loaded plugins: ${pluginManager().plugins.map { it.pluginId }}" }
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package de.grimsi.gameyfin.games
|
||||
|
||||
import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadataPlugin
|
||||
import de.grimsi.gameyfin.pluginapi.gamemetadata.GameMetadataFetcher
|
||||
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
|
||||
@@ -16,15 +14,8 @@ class GameService(
|
||||
) {
|
||||
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 }}" }
|
||||
}
|
||||
private val metadataPlugins: List<GameMetadataFetcher>
|
||||
get() = pluginManager.getExtensions(GameMetadataFetcher::class.java)
|
||||
|
||||
fun createOrUpdate(game: Game): Game {
|
||||
return gameRepository.save(game)
|
||||
|
||||
Reference in New Issue
Block a user