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

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this lib really needed? we already have a way to parse semver in

you would just need to add a method to compare them which should be easy

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I didnt see this thanks!

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
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please not regex XML?
With #1049 we want to parse the maven-metadata.xml anyway

}
}

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