Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Plugin Update Checker #1121

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions LavalinkServer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation(libs.kotlin.reflect)
implementation(libs.logback)
implementation(libs.sentry.logback)
implementation(libs.semver)
topi314 marked this conversation as resolved.
Show resolved Hide resolved
implementation(libs.oshi) {
// This version of SLF4J does not recognise Logback 1.2.3
exclude(group = "org.slf4j", module = "slf4j-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import java.io.FileOutputStream
import java.io.InputStream
import java.net.URL
import java.net.URLClassLoader
import java.net.HttpURLConnection
import java.nio.channels.Channels
import java.util.*
import java.util.jar.JarFile
import io.github.z4kn4fein.semver.toVersion

@SpringBootApplication
class PluginManager(val config: PluginsConfig) {
Expand Down Expand Up @@ -83,6 +85,37 @@ class PluginManager(val config: PluginsConfig) {
val file = File(directory, declaration.canonicalJarName)
downloadJar(file, url)
}

checkPluginForUpdates(declaration)
}
}

private fun checkPluginForUpdates(declaration: Declaration) {
val splitPath = declaration.url.split('/')

val baseSplitPath = splitPath.dropLast(2)
val basePath = baseSplitPath.joinToString("/") + "/maven-metadata.xml"

val connection = URL(basePath).openConnection() as HttpURLConnection
connection.inputStream.bufferedReader().use {
val lines = it.readLines()
for (line in lines) {
val regex = "<latest>(.*?)</latest>".toRegex()
val match = regex.find(line)
val latest = match?.groups?.get(1)?.value
if (latest != null) {
val latestVersion = latest.toVersion()
val currentVersion = declaration.version.toVersion()

if(latestVersion > currentVersion) {
log.warn("A newer version of ${declaration.name} was found: $latestVersion. " +
"The current version is $currentVersion.")
} else {
log.info("Plugin ${declaration.name} is up to date")
}
break
}
}
topi314 marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ fun VersionCatalogBuilder.common() {
library("logback", "ch.qos.logback", "logback-classic").version("1.5.6")
library("sentry-logback", "io.sentry", "sentry-logback").version("7.10.0")
library("oshi", "com.github.oshi", "oshi-core").version("6.4.11")
library("semver", "io.github.z4kn4fein", "semver").version("2.0.0")
}

fun VersionCatalogBuilder.other() {
Expand Down