Skip to content

Commit

Permalink
add plugin checker
Browse files Browse the repository at this point in the history
  • Loading branch information
Neuheit committed Dec 10, 2024
1 parent cdc0a89 commit 26bf4bf
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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)
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
}
}
}
}

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

0 comments on commit 26bf4bf

Please sign in to comment.