mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-13 16:40:01 +00:00
More sophisticated fix (thanks to stefv from SO)
This commit is contained in:
@@ -100,6 +100,10 @@ tasks.register<Jar>("uberJar") {
|
||||
from({
|
||||
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
|
||||
})
|
||||
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
isZip64 = true
|
||||
|
||||
manifest {
|
||||
attributes["Main-Class"] = appMainClass
|
||||
}
|
||||
|
||||
@@ -12,6 +12,5 @@ import org.springframework.transaction.annotation.EnableTransactionManagement
|
||||
class GameyfinApplication
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
System.setProperty("spring.devtools.restart.enabled", "false");
|
||||
runApplication<GameyfinApplication>(*args)
|
||||
}
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
package de.grimsi.gameyfin.core
|
||||
package de.grimsi.gameyfin.core.plugins
|
||||
|
||||
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
|
||||
@@ -14,7 +13,7 @@ class PluginManagerConfig {
|
||||
private val pluginPath = Path.of("plugins")
|
||||
|
||||
@Bean
|
||||
fun pluginManager() = DefaultPluginManager(pluginPath)
|
||||
fun pluginManager() = SpringDevtoolsPluginManager(pluginPath)
|
||||
|
||||
@EventListener(ApplicationReadyEvent::class)
|
||||
fun loadedPlugins() {
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
package de.grimsi.gameyfin.core.plugins
|
||||
|
||||
import org.pf4j.DevelopmentPluginLoader
|
||||
import org.pf4j.PluginClassLoader
|
||||
import org.pf4j.PluginDescriptor
|
||||
import org.pf4j.PluginManager
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see https://stackoverflow.com/questions/73654174/my-application-cant-find-the-extension-with-pf4j
|
||||
*/
|
||||
class SpringDevtoolsDevelopmentPluginLoader(
|
||||
pluginManager: PluginManager,
|
||||
private val parentClassLoader: ClassLoader
|
||||
) : DevelopmentPluginLoader(pluginManager) {
|
||||
|
||||
override fun createPluginClassLoader(pluginPath: Path, pluginDescriptor: PluginDescriptor): PluginClassLoader {
|
||||
return PluginClassLoader(pluginManager, pluginDescriptor, parentClassLoader)
|
||||
}
|
||||
}
|
||||
+38
@@ -0,0 +1,38 @@
|
||||
package de.grimsi.gameyfin.core.plugins
|
||||
|
||||
import org.pf4j.CompoundPluginLoader
|
||||
import org.pf4j.CompoundPluginRepository
|
||||
import org.pf4j.DefaultPluginLoader
|
||||
import org.pf4j.DefaultPluginManager
|
||||
import org.pf4j.DefaultPluginRepository
|
||||
import org.pf4j.DevelopmentPluginRepository
|
||||
import org.pf4j.JarPluginLoader
|
||||
import org.pf4j.JarPluginRepository
|
||||
import org.pf4j.PluginLoader
|
||||
import org.pf4j.PluginRepository
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see https://stackoverflow.com/questions/73654174/my-application-cant-find-the-extension-with-pf4j
|
||||
*/
|
||||
class SpringDevtoolsPluginManager(path: Path) : DefaultPluginManager(path) {
|
||||
|
||||
override fun createPluginRepository(): PluginRepository {
|
||||
return CompoundPluginRepository()
|
||||
.add(DevelopmentPluginRepository(pluginsRoots), this::isDevelopment)
|
||||
.add(JarPluginRepository(pluginsRoots), this::isNotDevelopment)
|
||||
.add(DefaultPluginRepository(pluginsRoots), this::isNotDevelopment)
|
||||
}
|
||||
|
||||
override fun createPluginLoader(): PluginLoader {
|
||||
val compoundPluginLoader = CompoundPluginLoader()
|
||||
val developmentPluginLoader = SpringDevtoolsDevelopmentPluginLoader(this, javaClass.classLoader)
|
||||
val jarPluginLoader = JarPluginLoader(this)
|
||||
val defaultPluginLoader = DefaultPluginLoader(this)
|
||||
|
||||
return compoundPluginLoader
|
||||
.add(developmentPluginLoader, this::isDevelopment)
|
||||
.add(jarPluginLoader, this::isNotDevelopment)
|
||||
.add(defaultPluginLoader, this::isNotDevelopment)
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package de.grimsi.gameyfin.games
|
||||
|
||||
import jakarta.persistence.*
|
||||
import java.nio.file.Path
|
||||
|
||||
@Entity
|
||||
class Game(
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||
val id: Long? = null,
|
||||
var id: Long? = null,
|
||||
|
||||
val title: String,
|
||||
|
||||
|
||||
@@ -2,4 +2,6 @@ package de.grimsi.gameyfin.games
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository
|
||||
|
||||
interface GameRepository : JpaRepository<Game, Long>
|
||||
interface GameRepository : JpaRepository<Game, Long> {
|
||||
fun findByPath(path: String): Game?
|
||||
}
|
||||
@@ -18,6 +18,9 @@ class GameService(
|
||||
get() = pluginManager.getExtensions(GameMetadataFetcher::class.java)
|
||||
|
||||
fun createOrUpdate(game: Game): Game {
|
||||
gameRepository.findByPath(game.path)?.let {
|
||||
game.id = it.id
|
||||
}
|
||||
return gameRepository.save(game)
|
||||
}
|
||||
|
||||
@@ -50,7 +53,7 @@ class GameService(
|
||||
}
|
||||
|
||||
return GameDto(
|
||||
id = game.id,
|
||||
id = game.id!!,
|
||||
title = game.title
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user